فهرست منبع

feat: device filter by department

Casper Dai 2 سال پیش
والد
کامیت
5ff7595d84
2فایلهای تغییر یافته به همراه42 افزوده شده و 5 حذف شده
  1. 21 2
      src/views/device/index.vue
  2. 21 3
      src/views/realm/device/index.vue

+ 21 - 2
src/views/device/index.vue

@@ -4,9 +4,15 @@
     margin
     padding
     background
+    horizontal
   >
+    <department-tree
+      class="c-sibling-item c-sidebar u-width--md"
+      @change="onGroupChanged"
+    />
     <schema-table
       ref="table"
+      class="c-sibling-item far"
       row-key="id"
       :schema="schema"
       @row-click="onRowClick"
@@ -40,7 +46,7 @@ import {
 import { toDateStr } from '@/utils/event'
 import { publish } from '@/api/platform'
 import {
-  getDevices,
+  getDevicesByQuery,
   getSubDevices,
   activateDevice,
   deactivateDevice
@@ -55,7 +61,7 @@ export default {
       ratio: null,
       schema: {
         keepalive: true,
-        list: getDevices,
+        list: this.getDevicesByQuery,
         transform: this.transform,
         transformData: __SUB_DEVICE__ && this.transformTableData,
         filters: [
@@ -98,6 +104,19 @@ export default {
     }
   },
   methods: {
+    onGroupChanged (group) {
+      this.$group = group
+      this.$refs.table?.pageTo(1)
+    },
+    getDevicesByQuery (params) {
+      if (!this.$group) {
+        return Promise.resolve({ data: [] })
+      }
+      return getDevicesByQuery({
+        org: this.$group.path,
+        ...params
+      })
+    },
     transform (data) {
       return {
         ...data,

+ 21 - 3
src/views/realm/device/index.vue

@@ -4,9 +4,15 @@
     margin
     padding
     background
+    horizontal
   >
+    <department-tree
+      class="c-sibling-item c-sidebar u-width--md"
+      @change="onGroupChanged"
+    />
     <schema-table
       ref="table"
+      class="c-sibling-item far"
       row-key="id"
       :schema="schema"
       @row-click="onRowClick"
@@ -78,7 +84,7 @@ import {
   validLatitude
 } from '@/utils/validate'
 import {
-  getDevices,
+  getDevicesByQuery,
   getSubDevices,
   activateDevice,
   deactivateDevice,
@@ -91,7 +97,7 @@ export default {
     return {
       schema: {
         keepalive: true,
-        list: getDevices,
+        list: this.getDevicesByQuery,
         transform: this.transform,
         transformData: __SUB_DEVICE__ && this.transformTableData,
         filters: [
@@ -127,7 +133,6 @@ export default {
                 type: 'warning',
                 label: '未设置'
               } },
-          { prop: 'address', label: '地址', 'min-width': 100 },
           { type: 'tag', render: ({ empty, activate, onlineStatus }) => empty
             ? null
             : activate
@@ -149,6 +154,19 @@ export default {
     }
   },
   methods: {
+    onGroupChanged (group) {
+      this.$group = group
+      this.$refs.table?.pageTo(1)
+    },
+    getDevicesByQuery (params) {
+      if (!this.$group) {
+        return Promise.resolve({ data: [] })
+      }
+      return getDevicesByQuery({
+        org: this.$group.path,
+        ...params
+      })
+    },
     transform (data) {
       return {
         ...data,