2025-06-27 18:37:42 +08:00
|
|
|
<!--
|
|
|
|
|
* @Author: RenXiaoDong
|
|
|
|
|
* @Date: 2025-06-25 14:02:40
|
|
|
|
|
-->
|
|
|
|
|
<template>
|
|
|
|
|
<a-select
|
2025-07-23 14:30:44 +08:00
|
|
|
v-model="selectedValues"
|
2025-06-27 18:37:42 +08:00
|
|
|
:multiple="multiple"
|
|
|
|
|
size="medium"
|
|
|
|
|
:placeholder="placeholder"
|
2025-08-01 17:25:21 +08:00
|
|
|
:allow-clear="allClear"
|
2025-09-01 17:33:19 +08:00
|
|
|
:allow-search="allowSearch"
|
2025-07-23 14:30:44 +08:00
|
|
|
:max-tag-count="maxTagCount"
|
2025-06-27 18:37:42 +08:00
|
|
|
@change="handleChange"
|
|
|
|
|
>
|
|
|
|
|
<a-option v-for="(item, index) in options" :key="index" :value="item.id" :label="item.name">
|
|
|
|
|
{{ item.name }}
|
|
|
|
|
</a-option>
|
|
|
|
|
</a-select>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
import { ref, watch } from 'vue';
|
|
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
modelValue: {
|
|
|
|
|
type: [Array, String, Number],
|
|
|
|
|
default: () => [],
|
|
|
|
|
},
|
|
|
|
|
multiple: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: true,
|
|
|
|
|
},
|
|
|
|
|
placeholder: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: '全部',
|
|
|
|
|
},
|
|
|
|
|
options: {
|
|
|
|
|
type: Array,
|
|
|
|
|
default: () => [],
|
|
|
|
|
},
|
2025-07-23 14:30:44 +08:00
|
|
|
maxTagCount: {
|
|
|
|
|
type: Number,
|
|
|
|
|
default: 3,
|
|
|
|
|
},
|
2025-08-01 17:25:21 +08:00
|
|
|
allClear: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: true,
|
2025-09-01 17:33:19 +08:00
|
|
|
},
|
|
|
|
|
allowSearch: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false,
|
2025-08-01 17:25:21 +08:00
|
|
|
}
|
2025-06-27 18:37:42 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const emits = defineEmits(['update:modelValue', 'change']);
|
|
|
|
|
|
2025-07-23 14:30:44 +08:00
|
|
|
const selectedValues = ref(props.multiple ? [] : '');
|
2025-06-27 18:37:42 +08:00
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => props.modelValue,
|
|
|
|
|
(newVal) => {
|
2025-07-23 14:30:44 +08:00
|
|
|
selectedValues.value = newVal;
|
2025-06-27 18:37:42 +08:00
|
|
|
},
|
|
|
|
|
{ immediate: true },
|
|
|
|
|
);
|
2025-07-23 14:30:44 +08:00
|
|
|
|
|
|
|
|
watch(selectedValues, (newVal) => {
|
2025-06-27 18:37:42 +08:00
|
|
|
emits('update:modelValue', newVal);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const handleChange = (value) => {
|
2025-07-23 14:30:44 +08:00
|
|
|
selectedValues.value = value;
|
2025-06-27 18:37:42 +08:00
|
|
|
emits('change', value);
|
|
|
|
|
};
|
|
|
|
|
</script>
|