UNPKG

d-render

Version:

基于 Element Plus 二次封装的数据驱动渲染组件库 - 表单、搜索表单、表格配置化渲染

57 lines (54 loc) 1.63 kB
import { defineComponent, reactive, watchEffect, provide, inject, ref, computed } from 'vue'; import { useCipConfig } from '@d-render/shared'; import { localeContextKey } from '../hooks/use-locale'; function mergeConfig(...sources) { const result = {}; for (const source of sources) { if (!source) continue; for (const key of Object.keys(source)) { const val = source[key]; const prev = result[key]; if (val !== null && typeof val === "object" && !Array.isArray(val) && prev !== null && typeof prev === "object" && !Array.isArray(prev)) { result[key] = mergeConfig(prev, val); } else if (val !== void 0) { result[key] = val; } } } return result; } var index = /* @__PURE__ */ defineComponent({ name: "CipConfigProvide", inheritAttrs: false, props: { locale: Object }, setup(props, { attrs, slots }) { const parentConfig = useCipConfig(); const mergedConfig = reactive({}); watchEffect(() => { const merged = mergeConfig(parentConfig, attrs); for (const key of Object.keys(mergedConfig)) { if (!(key in merged)) { delete mergedConfig[key]; } } Object.assign(mergedConfig, merged); }); provide("cip-config", mergedConfig); const parentLocale = inject(localeContextKey, ref()); provide(localeContextKey, computed(() => { var _a; return (_a = props.locale) != null ? _a : parentLocale.value; })); return () => { var _a; return (_a = slots.default) == null ? void 0 : _a.call(slots); }; } }); export { index as default };