Files
admin-vben5/apps/web-antd/src/views/dashboard/analytics/index.vue

237 lines
6.3 KiB
Vue
Raw Normal View History

2025-06-18 11:03:42 +08:00
<script lang="ts" setup>
2025-09-06 00:49:44 +08:00
import { AnalysisChartCard, AnalysisOverview } from '@vben/common-ui';
2025-06-18 11:03:42 +08:00
import {
SvgBellIcon,
SvgCakeIcon,
SvgCardIcon,
SvgDownloadIcon,
} from '@vben/icons';
import AnalyticsTrends from './analytics-trends.vue';
import AnalyticsVisitsData from './analytics-visits-data.vue';
import AnalyticsVisitsSales from './analytics-visits-sales.vue';
import AnalyticsVisitsSource from './analytics-visits-source.vue';
2025-09-06 00:49:44 +08:00
import { ref, onMounted } from 'vue';
2025-09-05 19:12:46 +08:00
import { DatePicker } from 'ant-design-vue';
2025-09-06 00:49:44 +08:00
import { Radio } from 'ant-design-vue';
import {
getIndexCount,
getStatisticsCurrDay,
getStatistics,
} from '#/api/analytics/index';
import { getVisitorList } from '#/api/property/resident/passRecordManagement';
2025-09-06 00:49:44 +08:00
const overviewItems = ref<any[]>([
2025-06-18 11:03:42 +08:00
{
icon: SvgCardIcon,
title: '今日通行量',
totalTitle: '总通行量',
2025-09-06 00:49:44 +08:00
totalValue: 0,
value: 0,
2025-06-18 11:03:42 +08:00
},
{
icon: SvgCakeIcon,
2025-09-05 19:12:46 +08:00
title: '今日车流量',
totalTitle: '总车流量',
totalValue: 0,
value: 0,
2025-06-18 11:03:42 +08:00
},
{
icon: SvgDownloadIcon,
2025-09-05 19:12:46 +08:00
title: '今日预警数量',
totalTitle: '总预警量',
2025-09-06 00:49:44 +08:00
totalValue: 0,
value: 0,
2025-06-18 11:03:42 +08:00
},
{
icon: SvgBellIcon,
2025-09-05 19:12:46 +08:00
title: '今日工单数量',
totalTitle: '总工单量',
totalValue: 0,
value: 0,
2025-06-18 11:03:42 +08:00
},
2025-09-06 00:49:44 +08:00
]);
2025-06-18 11:03:42 +08:00
2025-09-05 19:12:46 +08:00
//tab选择
const timeUnit = ref(1);
// 月份选择
2025-09-06 00:49:44 +08:00
const selectedDate = ref<any>(null);
const paramDate = ref(null);
const statisticsList = ref<any>();
const workList = ref<any>();
const statusDataList = ref<any>();
const analyticsTrendsRef = ref<InstanceType<typeof AnalyticsTrends> | null>(
null,
);
const handleDateChange = (date: any) => {
paramDate.value = date.format('YYYY-MM');
// 调用子组件的方法
if (
analyticsTrendsRef.value &&
analyticsTrendsRef.value.getMeterRecordTrend
) {
analyticsTrendsRef.value.getMeterRecordTrend(paramDate);
}
2025-09-05 19:12:46 +08:00
};
// 通行量
async function getPersonCount() {
const date = new Date();
const nowDate = date
.toLocaleDateString('zh-CN', {
year: 'numeric',
month: '2-digit',
day: '2-digit',
})
.replace(/\//g, '-');
const historyData = {
pageNum: 1,
pageSize: 10,
begTime: '2025-09-01',
endTime: nowDate,
};
const todayData = {
pageNum: 1,
pageSize: 10,
begTime: nowDate,
endTime: nowDate,
};
const historyTotal = await getVisitorList(historyData);
const todayTotal = await getVisitorList(todayData);
overviewItems.value[0].totalValue = historyTotal.total;
overviewItems.value[0].value = todayTotal.total;
}
2025-09-05 19:12:46 +08:00
// 工单数量
async function getIndex() {
const res = await getIndexCount();
2025-09-06 00:49:44 +08:00
overviewItems.value[3].value = res.workOrdersToday;
overviewItems.value[3].totalValue = res.workOrdersTotal;
overviewItems.value[0].value = res.visitorsToday;
overviewItems.value[0].totalValue = res.visitorsTotal;
workList.value = res.satisfactionChartList;
statusDataList.value = res.statusChartVoChartList;
2025-09-05 19:12:46 +08:00
}
// 车流量
async function getCarCount() {
2025-09-06 00:49:44 +08:00
const startDate = new Date();
2025-09-05 19:12:46 +08:00
startDate.setHours(0, 0, 0, 0);
const endDate = new Date();
endDate.setHours(23, 59, 59, 999);
// 转换为正确的 ISO 格式,考虑时区偏移
const toLocalISOString = (date: Date) => {
const timezoneOffset = date.getTimezoneOffset() * 60000; // 转换为毫秒
const localTime = new Date(date.getTime() - timezoneOffset);
return localTime.toISOString().slice(0, -1) + 'Z';
};
2025-09-06 00:49:44 +08:00
const response = await fetch(
2025-09-06 10:55:22 +08:00
'https://server.cqnctc.com:6081/web/thirdParty/queryInParkData',
2025-09-06 00:49:44 +08:00
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json, text/plain, */*',
},
body: JSON.stringify({
pageReq: {
pageNum: 1,
pageSize: 10,
},
plNos: ['PFN000000012', 'PFN000000022', 'PFN000000025'],
parkInBeginTime: toLocalISOString(startDate),
parkInEndTime: toLocalISOString(endDate),
orgId: 10012,
parkOrderTypes: [100, 200, 201, 300, 500],
terminalSource: 50,
remark: '',
}),
2025-09-05 19:12:46 +08:00
},
2025-09-06 00:49:44 +08:00
);
const result = await response.json();
2025-09-06 13:32:28 +08:00
overviewItems.value[1].value = result.data.todayCount;
overviewItems.value[1].totalValue = result.data.allCount;
2025-09-05 19:12:46 +08:00
}
// 预警
async function getStatisticsCurrDayCount() {
2025-09-06 00:49:44 +08:00
const res = await getStatisticsCurrDay();
let total = 0;
for (const item of res) {
total += item.total;
}
overviewItems.value[2].value = total;
2025-09-05 19:12:46 +08:00
}
async function getStatisticsCount() {
2025-09-06 00:49:44 +08:00
const res = await getStatistics();
let total = 0;
for (const item of res) {
total += item.total;
}
overviewItems.value[2].totalValue = total;
statisticsList.value = res;
2025-09-05 19:12:46 +08:00
}
// 电量
onMounted(() => {
2025-09-06 00:49:44 +08:00
getIndex();
getCarCount();
getPersonCount();
2025-09-06 00:49:44 +08:00
getStatisticsCurrDayCount();
getStatisticsCount();
});
2025-06-18 11:03:42 +08:00
</script>
<template>
<div class="p-5">
<AnalysisOverview :items="overviewItems" />
2025-09-05 19:12:46 +08:00
<!-- <AnalysisChartsTabs :tabs="chartTabs" class="mt-5">
2025-06-18 11:03:42 +08:00
<template #trends>
<AnalyticsTrends />
</template>
<template #visits>
<AnalyticsVisits />
</template>
2025-09-05 19:12:46 +08:00
</AnalysisChartsTabs> -->
2025-09-06 00:49:44 +08:00
<div class="mt-5 rounded-lg bg-white">
2025-09-05 19:12:46 +08:00
<div
2025-09-06 00:49:44 +08:00
class="flex items-center justify-between p-5"
style="width: 100%; height: 100px"
2025-09-05 19:12:46 +08:00
>
2025-09-06 00:49:44 +08:00
<Radio.Group v-model:value="timeUnit" size="large">
2025-09-05 19:12:46 +08:00
<Radio.Button value="1">电量</Radio.Button>
</Radio.Group>
<DatePicker
v-model:value="selectedDate"
picker="month"
placeholder="请选择月份"
style="width: 150px"
@change="handleDateChange"
/>
</div>
<div v-if="timeUnit == 1">
2025-09-06 00:49:44 +08:00
<AnalyticsTrends
ref="analyticsTrendsRef"
:selected-date="selectedDate"
/>
2025-09-05 19:12:46 +08:00
</div>
</div>
2025-06-18 11:03:42 +08:00
<div class="mt-5 w-full md:flex">
2025-09-05 19:12:46 +08:00
<AnalysisChartCard class="mt-5 md:mr-4 md:mt-0 md:w-1/3" title="预警类型">
2025-09-06 00:49:44 +08:00
<AnalyticsVisitsData :statisticsData="statisticsList" />
2025-06-18 11:03:42 +08:00
</AnalysisChartCard>
2025-09-05 19:12:46 +08:00
<AnalysisChartCard
class="mt-5 md:mr-4 md:mt-0 md:w-1/3"
title="设备使用状态"
>
2025-09-06 00:49:44 +08:00
<AnalyticsVisitsSource :statusData="statusDataList" />
2025-06-18 11:03:42 +08:00
</AnalysisChartCard>
2025-09-05 19:12:46 +08:00
<AnalysisChartCard class="mt-5 md:mt-0 md:w-1/3" title="工单类型">
2025-09-06 00:49:44 +08:00
<AnalyticsVisitsSales :workData="workList" />
2025-06-18 11:03:42 +08:00
</AnalysisChartCard>
</div>
</div>
</template>