diff --git a/components.d.ts b/components.d.ts index a2e768b..01d25ef 100644 --- a/components.d.ts +++ b/components.d.ts @@ -9,6 +9,7 @@ declare module 'vue' { export interface GlobalComponents { RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] + VanBadge: typeof import('vant/es')['Badge'] VanButton: typeof import('vant/es')['Button'] VanCellGroup: typeof import('vant/es')['CellGroup'] VanEmpty: typeof import('vant/es')['Empty'] diff --git a/src/store/todo.ts b/src/store/todo.ts new file mode 100644 index 0000000..ec6f172 --- /dev/null +++ b/src/store/todo.ts @@ -0,0 +1,33 @@ +import { defineStore } from 'pinia' +import { getTodoStatistics } from '@/api/todo' +import type { TodoStatistics } from '@/api/todo' + +interface TodoState { + statistics: TodoStatistics | null +} + +export const useTodoStore = defineStore('todo', { + state: (): TodoState => ({ + statistics: null + }), + + actions: { + /** + * 获取待办事项统计 + */ + async fetchTodoStatistics() { + try { + const response = await getTodoStatistics() + if (response.status === 200 && response.data.code === 0) { + // The actual data is in response.data.data + this.statistics = response.data.data + } else { + throw new Error(response.data.msg || '获取待办统计失败') + } + } catch (error: any) { + console.error('获取待办统计接口调用失败:', error) + throw error + } + } + } +}) diff --git a/src/views/Home/index.vue b/src/views/Home/index.vue index a9269ec..8d33c5c 100644 --- a/src/views/Home/index.vue +++ b/src/views/Home/index.vue @@ -38,8 +38,13 @@ :class="{ active: currentMenu === menu.key }" @click="selectMenu(menu.key)" > - - {{ menu.title }} + + + + + + + {{ menu.title }} @@ -62,36 +67,42 @@ import { ref, computed, onMounted } from 'vue' import { useRouter, useRoute } from 'vue-router' import { showConfirmDialog, showSuccessToast, showFailToast } from 'vant' import { useAuthStore } from '@/store/auth' +import { useTodoStore } from '@/store/todo' +import { storeToRefs } from 'pinia' import OrderList from '@/views/List/index.vue' import PurchaseList from '@/views/Purchase/index.vue' const router = useRouter() const route = useRoute() const authStore = useAuthStore() +const todoStore = useTodoStore() +const { statistics } = storeToRefs(todoStore) // 抽屉显示状态 -const showDrawer = ref(false) +const showDrawer = ref(true) // 当前选中的菜单 const currentMenu = ref('order') // 菜单列表 -const menuList = [ +const menuList = computed(() => [ { key: 'order', title: '订单审批', - icon: 'notes-o' + icon: 'notes-o', + count: statistics.value?.order_approve || 0 }, { key: 'purchase', title: '采购审批', - icon: 'shopping-cart-o' + icon: 'shopping-cart-o', + count: statistics.value?.purchase_order_online || 0 } -] +]) // 当前菜单标题 const currentMenuTitle = computed(() => { - const menu = menuList.find(m => m.key === currentMenu.value) + const menu = menuList.value.find(m => m.key === currentMenu.value) return menu ? menu.title : '审批' }) @@ -103,6 +114,7 @@ const selectMenu = (key: string) => { // 初始化菜单 onMounted(() => { + todoStore.fetchTodoStatistics() const tab = route.query.tab as string if (tab && ['order', 'purchase'].includes(tab)) { currentMenu.value = tab @@ -287,6 +299,10 @@ const handleLogout = async () => { transition: all 0.2s ease; } +.menu-badge { + margin-left: 8px; +} + .menu-arrow { font-size: 16px; color: #999999;