diff --git a/src/components/FormFields/JSONManyToManySelect/ValueField.vue b/src/components/FormFields/JSONManyToManySelect/ValueField.vue index 29ade6513..d407625aa 100644 --- a/src/components/FormFields/JSONManyToManySelect/ValueField.vue +++ b/src/components/FormFields/JSONManyToManySelect/ValueField.vue @@ -31,11 +31,42 @@ export default { }, data() { return { - loading: false + loading: true, + type: 'string' } }, - computed: { - type() { + watch: { + match() { + this.getSetType() + }, + attr: { + handler() { + this.getSetType() + }, + deep: true + } + }, + mounted() { + this.getSetType() + this.loading = false + }, + methods: { + handleInput(value) { + this.$emit('input', value) + }, + getSetType() { + this.loading = true + this.type = this.getType() + if (['select', 'array'].includes(this.type) && typeof this.value === 'string') { + const value = this.value ? this.value.split(',') : [] + console.log('Type: ', this.type, 'Value: ', value) + this.handleInput(value) + } + this.$nextTick(() => { + this.loading = false + }) + }, + getType() { const attrType = this.attr.type if (attrType === 'm2m') { return 'select' @@ -44,28 +75,12 @@ export default { } else if (attrType === 'select') { return 'select' } - if (this.match in ['in', 'ip_in']) { + if (['in', 'ip_in'].includes(this.match)) { return 'array' } else { return 'string' } } - }, - watch: { - attr: { - handler() { - this.loading = true - this.$nextTick(() => { - this.loading = false - }) - }, - deep: true - } - }, - methods: { - handleInput(value) { - this.$emit('input', value) - } } } diff --git a/src/components/FormFields/JSONManyToManySelect/index.vue b/src/components/FormFields/JSONManyToManySelect/index.vue index 9c5015850..ea3e881ab 100644 --- a/src/components/FormFields/JSONManyToManySelect/index.vue +++ b/src/components/FormFields/JSONManyToManySelect/index.vue @@ -19,6 +19,7 @@ item.inTable).map(item => { return { prop: item.name, - label: item.label + label: item.label, + formatter: item.formatter } }) } @@ -153,7 +156,7 @@ export default { { prop: 'name', label: this.$t('common.AttrName'), formatter: tableFormatter('name') }, { prop: 'match', label: this.$t('common.Match'), formatter: tableFormatter('match') }, { prop: 'value', label: this.$t('common.AttrValue'), formatter: ValueFormatter, formatterArgs: { attrs: this.attrs }}, - { prop: 'action', label: this.$t('common.Action'), formatter: (row, col, cellValue, index) => { + { prop: 'action', label: this.$t('common.Action'), align: 'center', width: '120px', formatter: (row, col, cellValue, index) => { return (
{ option.hidden = !matchSupports.includes(option.value) }) - setTimeout(() => updateForm({ match: matchSupports[0] }), 0.1) + setTimeout(() => updateForm({ match: matchSupports[0], value: '' }), 0.1) } } }, @@ -226,6 +229,13 @@ export default { } } }, + watch: { + attrFormVisible(val) { + if (!val) { + this.getAttrsCount() + } + } + }, mounted() { this.formConfig.form = this.getDefaultAttrForm() if (this.value.type === 'attrs') { @@ -240,13 +250,17 @@ export default { this.attrMatchTableConfig.tableConfig.url = setUrlParam(this.select2.url, 'attr_rules', attrFilter) }, getAttrFilterKey() { + if (this.tableConfig.totalData.length === 0) return '' let attrFilter = { type: 'attrs', attrs: this.tableConfig.totalData } attrFilter = encodeURIComponent(btoa(JSON.stringify(attrFilter))) return attrFilter }, getAttrsCount() { const attrFilter = this.getAttrFilterKey() - console.log('attrFilter', attrFilter) + if (!attrFilter) { + this.attrMatchCount = 0 + return + } let url = setUrlParam(this.select2.url, 'attr_rules', attrFilter) url = setUrlParam(url, 'limit', 1) return this.$axios.get(url).then(res => { @@ -288,7 +302,7 @@ export default { const options = this.formConfig.fields[0].options const used = this.tableConfig.totalData.map(attr => attr.name) options.forEach(opt => { - if (used.includes(opt.value)) { + if (used.includes(opt.value) && opt.value !== this.formConfig.form.name) { opt.disabled = true } else { delete opt.disabled diff --git a/src/i18n/langs/zh.json b/src/i18n/langs/zh.json index 522413ee4..d060ba0b5 100644 --- a/src/i18n/langs/zh.json +++ b/src/i18n/langs/zh.json @@ -456,7 +456,7 @@ "ReLoginErr": "登录时长已超过 5 分钟,请重新登录" }, "common": { - "MatchedCount": "匹配条目", + "MatchedCount": "匹配结果", "SelectAttrs": "选择属性", "MatchResult": "匹配结果", "GreatEqualThan": "大于等于", diff --git a/src/views/assets/Asset/AssetCreateUpdate/components/AssetAccounts.vue b/src/views/assets/Asset/AssetCreateUpdate/components/AssetAccounts.vue index 3f2f41486..79bf4b0e8 100644 --- a/src/views/assets/Asset/AssetCreateUpdate/components/AssetAccounts.vue +++ b/src/views/assets/Asset/AssetCreateUpdate/components/AssetAccounts.vue @@ -19,7 +19,7 @@ - - +