index.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <template>
  2. <div class="home-container">
  3. <el-row :gutter="15" class="home-card-one mb15">
  4. <el-col :xs="24" :sm="12" :md="12" :lg="6" :xl="6" v-for="(v, k) in homeOne" :key="k">
  5. <div class="home-card-top-part">
  6. <div class="top">
  7. <img :src="'/imgs/' + v.icoimg" class="icoimg" />
  8. <div class="card-right">
  9. <span class="font30">{{ v.allnum }}</span>
  10. <div class="label">{{ v.num3 }}</div>
  11. </div>
  12. </div>
  13. </div>
  14. </el-col>
  15. </el-row>
  16. <div class="chart-wrapper">
  17. <div class="chart-item" style="flex: 1">
  18. <div class="chart-title">告警级别分布</div>
  19. <Chart height="300px" ref="chart1"></Chart>
  20. </div>
  21. <div class="chart-item" style="flex: 1.5">
  22. <div class="chart-title">告警趋势</div>
  23. <Chart height="300px" ref="chart2"></Chart>
  24. </div>
  25. </div>
  26. <div class="chart-wrapper">
  27. <div class="chart-item" style="flex: 1">
  28. <div class="chart-title">处理状态</div>
  29. <Chart height="300px" ref="chart3"></Chart>
  30. </div>
  31. <div class="chart-item" style="flex: 1.5">
  32. <div class="chart-title">设备告警TOP10</div>
  33. <Chart height="300px" ref="chart4"></Chart>
  34. </div>
  35. </div>
  36. <AlarmList></AlarmList>
  37. </div>
  38. </template>
  39. <script lang="ts" setup>
  40. import { toRefs, reactive, onMounted, ref, watch, nextTick, onActivated, getCurrentInstance, onUnmounted } from 'vue'
  41. import 'vue-data-ui/style.css'
  42. import api from '/@/api/alarm'
  43. import AlarmList from '/@/views/iot/alarm/list/index.vue'
  44. import { useThemeChange } from '/@/hooks/useCommon'
  45. import Chart from '/@/components/chart/index.vue'
  46. import { getLineOption } from '/@/components/chart/options'
  47. import dayjs from 'dayjs'
  48. const chart1 = ref()
  49. const chart2 = ref()
  50. const chart3 = ref()
  51. const chart4 = ref()
  52. const { proxy } = getCurrentInstance() as any
  53. const { alarm_type } = proxy.useDict('alarm_type')
  54. const alarmTypeMap: any = {}
  55. // 监听告警类型是否获取成功
  56. watch(
  57. () => alarm_type.value,
  58. (list) => {
  59. if (!list.length) return
  60. list.forEach((item: any) => {
  61. alarmTypeMap[item.value] = item.label
  62. })
  63. },
  64. {
  65. immediate: true,
  66. }
  67. )
  68. const homeOne = reactive([
  69. {
  70. allnum: 0,
  71. num3: '告警总数',
  72. icoimg: 'dashboard-icon1.svg',
  73. },
  74. {
  75. allnum: 0,
  76. num3: '已关闭告警数',
  77. icoimg: 'dashboard-icon2.svg',
  78. },
  79. {
  80. allnum: 0,
  81. num3: '未关闭告警数',
  82. icoimg: 'dashboard-icon3.svg',
  83. },
  84. {
  85. allnum: 0,
  86. num3: '平均处理时长MTTR',
  87. icoimg: 'dashboard-icon4.svg',
  88. },
  89. ])
  90. const getOverviewData = () => {
  91. // 顶部统计数据
  92. api.dashboard.getTotalAlarmStatistics().then((res: any) => {
  93. homeOne[0].allnum = res.alarmTotalCount
  94. homeOne[1].allnum = res.closeAlarmCount
  95. homeOne[2].allnum = res.unCloseAlarmCount
  96. homeOne[3].allnum = res.averageDealTime
  97. })
  98. // 告警级别分布
  99. api.dashboard
  100. .getAlarmLevel({
  101. searchType: null,
  102. startDate: dayjs().startOf('month').format('YYYY-MM-DD'),
  103. endDate: dayjs().endOf('month').format('YYYY-MM-DD'),
  104. })
  105. .then((res: any) => {
  106. const resData = res || [
  107. {
  108. alarmCount: 2548,
  109. alarmLevel: '1',
  110. levelName: '超紧急',
  111. },
  112. {
  113. alarmCount: 0,
  114. alarmLevel: '2',
  115. levelName: '紧急',
  116. },
  117. {
  118. alarmCount: 0,
  119. alarmLevel: '3',
  120. levelName: '严重',
  121. },
  122. {
  123. alarmCount: 0,
  124. alarmLevel: '4',
  125. levelName: '一般',
  126. },
  127. {
  128. alarmCount: 0,
  129. alarmLevel: '5',
  130. levelName: '提醒',
  131. },
  132. ]
  133. console.log(resData)
  134. })
  135. // 告警趋势 intervalType 统计间隔:1小时 2天 3月
  136. api.dashboard.getAnalyzeTrend({ intervalType: 2 }).then((res: any) => {
  137. const resData = res || []
  138. console.log(resData)
  139. })
  140. // 处理状态
  141. api.dashboard
  142. .getAlarmStatus({
  143. startDate: dayjs().startOf('month').format('YYYY-MM-DD'),
  144. endDate: dayjs().endOf('month').format('YYYY-MM-DD'),
  145. })
  146. .then((res: any) => {
  147. const resData = res || [
  148. {
  149. alarmCount: 4,
  150. status: '1',
  151. },
  152. {
  153. alarmCount: 2544,
  154. status: '0',
  155. },
  156. {
  157. alarmCount: 0,
  158. status: '2',
  159. },
  160. ]
  161. console.log(resData)
  162. })
  163. api.dashboard.getDeviceAlarmTop10().then((res: any) => {
  164. const list = res || []
  165. const chartData = getLineOption({
  166. datas: [list.map((item: any) => item.alarmCount)],
  167. xAxis: list.map((item: any) => item.deviceName),
  168. legend: ['告警设备top10'],
  169. })
  170. chart4.value.draw(chartData)
  171. })
  172. }
  173. // 页面加载时
  174. onMounted(() => {
  175. getOverviewData()
  176. })
  177. </script>
  178. <style scoped lang="scss">
  179. $homeNavLengh: 8;
  180. .chart-wrapper {
  181. display: flex;
  182. justify-content: space-between;
  183. align-items: stretch;
  184. gap: 16px;
  185. .chart-item {
  186. background-color: var(--el-color-white);
  187. padding: 12px 15px;
  188. border-radius: 8px;
  189. margin-bottom: 16px;
  190. flex: 1;
  191. min-width: 200px;
  192. }
  193. .chart-title {
  194. font-size: 15px;
  195. font-weight: bold;
  196. padding-left: 5px;
  197. }
  198. }
  199. .home-card-top-part {
  200. background-color: var(--el-color-white);
  201. border-radius: 8px;
  202. padding: 20px 20px;
  203. .top {
  204. display: flex;
  205. justify-content: space-around;
  206. overflow: hidden;
  207. align-items: center;
  208. }
  209. .icoimg {
  210. width: 54px !important;
  211. height: 54px !important;
  212. margin-right: 12px;
  213. }
  214. .label {
  215. font-size: 14px;
  216. font-weight: 500;
  217. }
  218. .divider {
  219. border-top: 1px solid var(--el-border-color-light);
  220. margin: 12px 0 15px;
  221. }
  222. .card-right {
  223. flex: 1;
  224. display: flex;
  225. flex-direction: column;
  226. justify-content: space-between;
  227. white-space: nowrap;
  228. line-height: 1;
  229. height: 54px;
  230. .font30 {
  231. color: #4285f4;
  232. font-weight: bold;
  233. font-size: 30px;
  234. }
  235. }
  236. .card-bottom {
  237. font-size: 12px;
  238. display: flex;
  239. align-items: center;
  240. justify-content: space-around;
  241. gap: 12px;
  242. white-space: nowrap;
  243. .split {
  244. border-right: 1px solid var(--el-border-color-light);
  245. height: 20px;
  246. }
  247. .icon {
  248. width: 17px;
  249. height: 17px;
  250. }
  251. .info {
  252. font-size: 12px;
  253. font-weight: 500;
  254. }
  255. }
  256. }
  257. .home-container {
  258. overflow: hidden;
  259. .home-card-one,
  260. .home-card-two,
  261. .home-card-three {
  262. .icoimg {
  263. width: 75px;
  264. height: 75px;
  265. }
  266. .title_status {
  267. width: 7px;
  268. height: 7px;
  269. background: #c1bbbb;
  270. border-radius: 50px;
  271. margin-right: 5px;
  272. }
  273. .home-card-item,
  274. .home-card-top {
  275. width: 100%;
  276. border-radius: 8px;
  277. transition: all ease 0.3s;
  278. padding: 10px 20px;
  279. overflow: hidden;
  280. background: var(--el-color-white);
  281. color: var(--el-text-color-primary);
  282. // border: 1px solid var(--next-border-color-light);
  283. &:hover {
  284. // box-shadow: 0 2px 12px var(--next-color-dark-hover);
  285. transition: all ease 0.3s;
  286. }
  287. &-icon {
  288. width: 70px;
  289. height: 70px;
  290. border-radius: 100%;
  291. flex-shrink: 1;
  292. i {
  293. color: var(--el-text-color-placeholder);
  294. }
  295. }
  296. &-title {
  297. font-size: 15px;
  298. font-weight: bold;
  299. height: 30px;
  300. }
  301. }
  302. }
  303. .home-card-three {
  304. .home-card-item-title {
  305. display: flex;
  306. justify-content: space-between;
  307. // span:nth-child(2) {
  308. // color: #409eff;
  309. // }
  310. }
  311. }
  312. .home-card-one {
  313. @for $i from 0 through 3 {
  314. .home-one-animation#{$i} {
  315. opacity: 0;
  316. animation-name: error-num;
  317. animation-duration: 0.5s;
  318. animation-fill-mode: forwards;
  319. animation-delay: calc($i/10) + s;
  320. }
  321. }
  322. }
  323. .home-card-two,
  324. .home-card-three {
  325. .home-card-top {
  326. height: 250px;
  327. .box-card {
  328. padding: 15px 20px 20px 10px;
  329. p {
  330. margin-bottom: 10px;
  331. }
  332. &-item {
  333. margin-bottom: 10px;
  334. }
  335. }
  336. }
  337. .home-card-item,
  338. .home-card-top {
  339. width: 100%;
  340. overflow: hidden;
  341. .home-monitor {
  342. height: 100%;
  343. .flex-warp-item {
  344. width: 25%;
  345. height: 111px;
  346. display: flex;
  347. .flex-warp-item-box {
  348. margin: auto;
  349. text-align: center;
  350. color: var(--el-text-color-primary);
  351. display: flex;
  352. border-radius: 5px;
  353. background: var(--next-bg-color);
  354. cursor: pointer;
  355. transition: all 0.3s ease;
  356. &:hover {
  357. background: var(--el-color-primary-light-9);
  358. transition: all 0.3s ease;
  359. }
  360. }
  361. @for $i from 0 through $homeNavLengh {
  362. .home-animation#{$i} {
  363. opacity: 0;
  364. animation-name: error-num;
  365. animation-duration: 0.5s;
  366. animation-fill-mode: forwards;
  367. animation-delay: calc($i/10) + s;
  368. }
  369. }
  370. }
  371. }
  372. }
  373. }
  374. .text-info {
  375. color: #23c6c8;
  376. }
  377. .text-danger {
  378. color: #ed5565;
  379. }
  380. .git-res {
  381. margin-top: 20px;
  382. }
  383. .git-res .el-link {
  384. margin-right: 30px;
  385. }
  386. ul,
  387. li {
  388. padding: 0;
  389. margin: 0;
  390. list-style: none;
  391. }
  392. .product {
  393. margin-top: 50px;
  394. h3 {
  395. margin-bottom: 15px;
  396. }
  397. }
  398. .product li {
  399. margin-bottom: 20px;
  400. float: left;
  401. width: 150px;
  402. }
  403. .box-card.xx {
  404. margin-top: 20px;
  405. }
  406. }
  407. .home-card-item.chart {
  408. padding: 10px !important;
  409. }
  410. </style>