浏览代码

feat: 物联概览页面顶部卡片数据定时轮训

yanglzh 1 年之前
父节点
当前提交
45cbd7bd5e
共有 2 个文件被更改,包括 102 次插入74 次删除
  1. 42 34
      src/api/datahub/index.ts
  2. 60 40
      src/views/iot/iotmanager/dashboard.vue

+ 42 - 34
src/api/datahub/index.ts

@@ -2,32 +2,32 @@ import { get, post, del, put, file } from '/@/utils/request';
 
 export default {
 
-  common: {
-    getList: (params: object) => get('/source/search', params),
-    add: (data: object) => post('/source/api/add', data),
-    delete: (ids: number) => del('/source/del', { ids }),
-    edit: (data: object) => put('/source/api/edit', data),
-    detail: (sourceId: number) => get('/source/detail', { sourceId }),
-    deploy: (data: object) => post('/source/deploy', data),
-    undeploy: (data: object) => post('/source/undeploy', data),  
-    api: (sourceId: number) => get('/source/api/get', { sourceId }),
-    devadd: (data: object) => post('/source/device/add', data),
-    devedit: (data: object) => put('/source/device/edit', data),
-    devapi: (sourceId: number) => get('/source/device/get', { sourceId }),
-    getdevList: (params: object) => get('/product/device/list', params),
-    getdata: (params: object) => get('/source/getdata', params),
-    getLists: (params: object) => get('/source/list', params),
-    copy: (params: object) => post('/source/copy', params),
+   common: {
+      getList: (params: object) => get('/source/search', params),
+      add: (data: object) => post('/source/api/add', data),
+      delete: (ids: number) => del('/source/del', { ids }),
+      edit: (data: object) => put('/source/api/edit', data),
+      detail: (sourceId: number) => get('/source/detail', { sourceId }),
+      deploy: (data: object) => post('/source/deploy', data),
+      undeploy: (data: object) => post('/source/undeploy', data),
+      api: (sourceId: number) => get('/source/api/get', { sourceId }),
+      devadd: (data: object) => post('/source/device/add', data),
+      devedit: (data: object) => put('/source/device/edit', data),
+      devapi: (sourceId: number) => get('/source/device/get', { sourceId }),
+      getdevList: (params: object) => get('/product/device/list', params),
+      getdata: (params: object) => get('/source/getdata', params),
+      getLists: (params: object) => get('/source/list', params),
+      copy: (params: object) => post('/source/copy', params),
 
-    dbadd: (data: object) => post('/source/db/add', data),
-    dbedit: (data: object) => put('/source/db/edit', data),
-    getfields: (sourceId: number) => get('/source/db/fields', { sourceId }),
+      dbadd: (data: object) => post('/source/db/add', data),
+      dbedit: (data: object) => put('/source/db/edit', data),
+      getfields: (sourceId: number) => get('/source/db/fields', { sourceId }),
 
-    devdb: (sourceId: number) => get('/source/db/get', { sourceId }),
+      devdb: (sourceId: number) => get('/source/db/get', { sourceId }),
 
-    },
-   
-   node:{
+   },
+
+   node: {
       getList: (params: object) => get('/source/node/list', params),
       add: (data: object) => post('/source/node/add', data),
       delete: (nodeId: number) => del('/source/node/del', { nodeId }),
@@ -35,34 +35,34 @@ export default {
       getpropertyList: (params: object) => get('/product/tsl/property/all', params),
    },
 
-   template:{
+   template: {
       getList: (params: object) => get('/source/template/search', params),
       add: (data: object) => post('/source/template/add', data),
       delete: (ids: number) => del('/source/template/del', { ids }),
       edit: (data: object) => put('/source/template/edit', data),
       detail: (id: string) => get('/source/template/detail', { id }),
       allList: (params: object) => get('/source/template/list', params), // 获取所有已发布列表
-      getdata: (params: object) => get('/source/template/getdata',  params ),
-      getDictData: (params: object) => get('/common/dict/data/getDictData',  params ),
-      cityTree: (params: object) => get('/common/city/tree',  params ),
+      getdata: (params: object) => get('/source/template/getdata', params),
+      getDictData: (params: object) => get('/common/dict/data/getDictData', params),
+      cityTree: (params: object) => get('/common/city/tree', params),
       copy: (params: object) => post('/source/template/copy', params),
       relation_check: (id: number) => get('/source/template/relation_check', { id }),
       source_list: (id: number) => get('/source/template/source_list', { id }),
       aggregate_from: (id: number) => get('/source/template/aggregate_from', { id }),
       relation: (data: object) => post('/source/template/relation', data),
       aggregate: (data: object) => post('/source/template/aggregate', data),
-   } ,
+   },
 
-   tnode:{
+   tnode: {
       getList: (params: object) => get('/source/template/node/list', params),
       add: (data: object) => post('/source/template/node/add', data),
       delete: (id: number) => del('/source/template/node/del', { id }),
       edit: (data: object) => put('/source/template/node/edit', data),
       deploy: (data: object) => post('/source/template/deploy', data),
-      undeploy: (data: object) => post('/source/template/undeploy', data),  
+      undeploy: (data: object) => post('/source/template/undeploy', data),
    },
-  
-   weather:{
+
+   weather: {
       getCityWeatherList: () => get('/envirotronics/weather/cityWeatherList'),
       getWhichCityWeather: (params: object) => get('/envirotronics/weather/getInfoById', params),
       getTemperatureEchartById: (params: object) => get('/envirotronics/weather/getTemperatureEchartById', params),
@@ -70,17 +70,25 @@ export default {
       getCityWeatherHistory: (params: object) => get('/envirotronics/weather/GetCityWeatherHistory', params),
       getCityWeatherHistoryExport: (params: object) => file('/envirotronics/weather/GetCityWeatherHistoryExport', params),
    },
-   statistics:{
+   statistics: {
       getStatisticsChartData: (params: object) => get('/statistics/bar/chart/data', params),
       getStatisticsLineChartData: (params: object) => get('/statistics/broken/line/data', params),
       getStatisticsTotalData: (params: object) => get('/statistics/city/data', params),
       getStatisticsPieData: (params: object) => get('/statistics/tempering/ratio/data', params),
       getStatisticsOverview: (params: object) => get('/statistics/overview', params),
    },
-   iotManage:{
+   iotManage: {
       getOverviewData: () => get('/thing/overview'),
       getAlarmList: (params: object) => get('/alarm/log/list', params),
       getAlarmDetail: (id: number) => get('/alarm/log/detail', { id }),
       getAlarmHandle: (data: object) => post('/alarm/log/handle', data),
+      // 设备消息总量本年统计
+      deviceDataTotalCount: (dateType: 'year' | 'month' | 'day') => get('/analysis/deviceDataTotalCount', { dateType }),
+      // 设备在线离线及总数统计
+      deviceOnlineOfflineCount: () => get('/analysis/deviceOnlineOfflineCount'),
+      // 本年度每月设备消息量统计 
+      deviceDataCount: (dateType: 'year' | 'month') => get('/analysis/deviceDataCount', { dateType }),
+      // 按告警级别统计
+      deviceAlarmLevelCount: (dateType: 'year' | 'month' | 'day', date: string) => get('/analysis/deviceAlarmLevelCount', { dateType, date }),
    }
 }

+ 60 - 40
src/views/iot/iotmanager/dashboard.vue

@@ -6,12 +6,10 @@
 					<div>{{ v.num3 }}</div>
 					<div class="flex-margin flex w100" :class="` home-one-animation${k}`">
 						<div class="flex-auto">
-
 							<span class="font30">{{ v.allnum }}</span>
 						</div>
 						<div class="home-card-item-icon flex">
 							<img :src="'/imgs/' + v.icoimg" class="icoimg">
-
 						</div>
 					</div>
 					<div class="flex" style="font-weight: bold;">
@@ -87,6 +85,7 @@ import { useRouter } from 'vue-router';
 import { useStore } from '/@/store/index';
 
 import api from '/@/api/datahub';
+import dayjs from 'dayjs';
 
 import EditDic from '../alarm/log/component/edit.vue';
 import DetailDic from '../alarm/log/component/detail.vue';
@@ -124,9 +123,9 @@ export default defineComponent({
 			},
 			homeOne: [
 				{
-					allnum: '0',
-					num1: '0',
-					num2: '0',
+					allnum: 0,
+					num1: 0,
+					num2: 0,
 					num3: '产品',
 					num4: 'icon-zidingyibuju',
 					color1: '#6690F9',
@@ -140,47 +139,47 @@ export default defineComponent({
 
 				},
 				{
-					allnum: '0',
-					num1: '0',
-					num2: '0',
-					num3: '设备',
+					allnum: 0,
+					num1: 0,
+					num2: 0,
+					num3: '在线设备',
 					num4: 'icon-putong',
 					color1: '#FF6462',
 					color2: '--next-color-primary-lighter',
 					color3: '--el-color-primary',
 					icoimg: 'index_device.svg',
-					title1: '在线',
-					title2: '离线',
+					title1: '启用',
+					title2: '禁用',
 					title1_bgcolor: '#3cd357',
 					title2_bgcolor: '#c1bbbb',
 				},
 				{
-					allnum: '0',
-					num1: '0',
-					num2: '0',
+					allnum: 0,
+					num1: 0,
+					num2: 0,
 					num3: '设备消息',
 					num4: 'icon-shidu',
 					color1: '#6690F9',
 					color2: '--el-color-success-lighter',
 					color3: '--el-color-success',
 					icoimg: 'index_sensor.svg',
-					title1: '总量',
+					title1: '本月',
 					title2: '今日',
 					title1_bgcolor: '#c1bbbb',
 					title2_bgcolor: '#18f3ff',
 				},
 				{
-					allnum: '0',
-					num1: '0',
-					num2: '0',
+					allnum: 0,
+					num1: 0,
+					num2: 0,
 					num3: '设备告警',
 					num4: 'icon-zaosheng',
 					color1: '#6690F9',
 					color2: '--el-color-warning-lighter',
 					color3: '--el-color-warning',
 					icoimg: 'index_alarm.svg',
-					title1: '总量',
-					title2: '新增',
+					title1: '本月',
+					title2: '今日',
 					title1_bgcolor: '#c1bbbb',
 					title2_bgcolor: '#ff1818',
 				},
@@ -389,30 +388,51 @@ export default defineComponent({
 		const initEchartsResize = () => {
 			window.addEventListener('resize', initEchartsResizeFun);
 		};
+
+		// 定时获取设备,在线信息,告警数量更新
+		function getLoopData() {
+			api.iotManage.deviceDataTotalCount('year').then((res: any) => {
+				state.homeOne[2].allnum = res.number;
+			})
+			api.iotManage.deviceDataTotalCount('month').then((res: any) => {
+				state.homeOne[2].num1 = res.number;
+			})
+			api.iotManage.deviceDataTotalCount('day').then((res: any) => {
+				state.homeOne[2].num2 = res.number;
+			})
+			api.iotManage.deviceOnlineOfflineCount().then((res: any) => {
+				// console.log(res)
+				state.homeOne[1].allnum = res.online;
+				state.homeOne[1].num1 = res.total - res.disable
+				state.homeOne[1].num2 = res.disable
+			})
+			// 按告警级别统计
+			api.iotManage.deviceAlarmLevelCount('year', dayjs().format('YYYY')).then((res: any) => {
+				const total = (res.data || []).reduce((a: any, b: any) => a + b.Value, 0)
+				state.homeOne[3].allnum = total;
+			})
+			api.iotManage.deviceAlarmLevelCount('month', dayjs().format('M')).then((res: any) => {
+				const total = (res.data || []).reduce((a: any, b: any) => a + b.Value, 0)
+				state.homeOne[3].num1 = total;
+			})
+			api.iotManage.deviceAlarmLevelCount('day', dayjs().format('D')).then((res: any) => {
+				const total = (res.data || []).reduce((a: any, b: any) => a + b.Value, 0)
+				state.homeOne[3].num2 = total;
+			})
+		}
+
+		// 每隔3秒更新数据
+		setInterval(getLoopData, 3000)
+
 		const getOverviewData = () => {
+
+			getLoopData()
+
 			api.iotManage.getOverviewData().then((res: any) => {
 				const { overview, device, alarmLevel } = res;
-				// overview
-				// "deviceTotal": 8, //设备总量
-				// "deviceOffline": 4, //离线设备数量
-				// "productTotal": 6, //产品总量
-				// "productAdded": 0, //今日产品增量
-				// "msgTotal": 107246, //设备消息总量
-				// "msgAdded": 7391, //今日设备消息增量
-				// "alarmTotal": 43, //设备报警总量
-				// "alarmAdded": 0 //今日设备报警增量
 				state.homeOne[0].allnum = overview.productTotal;
-				state.homeOne[0].num1 = `${overview.productActivation}`;
-				state.homeOne[0].num2 = `${overview.productDeactivation}`;
-				state.homeOne[1].allnum = overview.deviceTotal;
-				state.homeOne[1].num1 = `${overview.deviceTotal - overview.deviceOffline}`;
-				state.homeOne[1].num2 = `${overview.deviceOffline}`;
-				state.homeOne[2].allnum = overview.msgTotal;
-				state.homeOne[2].num1 = overview.msgTotal;
-				state.homeOne[2].num2 = `${overview.msgAdded}`;
-				state.homeOne[3].allnum = overview.alarmTotal;
-				state.homeOne[3].num1 = overview.alarmTotal;
-				state.homeOne[3].num2 = `${overview.alarmAdded}`;
+				state.homeOne[0].num1 = overview.productActivation
+				state.homeOne[0].num2 = overview.productDeactivation
 
 				// device
 				// msgTotal 设备消息量月度统计