feat: 字典组件支持Number类型

https://gitee.com/youlaiorg/vue3-element-admin/issues/I7N3DO #I7N3DO

Former-commit-id: 68a8da9e2d19e2ab3f842d3d97fb8850406d30c3
This commit is contained in:
郝先瑞
2023-08-04 12:58:39 +08:00
parent 8e37f9b7d2
commit 3e8df9a431
4 changed files with 26 additions and 6 deletions

View File

@@ -5,6 +5,7 @@
:placeholder="placeholder"
:disabled="disabled"
clearable
@change="handleChange"
>
<el-option
v-for="option in options"
@@ -20,6 +21,9 @@
import { getDictOptions } from "@/api/dict";
const props = defineProps({
/**
* 字典类型编码(eg: 性别-gender)
*/
typeCode: {
type: String,
required: true,
@@ -38,11 +42,15 @@ const props = defineProps({
},
});
const emits = defineEmits(["update:modelValue"]);
const emits = defineEmits(["update:modelValue"]); // 父组件监听事件,同步子组件值的变化给父组件
const selectedValue = useVModel(props, "modelValue", emits);
const options: Ref<OptionType[]> = ref([]); // 字典下拉数据源
const options: Ref<OptionType[]> = ref([]);
const selectedValue = computed(() => props.modelValue.toString()); // 将父组件的值统一转化String和下拉数据源进行比较避免值的类型不一致导致回显失败
function handleChange(val?: string) {
emits("update:modelValue", val);
}
onBeforeMount(() => {
// 根据字典类型编码(typeCode)获取字典选项

View File

@@ -41,7 +41,7 @@ declare global {
/**
* 值
*/
value: number;
value: string;
/**
* 文本
*/

View File

@@ -1,6 +1,7 @@
<!-- 字典组件示例 -->
<script setup lang="ts">
const genderDefaultValue = ref("1"); // 性别默认
const stringValue = ref("1"); // 性别(值为String)
const nmberValue = ref(1); // 性别(值为Number)
</script>
<template>
@@ -14,7 +15,17 @@ const genderDefaultValue = ref("1"); // 性别默认
>
<el-form>
<el-form-item label="性别">
<dictionary v-model="genderDefaultValue" type-code="gender" />
<dictionary v-model="stringValue" type-code="gender" />
<el-link :underline="false" type="primary" class="ml-5"
>值为String: const value = ref("1");
</el-link>
</el-form-item>
<el-form-item label="性别">
<dictionary v-model="nmberValue" type-code="gender" />
<el-link :underline="false" type="success" class="ml-5"
>值为Number: const value = ref(1);
</el-link>
</el-form-item>
</el-form>
</div>

View File

@@ -374,6 +374,7 @@ const readFile = (file: any, callback: any) => {
width: 100%;
height: calc(100vh - 84px);
padding: 10px;
overflow-y: auto;
.table-wrap {
// height: 100%;