Browse Source

fix: device filter

Casper Dai 2 years ago
parent
commit
729776b780

+ 1 - 1
src/api/base.js

@@ -36,7 +36,7 @@ export function addTenantAndOrg (data = {}) {
 }
 
 export function addTenantOrOrg (data = {}) {
-  return store.getters.isTopGroupAdmin
+  return store.getters.isTopGroup
     ? {
       ...data,
       tenant: store.getters.tenant

+ 28 - 21
src/api/device.js

@@ -1,3 +1,4 @@
+import store from '@/store'
 import request, { tenantRequest } from '@/utils/request'
 import {
   add,
@@ -100,33 +101,41 @@ export function deleteDevice ({ id, name, masterId }) {
 }
 
 export function getDevices (query, options) {
-  const scope = addTenantOrOrg({})
-  if (scope.tenant) {
-    return getDevicesByAdmin({
-      ...query,
-      ...scope
-    }, options)
+  return getDevicesByQuery(addTenantOrOrg(query), options)
+}
+
+export function getDevicesByQuery (query, options) {
+  const { tenant, org, ...params } = query
+  if (tenant || org && org === store.getters.tenant) {
+    return getDevicesByTenant(tenant || org, params, options)
   }
+  return getDevicesByOrg(org, params, options)
+}
+
+export function getDevicesByTenant (tenant, query, options) {
   const { pageNum: pageIndex, pageSize, ...params } = query
   return tenantRequest({
-    url: '/device/relation/page',
+    url: '/device/tenant/page',
     method: 'GET',
     params: {
-      pageIndex, pageSize,
-      ...params,
-      ...scope
+      tenant,
+      pageIndex,
+      pageSize,
+      ...params
     },
     ...options
   })
 }
 
-export function getDevicesByAdmin (query, options) {
+export function getDevicesByOrg (org, query, options) {
   const { pageNum: pageIndex, pageSize, ...params } = query
   return tenantRequest({
-    url: params.tenant ? '/device/tenant/page' : '/device/relation/page',
+    url: '/device/relation/page',
     method: 'GET',
     params: {
-      pageIndex, pageSize,
+      org,
+      pageIndex,
+      pageSize,
       ...params
     },
     ...options
@@ -313,19 +322,17 @@ export function deleteDeviceFromGroup (id, { id: deviceId, name }) {
   })
 }
 
-export function getDeviceStatistics (productId) {
-  return tenantRequest({
-    url: '/device/listDeviceTotal',
-    method: 'GET',
-    params: addTenantOrOrg({ productId })
-  })
+export function getDeviceStatistics () {
+  return getDeviceStatisticsByPath(store.getters.org)
 }
 
-export function getDeviceStatisticsByCustom (query) {
+export function getDeviceStatisticsByPath (path) {
   return tenantRequest({
     url: '/device/listDeviceTotal',
     method: 'GET',
-    params: query
+    params: path === store.getters.tenant
+      ? { tenant: path }
+      : { org: path }
   })
 }
 

+ 7 - 20
src/views/dashboard/Dashboard.vue

@@ -110,14 +110,13 @@
 </template>
 
 <script>
-import { mapGetters } from 'vuex'
 import {
   subscribe,
   unsubscribe
 } from '@/utils/mqtt'
 import {
-  getDevicesByAdmin,
-  getDeviceStatisticsByCustom
+  getDevicesByQuery,
+  getDeviceStatisticsByPath
 } from '@/api/device'
 import Card from './components/Card'
 import Device from './components/Device'
@@ -139,9 +138,6 @@ export default {
       group: {}
     }
   },
-  computed: {
-    ...mapGetters(['tenant', 'org'])
-  },
   created () {
     this.$timer = -1
     subscribe([
@@ -196,11 +192,7 @@ export default {
       this.monitor = monitor
       clearTimeout(this.$timer)
       this.deviceOptions = { loaded: false }
-      getDeviceStatisticsByCustom(
-        this.group.path === this.tenant
-          ? { tenant: this.group.path }
-          : { org: this.group.path }
-      ).then(({ data }) => {
+      getDeviceStatisticsByPath(this.group.path).then(({ data }) => {
         const { deactivatedTotal, notConnectedTotal, offLineTotal, onLineTotal, total } = data
         monitor.total = total
         monitor.online = onLineTotal
@@ -226,17 +218,12 @@ export default {
       }
       const options = { list: [], loaded: false }
       this.deviceOptions = options
-      const query = {
+      getDevicesByQuery({
         pageNum: 1,
         pageSize: total,
-        activate: 1
-      }
-      if (this.group.path === this.tenant) {
-        query.tenant = this.group.path
-      } else {
-        query.org = this.group.path
-      }
-      getDevicesByAdmin(query, { custom: true }).then(
+        activate: 1,
+        org: this.group.path
+      }, { custom: true }).then(
         ({ data }) => {
           options.list = data.sort(this.sort)
           options.loaded = true

+ 4 - 7
src/views/platform/tenant/device/components/Device.vue

@@ -89,7 +89,7 @@
 
 <script>
 import {
-  getDevicesByAdmin,
+  getDevicesByTenant,
   addDevice,
   deleteDevice,
   getSubDevices,
@@ -127,7 +127,7 @@ export default {
       productSelectSchema,
       schema: {
         keepalive: true,
-        list: this.getDevicesByAdmin,
+        list: this.getDevicesByTenant,
         transform: this.transform,
         transformData: __SUB_DEVICE__ && this.transformTableData,
         buttons: [
@@ -183,11 +183,8 @@ export default {
         ...params
       })
     },
-    getDevicesByAdmin (params) {
-      return getDevicesByAdmin({
-        tenant: this.tenant,
-        ...params
-      })
+    getDevicesByTenant (params) {
+      return getDevicesByTenant(this.tenant, params)
     },
     transform (data) {
       return {

+ 4 - 4
src/views/platform/upgrade/deploy/index.vue

@@ -77,7 +77,7 @@
           <device-tree
             :key="id"
             class="l-flex__fill c-sibling-item far u-overflow-y--auto"
-            :invoke="getDevices"
+            :invoke="getDevicesByTenant"
             @change="onChooseDevices"
           />
         </template>
@@ -87,7 +87,7 @@
 </template>
 
 <script>
-import { getDevicesByAdmin } from '@/api/device'
+import { getDevicesByTenant } from '@/api/device'
 import {
   getApks,
   getVersions,
@@ -212,8 +212,8 @@ export default {
         this.tenant = tenant
       }
     },
-    getDevices (params) {
-      return getDevicesByAdmin({ tenant: this.tenant.path, ...params })
+    getDevicesByTenant (params) {
+      return getDevicesByTenant(this.tenant.path, params)
     },
     onChooseDevices (devices) {
       this.$slectedDevices = devices

+ 2 - 79
src/views/screen/review/workflow/api.js

@@ -1,49 +1,18 @@
 import request, { tenantRequest } from '@/utils/request'
 import {
-  reject,
-  submit,
   confirmAndSend,
   del,
   send,
-  addScope,
-  addUser,
+  addTenantOrOrg,
   addTenant
 } from '@/api/base'
 
-export function getPublishes (query) {
-  const { pageNum: pageIndex, pageSize, ...params } = query
-  return tenantRequest({
-    url: '/orchestration/calendarReleaseSchedu/page',
-    method: 'GET',
-    params: addScope({
-      pageIndex, pageSize,
-      ...params
-    })
-  })
-}
-
-export function resolvePublish ({ id }) {
-  return send({
-    url: `/orchestration/calendarReleaseSchedu/${id}/approval`,
-    method: 'POST',
-    data: { remark: '' }
-  })
-}
-
-export function rejectPublish ({ id, name }, remark) {
-  return reject({
-    url: `/orchestration/calendarReleaseSchedu/${id}/reject`,
-    method: 'POST',
-    data: { remark }
-  }, name)
-}
-
 export function getPublishHistory (query) {
   const { pageNum: pageIndex, pageSize, ...params } = query
   return tenantRequest({
     url: '/orchestration/calendarReleaseHis/page',
     method: 'GET',
-    params: addScope({
+    params: addTenantOrOrg({
       pageIndex, pageSize,
       ...params
     })
@@ -57,30 +26,6 @@ export function cancelPublish (calendarReleaseHisId, name) {
   })
 }
 
-export function getMyWorkflows (query) {
-  const { pageNum: pageIndex, pageSize, ...params } = query
-  return tenantRequest({
-    url: '/workflow/calendarRelease/page',
-    method: 'POST',
-    data: addUser({
-      pageIndex, pageSize,
-      ...params
-    })
-  })
-}
-
-export function getPublishWorkflows (query) {
-  const { pageNum: pageIndex, pageSize, ...params } = query
-  return tenantRequest({
-    url: '/workflow/calendarRelease/page',
-    method: 'POST',
-    data: addTenant({
-      pageIndex, pageSize,
-      ...params
-    })
-  })
-}
-
 export function getWorkflowsByUser (query) {
   const { pageNum: pageIndex, pageSize, ...params } = query
   return request({
@@ -119,28 +64,6 @@ export function getWorkflow (workflowId) {
   })
 }
 
-export function reviewWorkflow (workflowId, data) {
-  return send({
-    url: `/workflow/calendarRelease/${workflowId}/reject`,
-    method: 'POST',
-    data
-  })
-}
-
-export function calendarPublishRestart (workflowId, name) {
-  return submit({
-    url: `/workflow/${workflowId}/restart `,
-    method: 'POST'
-  }, name)
-}
-
-export function calendarPublishStop (workflowId) {
-  return request({
-    url: `/workflow/${workflowId}/stop`,
-    method: 'POST'
-  })
-}
-
 export function getWorkflowHistory (workflowId) {
   return request({
     url: `/workflow/${workflowId}/history `,