inspect.vue 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. <template>
  2. <!-- 第一行:统计卡片行 -->
  3. <el-row :gutter="16" class="mb-4">
  4. <el-col :span="24">
  5. <el-card class="chart-card" shadow="never">
  6. <el-form
  7. class="-mb-15px"
  8. :model="queryParams"
  9. ref="queryFormRef"
  10. :inline="true"
  11. label-width="68px"
  12. >
  13. <el-form-item label="所属部门" prop="project_name">
  14. <el-tree-select
  15. v-model="queryParams.deptId"
  16. :data="deptList"
  17. :props="defaultProps"
  18. check-strictly
  19. node-key="id"
  20. filterable
  21. placeholder="请选择所在部门"
  22. clearable
  23. style="width: 180px"
  24. />
  25. </el-form-item>
  26. <el-form-item label="创建时间" prop="createTime">
  27. <el-date-picker
  28. v-model="queryParams.createTime"
  29. value-format="YYYY-MM-DD HH:mm:ss"
  30. type="daterange"
  31. start-placeholder="开始日期"
  32. end-placeholder="结束日期"
  33. :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
  34. class="!w-220px"
  35. />
  36. </el-form-item>
  37. <!-- <el-form-item label="填写状态" prop="project_name">
  38. <el-select
  39. v-model="queryParams.status"
  40. placeholder="填写状态"
  41. clearable
  42. class="!w-240px"
  43. >
  44. <el-option
  45. v-for="dict in getIntDictOptions(DICT_TYPE.OPERATION_FILL_ORDER_STATUS)"
  46. :key="dict.value"
  47. :label="dict.label"
  48. :value="dict.value"
  49. />
  50. </el-select>
  51. </el-form-item>-->
  52. <el-form-item>
  53. <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
  54. <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
  55. </el-form-item>
  56. </el-form>
  57. </el-card>
  58. </el-col>
  59. </el-row>
  60. <el-row :gutter="16" class="mb-4">
  61. <el-col :span="6">
  62. <el-card class="stat-card" shadow="never">
  63. <div class="flex flex-col">
  64. <div class="flex justify-between items-center text-gray-400">
  65. <span>昨日工单数量</span>
  66. <Icon icon="ep:menu" class="text-[32px] text-blue-400" />
  67. </div>
  68. <el-divider />
  69. <div class="flex justify-between items-center mb-1">
  70. <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
  71. >总数量</span
  72. >
  73. <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
  74. >未完成</span
  75. >
  76. </div>
  77. <div class="flex justify-between items-center mb-1">
  78. <span class="text-3xl font-bold text-gray-700">
  79. {{ day.total }}
  80. </span>
  81. <span class="text-3xl font-bold text-gray-700">
  82. {{ day.todo }}
  83. </span>
  84. </div>
  85. <!-- <el-divider class="my-2" />-->
  86. <!-- <div class="flex justify-between items-center text-gray-400 text-sm">-->
  87. <!-- <span>今日新增</span>-->
  88. <!-- <span class="text-green-500">+{{ statsData.productCategoryTodayCount }}</span>-->
  89. <!-- </div>-->
  90. </div>
  91. </el-card>
  92. </el-col>
  93. <el-col :span="6">
  94. <el-card class="stat-card" shadow="never">
  95. <div class="flex flex-col">
  96. <div class="flex justify-between items-center text-gray-400">
  97. <span>近一周工单数量</span>
  98. <Icon icon="ep:menu" class="text-[32px] text-blue-400" />
  99. </div>
  100. <el-divider />
  101. <div class="flex justify-between items-center mb-1">
  102. <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
  103. >总数量</span
  104. >
  105. <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
  106. >未完成</span
  107. >
  108. </div>
  109. <div class="flex justify-between items-center mb-1">
  110. <span class="text-3xl font-bold text-gray-700">
  111. {{ week.total }}
  112. </span>
  113. <span class="text-3xl font-bold text-gray-700">
  114. {{ week.todo }}
  115. </span>
  116. </div>
  117. <!-- <el-divider class="my-2" />-->
  118. <!-- <div class="flex justify-between items-center text-gray-400 text-sm">-->
  119. <!-- <span>今日新增</span>-->
  120. <!-- <span class="text-green-500">+{{ statsData.productCategoryTodayCount }}</span>-->
  121. <!-- </div>-->
  122. </div>
  123. </el-card>
  124. </el-col>
  125. <el-col :span="6">
  126. <el-card class="stat-card" shadow="never">
  127. <div class="flex flex-col">
  128. <div class="flex justify-between items-center text-gray-400">
  129. <span>近一月工单数量</span>
  130. <Icon icon="ep:menu" class="text-[32px] text-blue-400" />
  131. </div>
  132. <el-divider />
  133. <div class="flex justify-between items-center mb-1">
  134. <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
  135. >总数量</span
  136. >
  137. <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
  138. >未完成</span
  139. >
  140. </div>
  141. <div class="flex justify-between items-center mb-1">
  142. <span class="text-3xl font-bold text-gray-700">
  143. {{ month.total }}
  144. </span>
  145. <span class="text-3xl font-bold text-gray-700">
  146. {{ month.todo }}
  147. </span>
  148. </div>
  149. <!-- <el-divider class="my-2" />-->
  150. <!-- <div class="flex justify-between items-center text-gray-400 text-sm">-->
  151. <!-- <span>今日新增</span>-->
  152. <!-- <span class="text-green-500">+{{ statsData.productCategoryTodayCount }}</span>-->
  153. <!-- </div>-->
  154. </div>
  155. </el-card>
  156. </el-col>
  157. <el-col :span="6">
  158. <el-card class="stat-card" shadow="never">
  159. <div class="flex flex-col">
  160. <div class="flex justify-between items-center text-gray-400">
  161. <span>工单数量</span>
  162. <Icon icon="ep:menu" class="text-[32px] text-blue-400" />
  163. </div>
  164. <el-divider />
  165. <div class="flex justify-between items-center mb-1">
  166. <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
  167. >总数量</span
  168. >
  169. <span class="text-gray-500 text-base font-medium" style="font-size: 14px"
  170. >未完成</span
  171. >
  172. </div>
  173. <div class="flex justify-between items-center mb-1">
  174. <span class="text-3xl font-bold text-gray-700">
  175. {{ total.total }}
  176. </span>
  177. <span class="text-3xl font-bold text-gray-700">
  178. {{ total.todo }}
  179. </span>
  180. </div>
  181. </div>
  182. </el-card>
  183. </el-col>
  184. </el-row>
  185. <!-- 第二行:图表行 -->
  186. <el-row :gutter="16" class="mb-4">
  187. <el-col :span="12">
  188. <el-card class="chart-card" shadow="never">
  189. <template #header>
  190. <div class="flex items-center">
  191. <span class="text-base font-medium text-gray-600">设备状态统计</span>
  192. </div>
  193. </template>
  194. <el-row class="h-[220px]">
  195. <el-col :span="12" class="flex flex-col items-center">
  196. <div ref="writeTodayChartRef" class="h-[160px] w-full"></div>
  197. <div class="text-center mt-2" >
  198. <span class="text-sm text-gray-600" style="text-decoration: underline;color: orangered;cursor: pointer" @click="clickStatus('设备待执行')">未填写</span>
  199. </div>
  200. </el-col>
  201. <el-col :span="12" class="flex flex-col items-center">
  202. <div ref="finishedTodayChartRef" class="h-[160px] w-full"></div>
  203. <div class="text-center mt-2">
  204. <span class="text-sm text-gray-600" style="text-decoration: underline;color: dodgerblue;cursor: pointer" @click="clickStatus('设备已执行')">已填写</span>
  205. </div>
  206. </el-col>
  207. </el-row>
  208. </el-card>
  209. </el-col>
  210. <el-col :span="12">
  211. <el-card class="chart-card" shadow="never">
  212. <template #header>
  213. <div class="flex items-center">
  214. <span class="text-base font-medium text-gray-600">工单状态统计</span>
  215. </div>
  216. </template>
  217. <el-row class="h-[220px]">
  218. <el-col :span="12" class="flex flex-col items-center">
  219. <div ref="writeChartRef" class="h-[160px] w-full"></div>
  220. <div class="text-center mt-2">
  221. <span class="text-sm text-gray-600" style="text-decoration: underline;color: orangered;cursor: pointer" @click="clickStatus('工单待执行')">待执行</span>
  222. </div>
  223. </el-col>
  224. <el-col :span="12" class="flex flex-col items-center">
  225. <div ref="finishedChartRef" class="h-[160px] w-full"></div>
  226. <div class="text-center mt-2">
  227. <span class="text-sm text-gray-600" style="text-decoration: underline;color: dodgerblue;cursor: pointer" @click="clickStatus('工单已执行')">已执行</span>
  228. </div>
  229. </el-col>
  230. </el-row>
  231. </el-card>
  232. </el-col>
  233. </el-row>
  234. <!-- 第三行:消息统计行 -->
  235. <el-row>
  236. <el-col :span="24">
  237. <el-card class="chart-card" shadow="never">
  238. <template #header>
  239. <div class="flex items-center justify-between">
  240. <span class="text-base font-medium text-gray-600">近一年数量统计</span>
  241. </div>
  242. </template>
  243. <div ref="chartContainer" class="h-[300px]"></div>
  244. </el-card>
  245. </el-col>
  246. </el-row>
  247. <!-- TODO 第四行:地图 -->
  248. </template>
  249. <script setup lang="ts" name="Index">
  250. import * as echarts from 'echarts/core'
  251. import { BarChart } from 'echarts/charts'; // 显式导入柱状图模块
  252. import {
  253. GridComponent,
  254. LegendComponent,
  255. TitleComponent,
  256. ToolboxComponent,
  257. TooltipComponent
  258. } from 'echarts/components'
  259. import { GaugeChart, LineChart, PieChart } from 'echarts/charts'
  260. import { LabelLayout, UniversalTransition } from 'echarts/features'
  261. import { CanvasRenderer } from 'echarts/renderers'
  262. import {
  263. IotStatisticsDeviceMessageSummaryRespVO,
  264. IotStatisticsSummaryRespVO
  265. } from '@/api/iot/statistics'
  266. const { currentRoute, push } = useRouter()
  267. import { formatDate } from '@/utils/formatTime'
  268. import { IotStatApi } from '@/api/pms/stat'
  269. import {defaultProps, handleTree} from "@/utils/tree";
  270. import {ref} from "vue";
  271. import {DeptTreeItem} from "@/api/system/dept";
  272. import * as DeptApi from "@/api/system/dept";
  273. import {useUserStore} from "@/store/modules/user";
  274. // TODO @super:参考下 /Users/yunai/Java/yudao-ui-admin-vue3/src/views/mall/home/index.vue,拆一拆组件
  275. /** IoT 首页 */
  276. defineOptions({ name: 'IotInspectStat' })
  277. // TODO @super:使用下 Echart 组件,参考 yudao-ui-admin-vue3/src/views/mall/home/components/TradeTrendCard.vue 等
  278. echarts.use([
  279. TooltipComponent,
  280. LegendComponent,
  281. PieChart,
  282. CanvasRenderer,
  283. LabelLayout,
  284. TitleComponent,
  285. ToolboxComponent,
  286. GridComponent,
  287. LineChart,
  288. UniversalTransition,
  289. GaugeChart,
  290. BarChart
  291. ])
  292. const timeRange = ref('7d') // 修改默认选择为近一周
  293. const dateRange = ref<[Date, Date] | null>(null)
  294. const deptList = ref<DeptTreeItem[]>([]) // 树形结构部门列表
  295. const queryParams = reactive({
  296. deptId: undefined,
  297. createTime: undefined,
  298. startTime: Date.now() - 7 * 24 * 60 * 60 * 1000, // 设置默认开始时间为 7 天前
  299. endTime: Date.now() // 设置默认结束时间为当前时间
  300. })
  301. // const deviceCountChartRef = ref() // 设备数量统计的图表
  302. const reportingChartRef = ref() // 在线设备统计的图表
  303. const dealFinishedChartRef = ref() // 离线设备统计的图表
  304. const transOrderChartRef = ref() // 待激活设备统计的图表
  305. const orderFinishChartRef = ref()
  306. const deviceMessageCountChartRef = ref() // 上下行消息量统计的图表
  307. const writeChartRef = ref() // 上下行消息量统计的图表
  308. const finishedChartRef = ref() // 上下行消息量统计的图表
  309. const writeTodayChartRef = ref() // 上下行消息量统计的图表
  310. const finishedTodayChartRef = ref() // 上下行消息量统计的图表
  311. // 基础统计数据
  312. // TODO @super:初始为 -1,然后界面展示先是加载中?试试用 cursor 改哈
  313. const statsData = ref<IotStatisticsSummaryRespVO>({
  314. productCategoryCount: 0,
  315. productCount: 0,
  316. deviceCount: 0,
  317. deviceMessageCount: 0,
  318. productCategoryTodayCount: 0,
  319. productTodayCount: 0,
  320. deviceTodayCount: 0,
  321. deviceMessageTodayCount: 0,
  322. deviceOnlineCount: 0,
  323. deviceOfflineCount: 0,
  324. deviceInactiveCount: 0,
  325. productCategoryDeviceCounts: {}
  326. })
  327. const handleQuery = () => {
  328. getStats()
  329. // initChart()
  330. // initCharts()
  331. }
  332. const resetQuery = () => {
  333. // 重置查询参数
  334. queryParams.startTime = Date.now() - 7 * 24 * 60 * 60 * 1000
  335. queryParams.endTime = Date.now()
  336. queryParams.deptId = useUserStore().getUser.deptId;
  337. queryParams.createTime = null
  338. // 重新获取数据
  339. getStats()
  340. }
  341. const clickStatus = (type) => {
  342. let status = '';
  343. const createTime = queryParams.createTime;
  344. const deptId = queryParams.deptId;
  345. debugger
  346. if (type === '工单待执行') {
  347. status = 'todo'
  348. push({ name: 'IotInspectOrdere', params:{deptId,status,createTime}})
  349. } else if (type === '工单已执行') {
  350. status = 'finished'
  351. push({name: 'IotInspectOrdere', params:{deptId,status,createTime}})
  352. } else if (type==='设备待执行') {
  353. status = 'todo'
  354. debugger
  355. push({name:'IotInspectOrderDetailStat', params:{deptId,status,createTime}})
  356. } else if (type==='设备已执行'){
  357. status = 'finished'
  358. push({name:'IotInspectOrderDetailStat', params:{deptId,status,createTime}})
  359. }
  360. }
  361. const day = ref({
  362. total: undefined,
  363. todo: undefined
  364. })
  365. const week = ref({
  366. total: undefined,
  367. todo: undefined
  368. })
  369. const month = ref({
  370. total: undefined,
  371. todo: undefined
  372. })
  373. const total = ref({
  374. total: undefined,
  375. todo: undefined
  376. })
  377. const status = ref({
  378. finished: 0,
  379. todo: 0
  380. })
  381. const todayStatus = ref({
  382. finished: 0,
  383. todo: 0
  384. })
  385. // 消息统计数据
  386. const messageStats = ref<IotStatisticsDeviceMessageSummaryRespVO>({
  387. upstreamCounts: {},
  388. downstreamCounts: {}
  389. })
  390. /** 处理快捷时间范围选择 */
  391. const handleTimeRangeChange = (timeRange: string) => {
  392. const now = Date.now()
  393. let startTime: number
  394. // TODO @super:这个的计算,看看能不能结合 dayjs 简化。因为 1h、24h、7d 感觉是比较标准的。如果没有,抽到 utils/formatTime.ts 作为一个工具方法
  395. switch (timeRange) {
  396. case '1h':
  397. startTime = now - 60 * 60 * 1000
  398. break
  399. case '24h':
  400. startTime = now - 24 * 60 * 60 * 1000
  401. break
  402. case '7d':
  403. startTime = now - 7 * 24 * 60 * 60 * 1000
  404. break
  405. default:
  406. return
  407. }
  408. // 清空日期选择器
  409. dateRange.value = null
  410. // 更新查询参数
  411. queryParams.startTime = startTime
  412. queryParams.endTime = now
  413. // 重新获取数据
  414. getStats()
  415. }
  416. /** 处理自定义日期范围选择 */
  417. const handleDateRangeChange = (value: [Date, Date] | null) => {
  418. if (value) {
  419. // 清空快捷选项
  420. timeRange.value = ''
  421. // 更新查询参数
  422. queryParams.startTime = value[0].getTime()
  423. queryParams.endTime = value[1].getTime()
  424. // 重新获取数据
  425. getStats()
  426. }
  427. }
  428. /** 获取统计数据 */
  429. const getStats = async () => {
  430. // 获取基础统计数据
  431. IotStatApi.getInspectDay().then((res) => {
  432. day.value = res
  433. })
  434. IotStatApi.getInspectWeek().then((res) => {
  435. week.value = res
  436. })
  437. IotStatApi.getInspectMonth().then((res) => {
  438. month.value = res
  439. })
  440. IotStatApi.getInspectTotal().then((res) => {
  441. total.value = res
  442. })
  443. IotStatApi.getInspectStatus(queryParams).then((res) => {
  444. status.value = res
  445. initChart()
  446. initCharts()
  447. })
  448. IotStatApi.getInspectDeviceStatus(queryParams).then((res) => {
  449. todayStatus.value = res
  450. initChart()
  451. initCharts()
  452. })
  453. // statsData.value = await ProductCategoryApi.getIotStatisticsSummary()
  454. //
  455. // // 获取消息统计数据
  456. // messageStats.value = await ProductCategoryApi.getIotStatisticsDeviceMessageSummary(queryParams)
  457. // 初始化图表
  458. }
  459. /** 初始化图表 */
  460. const initCharts = () => {
  461. //待执行
  462. initGaugeChart(
  463. writeTodayChartRef.value,
  464. todayStatus.value.todo === undefined ? 0 : todayStatus.value.todo,
  465. '#f50',
  466. '设备待执行'
  467. )
  468. //已执行
  469. initGaugeChart(
  470. finishedTodayChartRef.value,
  471. todayStatus.value.finished === undefined ? 0 : todayStatus.value.finished,
  472. '#05b',
  473. '设备已执行'
  474. )
  475. // 工单待执行
  476. initGaugeChart(
  477. writeChartRef.value,
  478. status.value.todo === undefined ? 0 : status.value.todo,
  479. '#f50',
  480. '工单待执行'
  481. )
  482. //工单已执行
  483. initGaugeChart(
  484. finishedChartRef.value,
  485. status.value.finished === undefined ? 0 : status.value.finished,
  486. '#05b',
  487. '工单已执行'
  488. )
  489. // 消息量统计
  490. //initMessageChart()
  491. }
  492. /** 初始化仪表盘图表 */
  493. const initGaugeChart = (el: any, value: number, color: string, type: string) => {
  494. const chart = echarts.init(el);
  495. chart.setOption({
  496. series: [
  497. {
  498. type: 'gauge',
  499. startAngle: 360,
  500. endAngle: 0,
  501. min: 0,
  502. max: value, // 使用设备总数作为最大值
  503. progress: {
  504. show: true,
  505. width: 25,
  506. itemStyle: {
  507. color: color
  508. }
  509. },
  510. axisLine: {
  511. lineStyle: {
  512. width: 25,
  513. color: [[1, '#E5E7EB']]
  514. }
  515. },
  516. axisTick: { show: false },
  517. splitLine: { show: false },
  518. axisLabel: { show: false },
  519. pointer: { show: false },
  520. anchor: { show: false },
  521. title: { show: false },
  522. detail: {
  523. valueAnimation: true,
  524. fontSize: 20,
  525. fontWeight: 'bold',
  526. fontFamily: 'Inter, sans-serif',
  527. color: color,
  528. offsetCenter: [0, '0'],
  529. formatter: (value: number) => {
  530. return `${value} `
  531. }
  532. },
  533. data: [{ value: value, type: type }]
  534. }
  535. ]
  536. });
  537. // 添加点击事件监听器
  538. chart.on('click', (params) => {
  539. console.log('点击的数据值为:', params.value);
  540. console.log('点击的数据类型为:', params.data.type);
  541. const createTime = queryParams.createTime;
  542. const deptId = queryParams.deptId;
  543. let status = '';
  544. if (params.data.type === '工单待执行') {
  545. status = 'todo'
  546. push({ name: 'IotInspectOrdere', params:{deptId,status,createTime}})
  547. } else if (params.data.type === '工单已执行') {
  548. status = 'finished'
  549. push({name: 'IotInspectOrdere', params:{deptId,status,createTime}})
  550. } else if (params.data.type==='设备待执行') {
  551. status = 'todo'
  552. push({name:'IotInspectOrderDetailStat', params:{deptId,status,createTime}})
  553. } else if (params.data.type==='设备已执行'){
  554. status = 'finished'
  555. push({name:'IotInspectOrderDetailStat', params:{deptId,status,createTime}})
  556. }
  557. });
  558. }
  559. /** 初始化消息统计图表 */
  560. const initMessageChart = () => {
  561. // 获取所有时间戳并排序
  562. // TODO @super:一些 idea 里的红色报错,要去处理掉噢。
  563. const timestamps = Array.from(
  564. new Set([
  565. ...messageStats.value.upstreamCounts.map((item) => Number(Object.keys(item)[0])),
  566. ...messageStats.value.downstreamCounts.map((item) => Number(Object.keys(item)[0]))
  567. ])
  568. ).sort((a, b) => a - b) // 确保时间戳从小到大排序
  569. // 准备数据
  570. const xdata = timestamps.map((ts) => formatDate(ts, 'YYYY-MM-DD HH:mm'))
  571. const upData = timestamps.map((ts) => {
  572. const item = messageStats.value.upstreamCounts.find(
  573. (count) => Number(Object.keys(count)[0]) === ts
  574. )
  575. return item ? Object.values(item)[0] : 0
  576. })
  577. const downData = timestamps.map((ts) => {
  578. const item = messageStats.value.downstreamCounts.find(
  579. (count) => Number(Object.keys(count)[0]) === ts
  580. )
  581. return item ? Object.values(item)[0] : 0
  582. })
  583. // 配置图表
  584. echarts.init(deviceMessageCountChartRef.value).setOption({
  585. tooltip: {
  586. trigger: 'axis',
  587. backgroundColor: 'rgba(255, 255, 255, 0.9)',
  588. borderColor: '#E5E7EB',
  589. textStyle: {
  590. color: '#374151'
  591. }
  592. },
  593. legend: {
  594. data: ['上行消息量', '下行消息量'],
  595. textStyle: {
  596. color: '#374151',
  597. fontWeight: 500
  598. }
  599. },
  600. grid: {
  601. left: '3%',
  602. right: '4%',
  603. bottom: '3%',
  604. containLabel: true
  605. },
  606. xAxis: {
  607. type: 'category',
  608. boundaryGap: false,
  609. data: xdata,
  610. axisLine: {
  611. lineStyle: {
  612. color: '#E5E7EB'
  613. }
  614. },
  615. axisLabel: {
  616. color: '#6B7280'
  617. }
  618. },
  619. yAxis: {
  620. type: 'value',
  621. axisLine: {
  622. lineStyle: {
  623. color: '#E5E7EB'
  624. }
  625. },
  626. axisLabel: {
  627. color: '#6B7280'
  628. },
  629. splitLine: {
  630. lineStyle: {
  631. color: '#F3F4F6'
  632. }
  633. }
  634. },
  635. series: [
  636. {
  637. name: '上行消息量',
  638. type: 'line',
  639. smooth: true, // 添加平滑曲线
  640. data: upData,
  641. itemStyle: {
  642. color: '#3B82F6'
  643. },
  644. lineStyle: {
  645. width: 2
  646. },
  647. areaStyle: {
  648. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  649. { offset: 0, color: 'rgba(59, 130, 246, 0.2)' },
  650. { offset: 1, color: 'rgba(59, 130, 246, 0)' }
  651. ])
  652. }
  653. },
  654. {
  655. name: '下行消息量',
  656. type: 'line',
  657. smooth: true, // 添加平滑曲线
  658. data: downData,
  659. itemStyle: {
  660. color: '#10B981'
  661. },
  662. lineStyle: {
  663. width: 2
  664. },
  665. areaStyle: {
  666. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  667. { offset: 0, color: 'rgba(16, 185, 129, 0.2)' },
  668. { offset: 1, color: 'rgba(16, 185, 129, 0)' }
  669. ])
  670. }
  671. }
  672. ]
  673. })
  674. }
  675. const chartContainer = ref(null)
  676. let chartInstance = null
  677. // 生成过去12个月份的标签 (格式: YYYY-MM)
  678. const generateMonthLabels = () => {
  679. const months = []
  680. const date = new Date()
  681. for (let i = 11; i >= 0; i--) {
  682. const tempDate = new Date(date.getFullYear(), date.getMonth() - i, 1)
  683. const year = tempDate.getFullYear()
  684. const month = String(tempDate.getMonth() + 1).padStart(2, '0')
  685. months.push(`${year}-${month}`)
  686. }
  687. return months
  688. }
  689. // 模拟数据获取
  690. const fetchChartData = async () => {
  691. // 模拟异步请求
  692. return new Promise((resolve) => {
  693. setTimeout(() => {
  694. resolve({
  695. months: generateMonthLabels(),
  696. faults: [20,30,100,40,20,50,70,80,60,90,100,100],
  697. repairs: [10,30,90,30,10,20,60,50,22,34,70,85],
  698. })
  699. }, 300)
  700. })
  701. }
  702. // 初始化图表配置
  703. const initChart = async () => {
  704. if (!chartContainer.value) return
  705. // 获取数据
  706. const { months, faults, repairs } = await fetchChartData()
  707. // ECharts配置
  708. const option = {
  709. tooltip: {
  710. trigger: 'axis',
  711. axisPointer: {
  712. type: 'shadow'
  713. },
  714. formatter: (params) => {
  715. return `${params[0].axisValue}<br/>
  716. ${params[0].marker} ${params[0].seriesName}: ${params[0].value}`
  717. }
  718. },
  719. legend: {
  720. data: ['巡检工单数量'],
  721. top: 25
  722. },
  723. grid: {
  724. left: '3%',
  725. right: '4%',
  726. bottom: '3%',
  727. containLabel: true
  728. },
  729. xAxis: {
  730. type: 'category',
  731. data: months,
  732. axisLabel: {
  733. rotate: 45,
  734. margin: 15
  735. }
  736. },
  737. yAxis: {
  738. type: 'value',
  739. axisLabel: {
  740. formatter: (value) => Math.floor(value).toString()
  741. }
  742. },
  743. series: [
  744. {
  745. name: '巡检工单数量',
  746. type: 'bar',
  747. itemStyle: {
  748. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  749. { offset: 0, color: '#2196df' },
  750. { offset: 1, color: '#2196df' }
  751. ])
  752. },
  753. emphasis: {
  754. focus: 'series'
  755. },
  756. data: repairs
  757. }
  758. ]
  759. }
  760. // 初始化图表
  761. chartInstance = echarts.init(chartContainer.value)
  762. chartInstance.setOption(option)
  763. // 窗口缩放监听
  764. window.addEventListener('resize', handleResize)
  765. handleResize()
  766. }
  767. // 自适应调整
  768. const handleResize = () => {
  769. chartInstance?.resize()
  770. }
  771. /** 初始化 */
  772. onMounted(async () => {
  773. deptList.value = handleTree(await DeptApi.getSimpleDeptList())
  774. queryParams.deptId = useUserStore().getUser.deptId;
  775. await getStats()
  776. // await initChart()
  777. // await initCharts()
  778. })
  779. onUnmounted(() => {
  780. chartInstance?.dispose()
  781. window.removeEventListener('resize', handleResize)
  782. })
  783. </script>
  784. <style lang="scss" scoped>
  785. </style>