From b878d659e32bd0d4ff3644d8c788e314978eed7e Mon Sep 17 00:00:00 2001 From: lizw-2015 <1183409807@qq.com> Date: Tue, 1 Jul 2025 10:30:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(data-form):=20=E6=96=B0=E5=A2=9E=20RadioGr?= =?UTF-8?q?oup=20=E7=BB=84=E4=BB=B6=E5=B9=B6=E4=BC=98=E5=8C=96=20DataForm?= =?UTF-8?q?=20=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加自定义 RadioGroup 组件,支持 options 属性 - 更新 DataFormConstant,替换 Element Plus 的 ElRadioGroup 为自定义组件 - 新增 mergeExpose 函数,用于合并组件的 expose 对象 - 在 DataFormUtils 中添加新函数,增强组件合并功能 - 更新示例页面,展示 RadioGroup 组件的使用方法 --- src/components/data-form/DataFormConstant.ts | 4 +- src/components/data-form/DataFormUtils.tsx | 45 ++++++++++++ src/components/data-form/inputs/RadioGroup.vue | 96 ++++++++++++++++++++++++++ src/pages/DataForm01.vue | 5 +- 4 files changed, 147 insertions(+), 3 deletions(-) create mode 100644 src/components/data-form/inputs/RadioGroup.vue diff --git a/src/components/data-form/DataFormConstant.ts b/src/components/data-form/DataFormConstant.ts index d5d1768..539a2f7 100644 --- a/src/components/data-form/DataFormConstant.ts +++ b/src/components/data-form/DataFormConstant.ts @@ -11,7 +11,6 @@ import { ElInputTag, ElMention, ElRadio, - ElRadioGroup, ElRate, ElSelect, ElSelectV2, @@ -23,6 +22,7 @@ import { ElTreeSelect, ElUpload, } from "element-plus"; +import RadioGroup from "./inputs/RadioGroup.vue"; import type { DisplayMode } from "./DataFormTypes.ts"; /** 内建的表单输入组件 */ @@ -32,7 +32,7 @@ const builtInInputComponents = { Checkbox: markRaw(ElCheckbox), CheckboxGroup: markRaw(ElCheckboxGroup), Radio: markRaw(ElRadio), - RadioGroup: markRaw(ElRadioGroup), + RadioGroup: markRaw(RadioGroup), Switch: markRaw(ElSwitch), Select: markRaw(ElSelect), SelectV2: markRaw(ElSelectV2), diff --git a/src/components/data-form/DataFormUtils.tsx b/src/components/data-form/DataFormUtils.tsx index 184c658..6356f07 100644 --- a/src/components/data-form/DataFormUtils.tsx +++ b/src/components/data-form/DataFormUtils.tsx @@ -1,4 +1,5 @@ import lodash from "lodash"; +import { toRaw } from "vue"; import { Typeof } from "@ease-forge/shared"; /** @@ -28,10 +29,54 @@ function dataPathToNamePath(dataPath: string): string | number | Array, sources: any, onlyFun: boolean = false) { + if (!expose) return; + sources = toRaw(sources); + if (!sources || Typeof.isDate(sources) || Typeof.isArray(sources) || !Typeof.isObj(sources)) return; + // sources 是 dom 对象 + if (sources instanceof HTMLElement || (sources.constructor?.name?.includes("HTML") && sources.constructor?.name?.includes("Element"))) { + expose.$el = sources; + return; + } + // 压制警告[Vue warn] Object.keys(sources) + const rawConsoleWarn = console.warn; + console.warn = _emptyFun; + let keys = Object.keys(sources); + console.warn = rawConsoleWarn; + // 处理 expose + for (let key of keys) { + const newValue = sources[key]; + if (Typeof.noValue(newValue)) continue; + if (onlyFun && !Typeof.isFun(newValue)) continue; + expose[key] = newValue; + } + if (!onlyFun) { + // 处理 vue 组件内置属性 + keys = ["$data", "$props", "$attrs", "$slots", "$refs", "$emit", "$on", "$off", "$once", "$forceUpdate", "$nextTick", "$watch", "$el", "$options", "$parent", "$root"]; + for (let key of keys) { + const newValue = sources[key]; + if (Typeof.noValue(newValue)) continue; + expose[key] = newValue; + } + } +} + export default { dataPathToNamePath, + mergeExpose, } export { dataPathToNamePath, + mergeExpose, } diff --git a/src/components/data-form/inputs/RadioGroup.vue b/src/components/data-form/inputs/RadioGroup.vue new file mode 100644 index 0000000..3788d5a --- /dev/null +++ b/src/components/data-form/inputs/RadioGroup.vue @@ -0,0 +1,96 @@ + + + + + diff --git a/src/pages/DataForm01.vue b/src/pages/DataForm01.vue index 3469f80..d2d79a3 100644 --- a/src/pages/DataForm01.vue +++ b/src/pages/DataForm01.vue @@ -105,7 +105,10 @@ const dataForm1 = reactive({ { dataPath: 'radio_group_1', label: '单选组', input: 'RadioGroup', inputProps: { - // TODO options + options: [ + { value: "001", label: "选项1" }, + { value: "002", label: "选项2" }, + ], }, }, {