| | |
| | | const router = useRouter() |
| | | const activeTab = ref('running'); const chartPeriod = ref<'week' | 'month' | 'year'>('week') |
| | | const { snapshot, load: loadDashboard } = useDashboard() |
| | | const dashboardError = ref(''); const todoError = ref(''); const loading = ref(false) |
| | | const dashboardError = ref(''); const todoError = ref('') |
| | | const { records: todoRecords, load: loadTodos } = useTodos() |
| | | const permissions = ref<string[]>([]) |
| | | const has = (permission: string) => permissions.value.includes('*:*:*') || permissions.value.includes(permission) |
| | | const displayName = computed(() => getCurrentUser()?.displayName || getCurrentUser()?.username || '') |
| | | async function loadPage() { |
| | | loading.value = true; dashboardError.value = ''; todoError.value = '' |
| | | dashboardError.value = ''; todoError.value = '' |
| | | try { |
| | | permissions.value = (await getUserInfo()).permissions || [] |
| | | const results = await Promise.allSettled([loadDashboard(), has('todo:list:query') || has('todo:list:list') ? loadTodos() : Promise.resolve()]) |
| | |
| | | if (main.status === 'rejected') dashboardError.value = main.reason instanceof Error ? main.reason.message : '首页数据加载失败' |
| | | if (todos.status === 'rejected') todoError.value = todos.reason instanceof Error ? todos.reason.message : '待办加载失败' |
| | | } catch (error) { clearTodos(); clearDashboard(); dashboardError.value = error instanceof Error ? error.message : '首页加载失败' } |
| | | finally { loading.value = false } |
| | | } |
| | | onMounted(loadPage) |
| | | const testFilterVisible = ref(false); const testType = ref('全部'); const testTypeDraft = ref('全部') |
| | |
| | | <template> |
| | | <div class="dashboard"> |
| | | <el-alert v-if="dashboardError" :title="dashboardError" type="error" :closable="false" show-icon /> |
| | | <el-button :loading="loading" @click="loadPage">刷新</el-button> |
| | | <section class="welcome-row"> |
| | | <div> |
| | | <h2>欢迎回来,{{ displayName }}</h2> |