feat(shopDashboard): 为 Dashboard 添加新订单声音提醒功能

- 将 useOrderNotify 改造为实例安全的 Composable,支持多个页面独立调用
- 在 shop/dashboard 和 cms/dashboard 页面添加新订单提醒开关和测试按钮
- 新订单提醒触发时自动刷新 Dashboard 数据,提升数据同步性
- 新订单提醒包括叮声和语音播报,用户交互后自动解锁音频播放
- cms/dashboard 概况卡片标题添加提醒控件,shop/dashboard 欢迎横幅右侧添加提醒栏
- 提取 cms/dashboard loadData 函数实现复用,统一数据加载逻辑
- 优化组件状态管理,防止多个实例间状态冲突,提升稳定性和可维护性
This commit is contained in:
2026-07-14 20:58:40 +08:00
parent a2640ba7dc
commit 5106fe101c
4 changed files with 192 additions and 244 deletions

View File

@@ -3,7 +3,21 @@
<a-row :gutter="16">
<!-- 应用基本信息卡片 -->
<a-col :span="24" style="margin-bottom: 16px">
<a-card title="概况" :bordered="false">
<a-card :bordered="false">
<template #title>
<a-space>
<span>概况</span>
<a-divider type="vertical" />
<div class="order-notify-bar">
<span class="order-notify-label">新订单提醒</span>
<a-switch v-model:checked="notifyEnabled" @change="onNotifyToggle" size="small" />
<a-tooltip title="开启后每60秒自动检测新订单检测到后播放叮声并语音播报">
<InfoCircleOutlined class="order-notify-icon" />
</a-tooltip>
<a-button size="small" :disabled="!notifyEnabled" @click="onTestNotify">测试</a-button>
</div>
</a-space>
</template>
<a-row :gutter="16">
<a-col :span="6">
<a-image
@@ -183,6 +197,7 @@
<script lang="ts" setup>
import { ref, onMounted, onUnmounted, computed } from 'vue';
import { useOrderNotify } from '@/views/shop/shopOrder/useOrderNotify';
import {
UserOutlined,
CalendarOutlined,
@@ -192,7 +207,8 @@
SettingOutlined,
AccountBookOutlined,
FileTextOutlined,
MoneyCollectOutlined
MoneyCollectOutlined,
InfoCircleOutlined
} from '@ant-design/icons-vue';
import { openNew } from '@/utils/common';
import { useSiteStore } from '@/store/modules/site';
@@ -230,19 +246,27 @@
// 加载状态
const loading = computed(() => siteLoading.value || statisticsLoading.value);
onMounted(async () => {
// 加载网站信息和统计数据
// 加载数据
const loadData = async () => {
try {
await Promise.all([
siteStore.fetchSiteInfo(),
statisticsStore.fetchStatistics()
]);
// 开始自动刷新统计数据每5分钟
statisticsStore.startAutoRefresh();
} catch (error) {
console.error('加载数据失败:', error);
}
};
// 新订单声音提醒
const { enabled: notifyEnabled, toggle: onNotifyToggle, testNotify: onTestNotify } = useOrderNotify({
onNewOrder: () => loadData()
});
onMounted(async () => {
await loadData();
// 开始自动刷新统计数据每5分钟
statisticsStore.startAutoRefresh();
});
onUnmounted(() => {
@@ -256,6 +280,27 @@
margin-bottom: 8px;
}
/* 新订单提醒栏(概况卡片标题中) */
.order-notify-bar {
display: inline-flex;
align-items: center;
gap: 8px;
padding: 2px 12px;
background: #f0fdf4;
border: 1px solid #bbf7d0;
border-radius: 6px;
}
.order-notify-label {
font-size: 13px;
color: #166534;
white-space: nowrap;
}
.order-notify-icon {
color: #16a34a;
font-size: 14px;
cursor: help;
}
.stat-card {
text-align: center;
margin-bottom: 16px;