From d98534d0396c1652c58182db9761e212df5833db Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 13 Jun 2023 12:41:32 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20json=20attr=20form=20=E6=9B=B4=E6=94=B9?= =?UTF-8?q?=20name=20=E5=92=8C=20match=20=E6=96=B9=E5=BC=8F=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E5=86=8D=E6=B8=85=E7=A9=BA=20value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JSONManyToManySelect/AttrFormDialog.vue | 23 +++++++++++++++---- src/views/assets/const.js | 4 ++++ src/views/users/const.js | 3 ++- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/components/FormFields/JSONManyToManySelect/AttrFormDialog.vue b/src/components/FormFields/JSONManyToManySelect/AttrFormDialog.vue index 9e621043a..2f1c15875 100644 --- a/src/components/FormFields/JSONManyToManySelect/AttrFormDialog.vue +++ b/src/components/FormFields/JSONManyToManySelect/AttrFormDialog.vue @@ -41,8 +41,10 @@ export default { } }, data() { + const vm = this return { loading: true, + currentValue: '', formConfig: { // 为了方便更新,避免去取 fields 的索引 hasSaveContinue: false, @@ -69,11 +71,13 @@ export default { if (['m2m', 'select'].includes(attrType)) { defaultValue = [] } else if (['bool'].includes(attrType)) { - defaultValue = false + defaultValue = !!this.currentValue + } else { + defaultValue = typeof this.currentValue === 'string' ? this.currentValue : '' } setTimeout(() => { updateForm({ match: matchSupports[0], value: defaultValue }) - }, 0.1) + }, 10) } } }, @@ -85,11 +89,15 @@ export default { on: { change: ([value], updateForm) => { let defaultValue = '' - if (['in', 'ip_in'].includes(value)) { + if (['in', 'ip_in', 'm2m'].includes(value)) { defaultValue = [] + } else if (typeof vm.currentValue === 'string') { + defaultValue = vm.currentValue } - updateForm({ value: defaultValue }) - this.formConfig.fields[2].el.match = value + setTimeout(() => { + updateForm({ value: defaultValue }) + this.formConfig.fields[2].el.match = value + }, 10) } } }, @@ -100,6 +108,11 @@ export default { el: { match: attrMatchOptions[0].value, attr: this.attrs[0] + }, + on: { + input: ([value], updateForm) => { + vm.currentValue = value + } } } ] diff --git a/src/views/assets/const.js b/src/views/assets/const.js index 7797807e0..b8d4794d3 100644 --- a/src/views/assets/const.js +++ b/src/views/assets/const.js @@ -239,6 +239,10 @@ export const assetJSONSelectMeta = (vm) => { multiple: true, url: '/api/v1/assets/labels/' } + }, + { + name: 'comment', + label: vm.$t('common.Comment') } ] } diff --git a/src/views/users/const.js b/src/views/users/const.js index 943bc5b5d..07b146c63 100644 --- a/src/views/users/const.js +++ b/src/views/users/const.js @@ -32,7 +32,8 @@ export const userJSONSelectMeta = (vm) => { }, { name: 'comment', - label: vm.$t('common.Comment') + label: vm.$t('common.Comment'), + inTable: true }, { name: 'is_active',