no message

main
HUOJIN\92525 2025-09-25 13:52:02 +08:00
parent df31755799
commit fdbe124e02
1 changed files with 19 additions and 66 deletions

View File

@ -16,7 +16,7 @@
v-for="item in items"
:key="item.id"
:label="item.code"
:value="returnType === 'object' ? item : item[returnValueKey]"
:value="getOptionValue(item)"
>
<span>{{ item.code }}</span>
<span>{{ item.name }}</span>
@ -33,7 +33,7 @@ export default {
props: {
value: {
type: [String, Number, Boolean, Array, Object],
default: ''
default: () => null
},
width: {
type: String,
@ -43,18 +43,12 @@ export default {
type: String,
default: '请选择'
},
disabled: {
type: Boolean,
default: false
},
disabled: Boolean,
clearable: {
type: Boolean,
default: true
},
multiple: {
type: Boolean,
default: false
},
multiple: Boolean,
filterable: {
type: Boolean,
default: true
@ -71,26 +65,24 @@ export default {
type: Boolean,
default: true
},
//
returnType: {
type: String,
default: 'object', // 'object' | 'value'
validator: function(value) {
return ['object', 'value'].includes(value)
}
default: 'object',
validator: value => ['object', 'value'].includes(value)
},
// returnType'value'
returnValueKey: {
type: String,
default: 'id'
}
},
data() {
return {
items: [],
loading: false
}
},
computed: {
selectedValue: {
get() {
@ -101,77 +93,38 @@ export default {
}
}
},
watch: {
// returnType
returnType: {
handler() {
this.handleReturnTypeChange()
},
immediate: true
}
},
created() {
this.initData()
},
methods: {
async initData() {
this.loading = true
try {
const res = await curdArea.queryAreaList({ enabled: this.isEnabled, bexb: this.bexb })
const res = await curdArea.queryAreaList({
enabled: this.isEnabled,
bexb: this.bexb
})
this.items = res || []
} catch (error) {
this.crud.notify('获取数据失败', CRUD.NOTIFICATION_TYPE.ERROR)
this.items = []
this.loading = false
} finally {
this.loading = false
}
},
getOptionValue(item) {
return this.returnType === 'object' ? item : item[this.returnValueKey]
},
handleChange(val) {
let emitValue = val
//
if (this.returnType === 'value' && val) {
if (this.multiple) {
//
emitValue = Array.isArray(val) ? val.map(item =>
typeof item === 'object' ? item[this.returnValueKey] : item
) : []
} else {
//
emitValue = typeof val === 'object' ? val[this.returnValueKey] : val
}
}
this.$emit('change', emitValue)
this.$emit('change', val)
},
handleClear() {
this.$emit('clear')
},
//
handleReturnTypeChange() {
if (this.returnType === 'value') {
//
if (this.multiple) {
const values = Array.isArray(this.value) ? this.value.map(item => typeof item === 'object' ? item[this.returnValueKey] : item) : []
this.$emit('input', values)
} else {
const value = typeof this.value === 'object' ? this.value[this.returnValueKey] : this.value
this.$emit('input', value)
}
} else {
//
if (this.multiple) {
const objects = Array.isArray(this.value) ? this.value.map(val => this.items.find(item => item[this.returnValueKey] === val) || val) : []
this.$emit('input', objects)
} else {
const object = this.items.find(item => item[this.returnValueKey] === this.value) || this.value
this.$emit('input', object)
}
}
}
}
}