fix(dashboard): correct overview data and states
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script lang="tsx">
|
||||
import { compile, computed, defineComponent, h, ref } from 'vue';
|
||||
import { compile, computed, defineComponent, h, ref, watch } from 'vue';
|
||||
import type { RouteMeta } from 'vue-router';
|
||||
import { type RouteRecordRaw, useRoute, useRouter } from 'vue-router';
|
||||
import { useAppStore } from '@/store';
|
||||
@@ -67,21 +67,24 @@ export default defineComponent({
|
||||
});
|
||||
return result;
|
||||
};
|
||||
listenerRouteChange((newRoute) => {
|
||||
const syncMenuSelection = (newRoute: typeof route) => {
|
||||
const { requiresAuth, activeMenu, hideInMenu } = newRoute.meta;
|
||||
if (requiresAuth && (!hideInMenu || activeMenu)) {
|
||||
const target = (activeMenu || newRoute.name) as string;
|
||||
const menuOpenKeys = findMenuOpenKeys(
|
||||
(activeMenu || newRoute.name) as string,
|
||||
target,
|
||||
);
|
||||
|
||||
if (!menuOpenKeys.length) return;
|
||||
|
||||
const keySet = new Set([...menuOpenKeys, ...openKeys.value]);
|
||||
openKeys.value = [...keySet];
|
||||
|
||||
selectedKey.value = [
|
||||
activeMenu || menuOpenKeys[menuOpenKeys.length - 1],
|
||||
];
|
||||
selectedKey.value = [target];
|
||||
}
|
||||
}, true);
|
||||
};
|
||||
listenerRouteChange(syncMenuSelection, true);
|
||||
watch(menuTree, () => syncMenuSelection(route), { deep: true, flush: 'post' });
|
||||
const setCollapse = (val: boolean) => {
|
||||
if (appStore.device === 'desktop')
|
||||
appStore.updateSettings({ menuCollapse: val });
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
{{ errorMessage }}
|
||||
<template #action><a-button size="small" @click="loadOverview">重新加载</a-button></template>
|
||||
</a-alert>
|
||||
<div class="dashboard-meta">当前配送点业务汇总 · 更新时间:{{ updatedAt || '尚未加载' }}</div>
|
||||
<div class="dashboard-meta">当前配送点业务汇总 · 更新时间:{{ updatedAtLabel }}</div>
|
||||
<a-grid :cols="{ xs: 1, sm: 2, lg: 4 }" :col-gap="16" :row-gap="16">
|
||||
<a-grid-item v-for="item in cards" :key="item.key">
|
||||
<a-card :bordered="false" class="metric-card">
|
||||
@@ -17,12 +17,13 @@
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { Message } from '@arco-design/web-vue';
|
||||
import { onMounted, reactive, ref } from 'vue';
|
||||
import { computed, onMounted, reactive, ref } from 'vue';
|
||||
import { request } from '@/api/http';
|
||||
type Overview = Record<'staff_count' | 'user_count' | 'contract_count' | 'order_count', number>;
|
||||
const loading = ref(false);
|
||||
const errorMessage = ref('');
|
||||
const updatedAt = ref('');
|
||||
const updatedAtLabel = computed(() => updatedAt.value || (errorMessage.value ? '加载失败' : '加载中…'));
|
||||
const overview = reactive<Overview>({ staff_count: 0, user_count: 0, contract_count: 0, order_count: 0 });
|
||||
const cards: Array<{ key: keyof Overview; label: string; hint: string }> = [
|
||||
{ key: 'staff_count', label: '配送人员', hint: '本站关联配送人员' }, { key: 'user_count', label: '服务用户', hint: '本站有效服务关系' },
|
||||
@@ -44,6 +45,6 @@ onMounted(loadOverview);
|
||||
<style scoped lang="less">
|
||||
.dashboard-alert { margin-bottom: 16px; }
|
||||
.dashboard-meta { margin-bottom: 12px; color: var(--color-text-3); font-size: 12px; text-align: right; }
|
||||
.metric-card { min-height: 112px; }
|
||||
.metric-hint { margin-top: 8px; color: var(--color-text-3); font-size: 12px; }
|
||||
.metric-card { min-height: 132px; }
|
||||
.metric-hint { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--color-border-2); color: var(--color-text-2); font-size: 13px; line-height: 20px; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user