From 49b1409c6886034321042f9e7e19d119f1fe3901 Mon Sep 17 00:00:00 2001
From: loulijun2021 <1694218219@qq.com>
Date: 星期五, 07 十月 2022 09:01:40 +0800
Subject: [PATCH] 1.看板新增监测网络是否在线事件

---
 src/views/kb/bzcj.vue |   77 +++++++++++++++++++++++++++++++-------
 1 files changed, 63 insertions(+), 14 deletions(-)

diff --git a/src/views/kb/bzcj.vue b/src/views/kb/bzcj.vue
index d1d1072..9e0a854 100644
--- a/src/views/kb/bzcj.vue
+++ b/src/views/kb/bzcj.vue
@@ -3,7 +3,7 @@
     <div class="kb_dashboard">
       <div class="kb_header">
         <div class="flex_c_c kb_header_text">
-          鍖呰杞﹂棿鐪嬫澘
+          杞﹂棿缁煎悎鐪嬫澘
         </div>
         <div class="kb_headerPic" />
         <div class="kb_headTime">
@@ -22,7 +22,8 @@
           <div class="kb_left_top_title01 kb_title_text">
             <!--            <div class="PG01" />-->
             <!--            <svg-icon icon-class="sccx" />-->
-            浜х嚎鍔犲伐涓换鍔� <div style="margin-left: 30px">{{ number1 }} 鍗�</div>
+            浜х嚎鍔犲伐涓换鍔�
+            <div style="margin-left: 30px">{{ number1 }} 鍗�</div>
           </div>
 
           <div class="kb_left_top kb_pd10">
@@ -101,7 +102,9 @@
           <!-- 2-->
           <div class="kb_left_bottom kb_pd10">
             <div class="kb_left_bottom_content">
-              <div class="content_head kb_title_text">浜х嚎鍔犲伐浠诲姟 <div style="margin-left: 30px">{{ number2 }} 鍗�</div></div>
+              <div class="content_head kb_title_text">浜х嚎鍔犲伐浠诲姟
+                <div style="margin-left: 30px">{{ number2 }} 鍗�</div>
+              </div>
               <div class="content_body">
                 <el-table
                   ref="tableData"
@@ -319,6 +322,9 @@
   },
   data() {
     return {
+
+      onLine: navigator.onLine, // 鐩戝惉缃戠粶鏄惁鍦ㄧ嚎
+
       headTime: '',
 
       lineContent: [],
@@ -335,8 +341,14 @@
       number2: '',
 
       MarqueeTipsContent: '', // 鍏憡
-      speed: 100// 鍏憡鎾斁鐨勯�熷害
+      speed: 100, // 鍏憡鎾斁鐨勯�熷害
 
+      MarqueeTipsTask: null,
+      ShopSearchTask: null,
+      ShopSearchLineTask: null,
+      TableDataRollTask: null,
+      TableDataRankRollTask: null,
+      EchartsTask: null
     }
   },
 
@@ -344,9 +356,46 @@
     setInterval(this.getNowTime, 1000)
   },
   mounted() {
-    this.getValue()
+    // 鐩戝惉缃戠粶鏄惁鍦ㄧ嚎
+    window.addEventListener('online', this.updateOnlineStatus)
+    window.addEventListener('offline', this.updateOnlineStatus)
+    this.updateOnlineStatus({ type: this.onLine ? 'online' : 'offline', isFirst: true })
+  },
+  beforeDestroy() {
+    window.removeEventListener('online', this.updateOnlineStatus)
+    window.removeEventListener('offline', this.updateOnlineStatus)
   },
   methods: {
+    // 鏇存柊缃戠粶鐘舵��
+    updateOnlineStatus(e) {
+      if (e.isFirst) {
+        this.getValue()// 鑾峰彇鍊�
+      } else {
+        const loading = this.$loading({
+          lock: true,
+          text: '鏂綉浜嗭紝姝e湪鎷煎懡鑱旂綉涓紝璇锋鏌ョ綉缁滄槸鍚︽甯�...',
+          spinner: 'el-icon-loading',
+          customClass: 'osloading',
+          background: 'rgba(0, 0, 0, 0.7)'
+        })
+        const { type } = e
+        this.onLine = type === 'online'
+        if (this.onLine) {
+          this.getValue()
+          loading.close()
+          this.$message.success('缃戠粶杩炴帴鎴愬姛锛�')
+        } else {
+          clearInterval(this.MarqueeTipsTask)
+          clearInterval(this.ShopSearchTask)
+          clearInterval(this.ShopSearchLineTask)
+          clearInterval(this.TableDataRollTask)
+          clearInterval(this.TableDataRankRollTask)
+          clearInterval(this.EchartsTask)
+          this.$message.error('缃戠粶鎺夌嚎锛岃鍏虫敞缃戠粶鐘舵�侊紒')
+        }
+      }
+    },
+    // 鑾峰彇鍊�
     async getValue() {
       // await this.getShopSearch()
       await this.getShopSearchLine()
@@ -367,7 +416,7 @@
         this.MarqueeTipsContent = contentAll
         this.speed = this.MarqueeTipsContent.length / 10
 
-        setInterval(() => {
+        this.MarqueeTipsTask = setInterval(() => {
           WkspReportNotice({ shopcode: this.ShopArr.join(',') }).then(res1 => {
             let contentAll = ''
             res1.data.forEach(item => {
@@ -390,7 +439,7 @@
         })
       }
       setInterval(() => {
-        ShopSearch().then(res1 => {
+        this.ShopSearchTask = ShopSearch().then(res1 => {
           if (res1.code === '200') {
             this.ShopArr = []
             res1.data.forEach(item => {
@@ -413,7 +462,7 @@
       })
 
       let start = 0
-      const task = setInterval(() => {
+      this.ShopSearchLineTask = setInterval(() => {
         if (Math.floor(start / 3) === count && count !== 0) {
           start = 0
           LineSearchTopLeftData({ shopcode: this.ShopArr.join(',') }).then(res => {
@@ -425,7 +474,7 @@
             this.number1 = this.lineContent.length
           })
         } else if (count === 0) {
-          clearInterval(task)
+          clearInterval(this.ShopSearchLineTask)
           this.getShopSearchLine()
         }
         this.lineContent3 = this.lineContent.slice(start, start + 3)
@@ -441,7 +490,7 @@
 
         const divData = this.$refs.tableData.bodyWrapper
         // 鎷垮埌鍏冪礌鍚庯紝瀵瑰厓绱犺繘琛屽畾鏃跺鍔犺窛绂婚《閮ㄨ窛绂伙紝瀹炵幇婊氬姩鏁堟灉(姝ら厤缃负姣�100姣绉诲姩1鍍忕礌)
-        const task = setInterval(() => {
+        this.TableDataRollTask = setInterval(() => {
           // 鍏冪礌鑷璺濈椤堕儴1鍍忕礌
           divData.scrollTop += 1
           // divData.scrollTop += divData.scrollHeight / this.tableData.length
@@ -453,7 +502,7 @@
               this.tableData = res.data
               this.number2 = this.tableData.length
               if (this.tableData.length > 10) {
-                clearInterval(task)
+                clearInterval(this.TableDataRollTask)
                 this.getTableDataRoll()
               }
             })
@@ -468,7 +517,7 @@
 
         const divData = this.$refs.tableDataRank.bodyWrapper
         // 鎷垮埌鍏冪礌鍚庯紝瀵瑰厓绱犺繘琛屽畾鏃跺鍔犺窛绂婚《閮ㄨ窛绂伙紝瀹炵幇婊氬姩鏁堟灉(姝ら厤缃负姣�100姣绉诲姩1鍍忕礌)
-        const task = setInterval(() => {
+        this.TableDataRankRollTask = setInterval(() => {
           // 鍏冪礌鑷璺濈椤堕儴1鍍忕礌
           // divData.scrollTop += divData.scrollHeight / this.tableDataRank.length
           divData.scrollTop += 1
@@ -480,7 +529,7 @@
               this.tableDataRank = res.data
 
               if (this.tableDataRank.length > 9) {
-                clearInterval(task)
+                clearInterval(this.TableDataRankRollTask)
                 this.getTableDataRankRoll()
               }
             })
@@ -494,7 +543,7 @@
         loadEcharts('bar02', bar02(res.data.map(i => i.cont), res.data.map(i => i.name)))
       })
 
-      setInterval(() => {
+      this.EchartsTask = setInterval(() => {
         LineSearchBottomRightData({ shopcode: this.ShopArr.join(',') }).then(res => {
           loadEcharts('bar02', bar02(res.data.map(i => i.cont), res.data.map(i => i.name)))
         })

--
Gitblit v1.9.3