Index.vue 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  1. <template>
  2. <!-- 第一行:统计卡片行 -->
  3. <div class="page-container">
  4. <el-row :gutter="16" class="summary">
  5. <!-- 原有的统计卡片部分保持不变 -->
  6. <el-col :sm="3" :xs="12">
  7. <SummaryCard
  8. :value="device.total || 0"
  9. icon="fa-solid:project-diagram"
  10. icon-bg-color="text-blue-500"
  11. icon-color="bg-blue-100"
  12. :title="t('stat.deviceCount')"
  13. />
  14. </el-col>
  15. <el-col :sm="3" :xs="12">
  16. <SummaryCard
  17. :value="maintain.total || 0"
  18. icon="fa-solid:list"
  19. icon-bg-color="text-pink-500"
  20. icon-color="bg-blue-100"
  21. :title="t('stat.maintenanceOrder')"
  22. />
  23. </el-col>
  24. <el-col :sm="3" :xs="12">
  25. <SummaryCard
  26. :value="fill.unfilledCount || 0"
  27. icon="fa-solid:times-circle"
  28. icon-bg-color="text-purple-500"
  29. icon-color="bg-purple-100"
  30. :title="t('stat.operationNotFilled')"
  31. />
  32. </el-col>
  33. <el-col :sm="3" :xs="12">
  34. <SummaryCard
  35. :value="fill.filledCount || 0"
  36. icon="fa-solid:award"
  37. icon-bg-color="text-purple-500"
  38. icon-color="bg-purple-100"
  39. :title="t('stat.operationFilled')"
  40. />
  41. </el-col>
  42. <el-col :sm="3" :xs="12">
  43. <SummaryCard
  44. :value="by.todo || 0"
  45. icon="fa-solid:times-circle"
  46. icon-bg-color="text-green-500"
  47. icon-color="bg-green-100"
  48. :title="t('stat.notMaintained')"
  49. />
  50. </el-col>
  51. <el-col :sm="3" :xs="12">
  52. <SummaryCard
  53. :value="by.finished || 0"
  54. icon="fa-solid:award"
  55. icon-bg-color="text-green-500"
  56. icon-color="bg-green-100"
  57. :title="t('stat.maintained')"
  58. />
  59. </el-col>
  60. <el-col :sm="3" :xs="12">
  61. <SummaryCard
  62. :value="inspectt.todo || 0"
  63. icon="fa-solid:times-circle"
  64. icon-bg-color="text-yellow-500"
  65. icon-color="bg-yellow-100"
  66. :title="t('stat.notInspected')"
  67. />
  68. </el-col>
  69. <el-col :sm="3" :xs="12">
  70. <SummaryCard
  71. :value="inspectt.finished || 0"
  72. icon="fa-solid:award"
  73. icon-bg-color="text-yellow-500"
  74. icon-color="bg-yellow-100"
  75. :title="t('stat.inspected')"
  76. />
  77. </el-col>
  78. <!-- 其他统计卡片... -->
  79. </el-row>
  80. <!-- <el-row :gutter="16" class="mb-4">-->
  81. <!-- <el-col :span="6">-->
  82. <!-- <el-card class="stat-card" shadow="never">-->
  83. <!-- <div class="flex flex-col">-->
  84. <!-- <div class="flex justify-between items-center mb-1">-->
  85. <!-- <span class="text-gray-500 text-base font-medium">设备数量</span>-->
  86. <!-- <Icon icon="ep:menu" class="text-[32px] text-blue-400" />-->
  87. <!-- </div>-->
  88. <!-- <span class="text-3xl font-bold text-gray-700">-->
  89. <!-- {{ device.total }}-->
  90. <!-- </span>-->
  91. <!-- <el-divider class="my-2" />-->
  92. <!-- <div class="flex justify-between items-center text-gray-400 text-sm">-->
  93. <!-- <span>今日新增</span>-->
  94. <!-- <span class="text-green-500">+{{ device.today }}</span>-->
  95. <!-- </div>-->
  96. <!-- </div>-->
  97. <!-- </el-card>-->
  98. <!-- </el-col>-->
  99. <!-- <el-col :span="6">-->
  100. <!-- <el-card class="stat-card" shadow="never">-->
  101. <!-- <div class="flex flex-col">-->
  102. <!-- <div class="flex justify-between items-center mb-1">-->
  103. <!-- <span class="text-gray-500 text-base font-medium">维修工单数量</span>-->
  104. <!-- <Icon icon="ep:box" class="text-[32px] text-orange-400" />-->
  105. <!-- </div>-->
  106. <!-- <span class="text-3xl font-bold text-gray-700">{{ maintain.total }}</span>-->
  107. <!-- <el-divider class="my-2" />-->
  108. <!-- <div class="flex justify-between items-center text-gray-400 text-sm">-->
  109. <!-- <span>今日新增</span>-->
  110. <!-- <span class="text-green-500">+{{ maintain.today }}</span>-->
  111. <!-- </div>-->
  112. <!-- </div>-->
  113. <!-- </el-card>-->
  114. <!-- </el-col>-->
  115. <!-- <el-col :span="6">-->
  116. <!-- <el-card class="stat-card" shadow="never">-->
  117. <!-- <div class="flex flex-col">-->
  118. <!-- <div class="flex justify-between items-center mb-1">-->
  119. <!-- <span class="text-gray-500 text-base font-medium">保养工单数量</span>-->
  120. <!-- <Icon icon="ep:cpu" class="text-[32px] text-purple-400" />-->
  121. <!-- </div>-->
  122. <!-- <span class="text-3xl font-bold text-gray-700">{{ work.total }}</span>-->
  123. <!-- <el-divider class="my-2" />-->
  124. <!-- <div class="flex justify-between items-center text-gray-400 text-sm">-->
  125. <!-- <span>今日新增</span>-->
  126. <!-- <span class="text-green-500">+{{ work.today }}</span>-->
  127. <!-- </div>-->
  128. <!-- </div>-->
  129. <!-- </el-card>-->
  130. <!-- </el-col>-->
  131. <!-- <el-col :span="6">-->
  132. <!-- <el-card class="stat-card" shadow="never">-->
  133. <!-- <div class="flex flex-col">-->
  134. <!-- <div class="flex justify-between items-center mb-1">-->
  135. <!-- <span class="text-gray-500 text-base font-medium">巡检工单数量</span>-->
  136. <!-- <Icon icon="ep:camera" class="text-[32px] text-teal-400" />-->
  137. <!-- </div>-->
  138. <!-- <span class="text-3xl font-bold text-gray-700">-->
  139. <!-- {{ inspect.total }}-->
  140. <!-- </span>-->
  141. <!-- <el-divider class="my-2" />-->
  142. <!-- <div class="flex justify-between items-center text-gray-400 text-sm">-->
  143. <!-- <span>今日新增</span>-->
  144. <!-- <span class="text-green-500">+{{ inspect.today }}</span>-->
  145. <!-- </div>-->
  146. <!-- </div>-->
  147. <!-- </el-card>-->
  148. <!-- </el-col>-->
  149. <!-- </el-row>-->
  150. <!-- 第二行:图表行 -->
  151. <el-row :gutter="16" class="mb-4">
  152. <el-col :span="6">
  153. <el-card class="chart-card" shadow="never">
  154. <template #header>
  155. <div class="flex items-center justify-between">
  156. <span class="text-base font-medium " style="color: #b6c8da">{{t('stat.mttr')}}</span>
  157. <span class="text-base font-medium " style="color: #b6c8da">{{t('stat.materialsUnderInventory')}}</span>
  158. </div>
  159. </template>
  160. <div class="flex flex-col h-[250px]">
  161. <!-- <div class="flex justify-between items-center text-gray-400">-->
  162. <!-- <span>MTTR</span>-->
  163. <!-- </div>-->
  164. <!-- <el-divider />-->
  165. <div class="flex justify-between items-center mb-1 mt-15">
  166. <!-- <span class="text-gray-500 text-base font-medium">平均解决时间</span>-->
  167. <!-- <Icon icon="ep:menu" class="text-[32px] text-blue-400" />-->
  168. <span class="text-5xl font-bold text-gray-700" style="color: lightseagreen">
  169. {{ mttr+'h' }}
  170. </span>
  171. <span class="text-5xl font-bold text-gray-700" style="color: indianred">
  172. {{ safe }}
  173. </span>
  174. </div>
  175. </div>
  176. </el-card>
  177. </el-col>
  178. <el-col :span="9">
  179. <el-card class="chart-card" shadow="never">
  180. <template #header>
  181. <div class="flex items-center">
  182. <span class="text-base font-medium " style="color: #b6c8da">{{t('stat.deviceStatus')}}</span>
  183. </div>
  184. </template>
  185. <div ref="statusChartRef" class="h-[250px]"></div>
  186. </el-card>
  187. </el-col>
  188. <el-col :span="9">
  189. <el-card class="chart-card" shadow="never">
  190. <template #header>
  191. <div class="flex items-center">
  192. <span class="text-base font-medium " style="color: #b6c8da">{{t('stat.deviceClassifyTop5')}}</span>
  193. </div>
  194. </template>
  195. <div ref="topContainer" class="h-[250px]"></div>
  196. </el-card>
  197. </el-col>
  198. </el-row>
  199. <!-- 第三行:消息统计行 -->
  200. <el-row :gutter="16" class="mb-4">
  201. <el-col :span="6">
  202. <el-card class="chart-card" shadow="never">
  203. <template #header>
  204. <div class="flex items-center justify-between">
  205. <span class="text-base font-medium " style="color: #b6c8da">{{t('stat.lastWeekActivity')}}</span>
  206. </div>
  207. </template>
  208. <div ref="activeDom" class="h-[320px]"></div>
  209. </el-card>
  210. </el-col>
  211. <el-col :span="18">
  212. <el-card class="chart-card" shadow="never">
  213. <template #header>
  214. <div class="flex items-center justify-between">
  215. <span class="text-base font-medium" style="color: #b6c8da">{{t('stat.orderCount')}}</span>
  216. </div>
  217. </template>
  218. <div ref="qxRef" class="h-[320px]"></div>
  219. </el-card>
  220. </el-col>
  221. </el-row>
  222. </div>
  223. </template>
  224. <script setup lang="ts" name="Index">
  225. import * as echarts from 'echarts/core'
  226. import { BarChart, GaugeChart, LineChart, PieChart } from 'echarts/charts' // 显式导入柱状图模块
  227. import {
  228. GridComponent,
  229. LegendComponent,
  230. TitleComponent,
  231. ToolboxComponent,
  232. TooltipComponent
  233. } from 'echarts/components'
  234. import { LabelLayout, UniversalTransition } from 'echarts/features'
  235. import { CanvasRenderer } from 'echarts/renderers'
  236. import { useElementSize } from '@vueuse/core'
  237. import {
  238. IotStatisticsDeviceMessageSummaryRespVO,
  239. IotStatisticsSummaryRespVO
  240. } from '@/api/iot/statistics'
  241. import { formatDate } from '@/utils/formatTime'
  242. import { IotStatApi } from '@/api/pms/stat'
  243. import SummaryCard from "@/components/SummaryCard/index.vue";
  244. import {reactive, ref} from "vue";
  245. import { useLocaleStore } from '@/store/modules/locale'
  246. // TODO @super:参考下 /Users/yunai/Java/yudao-ui-admin-vue3/src/views/mall/home/index.vue,拆一拆组件
  247. /** IoT 首页 */
  248. defineOptions({ name: 'IoTHome' })
  249. // TODO @super:使用下 Echart 组件,参考 yudao-ui-admin-vue3/src/views/mall/home/components/TradeTrendCard.vue 等
  250. echarts.use([
  251. TooltipComponent,
  252. LegendComponent,
  253. PieChart,
  254. CanvasRenderer,
  255. LabelLayout,
  256. TitleComponent,
  257. ToolboxComponent,
  258. GridComponent,
  259. LineChart,
  260. UniversalTransition,
  261. GaugeChart,
  262. BarChart
  263. ])
  264. const timeRange = ref('7d') // 修改默认选择为近一周
  265. const dateRange = ref<[Date, Date] | null>(null)
  266. const queryParams = reactive({
  267. startTime: Date.now() - 7 * 24 * 60 * 60 * 1000, // 设置默认开始时间为 7 天前
  268. endTime: Date.now() // 设置默认结束时间为当前时间
  269. })
  270. const backendData = ref([])
  271. const statusChartRef = ref() // 设备数量统计的图表
  272. const deviceMessageCountChartRef = ref() // 上下行消息量统计的图表
  273. const { t } = useI18n() // 国际化
  274. // 基础统计数据
  275. // TODO @super:初始为 -1,然后界面展示先是加载中?试试用 cursor 改哈
  276. const statsData = ref<IotStatisticsSummaryRespVO>({
  277. productCategoryCount: 0,
  278. productCount: 0,
  279. deviceCount: 0,
  280. deviceMessageCount: 0,
  281. productCategoryTodayCount: 0,
  282. productTodayCount: 0,
  283. deviceTodayCount: 0,
  284. deviceMessageTodayCount: 0,
  285. deviceOnlineCount: 0,
  286. deviceOfflineCount: 0,
  287. deviceInactiveCount: 0,
  288. productCategoryDeviceCounts: {}
  289. })
  290. const orderSevenData = ref({})
  291. const by = ref({
  292. todo: undefined,
  293. finished: undefined
  294. })
  295. const fill = ref({
  296. filledCount: undefined,
  297. unfilledCount: undefined
  298. })
  299. const inspectt = ref({
  300. finished: 0,
  301. todo: 0
  302. })
  303. const device = ref({
  304. total: undefined,
  305. today: undefined
  306. })
  307. const maintain = ref({
  308. total: undefined,
  309. today: undefined
  310. })
  311. const work = ref({
  312. total: undefined,
  313. today: undefined
  314. })
  315. const inspect = ref({
  316. total: undefined,
  317. today: undefined
  318. })
  319. const status = ref({
  320. finished: 0,
  321. todo: 0
  322. })
  323. const todayStatus = ref({
  324. finished: 0,
  325. todo: 0
  326. })
  327. const typeData = ref({})
  328. // 消息统计数据
  329. const messageStats = ref<IotStatisticsDeviceMessageSummaryRespVO>({
  330. upstreamCounts: {},
  331. downstreamCounts: {}
  332. })
  333. const mttr = ref(0)
  334. const safe = ref()
  335. /** 获取统计数据 */
  336. const getStats = async () => {
  337. // 获取基础统计数据
  338. IotStatApi.getDeviceCount().then((res) => {
  339. device.value = res
  340. })
  341. IotStatApi.getMaintainCount().then((res) => {
  342. maintain.value = res
  343. })
  344. IotStatApi.getMainWorkCount().then((res) => {
  345. work.value = res
  346. })
  347. IotStatApi.getInspectCount().then((res) => {
  348. inspect.value = res
  349. })
  350. IotStatApi.getMaintenanceStatus().then((res) => {
  351. status.value = res
  352. initCharts()
  353. })
  354. IotStatApi.getMaintenanceTodayStatus().then((res) => {
  355. todayStatus.value = res
  356. initCharts()
  357. })
  358. IotStatApi.getDeviceStatusCount().then((res) => {
  359. typeData.value = res
  360. initCharts()
  361. })
  362. IotStatApi.getSafeCount().then((res) => {
  363. safe.value = res
  364. })
  365. IotStatApi.getMttr().then((res) => {
  366. mttr.value = res
  367. })
  368. IotStatApi.getOrderSeven('156').then((res) => {
  369. orderSevenData.value = res
  370. initQxChart()
  371. })
  372. IotStatApi.getMaintenanceStatus().then((res) => {
  373. by.value = res
  374. })
  375. const fillQueryParams = reactive({
  376. startTime: Date.now() - 7 * 24 * 60 * 60 * 1000, // 设置默认开始时间为 7 天前
  377. endTime: Date.now(), // 设置默认结束时间为当前时间
  378. createTime: [],
  379. deptId: null, // 选中的部门ID
  380. status: null // 填写状态
  381. })
  382. IotStatApi.getInspectStatuss(fillQueryParams, '156').then((res) => {
  383. inspectt.value = res
  384. })
  385. fillQueryParams.deptId = '156'
  386. IotStatApi.getDeptStatistics(fillQueryParams).then((res) => {
  387. fill.value = res.totalList[0] || []
  388. })
  389. }
  390. /** 初始化图表 */
  391. const initCharts = () => {
  392. // 设备数量统计
  393. echarts.init(statusChartRef.value).setOption({
  394. tooltip: {
  395. trigger: 'item'
  396. },
  397. legend: {
  398. top: '5%',
  399. right: '10%',
  400. align: 'left',
  401. orient: 'vertical',
  402. icon: 'circle',
  403. textStyle: {
  404. color: 'white'
  405. }
  406. },
  407. series: [
  408. {
  409. name: '',
  410. type: 'pie',
  411. radius: ['50%', '80%'],
  412. avoidLabelOverlap: false,
  413. center: ['30%', '50%'],
  414. label: {
  415. show: false,
  416. position: 'outside',
  417. color: 'white'
  418. },
  419. emphasis: {
  420. label: {
  421. show: true,
  422. fontSize: 20,
  423. fontWeight: 'bold'
  424. }
  425. },
  426. labelLine: {
  427. show: false
  428. },
  429. data: typeData.value
  430. }
  431. ]
  432. })
  433. //待执行
  434. // initGaugeChart(
  435. // writeTodayChartRef.value,
  436. // todayStatus.value.todo === undefined ? 0 : todayStatus.value.todo,
  437. // '#05b'
  438. // )
  439. // //已执行
  440. // initGaugeChart(
  441. // finishedTodayChartRef.value,
  442. // todayStatus.value.finished === undefined ? 0 : todayStatus.value.finished,
  443. // '#f50'
  444. // )
  445. // // 待执行
  446. // initGaugeChart(
  447. // writeChartRef.value,
  448. // status.value.todo === undefined ? 0 : status.value.todo,
  449. // '#05b'
  450. // )
  451. // //已执行
  452. // initGaugeChart(
  453. // finishedChartRef.value,
  454. // status.value.finished === undefined ? 0 : status.value.finished,
  455. // '#f50'
  456. // )
  457. // 消息量统计
  458. //initMessageChart()
  459. }
  460. /** 初始化仪表盘图表 */
  461. const initGaugeChart = (el: any, value: number, color: string) => {
  462. echarts.init(el).setOption({
  463. series: [
  464. {
  465. type: 'gauge',
  466. startAngle: 360,
  467. endAngle: 0,
  468. min: 0,
  469. max: statsData.value.deviceCount || 100, // 使用设备总数作为最大值
  470. progress: {
  471. show: true,
  472. width: 12,
  473. itemStyle: {
  474. color: color
  475. }
  476. },
  477. axisLine: {
  478. lineStyle: {
  479. width: 12,
  480. color: [[1, '#E5E7EB']]
  481. }
  482. },
  483. axisTick: { show: false },
  484. splitLine: { show: false },
  485. axisLabel: { show: false },
  486. pointer: { show: false },
  487. anchor: { show: false },
  488. title: { show: false },
  489. detail: {
  490. valueAnimation: true,
  491. fontSize: 24,
  492. fontWeight: 'bold',
  493. fontFamily: 'Inter, sans-serif',
  494. color: color,
  495. offsetCenter: [0, '0'],
  496. formatter: (value: number) => {
  497. return `${value} `
  498. }
  499. },
  500. data: [{ value: value }]
  501. }
  502. ]
  503. })
  504. }
  505. /** 初始化消息统计图表 */
  506. const initMessageChart = () => {
  507. // 获取所有时间戳并排序
  508. // TODO @super:一些 idea 里的红色报错,要去处理掉噢。
  509. const timestamps = Array.from(
  510. new Set([
  511. ...messageStats.value.upstreamCounts.map((item) => Number(Object.keys(item)[0])),
  512. ...messageStats.value.downstreamCounts.map((item) => Number(Object.keys(item)[0]))
  513. ])
  514. ).sort((a, b) => a - b) // 确保时间戳从小到大排序
  515. // 准备数据
  516. const xdata = timestamps.map((ts) => formatDate(ts, 'YYYY-MM-DD HH:mm'))
  517. const upData = timestamps.map((ts) => {
  518. const item = messageStats.value.upstreamCounts.find(
  519. (count) => Number(Object.keys(count)[0]) === ts
  520. )
  521. return item ? Object.values(item)[0] : 0
  522. })
  523. const downData = timestamps.map((ts) => {
  524. const item = messageStats.value.downstreamCounts.find(
  525. (count) => Number(Object.keys(count)[0]) === ts
  526. )
  527. return item ? Object.values(item)[0] : 0
  528. })
  529. // 配置图表
  530. echarts.init(deviceMessageCountChartRef.value).setOption({
  531. tooltip: {
  532. trigger: 'axis',
  533. backgroundColor: 'rgba(255, 255, 255, 0.9)',
  534. borderColor: '#E5E7EB',
  535. textStyle: {
  536. color: '#374151'
  537. }
  538. },
  539. legend: {
  540. data: ['上行消息量', '下行消息量'],
  541. textStyle: {
  542. color: '#374151',
  543. fontWeight: 500
  544. }
  545. },
  546. grid: {
  547. left: '3%',
  548. right: '4%',
  549. bottom: '3%',
  550. containLabel: true
  551. },
  552. xAxis: {
  553. type: 'category',
  554. boundaryGap: false,
  555. data: xdata,
  556. axisLine: {
  557. lineStyle: {
  558. color: '#E5E7EB'
  559. }
  560. },
  561. axisLabel: {
  562. color: '#6B7280'
  563. }
  564. },
  565. yAxis: {
  566. type: 'value',
  567. axisLine: {
  568. lineStyle: {
  569. color: '#E5E7EB'
  570. }
  571. },
  572. axisLabel: {
  573. color: '#6B7280'
  574. },
  575. splitLine: {
  576. lineStyle: {
  577. color: '#F3F4F6'
  578. }
  579. }
  580. },
  581. series: [
  582. {
  583. name: '上行消息量',
  584. type: 'line',
  585. smooth: true, // 添加平滑曲线
  586. data: upData,
  587. itemStyle: {
  588. color: '#3B82F6'
  589. },
  590. lineStyle: {
  591. width: 2
  592. },
  593. areaStyle: {
  594. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  595. { offset: 0, color: 'rgba(59, 130, 246, 0.2)' },
  596. { offset: 1, color: 'rgba(59, 130, 246, 0)' }
  597. ])
  598. }
  599. },
  600. {
  601. name: '下行消息量',
  602. type: 'line',
  603. smooth: true, // 添加平滑曲线
  604. data: downData,
  605. itemStyle: {
  606. color: '#10B981'
  607. },
  608. lineStyle: {
  609. width: 2
  610. },
  611. areaStyle: {
  612. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  613. { offset: 0, color: 'rgba(16, 185, 129, 0.2)' },
  614. { offset: 1, color: 'rgba(16, 185, 129, 0)' }
  615. ])
  616. }
  617. }
  618. ]
  619. })
  620. }
  621. const chartContainer = ref(null)
  622. let chartInstance = null
  623. // 生成过去12个月份的标签 (格式: YYYY-MM)
  624. const generateMonthLabels = () => {
  625. const months = []
  626. const date = new Date()
  627. for (let i = 11; i >= 0; i--) {
  628. const tempDate = new Date(date.getFullYear(), date.getMonth() - i, 1)
  629. const year = tempDate.getFullYear()
  630. const month = String(tempDate.getMonth() + 1).padStart(2, '0')
  631. months.push(`${year}-${month}`)
  632. }
  633. return months
  634. }
  635. // 模拟数据获取
  636. const fetchChartData = async () => {
  637. // 模拟异步请求
  638. return new Promise((resolve) => {
  639. setTimeout(() => {
  640. resolve({
  641. months: generateMonthLabels(),
  642. faults: [20, 30, 100, 40, 20, 50, 70, 80, 60, 90, 100, 100],
  643. repairs: [10, 30, 90, 30, 10, 20, 60, 50, 22, 34, 70, 85]
  644. })
  645. }, 300)
  646. })
  647. }
  648. // 初始化图表配置
  649. const initChart = async () => {
  650. if (!chartContainer.value) return
  651. // 获取数据
  652. const { months, faults, repairs } = await fetchChartData()
  653. // ECharts配置
  654. const option = {
  655. tooltip: {
  656. trigger: 'axis',
  657. axisPointer: {
  658. type: 'shadow'
  659. },
  660. formatter: (params) => {
  661. return `${params[0].axisValue}<br/>
  662. ${params[0].marker} ${params[0].seriesName}: ${params[0].value}`
  663. }
  664. },
  665. legend: {
  666. data: ['保养工单数量'],
  667. top: 25
  668. },
  669. grid: {
  670. left: '3%',
  671. right: '4%',
  672. bottom: '3%',
  673. containLabel: true
  674. },
  675. xAxis: {
  676. type: 'category',
  677. data: months,
  678. axisLabel: {
  679. rotate: 45,
  680. margin: 15
  681. }
  682. },
  683. yAxis: {
  684. type: 'value',
  685. axisLabel: {
  686. formatter: (value) => Math.floor(value).toString()
  687. }
  688. },
  689. series: [
  690. {
  691. name: '保养工单数量',
  692. type: 'bar',
  693. itemStyle: {
  694. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  695. { offset: 0, color: '#2196df' },
  696. { offset: 1, color: '#2196df' }
  697. ])
  698. },
  699. emphasis: {
  700. focus: 'series'
  701. },
  702. data: repairs
  703. }
  704. ]
  705. }
  706. // 初始化图表
  707. chartInstance = echarts.init(chartContainer.value)
  708. chartInstance.setOption(option)
  709. // 窗口缩放监听
  710. window.addEventListener('resize', handleResize)
  711. handleResize()
  712. }
  713. // 自适应调整
  714. const handleResize = () => {
  715. chartInstance?.resize()
  716. }
  717. const topContainer = ref(null)
  718. let topInstance = null
  719. // 响应式容器尺寸
  720. const { width, height } = useElementSize(topContainer)
  721. // 处理数据(排序+限制5条)
  722. const processedData = () => {
  723. const data = IotStatApi.getDeviceTypeCount()
  724. backendData.value = data
  725. return [...backendData.value].sort((a, b) => a.value - b.value)
  726. }
  727. const fetchTop = () => {
  728. IotStatApi.getDeviceTypeCount().then((res) => {
  729. backendData.value = res
  730. })
  731. }
  732. // 初始化图表配置
  733. const getTopOption = () => {
  734. // backendData.value = data
  735. const data = backendData.value.sort((a, b) => a.value - b.value)
  736. return {
  737. tooltip: {
  738. trigger: 'axis',
  739. axisPointer: { type: 'shadow' },
  740. formatter: (params) => {
  741. const item = params[0]
  742. return `${item.name}<br/>${item.marker} ${item.value.toLocaleString()}`
  743. }
  744. },
  745. grid: {
  746. height: '200px',
  747. left: '6%',
  748. right: '6%',
  749. bottom: '5%',
  750. containLabel: true
  751. },
  752. xAxis: {
  753. type: 'value',
  754. axisLabel: {
  755. color: 'white',
  756. formatter: (value) => {
  757. if (value >= 10000) return `${(value / 10000).toFixed(1)}万`
  758. return value.toLocaleString()
  759. }
  760. },
  761. axisLine: {
  762. lineStyle: {
  763. color: '#B6C8DA' // X轴线白色半透明
  764. }
  765. },
  766. splitLine: {
  767. show: true, // 显示水平网格线(默认显示)
  768. lineStyle: {
  769. // 水平网格线颜色(可设置为纯色或带透明度的颜色)
  770. color: '#B6C8DA', // 浅灰色半透明
  771. // 可选:设置线条类型(实线/虚线/点线)
  772. type: 'dashed'
  773. }
  774. }
  775. },
  776. yAxis: {
  777. type: 'category',
  778. data: data.map((item) => item.category),
  779. axisTick: { show: false },
  780. axisLabel: { color: '#B6C8DA' },
  781. axisLine: {
  782. lineStyle: {
  783. color: '#B6C8DA' // X轴线白色半透明
  784. }
  785. }
  786. },
  787. series: [
  788. {
  789. type: 'bar',
  790. data: data.map((item) => item.value),
  791. itemStyle: {
  792. color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
  793. { offset: 0, color: '#83bff6' },
  794. { offset: 0.7, color: '#188df0' },
  795. { offset: 1, color: '#188df0' }
  796. ]),
  797. borderRadius: [0, 8, 8, 0]
  798. },
  799. label: {
  800. show: true,
  801. position: 'right',
  802. formatter: '{@value}',
  803. color: 'white',
  804. fontWeight: 'bold'
  805. },
  806. emphasis: {
  807. itemStyle: {
  808. shadowBlur: 10,
  809. shadowColor: 'rgba(0, 0, 0, 0.5)'
  810. }
  811. }
  812. }
  813. ]
  814. }
  815. }
  816. // 初始化图表
  817. const initTopChart = async () => {
  818. await IotStatApi.getDeviceTypeCount('yf').then((res) => {
  819. backendData.value = res
  820. })
  821. if (!topContainer.value) return
  822. topInstance = echarts.init(topContainer.value)
  823. updateTopChart()
  824. }
  825. // 更新图表
  826. const updateTopChart = () => {
  827. if (!topInstance) return
  828. topInstance.setOption(getTopOption())
  829. }
  830. // 自适应调整
  831. watch([width, height], () => {
  832. topInstance?.resize()
  833. })
  834. // 监听数据变化
  835. watch(
  836. backendData,
  837. () => {
  838. updateTopChart()
  839. },
  840. { deep: true }
  841. )
  842. const activeDom = ref(null)
  843. let activeInstance = null
  844. // 模拟后端数据结构
  845. // const activeData = ref([
  846. // { department: '瑞恒兴域', total: 356, active: 278 },
  847. // { department: '瑞鹰国际', total: 284, active: 192 },
  848. // { department: '四川瑞都', total: 432, active: 325 },
  849. // { department: '运营中心', total: 157, active: 89 }
  850. // ])
  851. const activeData = ref([])
  852. const initActiveChart = async (total:any, active:any,people:any) => {
  853. if (!activeDom.value) return
  854. activeData.value = await IotStatApi.getDeptCount()
  855. activeInstance = echarts.init(activeDom.value)
  856. const option = {
  857. tooltip: {
  858. trigger: 'axis',
  859. axisPointer: { type: 'shadow' }, //:ml-citation{ref="1,7" data="citationList"}
  860. formatter: (params) => `
  861. ${params[0].name}<br/>
  862. ${params[0].marker} ${total}: ${params[0].value}<br/>
  863. ${params[1].marker} ${active}: ${params[1].value}
  864. `
  865. },
  866. legend: {
  867. data: [total, active],
  868. top: 30,
  869. textStyle: {
  870. color: '#B6C8DA',
  871. }
  872. },
  873. grid: {
  874. left: '3%',
  875. right: '4%',
  876. bottom: '3%',
  877. containLabel: true //:ml-citation{ref="2,7" data="citationList"}
  878. },
  879. xAxis: {
  880. type: 'category',
  881. data: activeData.value.map((item) => item.department),
  882. axisLabel: {
  883. color: '#B6C8DA',
  884. interval: 0,
  885. rotate: 0 //:ml-citation{ref="5" data="citationList"}
  886. },
  887. axisLine: {
  888. lineStyle: {
  889. color: '#B6C8DA'
  890. }
  891. }
  892. },
  893. yAxis: {
  894. type: 'value',
  895. name: people,
  896. axisLabel: {
  897. color: '#B6C8DA',
  898. },
  899. splitLine: {
  900. show: true, // 显示水平网格线(默认显示)
  901. lineStyle: {
  902. // 水平网格线颜色(可设置为纯色或带透明度的颜色)
  903. color: '#457794', // 浅灰色半透明
  904. // 可选:设置线条类型(实线/虚线/点线)
  905. type: 'dashed'
  906. }
  907. },
  908. axisLine: {
  909. lineStyle: {
  910. color: '#B6C8DA'
  911. }
  912. }
  913. },
  914. series: [
  915. {
  916. name: total,
  917. type: 'bar',
  918. data: activeData.value.map((item) => item.total),
  919. itemStyle: {
  920. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  921. { offset: 0, color: '#5470c6' },
  922. { offset: 1, color: '#83bff6' }
  923. ])
  924. },
  925. barWidth: 30
  926. },
  927. {
  928. name: active,
  929. type: 'bar',
  930. data: activeData.value.map((item) => item.active),
  931. itemStyle: {
  932. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  933. { offset: 0, color: '#91cc75' },
  934. { offset: 1, color: '#e6f4d2' }
  935. ])
  936. },
  937. barWidth: 30
  938. }
  939. ]
  940. }
  941. activeInstance.setOption(option)
  942. }
  943. const qxRef = ref(null)
  944. let qxInstance = null
  945. // 生成近12个月份 (包含当年和去年)
  946. const generateMonths = () => {
  947. const months = []
  948. const date = new Date()
  949. date.setMonth(date.getMonth() + 1, 1) // 从下个月开始倒推
  950. for (let i = 0; i < 12; i++) {
  951. date.setMonth(date.getMonth() - 1)
  952. months.push(`${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}`)
  953. }
  954. return months.reverse()
  955. }
  956. const initQxChart = () => {
  957. if (!qxRef.value) return
  958. qxInstance = echarts.init(qxRef.value)
  959. const option = {
  960. tooltip: {
  961. trigger: 'axis',
  962. axisPointer: {
  963. type: 'cross',
  964. label: {
  965. backgroundColor: '#6a7985'
  966. }
  967. }
  968. },
  969. legend: {
  970. data: orderSevenData.value.series.map((item) => item.name),
  971. top: 30,
  972. textStyle: {
  973. color: '#B6C8DA'
  974. }
  975. },
  976. grid: {
  977. left: '3%',
  978. right: '4%',
  979. bottom: '3%',
  980. containLabel: true
  981. },
  982. xAxis: {
  983. type: 'category',
  984. boundaryGap: false,
  985. data: orderSevenData.value.xAxis,
  986. axisLabel: {
  987. color: '#B6C8DA',
  988. formatter: (value) => value.split('-').join('/') // 显示为 2023/01
  989. },
  990. axisLine: {
  991. lineStyle: {
  992. color: '#B6C8DA'
  993. }
  994. }
  995. },
  996. yAxis: [
  997. {
  998. type: 'value',
  999. axisLabel: {
  1000. color: '#B6C8DA',
  1001. formatter: '{value}'
  1002. },
  1003. splitLine: {
  1004. show: true, // 显示水平网格线(默认显示)
  1005. lineStyle: {
  1006. // 水平网格线颜色(可设置为纯色或带透明度的颜色)
  1007. color: '#457794', // 浅灰色半透明
  1008. // 可选:设置线条类型(实线/虚线/点线)
  1009. type: 'dashed'
  1010. }
  1011. },
  1012. axisLine: {
  1013. lineStyle: {
  1014. color: '#B6C8DA'
  1015. }
  1016. },
  1017. position: 'left' // 左侧 Y 轴
  1018. },
  1019. {
  1020. type: 'value',
  1021. axisLabel: {
  1022. formatter: '{value}'
  1023. },
  1024. axisLine: {
  1025. lineStyle: {
  1026. color: '#B6C8DA'
  1027. }
  1028. },
  1029. position: 'right', // 右侧 Y 轴
  1030. splitLine: {
  1031. show: false // 隐藏右侧 Y 轴的分割线
  1032. }
  1033. }
  1034. ],
  1035. series: orderSevenData.value.series.map((item, index) => {
  1036. // 假设前两条曲线使用左侧 Y 轴,后两条曲线使用右侧 Y 轴
  1037. const yAxisIndex = index < 2 ? 0 : 1
  1038. return {
  1039. name: item.name,
  1040. type: 'line',
  1041. smooth: true,
  1042. symbol: 'circle',
  1043. symbolSize: 8,
  1044. itemStyle: {
  1045. color: ['#5470c6', '#f1d209', '#e14f0f', '#91cc75'][index]
  1046. },
  1047. areaStyle: {
  1048. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  1049. { offset: 0, color: 'rgba(84,112,198,0.4)' },
  1050. { offset: 1, color: 'rgba(84,112,198,0.1)' }
  1051. ])
  1052. },
  1053. data: item.data,
  1054. yAxisIndex: yAxisIndex // 指定使用的 Y 轴
  1055. }
  1056. })
  1057. }
  1058. qxInstance.setOption(option)
  1059. }
  1060. // 响应式调整
  1061. const resizeQxChart = () => qxInstance?.resize()
  1062. /** 初始化 */
  1063. onMounted(() => {
  1064. getStats()
  1065. // initChart()
  1066. initTopChart()
  1067. const localeStore = useLocaleStore()
  1068. const lang = localeStore.getCurrentLocale.lang
  1069. if (lang==='zh-CN') {
  1070. initActiveChart('总人数','活跃人数','人数')
  1071. } else if (lang==='en') {
  1072. initActiveChart('totalPeople','activePeople','count')
  1073. }
  1074. // initQxChart()
  1075. window.addEventListener('resize', resizeQxChart)
  1076. // fetchTop()
  1077. window.addEventListener('resize', () => topInstance?.resize())
  1078. })
  1079. onBeforeUnmount(() => {
  1080. chartInstance?.dispose()
  1081. window.removeEventListener('resize', () => chartInstance?.resize())
  1082. topInstance?.dispose()
  1083. window.removeEventListener('resize', handleResize)
  1084. qxInstance?.dispose()
  1085. window.removeEventListener('resize', resizeQxChart)
  1086. })
  1087. </script>
  1088. <style lang="scss" scoped>
  1089. .page-container {
  1090. background-color: #3a6fa3;
  1091. min-height: 90vh;
  1092. padding: 20px;
  1093. }
  1094. .summary {
  1095. margin-bottom: 20px;
  1096. }
  1097. ::v-deep .chart-card {
  1098. background-color: rgba(0, 0, 0, 0.3);
  1099. border-radius: 8px;
  1100. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  1101. transition: all 0.3s ease;
  1102. border: none;
  1103. &:hover {
  1104. box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  1105. }
  1106. }
  1107. .safety-days-card {
  1108. .safety-days-content {
  1109. display: flex;
  1110. flex-direction: column;
  1111. align-items: center;
  1112. justify-content: center;
  1113. height: 150px;
  1114. position: relative;
  1115. .days-number {
  1116. font-size: 58px;
  1117. font-weight: bold;
  1118. color: darkorange;
  1119. line-height: 1;
  1120. transition: all 0.3s ease;
  1121. }
  1122. .days-number:hover {
  1123. transform: scale(1.05);
  1124. }
  1125. .days-label {
  1126. font-size: 20px;
  1127. color: white;
  1128. margin-top: 8px;
  1129. }
  1130. .safety-desc {
  1131. font-size: 14px;
  1132. color: #999;
  1133. position: absolute;
  1134. bottom: 10px;
  1135. text-align: center;
  1136. width: 90%;
  1137. }
  1138. }
  1139. }
  1140. @media (max-width: 768px) {
  1141. .page-container {
  1142. padding: 10px;
  1143. }
  1144. }
  1145. ::v-deep .el-card__header {
  1146. border-bottom: none !important;
  1147. padding-bottom: 0;
  1148. }
  1149. </style>