Răsfoiți Sursa

feat: tenant settings

Casper Dai 3 ani în urmă
părinte
comite
9b575c61cd

+ 4 - 7
src/api/user.js

@@ -113,7 +113,6 @@ function normalizeGroups (groups, parentGroup, onlyOnce) {
       path,
       name,
       remark,
-      aiAudit: parentGroup ? void 0 : attributes.aiAudit?.[0] || '0',
       label: remark || name
     }
     if (onlyOnce) {
@@ -155,15 +154,14 @@ export function getTenantTree () {
   })
 }
 
-export function addTenant ({ name, remark, aiAudit }) {
+export function addTenant ({ name, remark }) {
   return add({
     url: `/groups`,
     method: 'POST',
     data: {
       name,
       attributes: {
-        remark: [remark],
-        aiAudit: aiAudit ? [aiAudit] : void 0
+        remark: [remark]
       }
     }
   }, keycloakRequest)
@@ -200,15 +198,14 @@ export function addSubGroup ({ id }, { name, remark }) {
   }, keycloakRequest)
 }
 
-export function updateGroup ({ id, name, remark, aiAudit }) {
+export function updateGroup ({ id, name, remark }) {
   return update({
     url: `/groups/${id}`,
     method: 'PUT',
     data: {
       name,
       attributes: {
-        remark: [remark],
-        aiAudit: aiAudit ? [aiAudit] : void 0
+        remark: [remark]
       }
     }
   }, null, keycloakRequest)

+ 7 - 0
src/router/index.js

@@ -260,6 +260,13 @@ export const asyncRoutes = [
     component: Layout,
     meta: { title: '平台管理', icon: 'pm' },
     children: [
+      {
+        name: 'settings',
+        path: 'settings',
+        component: () => import('@/views/realm/settings/index'),
+        access: [Access.MANAGE_TENANTS, Access.MANAGE_TENANT],
+        meta: { title: '功能管理' }
+      },
       {
         name: 'org',
         path: 'org',

+ 1 - 4
src/views/realm/ai-timing/Tenant.vue

@@ -17,10 +17,7 @@
           @node-click="onGroupTreeClick"
         />
       </div>
-      <group-timing-table
-        :group="group.path"
-        admin
-      />
+      <group-timing-table :group="group.path" />
     </template>
     <template v-else>
       <div

+ 0 - 24
src/views/realm/ai-timing/api.js

@@ -5,30 +5,6 @@ import {
   send
 } from '@/api/base'
 
-export function getTenantConfig (tenant) {
-  return send({
-    url: '/device/deviceAuditConfig/tenantServiceConfig',
-    method: 'GET',
-    params: { tenant }
-  })
-}
-
-export function addTenantConfig (data) {
-  return add({
-    url: '/device/deviceAuditConfig/tenantServiceConfig',
-    method: 'POST',
-    data
-  })
-}
-
-export function updateTenantConfig (data) {
-  return update({
-    url: '/device/deviceAuditConfig/tenantServiceConfig',
-    method: 'PUT',
-    data
-  })
-}
-
 export function getTenantStratConfig (tenant) {
   return send({
     url: '/device/deviceAuditConfig/deviceAuditConfig',

+ 4 - 2
src/views/realm/ai-timing/components/DeviceServiceConfigDialog.vue

@@ -1,7 +1,7 @@
 <template>
   <confirm-dialog
     ref="configDialog"
-    title="设备服务配置"
+    :title="title"
     @confirm="onSave"
   >
     <div class="c-grid-form mini u-align-self--center">
@@ -28,11 +28,13 @@ export default {
   name: 'DeviceServiceConfigDialog',
   data () {
     return {
+      title: '',
       deviceServiceConfig: {}
     }
   },
   methods: {
-    show (deviceId) {
+    show (deviceId, name) {
+      this.title = name ? `${name}服务配置` : '设备服务配置'
       getDeviceServiceConfig(deviceId).then(({ data }) => {
         this.deviceServiceConfig = data || {
           deviceId,

+ 3 - 11
src/views/realm/ai-timing/components/GroupTimingTable.vue

@@ -3,7 +3,6 @@
     ref="table"
     :schema="schema"
   >
-    <service-config-dialog ref="serviceConfigDialog" />
     <strat-config-dialog ref="stratConfigDialog" />
     <table-dialog
       ref="historyDialog"
@@ -17,14 +16,12 @@
 <script>
 import { getDevicesByAdmin } from '@/api/device'
 import { getHistory } from '../api'
-import ServiceConfigDialog from './ServiceConfigDialog'
 import StratConfigDialog from './StratConfigDialog'
 import DeviceServiceConfigDialog from './DeviceServiceConfigDialog'
 
 export default {
   name: 'AITimingTable',
   components: {
-    ServiceConfigDialog,
     StratConfigDialog,
     DeviceServiceConfigDialog
   },
@@ -32,10 +29,6 @@ export default {
     group: {
       type: String,
       required: true
-    },
-    admin: {
-      type: [Boolean, String],
-      default: false
     }
   },
   data () {
@@ -47,10 +40,9 @@ export default {
           { key: 'name', type: 'search', placeholder: '设备名称' }
         ],
         buttons: [
-          this.admin ? { label: '服务配置', on: this.onServiceConfig } : null,
           { label: '策略配置', on: this.onStratConfig },
           { label: '全部回采记录', on: this.onAllHistory }
-        ].filter(Boolean),
+        ],
         cols: [
           { prop: 'name', label: '设备名称', 'min-width': 120 },
           { prop: 'serialNumber', label: '序列号' },
@@ -175,8 +167,8 @@ export default {
       this.device = null
       this.$refs.historyDialog.show()
     },
-    onDeviceServiceConfig ({ id }) {
-      this.$refs.deviceServiceConfigDialog.show(id)
+    onDeviceServiceConfig ({ id, name }) {
+      this.$refs.deviceServiceConfigDialog.show(id, name)
     },
     onDeviceHistory ({ id, name }) {
       this.device = { id, name }

+ 0 - 50
src/views/realm/ai-timing/components/ServiceConfigDialog.vue

@@ -1,50 +0,0 @@
-<template>
-  <confirm-dialog
-    ref="configDialog"
-    title="服务配置"
-    @confirm="onSave"
-  >
-    <div class="c-grid-form mini u-align-self--center">
-      <span class="c-grid-form__label u-bold">开启:</span>
-      <div class="l-flex--row c-grid-form__option">
-        <el-switch
-          v-model="tenantConfig.enabled"
-          active-color="#13ce66"
-          inactive-color="#ff4949"
-        />
-      </div>
-    </div>
-  </confirm-dialog>
-</template>
-
-<script>
-import {
-  getTenantConfig,
-  addTenantConfig,
-  updateTenantConfig
-} from '../api'
-
-export default {
-  name: 'ServiceConfigDialog',
-  data () {
-    return {
-      tenantConfig: {}
-    }
-  },
-  methods: {
-    show (tenant) {
-      getTenantConfig(tenant).then(({ data }) => {
-        this.tenantConfig = data || {
-          tenant,
-          enabled: false,
-          collectDevice: 1
-        }
-        this.$refs.configDialog.show()
-      })
-    },
-    onSave (done) {
-      (this.tenantConfig.id ? updateTenantConfig : addTenantConfig)(this.tenantConfig).then(done)
-    }
-  }
-}
-</script>

+ 26 - 0
src/views/realm/settings/Group.vue

@@ -0,0 +1,26 @@
+<template>
+  <wrapper
+    :vertical="false"
+    fill
+    margin
+    padding
+    background
+  >
+    <settings :group="tenant" />
+  </wrapper>
+</template>
+
+<script>
+import { mapGetters } from 'vuex'
+import Settings from './components/Settings'
+
+export default {
+  name: 'SettingsGroup',
+  components: {
+    Settings
+  },
+  computed: {
+    ...mapGetters(['tenant'])
+  }
+}
+</script>

+ 95 - 0
src/views/realm/settings/Tenant.vue

@@ -0,0 +1,95 @@
+<template>
+  <wrapper
+    :vertical="false"
+    fill
+    margin
+    padding
+    background
+  >
+    <template v-if="groups">
+      <div class="c-tree-sidebar u-overflow-y--auto">
+        <el-tree
+          ref="groupTree"
+          :data="groups"
+          class="c-tree-sidebar__main"
+          node-key="path"
+          highlight-current
+          @node-click="onGroupTreeClick"
+        />
+      </div>
+      <settings
+        :group="group.path"
+        admin
+      />
+    </template>
+    <template v-else>
+      <div
+        v-loading="loading"
+        class="l-flex__auto l-flex--row center"
+      >
+        <template v-if="!loading">
+          <warning
+            v-if="error"
+            @click="getTreeData"
+          />
+          <div
+            v-else
+            class="u-bold"
+          >
+            暂无租户,请先添加租户
+          </div>
+        </template>
+      </div>
+    </template>
+  </wrapper>
+</template>
+
+<script>
+import { getTopGroups } from '@/api/user'
+import Settings from './components/Settings'
+
+export default {
+  name: 'SettingsTenant',
+  components: {
+    Settings
+  },
+  data () {
+    return {
+      loading: true,
+      error: false,
+      groups: null,
+      group: null
+    }
+  },
+  created () {
+    this.getTreeData()
+  },
+  methods: {
+    getTreeData () {
+      this.loading = true
+      this.error = false
+      getTopGroups().then(
+        ({ data }) => {
+          if (data.length) {
+            this.groups = data
+            this.group = this.groups[0]
+            this.$nextTick(() => {
+              this.$refs.groupTree.setCurrentKey(this.group.path)
+            })
+          }
+        },
+        () => {
+          this.error = true
+        }
+      ).finally(() => {
+        this.loading = false
+      })
+    },
+    onGroupTreeClick (group) {
+      if (!this.group || this.group.id !== group.id) {
+        this.group = group
+      }
+    }
+  }
+}
+</script>

+ 27 - 2
src/views/realm/tenant/api.js → src/views/realm/settings/api.js

@@ -1,6 +1,7 @@
 import {
-  send,
-  update
+  add,
+  update,
+  send
 } from '@/api/base'
 import {
   AlarmStrategy,
@@ -47,3 +48,27 @@ export function updateInformStrategy (tenant, strategy) {
     }
   })
 }
+
+export function getTenantServiceConfig (tenant, type) {
+  return send({
+    url: '/device/deviceAuditConfig/tenantServiceConfig',
+    method: 'GET',
+    params: { tenant, type }
+  })
+}
+
+export function addTenantServiceConfig (data) {
+  return add({
+    url: '/device/deviceAuditConfig/tenantServiceConfig',
+    method: 'POST',
+    data
+  })
+}
+
+export function updateTenantServiceConfig (data) {
+  return update({
+    url: '/device/deviceAuditConfig/tenantServiceConfig',
+    method: 'PUT',
+    data
+  })
+}

+ 74 - 0
src/views/realm/settings/components/AlarmStratConfigDialog.vue

@@ -0,0 +1,74 @@
+<template>
+  <confirm-dialog
+    ref="configDialog"
+    title="告警设置"
+    @confirm="onSave"
+  >
+    <div class="u-align-self--center">
+      <div
+        v-for="strategy in strategies"
+        :key="strategy.level"
+        class="c-sibling-item--v far"
+      >
+        <div class="c-sibling-item--v u-bold">{{ strategy.name }}</div>
+        <div class="l-flex--row c-sibling-item--v">
+          <div
+            v-for="option in strategy.options"
+            :key="option.key"
+            class="c-sibling-item far"
+          >
+            <span class="c-sibling-item">{{ option.label }}</span>
+            <el-switch
+              v-model="option.value"
+              class="c-sibling-item"
+              active-color="#13ce66"
+              inactive-color="#ff4949"
+            />
+          </div>
+        </div>
+      </div>
+    </div>
+  </confirm-dialog>
+</template>
+
+<script>
+import {
+  getInformStrategy,
+  updateInformStrategy
+} from '../api'
+
+export default {
+  name: 'AlarmStratConfigDialog',
+  data () {
+    return {
+      strategies: []
+    }
+  },
+  methods: {
+    show (tenant) {
+      this.$tenant = tenant
+      getInformStrategy(tenant).then(data => {
+        this.strategies = data
+        this.$refs.configDialog.show()
+      })
+    },
+    onSave (done) {
+      const strategies = {}
+      this.strategies.forEach(({ level, options }) => {
+        const strategy = {}
+        options.forEach(({ key, value }) => {
+          strategy[key] = value
+        })
+        strategies[level] = strategy
+      })
+      updateInformStrategy(this.$tenant, strategies).then(done)
+    }
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+.o-strategy-name {
+  width: 60px;
+}
+</style>

+ 56 - 0
src/views/realm/settings/components/ServiceConfigDialog.vue

@@ -0,0 +1,56 @@
+<template>
+  <confirm-dialog
+    ref="configDialog"
+    :title="title"
+    @confirm="onSave"
+  >
+    <div class="c-grid-form mini u-align-self--center">
+      <span class="c-grid-form__label u-bold">开启:</span>
+      <div class="l-flex--row c-grid-form__option">
+        <el-switch
+          v-model="tenantServiceConfig.enabled"
+          active-color="#13ce66"
+          inactive-color="#ff4949"
+        />
+      </div>
+    </div>
+  </confirm-dialog>
+</template>
+
+<script>
+import {
+  getTenantServiceConfig,
+  addTenantServiceConfig,
+  updateTenantServiceConfig
+} from '../api'
+
+export default {
+  name: 'ServiceConfigDialog',
+  data () {
+    return {
+      title: '',
+      tenantServiceConfig: {}
+    }
+  },
+  methods: {
+    show (tenant, type) {
+      getTenantServiceConfig(tenant, type).then(({ data }) => {
+        this.title = type === 1 ? 'AI抽帧检测服务配置' : '媒资AI审核服务配置'
+        this.$has = !!data
+        this.tenantServiceConfig = {
+          tenant,
+          type,
+          enabled: data ? data.enabled : false
+        }
+        if (type === 1) {
+          this.tenantServiceConfig.collectDevice = 1
+        }
+        this.$refs.configDialog.show()
+      })
+    },
+    onSave (done) {
+      (this.$has ? updateTenantServiceConfig : addTenantServiceConfig)(this.tenantServiceConfig).then(done)
+    }
+  }
+}
+</script>

+ 70 - 0
src/views/realm/settings/components/Settings.vue

@@ -0,0 +1,70 @@
+<template>
+  <div class="l-flex__auto o-settings">
+    <button
+      class="o-button"
+      @click="onAlarmStratConfig"
+    >
+      告警策略
+    </button>
+    <button
+      v-if="admin"
+      class="o-button"
+      @click="onAssetServiceConfig"
+    >
+      媒资AI审核
+    </button>
+    <button
+      v-if="admin"
+      class="o-button"
+      @click="onTimingServiceConfig"
+    >
+      AI抽帧检测
+    </button>
+    <alarm-strat-config-dialog ref="alarmStratConfigDialog" />
+    <service-config-dialog ref="serviceConfigDialog" />
+  </div>
+</template>
+
+<script>
+import AlarmStratConfigDialog from './AlarmStratConfigDialog'
+import ServiceConfigDialog from './ServiceConfigDialog'
+
+export default {
+  name: 'SettingsList',
+  components: {
+    AlarmStratConfigDialog,
+    ServiceConfigDialog
+  },
+  props: {
+    group: {
+      type: String,
+      required: true
+    },
+    admin: {
+      type: [Boolean, String],
+      default: false
+    }
+  },
+  methods: {
+    onAlarmStratConfig () {
+      this.$refs.alarmStratConfigDialog.show(this.group)
+    },
+    onAssetServiceConfig () {
+      this.$refs.serviceConfigDialog.show(this.group, 2)
+    },
+    onTimingServiceConfig () {
+      this.$refs.serviceConfigDialog.show(this.group, 1)
+    }
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+.o-settings {
+  align-self: flex-start;
+  display: flex;
+  align-items: flex-start;
+  flex-wrap: wrap;
+  gap: $spacing;
+}
+</style>

+ 19 - 0
src/views/realm/settings/index.vue

@@ -0,0 +1,19 @@
+<script>
+import { mapGetters } from 'vuex'
+import Tenant from './Tenant'
+import Group from './Group'
+
+export default {
+  name: 'Settings',
+  components: {
+    Tenant,
+    Group
+  },
+  computed: {
+    ...mapGetters(['isSuperAdmin'])
+  },
+  render (h) {
+    return h(this.isSuperAdmin ? 'Tenant' : 'Group')
+  }
+}
+</script>

+ 4 - 89
src/views/realm/tenant/Tenant.vue

@@ -39,49 +39,6 @@
           maxlength="50"
           clearable
         />
-        <template v-if="isTenant">
-          <span class="c-grid-form__label">媒资AI机审:</span>
-          <div class="l-flex--row c-grid-form__option">
-            <el-switch
-              v-model="group.aiAudit"
-              class="c-sibling-item"
-              active-value="1"
-              inactive-value="0"
-              active-color="#13ce66"
-              inactive-color="#ff4949"
-            />
-          </div>
-        </template>
-      </div>
-    </confirm-dialog>
-    <confirm-dialog
-      ref="strategyDialog"
-      title="告警设置"
-      @confirm="onSaveStrategy"
-    >
-      <div class="u-align-self--center">
-        <div
-          v-for="strategy in strategies"
-          :key="strategy.level"
-          class="c-sibling-item--v far"
-        >
-          <div class="c-sibling-item--v u-bold">{{ strategy.name }}</div>
-          <div class="l-flex--row c-sibling-item--v">
-            <div
-              v-for="option in strategy.options"
-              :key="option.key"
-              class="c-sibling-item far"
-            >
-              <span class="c-sibling-item">{{ option.label }}</span>
-              <el-switch
-                v-model="option.value"
-                class="c-sibling-item"
-                active-color="#13ce66"
-                inactive-color="#ff4949"
-              />
-            </div>
-          </div>
-        </div>
       </div>
     </confirm-dialog>
   </wrapper>
@@ -95,10 +52,6 @@ import {
   updateGroup,
   deleteGroup
 } from '@/api/user'
-import {
-  getInformStrategy,
-  updateInformStrategy
-} from './api'
 import { unbindDevices } from '@/api/device'
 
 export default {
@@ -120,17 +73,8 @@ export default {
         cols: [
           { prop: 'name', label: '标识' },
           { prop: 'remark', label: '名称' },
-          { label: '媒资AI机审', type: 'tag', render ({ parentGroup, aiAudit }) {
-            return parentGroup
-              ? null
-              : {
-                type: aiAudit === '1' ? 'success' : 'danger',
-                label: aiAudit === '1' ? '开启' : '关闭'
-              }
-          } },
           { type: 'invoke', width: 240, render: [
             { label: '编辑', on: this.onEdit },
-            { label: '告警设置', render ({ parentGroup }) { return !parentGroup }, on: this.onStrategy },
             { label: '新增下级', render ({ parentGroup }) { return !parentGroup }, on: this.onAddSub },
             { label: '删除', on: this.onDel }
           ] }
@@ -150,8 +94,7 @@ export default {
       this.dialogTitle = '新增租户'
       this.group = {
         name: '',
-        remark: '',
-        aiAudit: '1'
+        remark: ''
       }
       this.$refs.editDialog.show()
     },
@@ -159,9 +102,9 @@ export default {
       this.isAdd = false
       this.isTenant = !group.parentGroup
       this.dialogTitle = group.parentGroup ? '编辑部门' : '编辑租户'
-      const { id, name, remark, aiAudit } = group
+      const { id, name, remark } = group
       this.$group = group
-      this.group = { id, name, remark, aiAudit: this.isTenant ? aiAudit : void 0 }
+      this.group = { id, name, remark }
       this.$refs.editDialog.show()
     },
     onAddSub (group) {
@@ -201,13 +144,10 @@ export default {
         })
         return
       }
-      if (this.$group.remark !== this.group.remark
-        || this.isTenant && this.$group.aiAudit !== this.group.aiAudit
-      ) {
+      if (this.$group.remark !== this.group.remark) {
         updateGroup(this.group).then(() => {
           done()
           this.$group.remark = this.group.remark
-          this.$group.aiAudit = this.group.aiAudit
         })
       }
     },
@@ -242,32 +182,7 @@ export default {
             this.$closeLoading(loading)
           })
       })
-    },
-    onStrategy ({ path }) {
-      this.$tenant = path
-      getInformStrategy(path).then(data => {
-        console.log(data)
-        this.strategies = data
-        this.$refs.strategyDialog.show()
-      })
-    },
-    onSaveStrategy (done) {
-      const strategies = {}
-      this.strategies.forEach(({ level, options }) => {
-        const strategy = {}
-        options.forEach(({ key, value }) => {
-          strategy[key] = value
-        })
-        strategies[level] = strategy
-      })
-      updateInformStrategy(this.$tenant, strategies).then(done)
     }
   }
 }
 </script>
-
-<style lang="scss" scoped>
-.o-strategy-name {
-  width: 60px;
-}
-</style>