diff --git a/src/components/Form/FormFields/TransferSelect.vue b/src/components/Form/FormFields/TransferSelect.vue index 2143e9c2b..906bea91b 100644 --- a/src/components/Form/FormFields/TransferSelect.vue +++ b/src/components/Form/FormFields/TransferSelect.vue @@ -126,13 +126,17 @@ export default { return _.uniq(value) }, set(val) { - this.$emit('input', val) + this.emit(val) } } }, methods: { + emit(val) { + const value = _.uniq(val) + this.$emit('input', value) + }, onInputChange(val) { - this.$emit('input', val) + this.emit(val) }, handleFocus() { this.$refs.select2.selectRef.blur() @@ -155,7 +159,7 @@ export default { return { value: item.id, label: item.label } }) this.select2.options = options - this.$emit('input', options.map(item => item.value)) + this.emit(options.map(item => item.value)) this.showTransfer = false } } diff --git a/src/components/Table/TableFormatters/AmountFormatter.vue b/src/components/Table/TableFormatters/AmountFormatter.vue index 951e6d3e5..b3766f196 100644 --- a/src/components/Table/TableFormatters/AmountFormatter.vue +++ b/src/components/Table/TableFormatters/AmountFormatter.vue @@ -3,17 +3,19 @@ @@ -37,41 +39,73 @@ export default { showItems: true, getItem(item) { return item.name - } + }, + async: false, + ajax: {}, + title: '' } } } }, data() { + const formatterArgs = Object.assign(this.formatterArgsDefault, this.col.formatterArgs || {}) return { - formatterArgs: Object.assign(this.formatterArgsDefault, this.col.formatterArgs || {}) + formatterArgs: formatterArgs, + data: formatterArgs.async ? [] : (this.cellValue || []), + amount: '', + asyncGetDone: false } }, computed: { title() { - return this.formatterArgs.title || '' + return this.formatterArgs.title || this.col.label.replace('amount', '').replace('数量', '') }, items() { + if (this.formatterArgs.async && !this.asyncGetDone) { + return [this.$t('common.tree.Loading') + '...'] + } const getItem = this.formatterArgs.getItem || (item => item.name) - let data = this.cellValue?.map(item => getItem(item)) || [] + let data = this.data.map(item => getItem(item)) || [] data = data.filter(Boolean) return data }, showItems() { - return this.formatterArgs.showItems !== false && this.cellValue?.length > 0 + return this.amount !== 0 && this.amount !== '' } }, + async mounted() { + this.amount = this.formatterArgs.async ? this.cellValue : (this.cellValue || []).length + }, methods: { getKey(item) { - const id = Math.random().toString(36).substring(2) + const id = Math.random().toString(36).substring(16) return id + item + }, + getDefaultUrl() { + const url = new URL(this.url, location.origin) + url.pathname += this.row.id + '/' + return url.pathname + }, + async getAsyncItems() { + if (!this.formatterArgs.async) { + return + } + if (this.asyncGetDone) { + return + } + const url = this.formatterArgs.ajax.url || this.getDefaultUrl() + const params = this.formatterArgs.ajax.params || {} + const transform = this.formatterArgs.ajax.transform || (resp => resp[this.col.prop.replace('_amount', '')]) + const response = await this.$axios.get(url, { params: params }) + this.data = transform(response) + this.asyncGetDone = true } } } diff --git a/src/views/assets/Domain/DomainList.vue b/src/views/assets/Domain/DomainList.vue index 046a1d737..5aac70316 100644 --- a/src/views/assets/Domain/DomainList.vue +++ b/src/views/assets/Domain/DomainList.vue @@ -4,7 +4,7 @@