From 9fc3a1d5a70a5af805b37476d47331dad0b21d65 Mon Sep 17 00:00:00 2001
From: whyczyk <525500596@qq.com>
Date: 星期六, 09 十月 2021 15:09:32 +0800
Subject: [PATCH] 模块socket优化请求数据

---
 src/components/charts/CustomPie.vue |  110 +++++++++++++++++++++++++++----------------------------
 1 files changed, 54 insertions(+), 56 deletions(-)

diff --git a/src/components/charts/CustomPie.vue b/src/components/charts/CustomPie.vue
index 0f38ddd..408d4ae 100644
--- a/src/components/charts/CustomPie.vue
+++ b/src/components/charts/CustomPie.vue
@@ -10,15 +10,15 @@
 import {
 	chartFontsize
 } from '@/assets/js/chartFontsize';
-import {
-	powerAlarmError
-} from '@/assets/js/api'
+import { WebSocketClass } from '@/assets/js/socket'
 export default {
 	name: "CustomPie",
 	chart: "",
 	chartData: {},
 	data() {
-		return {}
+		return {
+			websock: null
+		}
 	},
 	methods: {
 		toParentPage() {
@@ -297,63 +297,61 @@
 				this.organizeData(sendData)
 			} else {
 				this.postData()
-				setInterval(() => {
-					this.postData()
-				}, 3000)
 			}
 		},
 		postData() {
 			let userId = localStorage.getItem('userId');
-			let params = {
-				userId: userId
-			}
-			powerAlarmError(params).then((res) => {
-				if (res.data.code == 1) {
-					let optionData = [{
-						value: 0,
-						name: '閫氳鏁呴殰',
-						color: '#5062DE'
-					},
-					{
-						value: 0,
-						name: '鐩存祦鎬绘晠闅�',
-						color: '#FD5E02'
-					},
-					{
-						value: 0,
-						name: '闃查浄鍣ㄦ晠闅�',
-						color: '#8C6BFA'
-					},
-					{
-						value: 0,
-						name: '寮�鍏虫煖鏁呴殰',
-						color: '#F58881'
-					},
-					{
-						value: 0,
-						name: '鐩戞帶鍣ㄦ晠闅�',
-						color: '#EDE611'
-					},
-					{
-						value: 0,
-						name: '浜ゆ祦鎬绘晠闅�',
-						color: '#43F9FD'
-					},
-					]
-					let resData = res.data.data;
-					for (let key in resData) {
-						optionData.map(item => {
-							if (item.name == key) {
-								item.value = resData[key]
-							}
-						})
-					}
-					this.$options.chartData = optionData;
-					this.organizeData(optionData)
+			this.websock = new WebSocketClass(`/screen/powerAlarm/error/${userId}`, this.wsMessage, 4000)
+		},
+		wsMessage(res) {
+			if (res.code == 1) {
+				let optionData = [{
+					value: 0,
+					name: '閫氳鏁呴殰',
+					color: '#5062DE'
+				},
+				{
+					value: 0,
+					name: '鐩存祦鎬绘晠闅�',
+					color: '#FD5E02'
+				},
+				{
+					value: 0,
+					name: '闃查浄鍣ㄦ晠闅�',
+					color: '#8C6BFA'
+				},
+				{
+					value: 0,
+					name: '寮�鍏虫煖鏁呴殰',
+					color: '#F58881'
+				},
+				{
+					value: 0,
+					name: '鐩戞帶鍣ㄦ晠闅�',
+					color: '#EDE611'
+				},
+				{
+					value: 0,
+					name: '浜ゆ祦鎬绘晠闅�',
+					color: '#43F9FD'
+				},
+				]
+				let resData = res.data;
+				for (let key in resData) {
+					optionData.map(item => {
+						if (item.name == key) {
+							item.value = resData[key]
+						}
+					})
 				}
-			}).catch((err) => {
-				console.log(err)
-			});
+				this.$options.chartData = optionData;
+				this.organizeData(optionData)
+			}
+		},
+		outClear() {
+			this.websock.closeMyself()
+			this.websock = null
+			window.removeEventListener('resize', this.resize);
 		},
 		resize() {
 			setTimeout(() => {

--
Gitblit v1.9.1