@aspire-ui/element-component-pro 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ import { reactive } from 'vue'
2
+
3
+ /** 组件默认配置存储:组件名 -> 默认 props/配置 */
4
+ const componentSettings = reactive<Record<string, Record<string, unknown>>>({})
5
+
6
+ export interface UseComponentSettingReturn {
7
+ /** 获取组件默认配置;不传参时返回全部组件的配置 */
8
+ getSetting: (componentName?: string) => Record<string, unknown>
9
+ /** 设置组件默认配置(与已有配置浅合并) */
10
+ setSetting: (componentName: string, config: Record<string, unknown>) => void
11
+ }
12
+
13
+ /**
14
+ * 组件默认配置:供所有组件统一获取/设置默认配置
15
+ * - getSetting:获取组件默认配置,用于初始化或合并 props
16
+ * - setSetting:设置组件默认配置,可在应用入口或按需调用
17
+ */
18
+ export function useComponentSetting(): UseComponentSettingReturn {
19
+ const getSetting = (componentName?: string): Record<string, unknown> => {
20
+ if (componentName === undefined) {
21
+ return { ...componentSettings }
22
+ }
23
+ return { ...(componentSettings[componentName] ?? {}) }
24
+ }
25
+
26
+ const setSetting = (componentName: string, config: Record<string, unknown>): void => {
27
+ const current = componentSettings[componentName]
28
+ componentSettings[componentName] = current ? { ...current, ...config } : { ...config }
29
+ }
30
+
31
+ return {
32
+ getSetting,
33
+ setSetting,
34
+ }
35
+ }