From 8449dafd55aafe0cef2308946acbf8401c82fc10 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 15 Jun 2023 17:59:23 +0800 Subject: [PATCH 1/2] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=20attr=20form=20?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../JSONManyToManySelect/AttrFormDialog.vue | 47 ++++++++--------- .../JSONManyToManySelect/ValueField.vue | 51 ++++++++++++------- src/i18n/langs/zh.json | 4 +- 3 files changed, 58 insertions(+), 44 deletions(-) diff --git a/src/components/FormFields/JSONManyToManySelect/AttrFormDialog.vue b/src/components/FormFields/JSONManyToManySelect/AttrFormDialog.vue index bd0be0013..20b3ed629 100644 --- a/src/components/FormFields/JSONManyToManySelect/AttrFormDialog.vue +++ b/src/components/FormFields/JSONManyToManySelect/AttrFormDialog.vue @@ -62,24 +62,13 @@ export default { }), on: { change: ([val], updateForm) => { + // 变化会影响 match 的选项 const attr = this.attrs.find(attr => attr.name === val) if (!attr) return - this.formConfig.fields[2].el.attr = attr - const attrType = attr.type || 'str' - const matchSupports = typeMatchMapper[attrType] - attrMatchOptions.forEach((option) => { - option.hidden = !matchSupports.includes(option.value) - }) - let defaultValue = '' - if (['m2m', 'select'].includes(attrType)) { - defaultValue = [] - } else if (['bool'].includes(attrType)) { - defaultValue = !!this.currentValue - } else { - defaultValue = typeof this.currentValue === 'string' ? this.currentValue : '' - } + const matchSupports = vm.updateMatchOptions(attr) + const matchOption = matchSupports.find(item => item.value === vm.form.match) || matchSupports[0] setTimeout(() => { - updateForm({ match: matchSupports[0], value: defaultValue }) + updateForm({ match: matchOption.value }) }, 10) } } @@ -91,14 +80,8 @@ export default { options: attrMatchOptions, on: { change: ([value], updateForm) => { - let defaultValue = '' - if (['in', 'ip_in', 'm2m'].includes(value)) { - defaultValue = [] - } else if (typeof vm.currentValue === 'string') { - defaultValue = vm.currentValue - } + // 变化会影响 value 的选项 setTimeout(() => { - updateForm({ value: defaultValue }) this.formConfig.fields[2].el.match = value }, 10) } @@ -126,9 +109,8 @@ export default { if (this.form.index === undefined || this.form.index === -1) { Object.assign(this.form, this.getDefaultAttrForm()) } - this.formConfig.fields[2].el.attr = this.attrs.find(attr => attr.name === this.form.name) - this.formConfig.fields[2].el.match = this.form.match - this.$log.debug('Form config: ', this.formConfig) + this.updateMatchOptions() + this.$log.debug('Attr Form config: ', this.formConfig) this.loading = false }, methods: { @@ -148,6 +130,21 @@ export default { }, onAttrDialogConfirm(form) { this.$emit('confirm', form) + }, + updateMatchOptions(attr) { + if (!attr) { + attr = this.attrs.find(attr => attr.name === this.form.name) + } + if (!attr) return + const attrType = attr.type || 'str' + const matchSupports = typeMatchMapper[attrType] + attrMatchOptions.forEach((option) => { + option.hidden = !matchSupports.includes(option.value) + }) + this.formConfig.fields[2].el.attr = attr + const supports = attrMatchOptions.filter(option => !option.hidden) + this.formConfig.fields[2].el.match = supports[0].value + return supports } } } diff --git a/src/components/FormFields/JSONManyToManySelect/ValueField.vue b/src/components/FormFields/JSONManyToManySelect/ValueField.vue index dfb87c1a4..59c5d089a 100644 --- a/src/components/FormFields/JSONManyToManySelect/ValueField.vue +++ b/src/components/FormFields/JSONManyToManySelect/ValueField.vue @@ -1,9 +1,9 @@ @@ -35,35 +35,52 @@ export default { type: 'string' } }, + computed: { + iValue: { + get() { + const multipleTypes = ['array', 'select'] + let newValue = this.value + if (multipleTypes.includes(this.type)) { + if (!Array.isArray(this.value)) { + newValue = [] + } + } else if (this.type === 'bool') { + newValue = !!this.value + } else { + if (Array.isArray(this.value)) { + newValue = '' + } else { + newValue = this.value.toString() + } + } + if (this.value !== newValue) { + this.handleInput(newValue) + } + return newValue + } + } + }, watch: { match() { - this.setTypeAndValue() + this.changeValueType() }, attr: { handler() { - this.setTypeAndValue() + this.changeValueType() }, deep: true } }, mounted() { - this.setTypeAndValue() + this.changeValueType() }, methods: { handleInput(value) { this.$emit('input', value) }, - setTypeAndValue() { - this.loading = false + changeValueType() { + this.loading = true this.type = this.getType() - this.$log.debug('ValueField: Type: ', this.type, 'Value: ', this.value) - if (['select', 'array'].includes(this.type) && typeof this.value === 'string') { - const value = this.value ? this.value.split(',') : [] - this.handleInput(value) - } else if (this.type === 'bool') { - const value = !!this.value - this.handleInput(value) - } this.$nextTick(() => { this.loading = false }) diff --git a/src/i18n/langs/zh.json b/src/i18n/langs/zh.json index 513da6321..bea3fbed8 100644 --- a/src/i18n/langs/zh.json +++ b/src/i18n/langs/zh.json @@ -223,7 +223,7 @@ }, "assets": { "CustomType": "自定义类型", - "CustomHelpMessage": "自定义类型资产,需要 Applet 插件的支持,请确保对应 Applet 已部署安装", + "CustomHelpMessage": "自定义类型资产,依赖于远程应用,请前往系统设置在远程应用中配置", "CustomFields": "自定义属性", "CommentHelpText": "注意:备注信息会在 Luna 页面的用户授权资产树中进行悬停显示,普通用户可以查看,请不要填写敏感信息。", "BulkUpdatePlatformHelpText": "只有资产的原平台类型与所选平台类型相同时才会进行更新,若更新前后的平台类型不同则不会更新。", @@ -326,7 +326,7 @@ "Domain": "网域", "DomainDetail": "网域详情", "DomainHelpMessage": "网域功能是为了解决部分环境(如:混合云)无法直接连接而新增的功能,原理是通过网关服务器进行跳转登录。JMS => 网域网关 => 目标资产", - "WebHelpMessage": "Web 类型资产依赖于远程应用,请前往系统设置在远程应用中配置发布机。", + "WebHelpMessage": "Web 类型资产依赖于远程应用,请前往系统设置在远程应用中配置", "FullName": "全称", "Gateway": "网关", "GatewayProtocolHelpText": "SSH网关,支持代理SSH,RDP和VNC", From e60a33a2b1bcfbe7b654bf7f17afac51f34cc370 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 15 Jun 2023 18:28:16 +0800 Subject: [PATCH 2/2] =?UTF-8?q?perf:=20=E4=BF=AE=E6=94=B9=20json=20attr=20?= =?UTF-8?q?form=20=E8=A1=A8=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FormFields/JSONManyToManySelect/AttrFormDialog.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/FormFields/JSONManyToManySelect/AttrFormDialog.vue b/src/components/FormFields/JSONManyToManySelect/AttrFormDialog.vue index 20b3ed629..d3dd022f4 100644 --- a/src/components/FormFields/JSONManyToManySelect/AttrFormDialog.vue +++ b/src/components/FormFields/JSONManyToManySelect/AttrFormDialog.vue @@ -65,8 +65,7 @@ export default { // 变化会影响 match 的选项 const attr = this.attrs.find(attr => attr.name === val) if (!attr) return - const matchSupports = vm.updateMatchOptions(attr) - const matchOption = matchSupports.find(item => item.value === vm.form.match) || matchSupports[0] + const matchOption = vm.updateMatchOptions(attr) setTimeout(() => { updateForm({ match: matchOption.value }) }, 10) @@ -143,8 +142,9 @@ export default { }) this.formConfig.fields[2].el.attr = attr const supports = attrMatchOptions.filter(option => !option.hidden) - this.formConfig.fields[2].el.match = supports[0].value - return supports + const matchOption = supports.find(item => item.value === this.form.match) || supports[0] + this.formConfig.fields[2].el.match = matchOption.value + return matchOption } } }