面板api请求封装到组件

This commit is contained in:
WindowBird 2025-11-06 10:27:40 +08:00
parent 10950db757
commit badefc18f1
2 changed files with 123 additions and 40 deletions

View File

@ -1,6 +1,11 @@
<template>
<scroll-view class="dashboard-scroll" scroll-y>
<view class="dashboard-content">
<!-- 加载状态 -->
<view v-if="loading" class="loading-container">
<view class="loading-text">加载中...</view>
</view>
<view class="dashboard-content" v-else>
<!-- 任务概览 -->
<view class="task-overview">
<view
@ -145,15 +150,17 @@
</template>
<script setup>
import { ref } from 'vue';
import { ref, onMounted } from 'vue';
import { getTaskStatusType, getTaskStatusStyle, getStatusText } from '@/utils/taskConfig.js';
import { getDashboardBrief } from '@/common/api';
import { useUserStore } from '@/store/user';
//
const taskStats = ref([
{ label: '完成任务', count: 78 },
{ label: '待完成任务', count: 28 },
{ label: '即将预期', count: 8 },
{ label: '逾期任务', count: 1 }
{ label: '完成任务', count: 0 },
{ label: '待完成任务', count: 0 },
{ label: '即将预期', count: 0 },
{ label: '逾期任务', count: 0 }
]);
//
@ -180,20 +187,108 @@ const announcements = ref([
//
const projectStatus = ref([
{ label: '运行中', count: 1 },
{ label: '运维中', count: 1 },
{ label: '即将到期', count: 1 },
{ label: '开发超期', count: 1 }
{ label: '运行中', count: 0 },
{ label: '运维中', count: 0 },
{ label: '即将到期', count: 0 },
{ label: '开发超期', count: 0 }
]);
//
const customerStatus = ref([
{ label: '今日新增', count: 1 },
{ label: '今日已跟进', count: 1 },
{ label: '今日待跟进', count: 1 },
{ label: '即将跟进', count: 1 }
{ label: '今日新增', count: 0 },
{ label: '今日已跟进', count: 0 },
{ label: '今日待跟进', count: 0 },
{ label: '即将跟进', count: 0 }
]);
//
const loading = ref(false);
// API
const mapApiDataToComponent = (apiData) => {
if (!apiData) return;
//
const task = apiData.task || {};
taskStats.value = [
{ label: '完成任务', count: task.completed || 0 },
{ label: '待完成任务', count: task.inProgress || 0 },
{ label: '即将预期', count: task.soonExpire || 0 },
{ label: '逾期任务', count: task.overdueUncompleted || 0 }
];
//
const project = apiData.project || {};
projectStatus.value = [
{ label: '运行中', count: project.inProgress || 0 },
{ label: '运维中', count: project.maintenance || 0 },
{ label: '即将到期', count: project.devSoonExpire || 0 },
{ label: '开发超期', count: project.developmentOverdue || 0 }
];
//
const customer = apiData.customer || {};
customerStatus.value = [
{ label: '今日新增', count: customer.today || 0 },
{ label: '今日已跟进', count: customer.todayFollowed || 0 },
{ label: '今日待跟进', count: customer.todayWaitFollow || 0 },
{ label: '即将跟进', count: customer.soonFollow || 0 }
];
//
// API
// overdueTasks.value = [];
};
//
const loadDashboardData = async () => {
try {
loading.value = true;
const keys = [
'taskStatus',
'taskTodayCompleted',
'taskSoonExpire',
'taskOverdueUncompleted',
'projectStatus',
'projectDevSoonExpire',
'projectDevOverdue',
'customerTodayCreate',
'customerTodayFollowed',
'customerTodayWaitFollow',
'customerSoonFollow',
'customerMonthFollow',
'customerMonthFollowCount'
];
// store ID使
const userStore = useUserStore();
// userInfo ID使
const joinUserId = userStore.userInfo?.id || userStore.userInfo?.userId || '23';
const res = await getDashboardBrief({
joinUserId,
keys
});
console.log('看板数据加载成功:', res);
mapApiDataToComponent(res);
} catch (err) {
console.error('加载看板数据失败:', err);
uni.showToast({
title: '加载数据失败',
icon: 'none'
});
} finally {
loading.value = false;
}
};
//
onMounted(() => {
loadDashboardData();
});
//
const goToTaskList = (label) => {
//
@ -640,5 +735,17 @@ const getTagCustomStyle = (status) => {
color: #666;
text-align: center;
}
.loading-container {
display: flex;
justify-content: center;
align-items: center;
padding: 40px 0;
}
.loading-text {
font-size: 14px;
color: #999;
}
</style>

View File

@ -45,7 +45,7 @@
import { ref, computed, watch, onMounted } from 'vue';
import { onShow } from '@dcloudio/uni-app';
import { useUserStore } from '@/store/user';
import { getUserInfo, getDashboardBrief } from '@/common/api';
import { getUserInfo } from '@/common/api';
import FabPlus from '@/components/FabPlus.vue';
import AddEventModal from '@/components/AddEventModal.vue';
@ -137,31 +137,7 @@ onMounted(() => {
console.error('getInfo 接口请求失败:', err);
});
//
const keys = [
'taskStatus',
'taskTodayCompleted',
'taskSoonExpire',
'taskOverdueUncompleted',
'projectStatus',
'projectDevSoonExpire',
'projectDevOverdue',
'customerTodayCreate',
'customerTodayFollowed',
'customerTodayWaitFollow',
'customerSoonFollow',
'customerMonthFollow',
'customerMonthFollowCount'
];
getDashboardBrief({
joinUserId: '23',
keys
}).then(res => {
console.log('dashboard/brief 接口返回:', res);
}).catch(err => {
console.error('dashboard/brief 接口请求失败:', err);
});
// ContentDashboard
});
//