123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828 |
- <template>
- <!-- 第一行:统计卡片行 -->
- <el-row :gutter="16" class="mb-4">
- <el-col :span="24">
- <el-card class="chart-card" shadow="never">
- <el-form
- class="-mb-15px"
- :model="queryParams"
- ref="queryFormRef"
- :inline="true"
- label-width="68px"
- >
- <el-form-item label="所属部门" prop="project_name">
- <el-tree-select
- v-model="queryParams.deptId"
- :data="deptList"
- :props="defaultProps"
- check-strictly
- node-key="id"
- filterable
- placeholder="请选择所在部门"
- clearable
- style="width: 180px"
- />
- </el-form-item>
- <el-form-item label="创建时间" prop="createTime">
- <el-date-picker
- v-model="queryParams.createTime"
- value-format="YYYY-MM-DD HH:mm:ss"
- type="daterange"
- start-placeholder="开始日期"
- end-placeholder="结束日期"
- :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
- class="!w-220px"
- />
- </el-form-item>
- <!-- <el-form-item label="填写状态" prop="project_name">
- <el-select
- v-model="queryParams.status"
- placeholder="填写状态"
- clearable
- class="!w-240px"
- >
- <el-option
- v-for="dict in getIntDictOptions(DICT_TYPE.OPERATION_FILL_ORDER_STATUS)"
- :key="dict.value"
- :label="dict.label"
- :value="dict.value"
- />
- </el-select>
- </el-form-item>-->
- <el-form-item>
- <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
- <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
- </el-form-item>
- </el-form>
- </el-card>
- </el-col>
- </el-row>
- <el-row :gutter="16" class="mb-4">
- <el-col :span="6">
- <el-card class="stat-card" shadow="never">
- <div class="flex flex-col">
- <div class="flex justify-between items-center text-gray-400">
- <span>昨日工单数量</span>
- <Icon icon="ep:menu" class="text-[32px] text-blue-400" />
- </div>
- <el-divider />
- <div class="flex justify-between items-center mb-1">
- <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
- >总数量</span
- >
- <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
- >未完成</span
- >
- </div>
- <div class="flex justify-between items-center mb-1">
- <span class="text-3xl font-bold text-gray-700">
- {{ day.total }}
- </span>
- <span class="text-3xl font-bold text-gray-700">
- {{ day.todo }}
- </span>
- </div>
- <!-- <el-divider class="my-2" />-->
- <!-- <div class="flex justify-between items-center text-gray-400 text-sm">-->
- <!-- <span>今日新增</span>-->
- <!-- <span class="text-green-500">+{{ statsData.productCategoryTodayCount }}</span>-->
- <!-- </div>-->
- </div>
- </el-card>
- </el-col>
- <el-col :span="6">
- <el-card class="stat-card" shadow="never">
- <div class="flex flex-col">
- <div class="flex justify-between items-center text-gray-400">
- <span>近一周工单数量</span>
- <Icon icon="ep:menu" class="text-[32px] text-blue-400" />
- </div>
- <el-divider />
- <div class="flex justify-between items-center mb-1">
- <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
- >总数量</span
- >
- <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
- >未完成</span
- >
- </div>
- <div class="flex justify-between items-center mb-1">
- <span class="text-3xl font-bold text-gray-700">
- {{ week.total }}
- </span>
- <span class="text-3xl font-bold text-gray-700">
- {{ week.todo }}
- </span>
- </div>
- <!-- <el-divider class="my-2" />-->
- <!-- <div class="flex justify-between items-center text-gray-400 text-sm">-->
- <!-- <span>今日新增</span>-->
- <!-- <span class="text-green-500">+{{ statsData.productCategoryTodayCount }}</span>-->
- <!-- </div>-->
- </div>
- </el-card>
- </el-col>
- <el-col :span="6">
- <el-card class="stat-card" shadow="never">
- <div class="flex flex-col">
- <div class="flex justify-between items-center text-gray-400">
- <span>近一月工单数量</span>
- <Icon icon="ep:menu" class="text-[32px] text-blue-400" />
- </div>
- <el-divider />
- <div class="flex justify-between items-center mb-1">
- <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
- >总数量</span
- >
- <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
- >未完成</span
- >
- </div>
- <div class="flex justify-between items-center mb-1">
- <span class="text-3xl font-bold text-gray-700">
- {{ month.total }}
- </span>
- <span class="text-3xl font-bold text-gray-700">
- {{ month.todo }}
- </span>
- </div>
- <!-- <el-divider class="my-2" />-->
- <!-- <div class="flex justify-between items-center text-gray-400 text-sm">-->
- <!-- <span>今日新增</span>-->
- <!-- <span class="text-green-500">+{{ statsData.productCategoryTodayCount }}</span>-->
- <!-- </div>-->
- </div>
- </el-card>
- </el-col>
- <el-col :span="6">
- <el-card class="stat-card" shadow="never">
- <div class="flex flex-col">
- <div class="flex justify-between items-center text-gray-400">
- <span>工单数量</span>
- <Icon icon="ep:menu" class="text-[32px] text-blue-400" />
- </div>
- <el-divider />
- <div class="flex justify-between items-center mb-1">
- <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
- >总数量</span
- >
- <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
- >未完成</span
- >
- </div>
- <div class="flex justify-between items-center mb-1">
- <span class="text-3xl font-bold text-gray-700">
- {{ total.total }}
- </span>
- <span class="text-3xl font-bold text-gray-700">
- {{ total.todo }}
- </span>
- </div>
- </div>
- </el-card>
- </el-col>
- </el-row>
- <!-- 第二行:图表行 -->
- <el-row :gutter="16" class="mb-4">
- <el-col :span="12">
- <el-card class="chart-card" shadow="never">
- <template #header>
- <div class="flex items-center">
- <span class="text-base font-medium text-gray-600">设备状态统计</span>
- </div>
- </template>
- <el-row class="h-[220px]">
- <el-col :span="12" class="flex flex-col items-center">
- <div ref="writeTodayChartRef" class="h-[160px] w-full"></div>
- <div class="text-center mt-2" >
- <span class="text-sm text-gray-600" style="text-decoration: underline;color: orangered;cursor: pointer" @click="clickStatus('设备待执行')">未填写</span>
- </div>
- </el-col>
- <el-col :span="12" class="flex flex-col items-center">
- <div ref="finishedTodayChartRef" class="h-[160px] w-full"></div>
- <div class="text-center mt-2">
- <span class="text-sm text-gray-600" style="text-decoration: underline;color: dodgerblue;cursor: pointer" @click="clickStatus('设备已执行')">已填写</span>
- </div>
- </el-col>
- </el-row>
- </el-card>
- </el-col>
- <el-col :span="12">
- <el-card class="chart-card" shadow="never">
- <template #header>
- <div class="flex items-center">
- <span class="text-base font-medium text-gray-600">工单状态统计</span>
- </div>
- </template>
- <el-row class="h-[220px]">
- <el-col :span="12" class="flex flex-col items-center">
- <div ref="writeChartRef" class="h-[160px] w-full"></div>
- <div class="text-center mt-2">
- <span class="text-sm text-gray-600" style="text-decoration: underline;color: orangered;cursor: pointer" @click="clickStatus('工单待执行')">待执行</span>
- </div>
- </el-col>
- <el-col :span="12" class="flex flex-col items-center">
- <div ref="finishedChartRef" class="h-[160px] w-full"></div>
- <div class="text-center mt-2">
- <span class="text-sm text-gray-600" style="text-decoration: underline;color: dodgerblue;cursor: pointer" @click="clickStatus('工单已执行')">已执行</span>
- </div>
- </el-col>
- </el-row>
- </el-card>
- </el-col>
- </el-row>
- <!-- 第三行:消息统计行 -->
- <el-row>
- <el-col :span="24">
- <el-card class="chart-card" shadow="never">
- <template #header>
- <div class="flex items-center justify-between">
- <span class="text-base font-medium text-gray-600">近一年数量统计</span>
- </div>
- </template>
- <div ref="chartContainer" class="h-[300px]"></div>
- </el-card>
- </el-col>
- </el-row>
- <!-- TODO 第四行:地图 -->
- </template>
- <script setup lang="ts" name="Index">
- import * as echarts from 'echarts/core'
- import { BarChart } from 'echarts/charts'; // 显式导入柱状图模块
- import {
- GridComponent,
- LegendComponent,
- TitleComponent,
- ToolboxComponent,
- TooltipComponent
- } from 'echarts/components'
- import { GaugeChart, LineChart, PieChart } from 'echarts/charts'
- import { LabelLayout, UniversalTransition } from 'echarts/features'
- import { CanvasRenderer } from 'echarts/renderers'
- import {
- IotStatisticsDeviceMessageSummaryRespVO,
- IotStatisticsSummaryRespVO
- } from '@/api/iot/statistics'
- const { currentRoute, push } = useRouter()
- import { formatDate } from '@/utils/formatTime'
- import { IotStatApi } from '@/api/pms/stat'
- import {defaultProps, handleTree} from "@/utils/tree";
- import {ref} from "vue";
- import {DeptTreeItem} from "@/api/system/dept";
- import * as DeptApi from "@/api/system/dept";
- import {useUserStore} from "@/store/modules/user";
- // TODO @super:参考下 /Users/yunai/Java/yudao-ui-admin-vue3/src/views/mall/home/index.vue,拆一拆组件
- /** IoT 首页 */
- defineOptions({ name: 'IotInspectStat' })
- // TODO @super:使用下 Echart 组件,参考 yudao-ui-admin-vue3/src/views/mall/home/components/TradeTrendCard.vue 等
- echarts.use([
- TooltipComponent,
- LegendComponent,
- PieChart,
- CanvasRenderer,
- LabelLayout,
- TitleComponent,
- ToolboxComponent,
- GridComponent,
- LineChart,
- UniversalTransition,
- GaugeChart,
- BarChart
- ])
- const timeRange = ref('7d') // 修改默认选择为近一周
- const dateRange = ref<[Date, Date] | null>(null)
- const deptList = ref<DeptTreeItem[]>([]) // 树形结构部门列表
- const queryParams = reactive({
- deptId: undefined,
- createTime: undefined,
- startTime: Date.now() - 7 * 24 * 60 * 60 * 1000, // 设置默认开始时间为 7 天前
- endTime: Date.now() // 设置默认结束时间为当前时间
- })
- // const deviceCountChartRef = ref() // 设备数量统计的图表
- const reportingChartRef = ref() // 在线设备统计的图表
- const dealFinishedChartRef = ref() // 离线设备统计的图表
- const transOrderChartRef = ref() // 待激活设备统计的图表
- const orderFinishChartRef = ref()
- const deviceMessageCountChartRef = ref() // 上下行消息量统计的图表
- const writeChartRef = ref() // 上下行消息量统计的图表
- const finishedChartRef = ref() // 上下行消息量统计的图表
- const writeTodayChartRef = ref() // 上下行消息量统计的图表
- const finishedTodayChartRef = ref() // 上下行消息量统计的图表
- // 基础统计数据
- // TODO @super:初始为 -1,然后界面展示先是加载中?试试用 cursor 改哈
- const statsData = ref<IotStatisticsSummaryRespVO>({
- productCategoryCount: 0,
- productCount: 0,
- deviceCount: 0,
- deviceMessageCount: 0,
- productCategoryTodayCount: 0,
- productTodayCount: 0,
- deviceTodayCount: 0,
- deviceMessageTodayCount: 0,
- deviceOnlineCount: 0,
- deviceOfflineCount: 0,
- deviceInactiveCount: 0,
- productCategoryDeviceCounts: {}
- })
- const handleQuery = () => {
- getStats()
- // initChart()
- // initCharts()
- }
- const resetQuery = () => {
- // 重置查询参数
- queryParams.startTime = Date.now() - 7 * 24 * 60 * 60 * 1000
- queryParams.endTime = Date.now()
- queryParams.deptId = useUserStore().getUser.deptId;
- queryParams.createTime = null
- // 重新获取数据
- getStats()
- }
- const clickStatus = (type) => {
- let status = '';
- const createTime = queryParams.createTime;
- const deptId = queryParams.deptId;
- debugger
- if (type === '工单待执行') {
- status = 'todo'
- push({ name: 'IotInspectOrdere', params:{deptId,status,createTime}})
- } else if (type === '工单已执行') {
- status = 'finished'
- push({name: 'IotInspectOrdere', params:{deptId,status,createTime}})
- } else if (type==='设备待执行') {
- status = 'todo'
- debugger
- push({name:'IotInspectOrderDetailStat', params:{deptId,status,createTime}})
- } else if (type==='设备已执行'){
- status = 'finished'
- push({name:'IotInspectOrderDetailStat', params:{deptId,status,createTime}})
- }
- }
- const day = ref({
- total: undefined,
- todo: undefined
- })
- const week = ref({
- total: undefined,
- todo: undefined
- })
- const month = ref({
- total: undefined,
- todo: undefined
- })
- const total = ref({
- total: undefined,
- todo: undefined
- })
- const status = ref({
- finished: 0,
- todo: 0
- })
- const todayStatus = ref({
- finished: 0,
- todo: 0
- })
- // 消息统计数据
- const messageStats = ref<IotStatisticsDeviceMessageSummaryRespVO>({
- upstreamCounts: {},
- downstreamCounts: {}
- })
- /** 处理快捷时间范围选择 */
- const handleTimeRangeChange = (timeRange: string) => {
- const now = Date.now()
- let startTime: number
- // TODO @super:这个的计算,看看能不能结合 dayjs 简化。因为 1h、24h、7d 感觉是比较标准的。如果没有,抽到 utils/formatTime.ts 作为一个工具方法
- switch (timeRange) {
- case '1h':
- startTime = now - 60 * 60 * 1000
- break
- case '24h':
- startTime = now - 24 * 60 * 60 * 1000
- break
- case '7d':
- startTime = now - 7 * 24 * 60 * 60 * 1000
- break
- default:
- return
- }
- // 清空日期选择器
- dateRange.value = null
- // 更新查询参数
- queryParams.startTime = startTime
- queryParams.endTime = now
- // 重新获取数据
- getStats()
- }
- /** 处理自定义日期范围选择 */
- const handleDateRangeChange = (value: [Date, Date] | null) => {
- if (value) {
- // 清空快捷选项
- timeRange.value = ''
- // 更新查询参数
- queryParams.startTime = value[0].getTime()
- queryParams.endTime = value[1].getTime()
- // 重新获取数据
- getStats()
- }
- }
- /** 获取统计数据 */
- const getStats = async () => {
- // 获取基础统计数据
- IotStatApi.getInspectDay().then((res) => {
- day.value = res
- })
- IotStatApi.getInspectWeek().then((res) => {
- week.value = res
- })
- IotStatApi.getInspectMonth().then((res) => {
- month.value = res
- })
- IotStatApi.getInspectTotal().then((res) => {
- total.value = res
- })
- IotStatApi.getInspectStatus(queryParams).then((res) => {
- status.value = res
- initChart()
- initCharts()
- })
- IotStatApi.getInspectDeviceStatus(queryParams).then((res) => {
- todayStatus.value = res
- initChart()
- initCharts()
- })
- // statsData.value = await ProductCategoryApi.getIotStatisticsSummary()
- //
- // // 获取消息统计数据
- // messageStats.value = await ProductCategoryApi.getIotStatisticsDeviceMessageSummary(queryParams)
- // 初始化图表
- }
- /** 初始化图表 */
- const initCharts = () => {
- //待执行
- initGaugeChart(
- writeTodayChartRef.value,
- todayStatus.value.todo === undefined ? 0 : todayStatus.value.todo,
- '#f50',
- '设备待执行'
- )
- //已执行
- initGaugeChart(
- finishedTodayChartRef.value,
- todayStatus.value.finished === undefined ? 0 : todayStatus.value.finished,
- '#05b',
- '设备已执行'
- )
- // 工单待执行
- initGaugeChart(
- writeChartRef.value,
- status.value.todo === undefined ? 0 : status.value.todo,
- '#f50',
- '工单待执行'
- )
- //工单已执行
- initGaugeChart(
- finishedChartRef.value,
- status.value.finished === undefined ? 0 : status.value.finished,
- '#05b',
- '工单已执行'
- )
- // 消息量统计
- //initMessageChart()
- }
- /** 初始化仪表盘图表 */
- const initGaugeChart = (el: any, value: number, color: string, type: string) => {
- const chart = echarts.init(el);
- chart.setOption({
- series: [
- {
- type: 'gauge',
- startAngle: 360,
- endAngle: 0,
- min: 0,
- max: value, // 使用设备总数作为最大值
- progress: {
- show: true,
- width: 25,
- itemStyle: {
- color: color
- }
- },
- axisLine: {
- lineStyle: {
- width: 25,
- color: [[1, '#E5E7EB']]
- }
- },
- axisTick: { show: false },
- splitLine: { show: false },
- axisLabel: { show: false },
- pointer: { show: false },
- anchor: { show: false },
- title: { show: false },
- detail: {
- valueAnimation: true,
- fontSize: 20,
- fontWeight: 'bold',
- fontFamily: 'Inter, sans-serif',
- color: color,
- offsetCenter: [0, '0'],
- formatter: (value: number) => {
- return `${value} `
- }
- },
- data: [{ value: value, type: type }]
- }
- ]
- });
- // 添加点击事件监听器
- chart.on('click', (params) => {
- console.log('点击的数据值为:', params.value);
- console.log('点击的数据类型为:', params.data.type);
- const createTime = queryParams.createTime;
- const deptId = queryParams.deptId;
- let status = '';
- if (params.data.type === '工单待执行') {
- status = 'todo'
- push({ name: 'IotInspectOrdere', params:{deptId,status,createTime}})
- } else if (params.data.type === '工单已执行') {
- status = 'finished'
- push({name: 'IotInspectOrdere', params:{deptId,status,createTime}})
- } else if (params.data.type==='设备待执行') {
- status = 'todo'
- push({name:'IotInspectOrderDetailStat', params:{deptId,status,createTime}})
- } else if (params.data.type==='设备已执行'){
- status = 'finished'
- push({name:'IotInspectOrderDetailStat', params:{deptId,status,createTime}})
- }
- });
- }
- /** 初始化消息统计图表 */
- const initMessageChart = () => {
- // 获取所有时间戳并排序
- // TODO @super:一些 idea 里的红色报错,要去处理掉噢。
- const timestamps = Array.from(
- new Set([
- ...messageStats.value.upstreamCounts.map((item) => Number(Object.keys(item)[0])),
- ...messageStats.value.downstreamCounts.map((item) => Number(Object.keys(item)[0]))
- ])
- ).sort((a, b) => a - b) // 确保时间戳从小到大排序
- // 准备数据
- const xdata = timestamps.map((ts) => formatDate(ts, 'YYYY-MM-DD HH:mm'))
- const upData = timestamps.map((ts) => {
- const item = messageStats.value.upstreamCounts.find(
- (count) => Number(Object.keys(count)[0]) === ts
- )
- return item ? Object.values(item)[0] : 0
- })
- const downData = timestamps.map((ts) => {
- const item = messageStats.value.downstreamCounts.find(
- (count) => Number(Object.keys(count)[0]) === ts
- )
- return item ? Object.values(item)[0] : 0
- })
- // 配置图表
- echarts.init(deviceMessageCountChartRef.value).setOption({
- tooltip: {
- trigger: 'axis',
- backgroundColor: 'rgba(255, 255, 255, 0.9)',
- borderColor: '#E5E7EB',
- textStyle: {
- color: '#374151'
- }
- },
- legend: {
- data: ['上行消息量', '下行消息量'],
- textStyle: {
- color: '#374151',
- fontWeight: 500
- }
- },
- grid: {
- left: '3%',
- right: '4%',
- bottom: '3%',
- containLabel: true
- },
- xAxis: {
- type: 'category',
- boundaryGap: false,
- data: xdata,
- axisLine: {
- lineStyle: {
- color: '#E5E7EB'
- }
- },
- axisLabel: {
- color: '#6B7280'
- }
- },
- yAxis: {
- type: 'value',
- axisLine: {
- lineStyle: {
- color: '#E5E7EB'
- }
- },
- axisLabel: {
- color: '#6B7280'
- },
- splitLine: {
- lineStyle: {
- color: '#F3F4F6'
- }
- }
- },
- series: [
- {
- name: '上行消息量',
- type: 'line',
- smooth: true, // 添加平滑曲线
- data: upData,
- itemStyle: {
- color: '#3B82F6'
- },
- lineStyle: {
- width: 2
- },
- areaStyle: {
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
- { offset: 0, color: 'rgba(59, 130, 246, 0.2)' },
- { offset: 1, color: 'rgba(59, 130, 246, 0)' }
- ])
- }
- },
- {
- name: '下行消息量',
- type: 'line',
- smooth: true, // 添加平滑曲线
- data: downData,
- itemStyle: {
- color: '#10B981'
- },
- lineStyle: {
- width: 2
- },
- areaStyle: {
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
- { offset: 0, color: 'rgba(16, 185, 129, 0.2)' },
- { offset: 1, color: 'rgba(16, 185, 129, 0)' }
- ])
- }
- }
- ]
- })
- }
- const chartContainer = ref(null)
- let chartInstance = null
- // 生成过去12个月份的标签 (格式: YYYY-MM)
- const generateMonthLabels = () => {
- const months = []
- const date = new Date()
- for (let i = 11; i >= 0; i--) {
- const tempDate = new Date(date.getFullYear(), date.getMonth() - i, 1)
- const year = tempDate.getFullYear()
- const month = String(tempDate.getMonth() + 1).padStart(2, '0')
- months.push(`${year}-${month}`)
- }
- return months
- }
- // 模拟数据获取
- const fetchChartData = async () => {
- // 模拟异步请求
- return new Promise((resolve) => {
- setTimeout(() => {
- resolve({
- months: generateMonthLabels(),
- faults: [20,30,100,40,20,50,70,80,60,90,100,100],
- repairs: [10,30,90,30,10,20,60,50,22,34,70,85],
- })
- }, 300)
- })
- }
- // 初始化图表配置
- const initChart = async () => {
- if (!chartContainer.value) return
- // 获取数据
- const { months, faults, repairs } = await fetchChartData()
- // ECharts配置
- const option = {
- tooltip: {
- trigger: 'axis',
- axisPointer: {
- type: 'shadow'
- },
- formatter: (params) => {
- return `${params[0].axisValue}<br/>
- ${params[0].marker} ${params[0].seriesName}: ${params[0].value}`
- }
- },
- legend: {
- data: ['巡检工单数量'],
- top: 25
- },
- grid: {
- left: '3%',
- right: '4%',
- bottom: '3%',
- containLabel: true
- },
- xAxis: {
- type: 'category',
- data: months,
- axisLabel: {
- rotate: 45,
- margin: 15
- }
- },
- yAxis: {
- type: 'value',
- axisLabel: {
- formatter: (value) => Math.floor(value).toString()
- }
- },
- series: [
- {
- name: '巡检工单数量',
- type: 'bar',
- itemStyle: {
- color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
- { offset: 0, color: '#2196df' },
- { offset: 1, color: '#2196df' }
- ])
- },
- emphasis: {
- focus: 'series'
- },
- data: repairs
- }
- ]
- }
- // 初始化图表
- chartInstance = echarts.init(chartContainer.value)
- chartInstance.setOption(option)
- // 窗口缩放监听
- window.addEventListener('resize', handleResize)
- handleResize()
- }
- // 自适应调整
- const handleResize = () => {
- chartInstance?.resize()
- }
- /** 初始化 */
- onMounted(async () => {
- deptList.value = handleTree(await DeptApi.getSimpleDeptList())
- queryParams.deptId = useUserStore().getUser.deptId;
- await getStats()
- // await initChart()
- // await initCharts()
- })
- onUnmounted(() => {
- chartInstance?.dispose()
- window.removeEventListener('resize', handleResize)
- })
- </script>
- <style lang="scss" scoped>
- </style>
|