Initial commit
This commit is contained in:
58
src/components/SelectSpec/index.vue
Normal file
58
src/components/SelectSpec/index.vue
Normal file
@@ -0,0 +1,58 @@
|
||||
<!-- 选择下拉框 -->
|
||||
<template>
|
||||
<a-select
|
||||
:allow-clear="allowClear"
|
||||
:show-search="showSearch"
|
||||
optionFilterProp="label"
|
||||
:options="specDict"
|
||||
:value="value"
|
||||
:placeholder="placeholder"
|
||||
@update:value="updateValue"
|
||||
:style="`width: ${width}px`"
|
||||
@blur="onBlur"
|
||||
@change="onChange"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { Spec } from '@/api/shop/spec/model';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
value?: string;
|
||||
placeholder?: string;
|
||||
showSearch?: string;
|
||||
allowClear?: boolean;
|
||||
width?: number;
|
||||
specDict?: Spec[];
|
||||
index?: number;
|
||||
}>(),
|
||||
{
|
||||
placeholder: '请选择服务器厂商'
|
||||
}
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:value', value: string): void;
|
||||
(e: 'blur'): void;
|
||||
(e: 'done', value: Spec, index: number): void;
|
||||
}>();
|
||||
|
||||
/* 更新选中数据 */
|
||||
const updateValue = (value: string) => {
|
||||
emit('update:value', value);
|
||||
};
|
||||
|
||||
/* 失去焦点 */
|
||||
const onBlur = () => {
|
||||
emit('blur');
|
||||
};
|
||||
|
||||
const onChange = (value: string) => {
|
||||
props.specDict?.map((d) => {
|
||||
if (d.value == value) {
|
||||
emit('done', d, Number(props.index));
|
||||
}
|
||||
});
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user