@aspire-ui/element-component-pro 1.0.13 → 1.0.15
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.
- package/README.md +1 -0
- package/dist/ProForm/ApiSelect.vue.d.ts +9 -1
- package/dist/ProForm/ProForm.vue.d.ts +8 -0
- package/dist/ProForm/ProFormItem.vue.d.ts +4 -0
- package/dist/ProTable/ProTable.vue.d.ts +7 -1
- package/dist/ProTable/types/index.d.ts +1 -0
- package/dist/ProTableForm/ProTableForm.vue.d.ts +164 -0
- package/dist/ProTableForm/index.d.ts +5 -0
- package/dist/ProTableForm/types.d.ts +69 -0
- package/dist/element-component-pro.es.js +1305 -980
- package/dist/element-component-pro.es.js.map +1 -1
- package/dist/element-component-pro.umd.js +2 -2
- package/dist/element-component-pro.umd.js.map +1 -1
- package/dist/index.d.ts +796 -243
- package/dist/style.css +1 -1
- package/dist/types/index.d.ts +20 -1
- package/dist/useComponentSetting.d.ts +9 -4
- package/package.json +1 -1
- package/src/ProDescriptions/ProDescriptions.vue +2 -2
- package/src/ProForm/ApiSelect.vue +17 -5
- package/src/ProForm/ProForm.vue +47 -4
- package/src/ProForm/ProFormItem.vue +19 -1
- package/src/ProTable/ProTable.vue +36 -5
- package/src/ProTable/types/index.ts +1 -0
- package/src/ProTableForm/ProTableForm.vue +555 -0
- package/src/ProTableForm/index.ts +9 -0
- package/src/ProTableForm/types.ts +72 -0
- package/src/index.ts +10 -0
- package/src/types/index.ts +15 -0
- package/src/useComponentSetting.ts +63 -8
package/src/types/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { VNode } from 'vue'
|
|
2
|
+
import type { ComponentPublicInstance } from 'vue'
|
|
2
3
|
|
|
3
4
|
/** 栅格配置 */
|
|
4
5
|
export interface ColEx {
|
|
@@ -31,6 +32,13 @@ export interface ScrollToFieldOptions {
|
|
|
31
32
|
inline?: ScrollLogicalPosition
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
/** ApiSelect 暴露的实例类型 */
|
|
36
|
+
export interface ApiSelectInstance {
|
|
37
|
+
options: Array<{ label: string; value: unknown }>
|
|
38
|
+
loading: boolean
|
|
39
|
+
fetchOptions: () => Promise<void>
|
|
40
|
+
}
|
|
41
|
+
|
|
34
42
|
/** 表单操作类型(参考 Vben Admin FormActionType) */
|
|
35
43
|
export interface FormActionType {
|
|
36
44
|
getFieldsValue: () => Record<string, unknown>
|
|
@@ -45,6 +53,12 @@ export interface FormActionType {
|
|
|
45
53
|
appendSchemaByField: (schema: ProFormSchema, prefixField?: string, first?: boolean) => Promise<void>
|
|
46
54
|
removeSchemaByField: (field: string | string[]) => Promise<void>
|
|
47
55
|
setProps: (props: Partial<ProFormProps>) => Promise<void>
|
|
56
|
+
/** 获取指定字段的组件实例 */
|
|
57
|
+
getComponentInstance: (field: string) => ComponentPublicInstance | null
|
|
58
|
+
/** 获取 api-select 字段的 options */
|
|
59
|
+
getFieldOptions: (field: string) => Array<{ label: string; value: unknown }>
|
|
60
|
+
/** 获取 api-select 字段的加载状态 */
|
|
61
|
+
isFieldLoading: (field: string) => boolean
|
|
48
62
|
}
|
|
49
63
|
|
|
50
64
|
/** 时间字段映射 [表单字段, [开始字段, 结束字段], 格式?] */
|
|
@@ -207,6 +221,7 @@ export interface DescriptionSchema {
|
|
|
207
221
|
|
|
208
222
|
/** Description Props */
|
|
209
223
|
export interface DescriptionProps {
|
|
224
|
+
[key: string]: unknown
|
|
210
225
|
title?: string
|
|
211
226
|
helpMessage?: string | string[]
|
|
212
227
|
size?: 'medium' | 'small'
|
|
@@ -3,33 +3,88 @@ import { reactive } from 'vue'
|
|
|
3
3
|
/** 组件默认配置存储:组件名 -> 默认 props/配置 */
|
|
4
4
|
const componentSettings = reactive<Record<string, Record<string, unknown>>>({})
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* 深度合并两个对象
|
|
8
|
+
* - source 的值会覆盖 target 的值
|
|
9
|
+
* - 对于嵌套对象,会递归合并
|
|
10
|
+
* - 数组直接替换,不合并
|
|
11
|
+
*/
|
|
12
|
+
function deepMerge(target: Record<string, unknown>, source?: Record<string, unknown>): Record<string, unknown> {
|
|
13
|
+
if (!source) return target
|
|
14
|
+
|
|
15
|
+
for (const key in source) {
|
|
16
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
17
|
+
const targetValue = target[key]
|
|
18
|
+
const sourceValue = source[key]
|
|
19
|
+
|
|
20
|
+
if (isPlainObject(sourceValue)) {
|
|
21
|
+
if (!isPlainObject(targetValue)) {
|
|
22
|
+
target[key] = { ...(sourceValue as Record<string, unknown>) }
|
|
23
|
+
} else {
|
|
24
|
+
target[key] = deepMerge(
|
|
25
|
+
targetValue as Record<string, unknown>,
|
|
26
|
+
sourceValue as Record<string, unknown>
|
|
27
|
+
)
|
|
28
|
+
}
|
|
29
|
+
} else {
|
|
30
|
+
target[key] = sourceValue
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return target
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 判断是否为普通对象(非数组、非 null) */
|
|
39
|
+
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
40
|
+
if (!value || typeof value !== 'object') return false
|
|
41
|
+
const proto = Object.getPrototypeOf(value)
|
|
42
|
+
return proto === Object.prototype || proto === null
|
|
43
|
+
}
|
|
44
|
+
|
|
6
45
|
export interface UseComponentSettingReturn {
|
|
7
46
|
/** 获取组件默认配置;不传参时返回全部组件的配置 */
|
|
8
|
-
getSetting:
|
|
9
|
-
/**
|
|
47
|
+
getSetting: <T extends Record<string, unknown> = Record<string, unknown>>(componentName?: string) => T
|
|
48
|
+
/** 设置组件默认配置(与已有配置深度合并) */
|
|
10
49
|
setSetting: (componentName: string, config: Record<string, unknown>) => void
|
|
50
|
+
/** 合并组件配置:全局配置与组件 props 合并,返回合并后的结果 */
|
|
51
|
+
mergeSettings: <T extends Record<string, unknown> = Record<string, unknown>>(componentName: string, props: Record<string, unknown>) => T
|
|
11
52
|
}
|
|
12
53
|
|
|
13
54
|
/**
|
|
14
55
|
* 组件默认配置:供所有组件统一获取/设置默认配置
|
|
15
|
-
* - getSetting
|
|
16
|
-
* - setSetting
|
|
56
|
+
* - getSetting:获取组件默认配置
|
|
57
|
+
* - setSetting:设置组件默认配置(深度合并),可在应用入口或按需调用
|
|
58
|
+
* - mergeSettings:合并全局配置与组件 props,props 优先级更高
|
|
59
|
+
*
|
|
60
|
+
* 合并优先级:组件默认值 < 全局配置 < 组件 props
|
|
17
61
|
*/
|
|
18
62
|
export function useComponentSetting(): UseComponentSettingReturn {
|
|
19
|
-
const getSetting =
|
|
63
|
+
const getSetting = <T extends Record<string, unknown> = Record<string, unknown>>(componentName?: string): T => {
|
|
20
64
|
if (componentName === undefined) {
|
|
21
|
-
return
|
|
65
|
+
return JSON.parse(JSON.stringify(componentSettings)) as T
|
|
22
66
|
}
|
|
23
|
-
return
|
|
67
|
+
return JSON.parse(JSON.stringify(componentSettings[componentName] ?? {})) as T
|
|
24
68
|
}
|
|
25
69
|
|
|
26
70
|
const setSetting = (componentName: string, config: Record<string, unknown>): void => {
|
|
27
71
|
const current = componentSettings[componentName]
|
|
28
|
-
|
|
72
|
+
if (current) {
|
|
73
|
+
componentSettings[componentName] = deepMerge({ ...current }, config)
|
|
74
|
+
} else {
|
|
75
|
+
componentSettings[componentName] = { ...config }
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** 合并全局配置与组件 props,props 优先级更高 */
|
|
80
|
+
const mergeSettings = <T extends Record<string, unknown> = Record<string, unknown>>(componentName: string, props: Record<string, unknown>): T => {
|
|
81
|
+
const globalSetting = componentSettings[componentName] ?? {}
|
|
82
|
+
return deepMerge({ ...globalSetting }, props) as T
|
|
29
83
|
}
|
|
30
84
|
|
|
31
85
|
return {
|
|
32
86
|
getSetting,
|
|
33
87
|
setSetting,
|
|
88
|
+
mergeSettings,
|
|
34
89
|
}
|
|
35
90
|
}
|