Browse Source

feat(data-form): 新增 Select组件并更新相关页面

- 添加 Select 组件以支持下拉列表功能
- 在 DataFormConstant 中替换原有的 ElSelect 为自定义 Select
- 在示例页面 DataForm01 中添加 Select 组件的使用
master
lizw-2015 6 months ago
parent
commit
0ab3344025
  1. 4
      src/components/data-form/DataFormConstant.ts
  2. 96
      src/components/data-form/inputs/Select.vue
  3. 9
      src/pages/DataForm01.vue

4
src/components/data-form/DataFormConstant.ts

@ -11,7 +11,6 @@ import {
ElMention, ElMention,
ElRadio, ElRadio,
ElRate, ElRate,
ElSelect,
ElSelectV2, ElSelectV2,
ElSlider, ElSlider,
ElSwitch, ElSwitch,
@ -23,6 +22,7 @@ import {
} from "element-plus"; } from "element-plus";
import CheckboxGroup from "./inputs/CheckboxGroup.vue"; import CheckboxGroup from "./inputs/CheckboxGroup.vue";
import RadioGroup from "./inputs/RadioGroup.vue"; import RadioGroup from "./inputs/RadioGroup.vue";
import Select from "./inputs/Select.vue";
import type { DisplayMode } from "./DataFormTypes.ts"; import type { DisplayMode } from "./DataFormTypes.ts";
/** 内建的表单输入组件 */ /** 内建的表单输入组件 */
@ -34,7 +34,7 @@ const builtInInputComponents = {
Radio: markRaw<any>(ElRadio), Radio: markRaw<any>(ElRadio),
RadioGroup: markRaw<any>(RadioGroup), RadioGroup: markRaw<any>(RadioGroup),
Switch: markRaw<any>(ElSwitch), Switch: markRaw<any>(ElSwitch),
Select: markRaw<any>(ElSelect), Select: markRaw<any>(Select),
SelectV2: markRaw<any>(ElSelectV2), SelectV2: markRaw<any>(ElSelectV2),
DatePicker: markRaw<any>(ElDatePicker), DatePicker: markRaw<any>(ElDatePicker),
TimePicker: markRaw<any>(ElTimePicker), TimePicker: markRaw<any>(ElTimePicker),

96
src/components/data-form/inputs/Select.vue

@ -0,0 +1,96 @@
<script setup lang="ts">
import lodash from "lodash";
import { computed, createVNode, defineExpose, onMounted, reactive, useAttrs, useSlots, useTemplateRef } from "vue";
import { ElOption, ElSelect } from "element-plus";
import { Typeof } from "@ease-forge/shared";
import { mergeExpose } from "../DataFormUtils.tsx";
defineOptions({
name: 'Select',
});
//
const attrs = useAttrs();
//
const slots = useSlots();
interface OptionItem {
value: string | number | boolean;
label: string;
[key: string]: any;
}
// Props
interface SelectProps {
options?: Array<OptionItem>;
}
// props
const props = withDefaults(defineProps<SelectProps>(), {
options: () => ([]),
});
// State
interface SelectState {
}
// state
const state = reactive<SelectState>({
loading: false,
});
//
const input = useTemplateRef<InstanceType<typeof ElSelect>>("inputRef");
//
const options = computed(() => {
let opts: Array<OptionItem> = [];
let options = props.options;
if (options) {
if (Typeof.isArray(options)) {
opts = options;
} else {
console.log("options 配置必须是数组类型");
}
}
return opts;
});
// props
const inputProps = computed<any>(() => {
const res: any = { ...attrs };
if (Typeof.hasValue(res.modelValue) && !Typeof.isStr(res.modelValue)) res.modelValue = lodash.toString(res.modelValue);
return res;
});
function toString(val: any) {
if (Typeof.hasValue(val) && !Typeof.isStr(val)) return lodash.toString(val);
return val;
}
const expose = {
/** 组件状态 */
state,
};
onMounted(() => {
if (input.value) mergeExpose(expose, input.value);
});
//
defineExpose(expose);
export type {
OptionItem,
SelectProps,
SelectState,
}
</script>
<template>
<component ref="inputRef" :is="createVNode(ElSelect, inputProps, slots)">
<ElOption v-for="(item, idx) in options" v-bind="item" :value="toString(item.value)"/>
</component>
</template>
<style scoped>
</style>

9
src/pages/DataForm01.vue

@ -129,7 +129,14 @@ const dataForm1 = reactive<DataFormProps>({
inputProps: { inputProps: {
placeholder: "请选择", placeholder: "请选择",
clearable: true, clearable: true,
// TODO options options: [
{ value: "001", label: "选项1" },
{ value: "002", label: "选项2" },
{ value: "003", label: "选项3" },
{ value: "004", label: "选项4" },
{ value: "005", label: "选项5" },
{ value: "006", label: "选项6" },
],
}, },
}, },
{ {

Loading…
Cancel
Save