Files
lingji-work-fe/src/components/common-select/index.vue

80 lines
1.5 KiB
Vue
Raw Normal View History

2025-06-27 18:37:42 +08:00
<!--
* @Author: RenXiaoDong
* @Date: 2025-06-25 14:02:40
-->
<template>
2025-09-04 12:07:18 +08:00
<Select
v-model:value="selectedValues"
:mode="multiple ? 'multiple' : undefined"
size="middle"
2025-06-27 18:37:42 +08:00
:placeholder="placeholder"
2025-09-04 12:07:18 +08:00
:allowClear="allClear"
:showSearch="allowSearch"
showArrow
2025-09-04 12:07:18 +08:00
:maxTagCount="maxTagCount"
2025-06-27 18:37:42 +08:00
@change="handleChange"
>
2025-09-04 12:07:18 +08:00
<Option v-for="(item, index) in options" :key="index" :value="item.id" :label="item.name">
2025-06-27 18:37:42 +08:00
{{ item.name }}
2025-09-04 12:07:18 +08:00
</Option>
</Select>
2025-06-27 18:37:42 +08:00
</template>
<script setup>
2025-09-04 12:07:18 +08:00
import { Select } from 'ant-design-vue';
const { Option } = Select;
2025-06-27 18:37:42 +08:00
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: () => [],
},
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']);
const selectedValues = ref(props.multiple ? [] : '');
2025-06-27 18:37:42 +08:00
watch(
() => props.modelValue,
(newVal) => {
selectedValues.value = newVal;
2025-06-27 18:37:42 +08:00
},
{ immediate: true },
);
watch(selectedValues, (newVal) => {
2025-06-27 18:37:42 +08:00
emits('update:modelValue', newVal);
});
const handleChange = (value) => {
selectedValues.value = value;
2025-06-27 18:37:42 +08:00
emits('change', value);
};
</script>