Просмотр исходного кода

fix(record): default checked devices

Casper Dai 2 лет назад
Родитель
Сommit
fa4ed464df
2 измененных файлов с 14 добавлено и 8 удалено
  1. 8 6
      src/components/tree/DeviceTree/index.vue
  2. 6 2
      src/views/device/record/index.vue

+ 8 - 6
src/components/tree/DeviceTree/index.vue

@@ -249,6 +249,9 @@ export default {
       this.setNodes(rootOption, this.onFilter(rootOption, this.$nodes, this.deviceName ? new RegExp(this.deviceName) : null))
       this.rootOption = rootOption
       this.customExpand = false
+      const diff = this.$presetNodeMap ? Object.keys(this.$presetNodeMap) : []
+      this.$presetNodeMap = null
+      return diff.length
     },
     onSearch () {
       this.filterNode(this.rootOption, this.deviceName ? new RegExp(this.deviceName) : null)
@@ -309,13 +312,12 @@ export default {
         })
         this.$presetNodeMap = map
         this.deviceName = ''
-        this.initData()
-        const diff = Object.keys(this.$presetNodeMap)
-        this.$presetNodeMap = null
-        return diff.length
+        if (this.$nodes) {
+          return this.initData()
+        }
+        return -1
       }
-      this.initData()
-      return 0
+      return this.initData()
     }
   }
 }

+ 6 - 2
src/views/device/record/index.vue

@@ -7,6 +7,7 @@
     horizontal
   >
     <device-tree
+      ref="tree"
       class="c-sibling-item c-sidebar u-width--lg"
       shrink
       checkbox
@@ -111,14 +112,17 @@ export default {
     onDeviceLoaded (data) {
       const count = this.colCount > 0 ? this.colCount * this.colCount : 9
       if (count) {
-        this.devices = this.addDefaultDevices(data, count, [])
+        const deviceIds = this.addDefaultDevices(data, count, [])
+        if (deviceIds.length > 0) {
+          this.$refs.tree.reset(deviceIds)
+        }
       }
     },
     addDefaultDevices ({ children, devices }, count, arr) {
       if (arr.length < count && devices?.length) {
         for (let i = 0; i < devices.length; i++) {
           if (devices[i].onlineStatus === 1) {
-            arr.push(this.transformDevice(devices[i]))
+            arr.push(devices[i].id)
             if (arr.length >= count) {
               return arr
             }