Kaynağa Gözat

fix: super admin tenant switching and power monitor

Casper Dai 1 yıl önce
ebeveyn
işleme
3cb6a442da

+ 1 - 1
src/api/user.js

@@ -184,7 +184,7 @@ export async function getTenants (query) {
 
 export async function getPlatformTenants () {
   const { count } = await getTenantCount()
-  return getTenantsByQuery({ max: count }, false)
+  return getTenantsByQuery({ pageSize: count }, false)
 }
 
 export function addTenant ({ name, remark }) {

+ 8 - 4
src/layout/components/Navbar/index.vue

@@ -23,11 +23,15 @@
           class="c-navbar__avatar"
           :src="avatar"
         >
-        <span class="c-sibling-item">{{ name }}</span>
+        <span class="c-sibling-item">
+          {{ name }}
+        </span>
         <i class="c-sibling-item near el-icon-arrow-down" />
       </div>
       <el-dropdown-menu slot="dropdown">
-        <el-dropdown-item command="profile">个人设置</el-dropdown-item>
+        <el-dropdown-item command="profile">
+          个人设置
+        </el-dropdown-item>
         <el-dropdown-item
           command="logout"
           divided
@@ -63,7 +67,7 @@
 <script>
 import { mapGetters } from 'vuex'
 import {
-  getPlatformTenants,
+  getTenants,
   resetDepartmentCache
 } from '@/api/user'
 import Breadcrumb from './Breadcrumb'
@@ -82,7 +86,7 @@ export default {
       drawer: false,
       tenantSchema: {
         condition: { name: '' },
-        list: getPlatformTenants,
+        list: getTenants,
         filters: [
           { key: 'name', type: 'search', placeholder: '标识' }
         ],

+ 1 - 1
src/utils/adapter/monitor.js

@@ -452,7 +452,7 @@ function startTask () {
       }
       queue = errorSet
     }
-  ).then(() => {
+  ).finally(() => {
     fetching = false
     started = false
     setTimeout(flush, 500)

+ 18 - 31
src/views/dashboard/components/DeviceCard.vue

@@ -32,7 +32,9 @@
           class="l-flex__none o-device__tip u-font-size--xs"
           :class="statusClass"
         >
-          <span class="u-color--white">{{ statusTip }}</span>
+          <span class="u-color--white">
+            {{ statusTip }}
+          </span>
         </div>
       </template>
       <i
@@ -58,7 +60,9 @@
             class="c-sibling-item"
             icon-class="volume"
           />
-          <span class="c-sibling-item nearest">{{ volumeTip }}</span>
+          <span class="c-sibling-item nearest">
+            {{ volumeTip }}
+          </span>
         </template>
       </div>
     </div>
@@ -75,14 +79,22 @@
           />
           <div class="l-flex__none l-flex--row c-sibling-item--v">
             <div class="u-relative">
-              <span class="u-font-size--md u-bold">{{ current.startTime }}</span>
-              <span class="o-device__ymd u-color--black light u-font-size--xs">{{ current.startDate }}</span>
+              <span class="u-font-size--md u-bold">
+                {{ current.startTime }}
+              </span>
+              <span class="o-device__ymd u-color--black light u-font-size--xs">
+                {{ current.startDate }}
+              </span>
             </div>
             <template v-if="current.endDate">
               <span class="o-device__line" />
               <div class="u-relative">
-                <span class="u-font-size--md u-bold">{{ current.endTime }}</span>
-                <span class="o-device__ymd u-color--black light u-font-size--xs">{{ current.endDate }}</span>
+                <span class="u-font-size--md u-bold">
+                  {{ current.endTime }}
+                </span>
+                <span class="o-device__ymd u-color--black light u-font-size--xs">
+                  {{ current.endDate }}
+                </span>
               </div>
             </template>
           </div>
@@ -229,36 +241,11 @@ export default {
   beforeCreate () {
     this.$timer = -1
     this.$refreshTimer = -1
-    this.$observer = null
-  },
-  mounted () {
-    if (!this.always) {
-      this.observe(this.$el)
-    }
   },
   beforeDestroy () {
     this.onReset(true)
-    this.$observer?.disconnect()
-    this.$observer = null
   },
   methods: {
-    observe () {
-      if (!this.$observer) {
-        this.$observer = new IntersectionObserver(entries => {
-          entries.forEach(entry => {
-            console.log('observe', this.device.name, entry.isIntersecting ? 'into view' : 'out view')
-            if (entry.isIntersecting) {
-              this.isInView = true
-            } else {
-              this.isInView = false
-            }
-          })
-        }, {
-          threshold: [0.25]
-        })
-      }
-      this.$observer.observe(this.$el)
-    },
     checkStatus () {
       if (!this.$firstView) {
         ScreenshotCache.watch(this.device, this.onScreenshotUpdate)

+ 38 - 13
src/views/dashboard/components/mixins/device.js

@@ -16,6 +16,7 @@ export default {
   },
   data () {
     return {
+      isInView: false,
       powerStatus: Status.LOADING,
       powerSwitchStatus: Power.LOADING,
       hasPower: true,
@@ -63,29 +64,53 @@ export default {
         return parseVolume(this.volume)
       }
       return ''
+    },
+    needWatch () {
+      return this.isOnline && this.isInView
     }
   },
   watch: {
-    isOnline: {
-      handler (val, old) {
-        if (val) {
-          addListener(this.device.id, this.onMessage)
-        } else {
-          if (old == null) {
-            return
-          }
-          removeListener(this.device.id, this.onMessage)
-        }
-      },
-      immediate: true
+    needWatch (val) {
+      if (val) {
+        addListener(this.device.id, this.onMessage)
+      } else {
+        removeListener(this.device.id, this.onMessage)
+      }
+    }
+  },
+  beforeCreate () {
+    this.$observer = null
+  },
+  mounted () {
+    if (!this.always) {
+      this.observe(this.$el)
     }
   },
   beforeDestroy () {
-    if (this.isOnline) {
+    if (this.needWatch) {
       removeListener(this.device.id, this.onMessage)
     }
+    this.$observer?.disconnect()
+    this.$observer = null
   },
   methods: {
+    observe () {
+      if (!this.$observer) {
+        this.$observer = new IntersectionObserver(entries => {
+          entries.forEach(entry => {
+            console.log('observe', this.device.name, entry.isIntersecting ? 'into view' : 'out view')
+            if (entry.isIntersecting) {
+              this.isInView = true
+            } else {
+              this.isInView = false
+            }
+          })
+        }, {
+          threshold: [0.25]
+        })
+      }
+      this.$observer.observe(this.$el)
+    },
     onMessage (value) {
       if (value.screen) {
         this.volume = value.screen.volume