You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.2 KiB
93 lines
2.2 KiB
2 years ago
|
<template>
|
||
2 years ago
|
<el-select :size="state.size.size" :class="['form-item', full && 'full']" v-model="myValue"
|
||
|
:placeholder="placeholder || t('rule.pleaseSelect')" :filterable="filterable" :disabled="disabled"
|
||
|
:clearable="clearable" @change="$emit('change', myValue)" :teleported="false">
|
||
2 years ago
|
<el-option v-if="dict" v-for="(val, key, i) in state.dict[dict]" :key="key" :value="key" :label="val" />
|
||
|
<el-option v-if="stateProp" v-for="item in state[stateProp]" :key="item[valueKey]" :value="item[valueKey]"
|
||
|
:label="item[labelKey]" />
|
||
2 years ago
|
<el-option v-if="maxValue" v-for="index in maxValue" :key="index" :value="index" />
|
||
|
<slot />
|
||
2 years ago
|
</el-select>
|
||
|
</template>
|
||
|
|
||
|
<script lang="ts" setup>
|
||
|
import { useStore } from "vuex";
|
||
2 years ago
|
import { onMounted, ref, watch } from "vue";
|
||
|
import { useI18n } from "vue3-i18n";
|
||
|
const { t } = useI18n();
|
||
2 years ago
|
|
||
|
const { state } = useStore();
|
||
|
const prop = defineProps({
|
||
|
modelValue: null,
|
||
|
placeholder: {
|
||
|
type: String
|
||
|
},
|
||
|
disabled: {
|
||
|
type: Boolean,
|
||
|
default: false,
|
||
|
},
|
||
|
clearable: {
|
||
|
type: Boolean,
|
||
|
default: true,
|
||
|
},
|
||
|
filterable: {
|
||
|
type: Boolean,
|
||
|
default: true,
|
||
|
},
|
||
2 years ago
|
full: {
|
||
|
type: Boolean,
|
||
|
default: false,
|
||
|
},
|
||
2 years ago
|
width: {
|
||
2 years ago
|
type: Number
|
||
2 years ago
|
},
|
||
|
dict: {
|
||
|
type: String
|
||
|
},
|
||
|
stateProp: {
|
||
|
type: String
|
||
|
},
|
||
2 years ago
|
maxValue: {
|
||
|
type: Number
|
||
|
},
|
||
2 years ago
|
valueKey: {
|
||
|
type: String,
|
||
|
default: 'key'
|
||
|
},
|
||
|
labelKey: {
|
||
|
type: String,
|
||
|
default: 'value'
|
||
|
},
|
||
|
});
|
||
|
const emit = defineEmits(["update:modelValue"]);
|
||
2 years ago
|
const myValue = ref<any>(null);
|
||
2 years ago
|
const width = ref('150px');
|
||
2 years ago
|
const setWidth = () => {
|
||
|
if (prop.width) {
|
||
|
width.value = prop.width + 'px';
|
||
|
} else {
|
||
|
width.value = state.size.searchWidth;
|
||
|
}
|
||
|
}
|
||
|
watch(() => state.size, (n, o) => {
|
||
|
setWidth();
|
||
|
})
|
||
2 years ago
|
watch(myValue, (n, o) => {
|
||
|
emit('update:modelValue', n);
|
||
|
})
|
||
2 years ago
|
watch(() => prop.modelValue, (n, o) => {
|
||
|
myValue.value = n;
|
||
|
})
|
||
2 years ago
|
onMounted(() => {
|
||
2 years ago
|
prop.modelValue && (myValue.value = prop.modelValue);
|
||
|
setWidth();
|
||
2 years ago
|
});
|
||
|
|
||
|
onMounted(() => { });
|
||
|
</script>
|
||
|
<style lang="scss" scoped>
|
||
|
//@import url(); 引入公共css类
|
||
2 years ago
|
.form-item {
|
||
2 years ago
|
width: v-bind('width');
|
||
|
}
|
||
|
</style>
|