@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
package/src/render/Checkbox.tsx
CHANGED
|
@@ -1,65 +1,65 @@
|
|
|
1
|
-
import { Checkbox } from '@antsoo-lib/components'
|
|
2
|
-
import type { CheckboxProps } from '@antsoo-lib/components'
|
|
3
|
-
import type { VoidFunction } from '@antsoo-lib/shared'
|
|
4
|
-
import { isFunction } from '@antsoo-lib/utils'
|
|
5
|
-
|
|
6
|
-
import { markRaw } from 'vue'
|
|
7
|
-
import type { VNode } from 'vue'
|
|
8
|
-
|
|
9
|
-
import type { ToolbarState } from './state'
|
|
10
|
-
import type { CheckboxToolbarItem, ToolbarItem } from './types'
|
|
11
|
-
|
|
12
|
-
// 复选框渲染函数
|
|
13
|
-
export function renderCheckbox(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
14
|
-
const checkboxItem = item as CheckboxToolbarItem
|
|
15
|
-
const { key, events = {} } = checkboxItem
|
|
16
|
-
const { props = {}, disabled = false } = checkboxItem
|
|
17
|
-
|
|
18
|
-
const isDisabled = isFunction(disabled)
|
|
19
|
-
? disabled(toolbarState.getAllValues(), toolbarState)
|
|
20
|
-
: disabled
|
|
21
|
-
const finalProps: Partial<CheckboxProps> & {
|
|
22
|
-
disabled?: boolean
|
|
23
|
-
checked?: boolean
|
|
24
|
-
value?: boolean
|
|
25
|
-
} = {
|
|
26
|
-
...props,
|
|
27
|
-
disabled: isDisabled,
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 处理事件,注入工具栏状态
|
|
31
|
-
const processedEvents: Record<string, VoidFunction> = {}
|
|
32
|
-
Object.keys(events).forEach((eventName) => {
|
|
33
|
-
processedEvents[eventName] = (...args: any[]) => {
|
|
34
|
-
// 对于复选框,自动更新状态
|
|
35
|
-
if (eventName === 'onUpdate:checked' || eventName === 'onChange') {
|
|
36
|
-
const checked = args[0]?.target?.checked ?? args[0] // 兼容不同的事件格式
|
|
37
|
-
toolbarState.setValue(key, checked)
|
|
38
|
-
// 显式触发 onUpdate:value,确保 BaseForm 能接收到数据更新
|
|
39
|
-
events['onUpdate:value']?.(checked, toolbarState.getAllValues(), toolbarState)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// 调用原始事件处理函数
|
|
43
|
-
events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
// 如果没有设置onChange事件,添加默认的状态更新
|
|
48
|
-
if (!processedEvents['onUpdate:checked'] && !processedEvents.onChange) {
|
|
49
|
-
processedEvents['onUpdate:checked'] = (checked: boolean) => {
|
|
50
|
-
toolbarState.setValue(key, checked)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const Comp = markRaw(Checkbox)
|
|
55
|
-
return (
|
|
56
|
-
<Comp
|
|
57
|
-
key={key}
|
|
58
|
-
checked={toolbarState.getValue(key) ?? finalProps.checked ?? finalProps.value ?? false}
|
|
59
|
-
{...finalProps}
|
|
60
|
-
{...processedEvents}
|
|
61
|
-
>
|
|
62
|
-
{checkboxItem.label}
|
|
63
|
-
</Comp>
|
|
64
|
-
)
|
|
65
|
-
}
|
|
1
|
+
import { Checkbox } from '@antsoo-lib/components'
|
|
2
|
+
import type { CheckboxProps } from '@antsoo-lib/components'
|
|
3
|
+
import type { VoidFunction } from '@antsoo-lib/shared'
|
|
4
|
+
import { isFunction } from '@antsoo-lib/utils'
|
|
5
|
+
|
|
6
|
+
import { markRaw } from 'vue'
|
|
7
|
+
import type { VNode } from 'vue'
|
|
8
|
+
|
|
9
|
+
import type { ToolbarState } from './state'
|
|
10
|
+
import type { CheckboxToolbarItem, ToolbarItem } from './types'
|
|
11
|
+
|
|
12
|
+
// 复选框渲染函数
|
|
13
|
+
export function renderCheckbox(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
14
|
+
const checkboxItem = item as CheckboxToolbarItem
|
|
15
|
+
const { key, events = {} } = checkboxItem
|
|
16
|
+
const { props = {}, disabled = false } = checkboxItem
|
|
17
|
+
|
|
18
|
+
const isDisabled = isFunction(disabled)
|
|
19
|
+
? disabled(toolbarState.getAllValues(), toolbarState)
|
|
20
|
+
: disabled
|
|
21
|
+
const finalProps: Partial<CheckboxProps> & {
|
|
22
|
+
disabled?: boolean
|
|
23
|
+
checked?: boolean
|
|
24
|
+
value?: boolean
|
|
25
|
+
} = {
|
|
26
|
+
...props,
|
|
27
|
+
disabled: isDisabled,
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// 处理事件,注入工具栏状态
|
|
31
|
+
const processedEvents: Record<string, VoidFunction> = {}
|
|
32
|
+
Object.keys(events).forEach((eventName) => {
|
|
33
|
+
processedEvents[eventName] = (...args: any[]) => {
|
|
34
|
+
// 对于复选框,自动更新状态
|
|
35
|
+
if (eventName === 'onUpdate:checked' || eventName === 'onChange') {
|
|
36
|
+
const checked = args[0]?.target?.checked ?? args[0] // 兼容不同的事件格式
|
|
37
|
+
toolbarState.setValue(key, checked)
|
|
38
|
+
// 显式触发 onUpdate:value,确保 BaseForm 能接收到数据更新
|
|
39
|
+
events['onUpdate:value']?.(checked, toolbarState.getAllValues(), toolbarState)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 调用原始事件处理函数
|
|
43
|
+
events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
// 如果没有设置onChange事件,添加默认的状态更新
|
|
48
|
+
if (!processedEvents['onUpdate:checked'] && !processedEvents.onChange) {
|
|
49
|
+
processedEvents['onUpdate:checked'] = (checked: boolean) => {
|
|
50
|
+
toolbarState.setValue(key, checked)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const Comp = markRaw(Checkbox)
|
|
55
|
+
return (
|
|
56
|
+
<Comp
|
|
57
|
+
key={key}
|
|
58
|
+
checked={toolbarState.getValue(key) ?? finalProps.checked ?? finalProps.value ?? false}
|
|
59
|
+
{...finalProps}
|
|
60
|
+
{...processedEvents}
|
|
61
|
+
>
|
|
62
|
+
{checkboxItem.label}
|
|
63
|
+
</Comp>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
import { CheckboxGroup } from '@antsoo-lib/components'
|
|
2
|
-
import type { CheckboxGroupProps } from '@antsoo-lib/components'
|
|
3
|
-
import type { VoidFunction } from '@antsoo-lib/shared'
|
|
4
|
-
import { isFunction } from '@antsoo-lib/utils'
|
|
5
|
-
|
|
6
|
-
import { markRaw } from 'vue'
|
|
7
|
-
import type { VNode } from 'vue'
|
|
8
|
-
|
|
9
|
-
import type { ToolbarState } from './state'
|
|
10
|
-
import type { CheckboxGroupToolbarItem, ToolbarItem } from './types'
|
|
11
|
-
|
|
12
|
-
// 复选框组渲染函数
|
|
13
|
-
export function renderCheckboxGroup(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
14
|
-
const groupItem = item as CheckboxGroupToolbarItem
|
|
15
|
-
const { key, events = {} } = groupItem
|
|
16
|
-
const { props = {}, disabled = false } = groupItem
|
|
17
|
-
|
|
18
|
-
const isDisabled = isFunction(disabled)
|
|
19
|
-
? disabled(toolbarState.getAllValues(), toolbarState)
|
|
20
|
-
: disabled
|
|
21
|
-
const finalProps: Partial<CheckboxGroupProps> & { disabled?: boolean; value?: any[] } = {
|
|
22
|
-
...props,
|
|
23
|
-
disabled: isDisabled,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// 处理事件,注入工具栏状态
|
|
27
|
-
const processedEvents: Record<string, VoidFunction> = {}
|
|
28
|
-
Object.keys(events).forEach((eventName) => {
|
|
29
|
-
processedEvents[eventName] = (...args: any[]) => {
|
|
30
|
-
// 对于复选框组,自动更新状态
|
|
31
|
-
if (eventName === 'onUpdate:value' || eventName === 'onChange') {
|
|
32
|
-
const value = args[0] // CheckboxGroup 的 onChange 直接返回选中的值数组
|
|
33
|
-
toolbarState.setValue(key, value)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// 调用原始事件处理函数
|
|
37
|
-
events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
|
|
38
|
-
}
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
// 如果没有设置onChange事件,添加默认的状态更新
|
|
42
|
-
if (!processedEvents['onUpdate:value'] && !processedEvents.onChange) {
|
|
43
|
-
processedEvents['onUpdate:value'] = (value) => {
|
|
44
|
-
toolbarState.setValue(key, value)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const Comp = markRaw(CheckboxGroup)
|
|
49
|
-
return (
|
|
50
|
-
<Comp
|
|
51
|
-
key={key}
|
|
52
|
-
value={toolbarState.getValue(key) || finalProps.value || []}
|
|
53
|
-
{...finalProps}
|
|
54
|
-
{...processedEvents}
|
|
55
|
-
/>
|
|
56
|
-
)
|
|
57
|
-
}
|
|
1
|
+
import { CheckboxGroup } from '@antsoo-lib/components'
|
|
2
|
+
import type { CheckboxGroupProps } from '@antsoo-lib/components'
|
|
3
|
+
import type { VoidFunction } from '@antsoo-lib/shared'
|
|
4
|
+
import { isFunction } from '@antsoo-lib/utils'
|
|
5
|
+
|
|
6
|
+
import { markRaw } from 'vue'
|
|
7
|
+
import type { VNode } from 'vue'
|
|
8
|
+
|
|
9
|
+
import type { ToolbarState } from './state'
|
|
10
|
+
import type { CheckboxGroupToolbarItem, ToolbarItem } from './types'
|
|
11
|
+
|
|
12
|
+
// 复选框组渲染函数
|
|
13
|
+
export function renderCheckboxGroup(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
14
|
+
const groupItem = item as CheckboxGroupToolbarItem
|
|
15
|
+
const { key, events = {} } = groupItem
|
|
16
|
+
const { props = {}, disabled = false } = groupItem
|
|
17
|
+
|
|
18
|
+
const isDisabled = isFunction(disabled)
|
|
19
|
+
? disabled(toolbarState.getAllValues(), toolbarState)
|
|
20
|
+
: disabled
|
|
21
|
+
const finalProps: Partial<CheckboxGroupProps> & { disabled?: boolean; value?: any[] } = {
|
|
22
|
+
...props,
|
|
23
|
+
disabled: isDisabled,
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// 处理事件,注入工具栏状态
|
|
27
|
+
const processedEvents: Record<string, VoidFunction> = {}
|
|
28
|
+
Object.keys(events).forEach((eventName) => {
|
|
29
|
+
processedEvents[eventName] = (...args: any[]) => {
|
|
30
|
+
// 对于复选框组,自动更新状态
|
|
31
|
+
if (eventName === 'onUpdate:value' || eventName === 'onChange') {
|
|
32
|
+
const value = args[0] // CheckboxGroup 的 onChange 直接返回选中的值数组
|
|
33
|
+
toolbarState.setValue(key, value)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 调用原始事件处理函数
|
|
37
|
+
events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
// 如果没有设置onChange事件,添加默认的状态更新
|
|
42
|
+
if (!processedEvents['onUpdate:value'] && !processedEvents.onChange) {
|
|
43
|
+
processedEvents['onUpdate:value'] = (value) => {
|
|
44
|
+
toolbarState.setValue(key, value)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const Comp = markRaw(CheckboxGroup)
|
|
49
|
+
return (
|
|
50
|
+
<Comp
|
|
51
|
+
key={key}
|
|
52
|
+
value={toolbarState.getValue(key) || finalProps.value || []}
|
|
53
|
+
{...finalProps}
|
|
54
|
+
{...processedEvents}
|
|
55
|
+
/>
|
|
56
|
+
)
|
|
57
|
+
}
|
package/src/render/Custom.tsx
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { VNode } from 'vue'
|
|
2
|
-
|
|
3
|
-
import type { ToolbarState } from './state'
|
|
4
|
-
import type { BaseToolbarItem, ToolbarItem } from './types'
|
|
5
|
-
|
|
6
|
-
// 自定义工具栏项目
|
|
7
|
-
export interface CustomToolbarItem extends BaseToolbarItem {
|
|
8
|
-
type: 'custom'
|
|
9
|
-
render: (toolbarState: ToolbarState) => VNode
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// 自定义渲染函数
|
|
13
|
-
export function renderCustom(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
14
|
-
const customItem = item as CustomToolbarItem
|
|
15
|
-
if (typeof customItem.render === 'function') {
|
|
16
|
-
return customItem.render(toolbarState)
|
|
17
|
-
}
|
|
18
|
-
return <div key={item.key}>{item.label || item.key || '未命名'}</div>
|
|
19
|
-
}
|
|
1
|
+
import type { VNode } from 'vue'
|
|
2
|
+
|
|
3
|
+
import type { ToolbarState } from './state'
|
|
4
|
+
import type { BaseToolbarItem, ToolbarItem } from './types'
|
|
5
|
+
|
|
6
|
+
// 自定义工具栏项目
|
|
7
|
+
export interface CustomToolbarItem extends BaseToolbarItem {
|
|
8
|
+
type: 'custom'
|
|
9
|
+
render: (toolbarState: ToolbarState) => VNode
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// 自定义渲染函数
|
|
13
|
+
export function renderCustom(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
14
|
+
const customItem = item as CustomToolbarItem
|
|
15
|
+
if (typeof customItem.render === 'function') {
|
|
16
|
+
return customItem.render(toolbarState)
|
|
17
|
+
}
|
|
18
|
+
return <div key={item.key}>{item.label || item.key || '未命名'}</div>
|
|
19
|
+
}
|
|
@@ -1,83 +1,83 @@
|
|
|
1
|
-
import { DatePicker, RangePicker } from '@antsoo-lib/components'
|
|
2
|
-
import type { DatePickerProps } from '@antsoo-lib/components'
|
|
3
|
-
import { rangePresets } from '@antsoo-lib/shared'
|
|
4
|
-
import type { VoidFunction } from '@antsoo-lib/shared'
|
|
5
|
-
import { isFunction } from '@antsoo-lib/utils'
|
|
6
|
-
|
|
7
|
-
import { markRaw, nextTick } from 'vue'
|
|
8
|
-
import type { ComponentPublicInstance, VNode } from 'vue'
|
|
9
|
-
|
|
10
|
-
import type { ToolbarState } from './state'
|
|
11
|
-
import type { DatePickerToolbarItem, ToolbarItem } from './types'
|
|
12
|
-
|
|
13
|
-
// 日期选择器渲染函数
|
|
14
|
-
export function renderDatePicker(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
15
|
-
const dateItem = item as DatePickerToolbarItem
|
|
16
|
-
const { key, events = {} } = dateItem
|
|
17
|
-
const { props = {}, disabled = false } = dateItem
|
|
18
|
-
|
|
19
|
-
const isDisabled = isFunction(disabled)
|
|
20
|
-
? disabled(toolbarState.getAllValues(), toolbarState)
|
|
21
|
-
: disabled
|
|
22
|
-
const finalProps: Partial<DatePickerProps> & {
|
|
23
|
-
disabled?: boolean
|
|
24
|
-
value?: any
|
|
25
|
-
autoFocus?: boolean
|
|
26
|
-
} = {
|
|
27
|
-
...props,
|
|
28
|
-
disabled: isDisabled,
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// 处理事件,注入工具栏状态
|
|
32
|
-
const processedEvents: Record<string, VoidFunction> = {}
|
|
33
|
-
Object.keys(events).forEach((eventName) => {
|
|
34
|
-
processedEvents[eventName] = (...args: any[]) => {
|
|
35
|
-
// 对于日期选择器,自动更新状态
|
|
36
|
-
if (eventName === 'onUpdate:value' || eventName === 'onChange') {
|
|
37
|
-
const value = args[0]
|
|
38
|
-
toolbarState.setValue(key, value)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// 调用原始事件处理函数
|
|
42
|
-
events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
// 如果没有设置onChange事件,添加默认的状态更新
|
|
47
|
-
if (!processedEvents['onUpdate:value'] && !processedEvents.onChange) {
|
|
48
|
-
processedEvents['onUpdate:value'] = (value) => {
|
|
49
|
-
toolbarState.setValue(key, value)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// 如果需要自动聚焦,添加ref处理
|
|
54
|
-
if (finalProps.autoFocus) {
|
|
55
|
-
processedEvents.ref = (el: Element | ComponentPublicInstance | null) => {
|
|
56
|
-
const element = el as HTMLElement
|
|
57
|
-
if (element) {
|
|
58
|
-
// 使用nextTick确保DOM已经渲染完成
|
|
59
|
-
nextTick(() => {
|
|
60
|
-
try {
|
|
61
|
-
element?.focus?.()
|
|
62
|
-
} catch {
|
|
63
|
-
// 忽略焦点设置失败的错误
|
|
64
|
-
}
|
|
65
|
-
})
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const isRange = dateItem.range
|
|
71
|
-
const Comp = markRaw(isRange ? RangePicker : DatePicker) as any
|
|
72
|
-
return (
|
|
73
|
-
<Comp
|
|
74
|
-
key={key}
|
|
75
|
-
value={toolbarState.getValue(key) || finalProps.value}
|
|
76
|
-
allowClear
|
|
77
|
-
presets={isRange ? (rangePresets as any) : undefined}
|
|
78
|
-
popupClassName={isRange ? 'custom-date-picker-presets' : undefined}
|
|
79
|
-
{...finalProps}
|
|
80
|
-
{...processedEvents}
|
|
81
|
-
/>
|
|
82
|
-
)
|
|
83
|
-
}
|
|
1
|
+
import { DatePicker, RangePicker } from '@antsoo-lib/components'
|
|
2
|
+
import type { DatePickerProps } from '@antsoo-lib/components'
|
|
3
|
+
import { rangePresets } from '@antsoo-lib/shared'
|
|
4
|
+
import type { VoidFunction } from '@antsoo-lib/shared'
|
|
5
|
+
import { isFunction } from '@antsoo-lib/utils'
|
|
6
|
+
|
|
7
|
+
import { markRaw, nextTick } from 'vue'
|
|
8
|
+
import type { ComponentPublicInstance, VNode } from 'vue'
|
|
9
|
+
|
|
10
|
+
import type { ToolbarState } from './state'
|
|
11
|
+
import type { DatePickerToolbarItem, ToolbarItem } from './types'
|
|
12
|
+
|
|
13
|
+
// 日期选择器渲染函数
|
|
14
|
+
export function renderDatePicker(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
15
|
+
const dateItem = item as DatePickerToolbarItem
|
|
16
|
+
const { key, events = {} } = dateItem
|
|
17
|
+
const { props = {}, disabled = false } = dateItem
|
|
18
|
+
|
|
19
|
+
const isDisabled = isFunction(disabled)
|
|
20
|
+
? disabled(toolbarState.getAllValues(), toolbarState)
|
|
21
|
+
: disabled
|
|
22
|
+
const finalProps: Partial<DatePickerProps> & {
|
|
23
|
+
disabled?: boolean
|
|
24
|
+
value?: any
|
|
25
|
+
autoFocus?: boolean
|
|
26
|
+
} = {
|
|
27
|
+
...props,
|
|
28
|
+
disabled: isDisabled,
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// 处理事件,注入工具栏状态
|
|
32
|
+
const processedEvents: Record<string, VoidFunction> = {}
|
|
33
|
+
Object.keys(events).forEach((eventName) => {
|
|
34
|
+
processedEvents[eventName] = (...args: any[]) => {
|
|
35
|
+
// 对于日期选择器,自动更新状态
|
|
36
|
+
if (eventName === 'onUpdate:value' || eventName === 'onChange') {
|
|
37
|
+
const value = args[0]
|
|
38
|
+
toolbarState.setValue(key, value)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// 调用原始事件处理函数
|
|
42
|
+
events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// 如果没有设置onChange事件,添加默认的状态更新
|
|
47
|
+
if (!processedEvents['onUpdate:value'] && !processedEvents.onChange) {
|
|
48
|
+
processedEvents['onUpdate:value'] = (value) => {
|
|
49
|
+
toolbarState.setValue(key, value)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// 如果需要自动聚焦,添加ref处理
|
|
54
|
+
if (finalProps.autoFocus) {
|
|
55
|
+
processedEvents.ref = (el: Element | ComponentPublicInstance | null) => {
|
|
56
|
+
const element = el as HTMLElement
|
|
57
|
+
if (element) {
|
|
58
|
+
// 使用nextTick确保DOM已经渲染完成
|
|
59
|
+
nextTick(() => {
|
|
60
|
+
try {
|
|
61
|
+
element?.focus?.()
|
|
62
|
+
} catch {
|
|
63
|
+
// 忽略焦点设置失败的错误
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const isRange = dateItem.range
|
|
71
|
+
const Comp = markRaw(isRange ? RangePicker : DatePicker) as any
|
|
72
|
+
return (
|
|
73
|
+
<Comp
|
|
74
|
+
key={key}
|
|
75
|
+
value={toolbarState.getValue(key) || finalProps.value}
|
|
76
|
+
allowClear
|
|
77
|
+
presets={isRange ? (rangePresets as any) : undefined}
|
|
78
|
+
popupClassName={isRange ? 'custom-date-picker-presets' : undefined}
|
|
79
|
+
{...finalProps}
|
|
80
|
+
{...processedEvents}
|
|
81
|
+
/>
|
|
82
|
+
)
|
|
83
|
+
}
|