瀏覽代碼

fix: 首页定时器问题,已发流程列表显示

liujt 2 天之前
父節點
當前提交
e6893e89f2
共有 4 個文件被更改,包括 42 次插入25 次删除
  1. 1 1
      manifest.json
  2. 21 14
      pages/home/home.vue
  3. 19 9
      pages/home/homeNew.vue
  4. 1 1
      pages/home/wt/send/send.vue

+ 1 - 1
manifest.json

@@ -2,7 +2,7 @@
     "name" : "AiMill工业互联网平台",
     "appid" : "__UNI__45B3907",
     "description" : "",
-    "versionName" : "V1.0.4.43",
+    "versionName" : "V1.0.4.44",
     "versionCode" : "100",
     "transformPx" : false,
     "h5" : {

+ 21 - 14
pages/home/home.vue

@@ -243,13 +243,24 @@
 			// this.getStatistics()
 		},
 		onUnload() {
+			console.log('onUnload~~~~~home')
 			uni.$off('scancodedate')
-			clearTimeout(this.timer);
-
+			if (this.timer) {
+				clearInterval(this.timer)
+				this.timer = null
+			}
+			// 子组件 homeNew 是组件而非页面,需手动停止其定时器
+			this.$refs.homeNewRef && this.$refs.homeNewRef.stopTimer()
 		},
 		onHide() {
+			console.log('onHide~~~~~home')
 			uni.$off('scancodedate')
-			clearTimeout(this.timer);
+			if (this.timer) {
+				clearInterval(this.timer)
+				this.timer = null
+			}
+			// 子组件 homeNew 是组件而非页面,需手动停止其定时器
+			this.$refs.homeNewRef && this.$refs.homeNewRef.stopTimer()
 		},
 		data() {
 			return {
@@ -320,17 +331,13 @@
 			},
 			init() {
 				this.getStatistics()
-				// this.$refs.navigationRef && this.$refs.navigationRef.getCount()
-				// this.$refs.equipmentRef && this.$refs.equipmentRef.getData()
-				// this.$refs.mochaRef && this.$refs.mochaRef.getData()
-				// this.$refs.mouldRef &&
-				// 	(this.$refs.mouldRef.getBoatInventoryCountList(),
-				// 		this.$refs.mouldRef.getModeInventoryCountList())
-				// this.$refs.sparePartRef && this.$refs.sparePartRef.getData()
-				this.timer = setTimeout(() => {
-					console.log('timer~~~home')
-					this.init()
-				}, 12000)
+				// 启动循环定时器,避免重复创建
+				if (!this.timer) {
+					this.timer = setInterval(() => {
+						console.log('timer~~~home~~~~')
+						this.getStatistics()
+					}, 12000)
+				}
 			},
 			// 获取工单统计数
 			getStatistics() {

+ 19 - 9
pages/home/homeNew.vue

@@ -148,14 +148,17 @@
 		onLoad() {
 		},
 		onUnload() {
+			console.log('onUnload~~~homenew')
 			this.stopTimer()
 			uni.$off('scancodedate')
 		},
 		onHide() {
+			console.log('onHide~~~homenew')
 			this.stopTimer()
 			uni.$off('scancodedate')
 		},
-		beforeDestroy() {
+		destroyed() {
+			console.log('destroyed~~~homenew')
 			this.stopTimer()
 		},
 		mounted() {
@@ -230,8 +233,10 @@
 			// 停止定时轮询
 			stopTimer() {
 				console.log('stopTimer')
-				this._destroyed = true
-				clearTimeout(this.timer)
+				if (this.timer) {
+					clearInterval(this.timer)
+					this.timer = null
+				}
 			},
 			// 刷新 manage 子组件数据(供父组件 tab 切换时调用)
 			refreshManage() {
@@ -265,6 +270,17 @@
 			})
 		},
 			init() {
+				this.refreshAll()
+				// 启动循环定时器(页面退出时由 stopTimer 关闭)
+				if (!this.timer) {
+					this.timer = setInterval(() => {
+						console.log('timer~~~homeNew~~~~')
+						this.refreshAll()
+					}, 12000)
+				}
+			},
+			// 刷新所有数据
+			refreshAll() {
 				this.getStatistics()
 				this.$refs.navigationRef && this.$refs.navigationRef.getCount()
 				this.$refs.equipmentRef && this.$refs.equipmentRef.getData()
@@ -273,12 +289,6 @@
 					(this.$refs.mouldRef.getBoatInventoryCountList(),
 						this.$refs.mouldRef.getModeInventoryCountList())
 				this.$refs.sparePartRef && this.$refs.sparePartRef.getData()
-				if (this._destroyed) return
-				this.timer = setTimeout(() => {
-					console.log('init timeout')
-					if (this._destroyed) return
-					this.init()
-				}, 12000)
 			},
 			// 获取工单统计数
 			getStatistics() {

+ 1 - 1
pages/home/wt/send/send.vue

@@ -160,7 +160,7 @@ export default {
       let paging = {
         pageNo: page,
         pageSize: size,
-        processType: 0,
+        // processType: 0,
       };
       let par = Object.assign(paging, this.params);
       isEnd = false;