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" }, + ], }, }, {