Selaa lähdekoodia

feat(ai): support threshold configuration

Casper Dai 3 vuotta sitten
vanhempi
sitoutus
3c7db89135

+ 16 - 14
src/components/table/GridTable/index.vue

@@ -7,26 +7,28 @@
       v-if="hasHeader"
       class="l-flex__none l-flex--row c-table__header"
     >
-      <div class="l-flex__greedy">
+      <div class="l-flex__fill">
         <slot
           name="header"
           :condition="options.params"
           :total-count="options.totalCount"
         />
         <template v-if="buttons">
-          <button
-            v-for="(button, index) in buttons"
-            :key="index"
-            class="o-button"
-            @click="onClickButton(button)"
-          >
-            <i
-              v-if="button.icon"
-              class="o-button__icon"
-              :class="button.icon"
-            />
-            {{ button.label }}
-          </button>
+          <div class="l-flex wrap">
+            <button
+              v-for="(button, index) in buttons"
+              :key="index"
+              class="c-sibling-item o-button"
+              @click="onClickButton(button)"
+            >
+              <i
+                v-if="button.icon"
+                class="o-button__icon"
+                :class="button.icon"
+              />
+              {{ button.label }}
+            </button>
+          </div>
         </template>
       </div>
       <template v-if="filters">

+ 0 - 3
src/components/table/Pagination/index.vue

@@ -44,9 +44,6 @@ export default {
       }
     }
   },
-  created () {
-    console.log(this.$attrs)
-  },
   methods: {
     onCurrentChange (val) {
       this.$emit('pagination', { page: val, limit: this.limit })

+ 16 - 14
src/components/table/Table/index.vue

@@ -8,26 +8,28 @@
       v-if="hasHeader"
       class="l-flex__none l-flex--row c-table__header"
     >
-      <div class="l-flex__greedy">
+      <div class="l-flex__fill">
         <slot
           name="header"
           :condition="options.params"
           :total-count="options.totalCount"
         />
         <template v-if="buttons">
-          <button
-            v-for="(button, index) in buttons"
-            :key="index"
-            class="o-button"
-            @click="onClickButton(button)"
-          >
-            <i
-              v-if="button.icon"
-              class="o-button__icon"
-              :class="button.icon"
-            />
-            {{ button.label }}
-          </button>
+          <div class="l-flex wrap">
+            <button
+              v-for="(button, index) in buttons"
+              :key="index"
+              class="c-sibling-item o-button"
+              @click="onClickButton(button)"
+            >
+              <i
+                v-if="button.icon"
+                class="o-button__icon"
+                :class="button.icon"
+              />
+              {{ button.label }}
+            </button>
+          </div>
         </template>
       </div>
       <template v-if="filters">

+ 4 - 6
src/scss/bem/_layout.scss

@@ -1,6 +1,10 @@
 .l-flex {
   display: flex;
 
+  &.wrap {
+    flex-wrap: wrap;
+  }
+
   &__auto {
     flex: 1 1 auto;
     min-width: 0;
@@ -16,12 +20,6 @@
   &__none {
     flex: none;
   }
-
-  &__greedy {
-    flex: 1 0 auto;
-    min-width: 0;
-    min-height: 0;
-  }
 }
 
 .l-flex--row {

+ 13 - 4
src/views/realm/ai-stock/Assign.vue

@@ -78,6 +78,7 @@
         </template>
       </div>
     </template>
+    <credit-config-dialog ref="creditDialog" />
   </div>
 </template>
 
@@ -89,9 +90,13 @@ import {
   addCredit,
   deleteCredit
 } from './api'
+import CreditConfigDialog from './components/CreditConfigDialog'
 
 export default {
   name: 'StockAssign',
+  components: {
+    CreditConfigDialog
+  },
   data () {
     const auditTypeOptions = [
       { value: 1, label: '图片' },
@@ -110,7 +115,8 @@ export default {
         condition: { auditType: void 0 },
         list: this.getTenantCredits,
         buttons: [
-          { type: 'add', label: '分配', on: this.onAdd }
+          { type: 'add', label: '分配', on: this.onAdd },
+          { label: '阈值配置', on: this.onConfig }
         ],
         filters: [
           { key: 'auditType', type: 'select', placeholder: '全部类型', options: auditTypeOptions }
@@ -205,7 +211,7 @@ export default {
       this.$refs.stockDialog.show()
     },
     onChoosen ({ value, done }) {
-      const { auditType, initialAmount, allocatedAmount } = value
+      const { auditType, initialAmount, allocatedAmount, effectiveDate, expiryDate } = value
       if (initialAmount - allocatedAmount < 1) {
         this.$message({
           type: 'warning',
@@ -216,8 +222,8 @@ export default {
       this.fromCredit = value
       this.credit = {
         auditType,
-        initialAmount: 1,
-        date: ''
+        initialAmount: this.remaining,
+        date: [effectiveDate, expiryDate]
       }
       done()
       this.$refs.addDialog.show()
@@ -248,6 +254,9 @@ export default {
       deleteCredit(credit).then(() => {
         this.$refs.table.decrease(1)
       })
+    },
+    onConfig () {
+      this.$refs.creditDialog.show(this.group.path)
     }
   }
 }

+ 21 - 3
src/views/realm/ai-stock/Stock.vue

@@ -33,6 +33,7 @@
         />
       </div>
     </confirm-dialog>
+    <credit-config-dialog ref="creditDialog" />
   </schema-table>
 </template>
 
@@ -42,9 +43,13 @@ import {
   addCredit,
   deleteCredit
 } from './api'
+import CreditConfigDialog from './components/CreditConfigDialog'
 
 export default {
   name: 'AIStock',
+  components: {
+    CreditConfigDialog
+  },
   data () {
     const auditTypeOptions = [
       { value: 1, label: '图片' },
@@ -59,7 +64,8 @@ export default {
         condition: { auditType: void 0 },
         list: getCredits,
         buttons: [
-          { type: 'add', on: this.onAdd }
+          { type: 'add', on: this.onAdd },
+          { label: '阈值配置', on: this.onConfig }
         ],
         filters: [
           { key: 'auditType', type: 'select', placeholder: '全部类型', options: auditTypeOptions }
@@ -81,14 +87,23 @@ export default {
           ] }
         ]
       },
-      credit: {}
+      credit: {},
+      creditConfig: {
+        has: false,
+        threshold: 0
+      }
+    }
+  },
+  computed: {
+    creditTitle () {
+      return this.creditConfig.has ? '更新阈值' : '新增阈值'
     }
   },
   methods: {
     onAdd () {
       this.credit = {
         auditType: 1,
-        initialAmount: 1,
+        initialAmount: 1000,
         date: ''
       }
       this.$refs.addDialog.show()
@@ -117,6 +132,9 @@ export default {
       deleteCredit(credit).then(() => {
         this.$refs.table.decrease(1)
       })
+    },
+    onConfig () {
+      this.$refs.creditDialog.show()
     }
   }
 }

+ 27 - 1
src/views/realm/ai-stock/api.js

@@ -1,7 +1,9 @@
 import request from '@/utils/request'
 import {
   add,
-  del
+  del,
+  update,
+  send
 } from '@/api/base'
 
 export function getCredits (query) {
@@ -44,3 +46,27 @@ export function deleteCredit ({ id, auditType }) {
     method: 'DELETE'
   }, ['库存', '图片库存', '视频库存'][auditType])
 }
+
+export function getCreditConfig (tenant) {
+  return send({
+    url: '/minio-data/ai/credit/warn/config',
+    method: 'GET',
+    params: { tenant }
+  })
+}
+
+export function addCreditConfig (threshold, tenant) {
+  return add({
+    url: '/minio-data/ai/credit/warn/config',
+    method: 'POST',
+    data: { tenant, threshold }
+  })
+}
+
+export function updateCreditConfig (threshold, tenant) {
+  return update({
+    url: '/minio-data/ai/credit/warn/config',
+    method: 'PUT',
+    data: { tenant, threshold }
+  })
+}

+ 62 - 0
src/views/realm/ai-stock/components/CreditConfigDialog.vue

@@ -0,0 +1,62 @@
+<template>
+  <confirm-dialog
+    ref="creditDialog"
+    :title="creditTitle"
+    @confirm="onSave"
+  >
+    <div class="c-grid-form mini u-align-self--center">
+      <span class="c-grid-form__label">阈值:</span>
+      <el-input-number
+        v-model="threshold"
+        :min="1"
+        :max="999999"
+        step-strictly
+      />
+    </div>
+  </confirm-dialog>
+</template>
+
+<script>
+import {
+  getCreditConfig,
+  addCreditConfig,
+  updateCreditConfig
+} from '../api'
+
+export default {
+  name: 'CreditConfigDialog',
+  data () {
+    return {
+      has: false,
+      threshold: 0
+    }
+  },
+  computed: {
+    creditTitle () {
+      return this.has ? '更新阈值' : '新增阈值'
+    }
+  },
+  methods: {
+    show (tenant) {
+      this.$tenant = tenant
+      getCreditConfig(tenant).then(({ data }) => {
+        if (data) {
+          this.has = true
+          this.threshold = data.threshold
+        } else {
+          this.has = false
+          this.threshold = 1000
+          this.$message({
+            type: 'warning',
+            message: '暂未配置阈值,请先配置'
+          })
+        }
+        this.$refs.creditDialog.show()
+      })
+    },
+    onSave (done) {
+      (this.has ? updateCreditConfig : addCreditConfig)(this.threshold, this.$tenant).then(done)
+    }
+  }
+}
+</script>