@antsoo-lib/core 3.0.0 → 3.0.1
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/CHANGELOG.md +6 -0
- package/dist/core.css +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +6 -5
- package/dist/types/BaseSearch/index.d.ts +1 -1
- package/dist/types/BaseTable/index.d.ts +5 -475
- package/dist/types/Form/CoreForm.d.ts +82 -0
- package/dist/types/SSelectPage/index.d.ts +102 -0
- package/package.json +3 -3
- package/src/BaseSearch/index.vue +371 -371
- package/src/BaseTable/index.vue +910 -910
- package/src/Form/CoreForm.vue +782 -782
- package/src/Form/types.ts +86 -86
- package/src/SSelectPage/index.vue +607 -607
- package/src/index.ts +17 -17
- package/src/render/AreaCascader.tsx +64 -64
- package/src/render/AutoComplete.tsx +101 -101
- package/src/render/Button.tsx +62 -62
- package/src/render/Cascader.tsx +45 -45
- package/src/render/Checkbox.tsx +65 -65
- package/src/render/CheckboxGroup.tsx +57 -57
- package/src/render/Custom.tsx +19 -19
- package/src/render/DatePicker.tsx +83 -83
- package/src/render/Input.tsx +140 -140
- package/src/render/InputGroup.tsx +115 -115
- package/src/render/InputNumber.tsx +205 -205
- package/src/render/InputPassword.tsx +81 -81
- package/src/render/InputRange.tsx +154 -154
- package/src/render/RadioGroup.tsx +63 -63
- package/src/render/Select.tsx +96 -96
- package/src/render/SselectPage.tsx +107 -107
- package/src/render/Switch.tsx +60 -60
- package/src/render/Tree.tsx +136 -136
- package/src/render/TreeSelect.tsx +81 -81
- package/src/render/Upload.tsx +91 -91
- package/src/render/helper.tsx +221 -221
- package/src/render/index.ts +108 -108
- package/src/render/registry.ts +20 -20
- package/src/render/state.ts +37 -37
- package/src/render/types.ts +567 -567
- package/src/utils/attrMapping.ts +106 -106
- package/vite.config.ts +61 -61
- package/.turbo/turbo-build.log +0 -40
|
@@ -1,81 +1,81 @@
|
|
|
1
|
-
import { TreeSelect } from '@antsoo-lib/components'
|
|
2
|
-
import type { VoidFunction } from '@antsoo-lib/shared'
|
|
3
|
-
import { isFunction } from '@antsoo-lib/utils'
|
|
4
|
-
|
|
5
|
-
import { computed, markRaw } from 'vue'
|
|
6
|
-
import type { VNode } from 'vue'
|
|
7
|
-
|
|
8
|
-
import type { ToolbarState } from './state'
|
|
9
|
-
import type { ToolbarItem, TreeSelectToolbarItem } from './types'
|
|
10
|
-
|
|
11
|
-
// 树选择器渲染函数
|
|
12
|
-
export function renderTreeSelect(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
13
|
-
const treeItem = item as TreeSelectToolbarItem
|
|
14
|
-
const { key, events = {} } = treeItem
|
|
15
|
-
const processedEvents: Record<string, VoidFunction> = {}
|
|
16
|
-
const { props = {}, disabled = false } = treeItem
|
|
17
|
-
|
|
18
|
-
const isDisabled = isFunction(disabled)
|
|
19
|
-
? disabled(toolbarState.getAllValues(), toolbarState)
|
|
20
|
-
: disabled
|
|
21
|
-
|
|
22
|
-
// 从props中提取treeData,避免在展开props时覆盖处理后的treeData
|
|
23
|
-
const { options: originalTreeData, ...otherProps } = props
|
|
24
|
-
|
|
25
|
-
// 响应式计算 treeData,增加对ref对象的处理
|
|
26
|
-
const computedTreeData = computed(() => {
|
|
27
|
-
if (isFunction(originalTreeData)) {
|
|
28
|
-
return originalTreeData(toolbarState.getAllValues())
|
|
29
|
-
}
|
|
30
|
-
// 处理ref对象
|
|
31
|
-
if (originalTreeData && typeof originalTreeData === 'object' && 'value' in originalTreeData) {
|
|
32
|
-
return originalTreeData.value || []
|
|
33
|
-
}
|
|
34
|
-
return originalTreeData || []
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
Object.keys(events).forEach((eventName) => {
|
|
38
|
-
processedEvents[eventName] = (...args: any[]) => {
|
|
39
|
-
// 对于树选择器,自动更新状态
|
|
40
|
-
if (eventName === 'onUpdate:value' || eventName === 'onChange') {
|
|
41
|
-
const value = args[0]
|
|
42
|
-
toolbarState.setValue(key, value)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// 调用原始事件处理函数
|
|
46
|
-
events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
// 如果没有设置onChange事件,添加默认的状态更新
|
|
50
|
-
if (!processedEvents['onUpdate:value'] && !processedEvents.onChange) {
|
|
51
|
-
processedEvents['onUpdate:value'] = (value: any) => {
|
|
52
|
-
toolbarState.setValue(key, value)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
// 计算安全的当前值
|
|
56
|
-
const rawVal = toolbarState.getValue(key)
|
|
57
|
-
const propVal = props.value
|
|
58
|
-
const isMulti = otherProps.multiple || otherProps.treeCheckable
|
|
59
|
-
|
|
60
|
-
const safeValue =
|
|
61
|
-
rawVal !== undefined && rawVal !== null
|
|
62
|
-
? rawVal
|
|
63
|
-
: propVal !== undefined && propVal !== null
|
|
64
|
-
? propVal
|
|
65
|
-
: isMulti
|
|
66
|
-
? []
|
|
67
|
-
: undefined
|
|
68
|
-
|
|
69
|
-
const finalProps = { ...otherProps, disabled: isDisabled }
|
|
70
|
-
|
|
71
|
-
const Comp = markRaw(TreeSelect)
|
|
72
|
-
return (
|
|
73
|
-
<Comp
|
|
74
|
-
key={key}
|
|
75
|
-
value={safeValue}
|
|
76
|
-
{...finalProps}
|
|
77
|
-
treeData={computedTreeData.value as any[]}
|
|
78
|
-
{...processedEvents}
|
|
79
|
-
/>
|
|
80
|
-
)
|
|
81
|
-
}
|
|
1
|
+
import { TreeSelect } from '@antsoo-lib/components'
|
|
2
|
+
import type { VoidFunction } from '@antsoo-lib/shared'
|
|
3
|
+
import { isFunction } from '@antsoo-lib/utils'
|
|
4
|
+
|
|
5
|
+
import { computed, markRaw } from 'vue'
|
|
6
|
+
import type { VNode } from 'vue'
|
|
7
|
+
|
|
8
|
+
import type { ToolbarState } from './state'
|
|
9
|
+
import type { ToolbarItem, TreeSelectToolbarItem } from './types'
|
|
10
|
+
|
|
11
|
+
// 树选择器渲染函数
|
|
12
|
+
export function renderTreeSelect(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
13
|
+
const treeItem = item as TreeSelectToolbarItem
|
|
14
|
+
const { key, events = {} } = treeItem
|
|
15
|
+
const processedEvents: Record<string, VoidFunction> = {}
|
|
16
|
+
const { props = {}, disabled = false } = treeItem
|
|
17
|
+
|
|
18
|
+
const isDisabled = isFunction(disabled)
|
|
19
|
+
? disabled(toolbarState.getAllValues(), toolbarState)
|
|
20
|
+
: disabled
|
|
21
|
+
|
|
22
|
+
// 从props中提取treeData,避免在展开props时覆盖处理后的treeData
|
|
23
|
+
const { options: originalTreeData, ...otherProps } = props
|
|
24
|
+
|
|
25
|
+
// 响应式计算 treeData,增加对ref对象的处理
|
|
26
|
+
const computedTreeData = computed(() => {
|
|
27
|
+
if (isFunction(originalTreeData)) {
|
|
28
|
+
return originalTreeData(toolbarState.getAllValues())
|
|
29
|
+
}
|
|
30
|
+
// 处理ref对象
|
|
31
|
+
if (originalTreeData && typeof originalTreeData === 'object' && 'value' in originalTreeData) {
|
|
32
|
+
return originalTreeData.value || []
|
|
33
|
+
}
|
|
34
|
+
return originalTreeData || []
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
Object.keys(events).forEach((eventName) => {
|
|
38
|
+
processedEvents[eventName] = (...args: any[]) => {
|
|
39
|
+
// 对于树选择器,自动更新状态
|
|
40
|
+
if (eventName === 'onUpdate:value' || eventName === 'onChange') {
|
|
41
|
+
const value = args[0]
|
|
42
|
+
toolbarState.setValue(key, value)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 调用原始事件处理函数
|
|
46
|
+
events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
// 如果没有设置onChange事件,添加默认的状态更新
|
|
50
|
+
if (!processedEvents['onUpdate:value'] && !processedEvents.onChange) {
|
|
51
|
+
processedEvents['onUpdate:value'] = (value: any) => {
|
|
52
|
+
toolbarState.setValue(key, value)
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
// 计算安全的当前值
|
|
56
|
+
const rawVal = toolbarState.getValue(key)
|
|
57
|
+
const propVal = props.value
|
|
58
|
+
const isMulti = otherProps.multiple || otherProps.treeCheckable
|
|
59
|
+
|
|
60
|
+
const safeValue =
|
|
61
|
+
rawVal !== undefined && rawVal !== null
|
|
62
|
+
? rawVal
|
|
63
|
+
: propVal !== undefined && propVal !== null
|
|
64
|
+
? propVal
|
|
65
|
+
: isMulti
|
|
66
|
+
? []
|
|
67
|
+
: undefined
|
|
68
|
+
|
|
69
|
+
const finalProps = { ...otherProps, disabled: isDisabled }
|
|
70
|
+
|
|
71
|
+
const Comp = markRaw(TreeSelect)
|
|
72
|
+
return (
|
|
73
|
+
<Comp
|
|
74
|
+
key={key}
|
|
75
|
+
value={safeValue}
|
|
76
|
+
{...finalProps}
|
|
77
|
+
treeData={computedTreeData.value as any[]}
|
|
78
|
+
{...processedEvents}
|
|
79
|
+
/>
|
|
80
|
+
)
|
|
81
|
+
}
|
package/src/render/Upload.tsx
CHANGED
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import type { UploadFile } from '@antsoo-lib/components'
|
|
2
|
-
import type { AnyObject } from '@antsoo-lib/shared'
|
|
3
|
-
import { isFunction } from '@antsoo-lib/utils'
|
|
4
|
-
|
|
5
|
-
import { markRaw } from 'vue'
|
|
6
|
-
import type { VNode } from 'vue'
|
|
7
|
-
|
|
8
|
-
import { getRegisteredComponent } from './registry'
|
|
9
|
-
import type { ToolbarState } from './state'
|
|
10
|
-
import type { ToolbarItem, UploadToolbarItem } from './types'
|
|
11
|
-
|
|
12
|
-
// 上传渲染函数
|
|
13
|
-
export function renderUpload(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
14
|
-
const uploadItem = item as UploadToolbarItem
|
|
15
|
-
const { key, events = {}, passage } = uploadItem
|
|
16
|
-
const { props = {}, disabled = false } = uploadItem
|
|
17
|
-
|
|
18
|
-
const isDisabled = isFunction(disabled)
|
|
19
|
-
? disabled(toolbarState.getAllValues(), toolbarState)
|
|
20
|
-
: disabled
|
|
21
|
-
const allValues = toolbarState.getAllValues()
|
|
22
|
-
|
|
23
|
-
const resolveExtraParams = () => {
|
|
24
|
-
if (!props.extraParams) return {}
|
|
25
|
-
return isFunction(props.extraParams)
|
|
26
|
-
? props.extraParams(allValues, toolbarState)
|
|
27
|
-
: props.extraParams
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const apiConfig = props.api
|
|
31
|
-
? {
|
|
32
|
-
url: props.api.url,
|
|
33
|
-
method: props.api.method || 'POST',
|
|
34
|
-
headers: props.api.headers || {},
|
|
35
|
-
}
|
|
36
|
-
: {
|
|
37
|
-
url: undefined as string | undefined, // 使用组件默认全局上传地址
|
|
38
|
-
method: 'POST',
|
|
39
|
-
headers: {},
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// 当前表单值(期望:[{ name, path }])
|
|
43
|
-
const currentValue = toolbarState.getValue(key) || props.value || []
|
|
44
|
-
|
|
45
|
-
// 组件触发值更新(仅写入规范化值)
|
|
46
|
-
const onUpdateValue = (value: UploadFile[]) => {
|
|
47
|
-
toolbarState.setValue(key, value)
|
|
48
|
-
events['onUpdate:value']?.(value, allValues, toolbarState)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const onChange = (info: UploadFile[]) => {
|
|
52
|
-
events.onChange?.(info, allValues, toolbarState)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const onSuccess = (response: AnyObject, file: UploadFile) => {
|
|
56
|
-
events.onSuccess?.(response, file, allValues, toolbarState)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const onError = (error: AnyObject, file: UploadFile) => {
|
|
60
|
-
events.onError?.(error, file, allValues, toolbarState)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const UploadComponent = getRegisteredComponent('Upload')
|
|
64
|
-
if (!UploadComponent) {
|
|
65
|
-
console.warn(
|
|
66
|
-
'BaseTable: Upload component is not registered. Please use registerBaseTableComponents to register it.',
|
|
67
|
-
)
|
|
68
|
-
return <span style={{ color: 'red' }}>Upload component missing</span>
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const finalProps: Record<string, any> = {
|
|
72
|
-
...props,
|
|
73
|
-
disabled: isDisabled,
|
|
74
|
-
api: apiConfig,
|
|
75
|
-
extraParams: resolveExtraParams(),
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const Comp = markRaw(UploadComponent) as any
|
|
79
|
-
return (
|
|
80
|
-
<Comp
|
|
81
|
-
key={key}
|
|
82
|
-
value={currentValue}
|
|
83
|
-
passage={passage}
|
|
84
|
-
props={finalProps}
|
|
85
|
-
onSuccess={onSuccess}
|
|
86
|
-
onError={onError}
|
|
87
|
-
onChange={onChange}
|
|
88
|
-
onUpdate:value={onUpdateValue}
|
|
89
|
-
/>
|
|
90
|
-
)
|
|
91
|
-
}
|
|
1
|
+
import type { UploadFile } from '@antsoo-lib/components'
|
|
2
|
+
import type { AnyObject } from '@antsoo-lib/shared'
|
|
3
|
+
import { isFunction } from '@antsoo-lib/utils'
|
|
4
|
+
|
|
5
|
+
import { markRaw } from 'vue'
|
|
6
|
+
import type { VNode } from 'vue'
|
|
7
|
+
|
|
8
|
+
import { getRegisteredComponent } from './registry'
|
|
9
|
+
import type { ToolbarState } from './state'
|
|
10
|
+
import type { ToolbarItem, UploadToolbarItem } from './types'
|
|
11
|
+
|
|
12
|
+
// 上传渲染函数
|
|
13
|
+
export function renderUpload(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
14
|
+
const uploadItem = item as UploadToolbarItem
|
|
15
|
+
const { key, events = {}, passage } = uploadItem
|
|
16
|
+
const { props = {}, disabled = false } = uploadItem
|
|
17
|
+
|
|
18
|
+
const isDisabled = isFunction(disabled)
|
|
19
|
+
? disabled(toolbarState.getAllValues(), toolbarState)
|
|
20
|
+
: disabled
|
|
21
|
+
const allValues = toolbarState.getAllValues()
|
|
22
|
+
|
|
23
|
+
const resolveExtraParams = () => {
|
|
24
|
+
if (!props.extraParams) return {}
|
|
25
|
+
return isFunction(props.extraParams)
|
|
26
|
+
? props.extraParams(allValues, toolbarState)
|
|
27
|
+
: props.extraParams
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const apiConfig = props.api
|
|
31
|
+
? {
|
|
32
|
+
url: props.api.url,
|
|
33
|
+
method: props.api.method || 'POST',
|
|
34
|
+
headers: props.api.headers || {},
|
|
35
|
+
}
|
|
36
|
+
: {
|
|
37
|
+
url: undefined as string | undefined, // 使用组件默认全局上传地址
|
|
38
|
+
method: 'POST',
|
|
39
|
+
headers: {},
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 当前表单值(期望:[{ name, path }])
|
|
43
|
+
const currentValue = toolbarState.getValue(key) || props.value || []
|
|
44
|
+
|
|
45
|
+
// 组件触发值更新(仅写入规范化值)
|
|
46
|
+
const onUpdateValue = (value: UploadFile[]) => {
|
|
47
|
+
toolbarState.setValue(key, value)
|
|
48
|
+
events['onUpdate:value']?.(value, allValues, toolbarState)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const onChange = (info: UploadFile[]) => {
|
|
52
|
+
events.onChange?.(info, allValues, toolbarState)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const onSuccess = (response: AnyObject, file: UploadFile) => {
|
|
56
|
+
events.onSuccess?.(response, file, allValues, toolbarState)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const onError = (error: AnyObject, file: UploadFile) => {
|
|
60
|
+
events.onError?.(error, file, allValues, toolbarState)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const UploadComponent = getRegisteredComponent('Upload')
|
|
64
|
+
if (!UploadComponent) {
|
|
65
|
+
console.warn(
|
|
66
|
+
'BaseTable: Upload component is not registered. Please use registerBaseTableComponents to register it.',
|
|
67
|
+
)
|
|
68
|
+
return <span style={{ color: 'red' }}>Upload component missing</span>
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const finalProps: Record<string, any> = {
|
|
72
|
+
...props,
|
|
73
|
+
disabled: isDisabled,
|
|
74
|
+
api: apiConfig,
|
|
75
|
+
extraParams: resolveExtraParams(),
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const Comp = markRaw(UploadComponent) as any
|
|
79
|
+
return (
|
|
80
|
+
<Comp
|
|
81
|
+
key={key}
|
|
82
|
+
value={currentValue}
|
|
83
|
+
passage={passage}
|
|
84
|
+
props={finalProps}
|
|
85
|
+
onSuccess={onSuccess}
|
|
86
|
+
onError={onError}
|
|
87
|
+
onChange={onChange}
|
|
88
|
+
onUpdate:value={onUpdateValue}
|
|
89
|
+
/>
|
|
90
|
+
)
|
|
91
|
+
}
|