@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,154 +1,154 @@
|
|
|
1
|
-
import { Form, Input } from '@antsoo-lib/components'
|
|
2
|
-
import type { AnyObject } from '@antsoo-lib/shared'
|
|
3
|
-
|
|
4
|
-
import { defineComponent, h, markRaw } from 'vue'
|
|
5
|
-
import type { VNode } from 'vue'
|
|
6
|
-
|
|
7
|
-
import type { ToolbarState } from './state'
|
|
8
|
-
import type { InputRangeToolbarItem, ToolbarItem } from './types'
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* InputRange 业务包装组件
|
|
12
|
-
* @description 统一处理 CoreForm 下 key/attr 映射、事件回调与校验触发
|
|
13
|
-
*/
|
|
14
|
-
const InputRangeWrapper = defineComponent({
|
|
15
|
-
name: 'InputRangeWrapper',
|
|
16
|
-
props: {
|
|
17
|
-
item: {
|
|
18
|
-
type: Object,
|
|
19
|
-
required: true,
|
|
20
|
-
},
|
|
21
|
-
toolbarState: {
|
|
22
|
-
type: Object,
|
|
23
|
-
required: true,
|
|
24
|
-
},
|
|
25
|
-
formValues: {
|
|
26
|
-
type: Object,
|
|
27
|
-
required: false,
|
|
28
|
-
default: undefined,
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
setup(props) {
|
|
32
|
-
const formItemContext = Form.useInjectFormItemContext()
|
|
33
|
-
|
|
34
|
-
return (): VNode => {
|
|
35
|
-
const inputRangeItem = props.item as InputRangeToolbarItem
|
|
36
|
-
const toolbarState = props.toolbarState as ToolbarState
|
|
37
|
-
const formValues = props.formValues as AnyObject | undefined
|
|
38
|
-
const attr = (inputRangeItem as AnyObject).attr
|
|
39
|
-
const allowClear = Boolean((inputRangeItem.props as AnyObject)?.allowClear)
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 解析区间值
|
|
43
|
-
* @description attr 模式优先取 formValues,回退到 toolbarState
|
|
44
|
-
*/
|
|
45
|
-
const getRangeValue = (): [string, string] => {
|
|
46
|
-
if (formValues && Array.isArray(attr) && attr.length >= 2) {
|
|
47
|
-
const [startKey, endKey] = attr as [string, string]
|
|
48
|
-
const start = formValues[startKey]
|
|
49
|
-
const end = formValues[endKey]
|
|
50
|
-
return [start != null ? String(start) : '', end != null ? String(end) : '']
|
|
51
|
-
}
|
|
52
|
-
const stateValue = toolbarState.getValue(inputRangeItem.key || '')
|
|
53
|
-
if (Array.isArray(stateValue)) {
|
|
54
|
-
const [start, end] = stateValue
|
|
55
|
-
return [start != null ? String(start) : '', end != null ? String(end) : '']
|
|
56
|
-
}
|
|
57
|
-
return ['', '']
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* 同步区间值并触发外部事件
|
|
62
|
-
*/
|
|
63
|
-
const handleRangeChange = (value: [string, string]) => {
|
|
64
|
-
if (!formValues || !Array.isArray(attr)) {
|
|
65
|
-
toolbarState.setValue(inputRangeItem.key || '', value)
|
|
66
|
-
}
|
|
67
|
-
const allValues = toolbarState.getAllValues()
|
|
68
|
-
inputRangeItem.events?.['onUpdate:value']?.(value, allValues, toolbarState)
|
|
69
|
-
inputRangeItem.events?.onChange?.(value, allValues, toolbarState)
|
|
70
|
-
formItemContext.onFieldChange()
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const [startValue, endValue] = getRangeValue()
|
|
74
|
-
const Comp = markRaw(Input)
|
|
75
|
-
|
|
76
|
-
const startInput = (
|
|
77
|
-
<Comp
|
|
78
|
-
{...inputRangeItem.props?.startProps}
|
|
79
|
-
value={startValue}
|
|
80
|
-
allowClear={Boolean(
|
|
81
|
-
(inputRangeItem.props as AnyObject)?.startProps?.allowClear ?? allowClear,
|
|
82
|
-
)}
|
|
83
|
-
placeholder={inputRangeItem.props?.startPlaceholder || '起始值'}
|
|
84
|
-
onUpdate:value={(value: string) => {
|
|
85
|
-
const [, currentEnd] = getRangeValue()
|
|
86
|
-
handleRangeChange([value, currentEnd])
|
|
87
|
-
}}
|
|
88
|
-
onChange={(event: Event) => {
|
|
89
|
-
const target = event.target as HTMLInputElement
|
|
90
|
-
const [, currentEnd] = getRangeValue()
|
|
91
|
-
handleRangeChange([target.value, currentEnd])
|
|
92
|
-
}}
|
|
93
|
-
/>
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
const endInput = (
|
|
97
|
-
<Comp
|
|
98
|
-
{...inputRangeItem.props?.endProps}
|
|
99
|
-
value={endValue}
|
|
100
|
-
allowClear={Boolean(
|
|
101
|
-
(inputRangeItem.props as AnyObject)?.endProps?.allowClear ?? allowClear,
|
|
102
|
-
)}
|
|
103
|
-
placeholder={inputRangeItem.props?.endPlaceholder || '结束值'}
|
|
104
|
-
onUpdate:value={(value: string) => {
|
|
105
|
-
const [currentStart] = getRangeValue()
|
|
106
|
-
handleRangeChange([currentStart, value])
|
|
107
|
-
}}
|
|
108
|
-
onChange={(event: Event) => {
|
|
109
|
-
const target = event.target as HTMLInputElement
|
|
110
|
-
const [currentStart] = getRangeValue()
|
|
111
|
-
handleRangeChange([currentStart, target.value])
|
|
112
|
-
}}
|
|
113
|
-
/>
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
const content = (
|
|
117
|
-
<div
|
|
118
|
-
key={inputRangeItem.key}
|
|
119
|
-
style={{
|
|
120
|
-
display: 'flex',
|
|
121
|
-
alignItems: 'center',
|
|
122
|
-
...(inputRangeItem as AnyObject).containerStyle,
|
|
123
|
-
}}
|
|
124
|
-
>
|
|
125
|
-
{startInput}
|
|
126
|
-
<span style={{ margin: '0 8px', color: '#999' }}>
|
|
127
|
-
{inputRangeItem.props?.separator || '至'}
|
|
128
|
-
</span>
|
|
129
|
-
{endInput}
|
|
130
|
-
</div>
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
return h(Form.ItemRest, null, {
|
|
134
|
-
default: () => content,
|
|
135
|
-
})
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
})
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* 渲染 InputRange
|
|
142
|
-
* @description 透传 toolbarState 与 formValues,供 CoreForm 统一状态管理
|
|
143
|
-
*/
|
|
144
|
-
export function renderInputRange(
|
|
145
|
-
item: ToolbarItem,
|
|
146
|
-
toolbarState: ToolbarState,
|
|
147
|
-
formValues?: AnyObject,
|
|
148
|
-
): VNode {
|
|
149
|
-
return h(InputRangeWrapper, {
|
|
150
|
-
item,
|
|
151
|
-
toolbarState,
|
|
152
|
-
formValues,
|
|
153
|
-
})
|
|
154
|
-
}
|
|
1
|
+
import { Form, Input } from '@antsoo-lib/components'
|
|
2
|
+
import type { AnyObject } from '@antsoo-lib/shared'
|
|
3
|
+
|
|
4
|
+
import { defineComponent, h, markRaw } from 'vue'
|
|
5
|
+
import type { VNode } from 'vue'
|
|
6
|
+
|
|
7
|
+
import type { ToolbarState } from './state'
|
|
8
|
+
import type { InputRangeToolbarItem, ToolbarItem } from './types'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* InputRange 业务包装组件
|
|
12
|
+
* @description 统一处理 CoreForm 下 key/attr 映射、事件回调与校验触发
|
|
13
|
+
*/
|
|
14
|
+
const InputRangeWrapper = defineComponent({
|
|
15
|
+
name: 'InputRangeWrapper',
|
|
16
|
+
props: {
|
|
17
|
+
item: {
|
|
18
|
+
type: Object,
|
|
19
|
+
required: true,
|
|
20
|
+
},
|
|
21
|
+
toolbarState: {
|
|
22
|
+
type: Object,
|
|
23
|
+
required: true,
|
|
24
|
+
},
|
|
25
|
+
formValues: {
|
|
26
|
+
type: Object,
|
|
27
|
+
required: false,
|
|
28
|
+
default: undefined,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
setup(props) {
|
|
32
|
+
const formItemContext = Form.useInjectFormItemContext()
|
|
33
|
+
|
|
34
|
+
return (): VNode => {
|
|
35
|
+
const inputRangeItem = props.item as InputRangeToolbarItem
|
|
36
|
+
const toolbarState = props.toolbarState as ToolbarState
|
|
37
|
+
const formValues = props.formValues as AnyObject | undefined
|
|
38
|
+
const attr = (inputRangeItem as AnyObject).attr
|
|
39
|
+
const allowClear = Boolean((inputRangeItem.props as AnyObject)?.allowClear)
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 解析区间值
|
|
43
|
+
* @description attr 模式优先取 formValues,回退到 toolbarState
|
|
44
|
+
*/
|
|
45
|
+
const getRangeValue = (): [string, string] => {
|
|
46
|
+
if (formValues && Array.isArray(attr) && attr.length >= 2) {
|
|
47
|
+
const [startKey, endKey] = attr as [string, string]
|
|
48
|
+
const start = formValues[startKey]
|
|
49
|
+
const end = formValues[endKey]
|
|
50
|
+
return [start != null ? String(start) : '', end != null ? String(end) : '']
|
|
51
|
+
}
|
|
52
|
+
const stateValue = toolbarState.getValue(inputRangeItem.key || '')
|
|
53
|
+
if (Array.isArray(stateValue)) {
|
|
54
|
+
const [start, end] = stateValue
|
|
55
|
+
return [start != null ? String(start) : '', end != null ? String(end) : '']
|
|
56
|
+
}
|
|
57
|
+
return ['', '']
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 同步区间值并触发外部事件
|
|
62
|
+
*/
|
|
63
|
+
const handleRangeChange = (value: [string, string]) => {
|
|
64
|
+
if (!formValues || !Array.isArray(attr)) {
|
|
65
|
+
toolbarState.setValue(inputRangeItem.key || '', value)
|
|
66
|
+
}
|
|
67
|
+
const allValues = toolbarState.getAllValues()
|
|
68
|
+
inputRangeItem.events?.['onUpdate:value']?.(value, allValues, toolbarState)
|
|
69
|
+
inputRangeItem.events?.onChange?.(value, allValues, toolbarState)
|
|
70
|
+
formItemContext.onFieldChange()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const [startValue, endValue] = getRangeValue()
|
|
74
|
+
const Comp = markRaw(Input)
|
|
75
|
+
|
|
76
|
+
const startInput = (
|
|
77
|
+
<Comp
|
|
78
|
+
{...inputRangeItem.props?.startProps}
|
|
79
|
+
value={startValue}
|
|
80
|
+
allowClear={Boolean(
|
|
81
|
+
(inputRangeItem.props as AnyObject)?.startProps?.allowClear ?? allowClear,
|
|
82
|
+
)}
|
|
83
|
+
placeholder={inputRangeItem.props?.startPlaceholder || '起始值'}
|
|
84
|
+
onUpdate:value={(value: string) => {
|
|
85
|
+
const [, currentEnd] = getRangeValue()
|
|
86
|
+
handleRangeChange([value, currentEnd])
|
|
87
|
+
}}
|
|
88
|
+
onChange={(event: Event) => {
|
|
89
|
+
const target = event.target as HTMLInputElement
|
|
90
|
+
const [, currentEnd] = getRangeValue()
|
|
91
|
+
handleRangeChange([target.value, currentEnd])
|
|
92
|
+
}}
|
|
93
|
+
/>
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
const endInput = (
|
|
97
|
+
<Comp
|
|
98
|
+
{...inputRangeItem.props?.endProps}
|
|
99
|
+
value={endValue}
|
|
100
|
+
allowClear={Boolean(
|
|
101
|
+
(inputRangeItem.props as AnyObject)?.endProps?.allowClear ?? allowClear,
|
|
102
|
+
)}
|
|
103
|
+
placeholder={inputRangeItem.props?.endPlaceholder || '结束值'}
|
|
104
|
+
onUpdate:value={(value: string) => {
|
|
105
|
+
const [currentStart] = getRangeValue()
|
|
106
|
+
handleRangeChange([currentStart, value])
|
|
107
|
+
}}
|
|
108
|
+
onChange={(event: Event) => {
|
|
109
|
+
const target = event.target as HTMLInputElement
|
|
110
|
+
const [currentStart] = getRangeValue()
|
|
111
|
+
handleRangeChange([currentStart, target.value])
|
|
112
|
+
}}
|
|
113
|
+
/>
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
const content = (
|
|
117
|
+
<div
|
|
118
|
+
key={inputRangeItem.key}
|
|
119
|
+
style={{
|
|
120
|
+
display: 'flex',
|
|
121
|
+
alignItems: 'center',
|
|
122
|
+
...(inputRangeItem as AnyObject).containerStyle,
|
|
123
|
+
}}
|
|
124
|
+
>
|
|
125
|
+
{startInput}
|
|
126
|
+
<span style={{ margin: '0 8px', color: '#999' }}>
|
|
127
|
+
{inputRangeItem.props?.separator || '至'}
|
|
128
|
+
</span>
|
|
129
|
+
{endInput}
|
|
130
|
+
</div>
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
return h(Form.ItemRest, null, {
|
|
134
|
+
default: () => content,
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* 渲染 InputRange
|
|
142
|
+
* @description 透传 toolbarState 与 formValues,供 CoreForm 统一状态管理
|
|
143
|
+
*/
|
|
144
|
+
export function renderInputRange(
|
|
145
|
+
item: ToolbarItem,
|
|
146
|
+
toolbarState: ToolbarState,
|
|
147
|
+
formValues?: AnyObject,
|
|
148
|
+
): VNode {
|
|
149
|
+
return h(InputRangeWrapper, {
|
|
150
|
+
item,
|
|
151
|
+
toolbarState,
|
|
152
|
+
formValues,
|
|
153
|
+
})
|
|
154
|
+
}
|
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
import { RadioGroup } from '@antsoo-lib/components'
|
|
2
|
-
import type { RadioGroupProps } 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 { RadioGroupToolbarItem, ToolbarItem } from './types'
|
|
11
|
-
|
|
12
|
-
// 单选框渲染函数
|
|
13
|
-
export function renderRadioGroup(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
14
|
-
const radioItem = item as RadioGroupToolbarItem
|
|
15
|
-
const { key, events = {} } = radioItem
|
|
16
|
-
const { props = {}, disabled = false } = radioItem
|
|
17
|
-
|
|
18
|
-
const isDisabled = isFunction(disabled)
|
|
19
|
-
? disabled(toolbarState.getAllValues(), toolbarState)
|
|
20
|
-
: disabled
|
|
21
|
-
const finalProps: Partial<RadioGroupProps> & { 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
|
-
// - v-model 使用 onUpdate:value 直接写入值
|
|
32
|
-
// - onChange 仅从 event.target.value 写入,避免事件对象被写入
|
|
33
|
-
if (eventName === 'onUpdate:value') {
|
|
34
|
-
toolbarState.setValue(key, args[0])
|
|
35
|
-
} else if (eventName === 'onChange') {
|
|
36
|
-
const ev = args[0]
|
|
37
|
-
const nextVal =
|
|
38
|
-
ev && typeof ev === 'object' && 'target' in ev ? ev.target?.value : undefined
|
|
39
|
-
if (nextVal !== undefined) toolbarState.setValue(key, nextVal)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// 调用原始事件处理函数
|
|
43
|
-
events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
// 如果没有设置onChange事件,添加默认的状态更新
|
|
48
|
-
if (!processedEvents['onUpdate:value'] && !processedEvents.onChange) {
|
|
49
|
-
processedEvents['onUpdate:value'] = (value: any) => {
|
|
50
|
-
toolbarState.setValue(key, value)
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const Comp = markRaw(RadioGroup)
|
|
55
|
-
return (
|
|
56
|
-
<Comp
|
|
57
|
-
key={key}
|
|
58
|
-
value={toolbarState.getValue(key) || finalProps.value}
|
|
59
|
-
{...finalProps}
|
|
60
|
-
{...processedEvents}
|
|
61
|
-
/>
|
|
62
|
-
)
|
|
63
|
-
}
|
|
1
|
+
import { RadioGroup } from '@antsoo-lib/components'
|
|
2
|
+
import type { RadioGroupProps } 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 { RadioGroupToolbarItem, ToolbarItem } from './types'
|
|
11
|
+
|
|
12
|
+
// 单选框渲染函数
|
|
13
|
+
export function renderRadioGroup(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
14
|
+
const radioItem = item as RadioGroupToolbarItem
|
|
15
|
+
const { key, events = {} } = radioItem
|
|
16
|
+
const { props = {}, disabled = false } = radioItem
|
|
17
|
+
|
|
18
|
+
const isDisabled = isFunction(disabled)
|
|
19
|
+
? disabled(toolbarState.getAllValues(), toolbarState)
|
|
20
|
+
: disabled
|
|
21
|
+
const finalProps: Partial<RadioGroupProps> & { 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
|
+
// - v-model 使用 onUpdate:value 直接写入值
|
|
32
|
+
// - onChange 仅从 event.target.value 写入,避免事件对象被写入
|
|
33
|
+
if (eventName === 'onUpdate:value') {
|
|
34
|
+
toolbarState.setValue(key, args[0])
|
|
35
|
+
} else if (eventName === 'onChange') {
|
|
36
|
+
const ev = args[0]
|
|
37
|
+
const nextVal =
|
|
38
|
+
ev && typeof ev === 'object' && 'target' in ev ? ev.target?.value : undefined
|
|
39
|
+
if (nextVal !== undefined) toolbarState.setValue(key, nextVal)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// 调用原始事件处理函数
|
|
43
|
+
events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
// 如果没有设置onChange事件,添加默认的状态更新
|
|
48
|
+
if (!processedEvents['onUpdate:value'] && !processedEvents.onChange) {
|
|
49
|
+
processedEvents['onUpdate:value'] = (value: any) => {
|
|
50
|
+
toolbarState.setValue(key, value)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const Comp = markRaw(RadioGroup)
|
|
55
|
+
return (
|
|
56
|
+
<Comp
|
|
57
|
+
key={key}
|
|
58
|
+
value={toolbarState.getValue(key) || finalProps.value}
|
|
59
|
+
{...finalProps}
|
|
60
|
+
{...processedEvents}
|
|
61
|
+
/>
|
|
62
|
+
)
|
|
63
|
+
}
|
package/src/render/Select.tsx
CHANGED
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import { Select } from '@antsoo-lib/components'
|
|
2
|
-
import type { SelectProps } from '@antsoo-lib/components'
|
|
3
|
-
import type { VoidFunction } from '@antsoo-lib/shared'
|
|
4
|
-
import { isFunction } from '@antsoo-lib/utils'
|
|
5
|
-
|
|
6
|
-
import { computed, markRaw } from 'vue'
|
|
7
|
-
import type { VNode } from 'vue'
|
|
8
|
-
|
|
9
|
-
import type { ToolbarState } from './state'
|
|
10
|
-
import type { SelectToolbarItem, ToolbarItem } from './types'
|
|
11
|
-
|
|
12
|
-
// 选择框渲染函数
|
|
13
|
-
export function renderSelect(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
14
|
-
const selectItem = item as SelectToolbarItem
|
|
15
|
-
const { key, events = {} } = selectItem
|
|
16
|
-
const { props = {}, disabled = false } = selectItem
|
|
17
|
-
|
|
18
|
-
const isDisabled = isFunction(disabled)
|
|
19
|
-
? disabled(toolbarState.getAllValues(), toolbarState)
|
|
20
|
-
: disabled
|
|
21
|
-
|
|
22
|
-
// Resolve options
|
|
23
|
-
const resolvedOptions = isFunction(props.options)
|
|
24
|
-
? props.options(toolbarState.getAllValues())
|
|
25
|
-
: props.options
|
|
26
|
-
|
|
27
|
-
// 从props中提取options,避免在展开props时覆盖处理后的options
|
|
28
|
-
const { options: _originalOptions, ...otherProps } = props
|
|
29
|
-
|
|
30
|
-
// 响应式计算 options,增加对ref对象的处理
|
|
31
|
-
const computedOptions = computed(() => {
|
|
32
|
-
if (isFunction(resolvedOptions)) {
|
|
33
|
-
// Should not happen if props.options was already resolved above, but handle ref() case
|
|
34
|
-
return resolvedOptions(toolbarState.getAllValues())
|
|
35
|
-
}
|
|
36
|
-
// 处理ref对象
|
|
37
|
-
if (resolvedOptions && typeof resolvedOptions === 'object' && 'value' in resolvedOptions) {
|
|
38
|
-
return resolvedOptions.value || []
|
|
39
|
-
}
|
|
40
|
-
return resolvedOptions || []
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
const finalProps: Partial<SelectProps> & { disabled?: boolean } = {
|
|
44
|
-
...otherProps,
|
|
45
|
-
disabled: isDisabled,
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// 定义processedEvents对象
|
|
49
|
-
const processedEvents: Record<string, VoidFunction> = {}
|
|
50
|
-
|
|
51
|
-
Object.keys(events).forEach((eventName) => {
|
|
52
|
-
processedEvents[eventName] = (...args: any[]) => {
|
|
53
|
-
// 对于选择框,自动更新状态
|
|
54
|
-
if (eventName === 'onUpdate:value' || eventName === 'onChange') {
|
|
55
|
-
const value = args[0]
|
|
56
|
-
toolbarState.setValue(key, value)
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 调用原始事件处理函数
|
|
60
|
-
events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
// 如果没有设置onChange事件,添加默认的状态更新
|
|
65
|
-
if (!processedEvents['onUpdate:value'] && !processedEvents.onChange) {
|
|
66
|
-
processedEvents['onUpdate:value'] = (value: any) => {
|
|
67
|
-
toolbarState.setValue(key, value)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// 获取当前值,确保正确显示
|
|
72
|
-
const rawVal = toolbarState.getValue(key)
|
|
73
|
-
const propVal = props.value
|
|
74
|
-
const isMulti = otherProps.mode === 'multiple' || otherProps.mode === 'tags'
|
|
75
|
-
|
|
76
|
-
const currentValue =
|
|
77
|
-
rawVal !== undefined && rawVal !== null
|
|
78
|
-
? rawVal
|
|
79
|
-
: propVal !== undefined && propVal !== null
|
|
80
|
-
? propVal
|
|
81
|
-
: isMulti
|
|
82
|
-
? []
|
|
83
|
-
: undefined
|
|
84
|
-
|
|
85
|
-
const Comp = markRaw(Select)
|
|
86
|
-
return (
|
|
87
|
-
<Comp
|
|
88
|
-
key={key}
|
|
89
|
-
value={currentValue}
|
|
90
|
-
allowClear
|
|
91
|
-
{...finalProps}
|
|
92
|
-
options={computedOptions.value}
|
|
93
|
-
{...processedEvents}
|
|
94
|
-
/>
|
|
95
|
-
)
|
|
96
|
-
}
|
|
1
|
+
import { Select } from '@antsoo-lib/components'
|
|
2
|
+
import type { SelectProps } from '@antsoo-lib/components'
|
|
3
|
+
import type { VoidFunction } from '@antsoo-lib/shared'
|
|
4
|
+
import { isFunction } from '@antsoo-lib/utils'
|
|
5
|
+
|
|
6
|
+
import { computed, markRaw } from 'vue'
|
|
7
|
+
import type { VNode } from 'vue'
|
|
8
|
+
|
|
9
|
+
import type { ToolbarState } from './state'
|
|
10
|
+
import type { SelectToolbarItem, ToolbarItem } from './types'
|
|
11
|
+
|
|
12
|
+
// 选择框渲染函数
|
|
13
|
+
export function renderSelect(item: ToolbarItem, toolbarState: ToolbarState): VNode {
|
|
14
|
+
const selectItem = item as SelectToolbarItem
|
|
15
|
+
const { key, events = {} } = selectItem
|
|
16
|
+
const { props = {}, disabled = false } = selectItem
|
|
17
|
+
|
|
18
|
+
const isDisabled = isFunction(disabled)
|
|
19
|
+
? disabled(toolbarState.getAllValues(), toolbarState)
|
|
20
|
+
: disabled
|
|
21
|
+
|
|
22
|
+
// Resolve options
|
|
23
|
+
const resolvedOptions = isFunction(props.options)
|
|
24
|
+
? props.options(toolbarState.getAllValues())
|
|
25
|
+
: props.options
|
|
26
|
+
|
|
27
|
+
// 从props中提取options,避免在展开props时覆盖处理后的options
|
|
28
|
+
const { options: _originalOptions, ...otherProps } = props
|
|
29
|
+
|
|
30
|
+
// 响应式计算 options,增加对ref对象的处理
|
|
31
|
+
const computedOptions = computed(() => {
|
|
32
|
+
if (isFunction(resolvedOptions)) {
|
|
33
|
+
// Should not happen if props.options was already resolved above, but handle ref() case
|
|
34
|
+
return resolvedOptions(toolbarState.getAllValues())
|
|
35
|
+
}
|
|
36
|
+
// 处理ref对象
|
|
37
|
+
if (resolvedOptions && typeof resolvedOptions === 'object' && 'value' in resolvedOptions) {
|
|
38
|
+
return resolvedOptions.value || []
|
|
39
|
+
}
|
|
40
|
+
return resolvedOptions || []
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const finalProps: Partial<SelectProps> & { disabled?: boolean } = {
|
|
44
|
+
...otherProps,
|
|
45
|
+
disabled: isDisabled,
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// 定义processedEvents对象
|
|
49
|
+
const processedEvents: Record<string, VoidFunction> = {}
|
|
50
|
+
|
|
51
|
+
Object.keys(events).forEach((eventName) => {
|
|
52
|
+
processedEvents[eventName] = (...args: any[]) => {
|
|
53
|
+
// 对于选择框,自动更新状态
|
|
54
|
+
if (eventName === 'onUpdate:value' || eventName === 'onChange') {
|
|
55
|
+
const value = args[0]
|
|
56
|
+
toolbarState.setValue(key, value)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// 调用原始事件处理函数
|
|
60
|
+
events[eventName]?.(...args, toolbarState.getAllValues(), toolbarState)
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
// 如果没有设置onChange事件,添加默认的状态更新
|
|
65
|
+
if (!processedEvents['onUpdate:value'] && !processedEvents.onChange) {
|
|
66
|
+
processedEvents['onUpdate:value'] = (value: any) => {
|
|
67
|
+
toolbarState.setValue(key, value)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 获取当前值,确保正确显示
|
|
72
|
+
const rawVal = toolbarState.getValue(key)
|
|
73
|
+
const propVal = props.value
|
|
74
|
+
const isMulti = otherProps.mode === 'multiple' || otherProps.mode === 'tags'
|
|
75
|
+
|
|
76
|
+
const currentValue =
|
|
77
|
+
rawVal !== undefined && rawVal !== null
|
|
78
|
+
? rawVal
|
|
79
|
+
: propVal !== undefined && propVal !== null
|
|
80
|
+
? propVal
|
|
81
|
+
: isMulti
|
|
82
|
+
? []
|
|
83
|
+
: undefined
|
|
84
|
+
|
|
85
|
+
const Comp = markRaw(Select)
|
|
86
|
+
return (
|
|
87
|
+
<Comp
|
|
88
|
+
key={key}
|
|
89
|
+
value={currentValue}
|
|
90
|
+
allowClear
|
|
91
|
+
{...finalProps}
|
|
92
|
+
options={computedOptions.value}
|
|
93
|
+
{...processedEvents}
|
|
94
|
+
/>
|
|
95
|
+
)
|
|
96
|
+
}
|