@wzyjs/uis 0.3.29 → 0.3.30

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.
Files changed (221) hide show
  1. package/dist/advanced/Com2Canvas/index.d.ts +8 -0
  2. package/dist/advanced/Com2Canvas/index.js +39 -0
  3. package/dist/advanced/Crud/components/CardList/index.d.ts +2 -0
  4. package/dist/advanced/Crud/components/CardList/index.js +90 -0
  5. package/dist/advanced/Crud/components/CreateUpdate/index.d.ts +2 -0
  6. package/dist/advanced/Crud/components/CreateUpdate/index.js +78 -0
  7. package/dist/advanced/Crud/components/ListTabs/index.d.ts +8 -0
  8. package/dist/advanced/Crud/components/ListTabs/index.js +7 -0
  9. package/dist/advanced/Crud/components/Provider/index.d.ts +7 -0
  10. package/dist/advanced/Crud/components/Provider/index.js +42 -0
  11. package/dist/advanced/Crud/components/QuickFilters/index.d.ts +8 -0
  12. package/dist/advanced/Crud/components/QuickFilters/index.js +20 -0
  13. package/dist/advanced/Crud/components/Remove/index.d.ts +2 -0
  14. package/dist/advanced/Crud/components/Remove/index.js +18 -0
  15. package/dist/advanced/Crud/components/index.d.ts +6 -0
  16. package/dist/advanced/Crud/components/index.js +6 -0
  17. package/dist/advanced/Crud/hooks/index.d.ts +5 -0
  18. package/dist/advanced/Crud/hooks/index.js +5 -0
  19. package/dist/advanced/Crud/hooks/useColumns.d.ts +11 -0
  20. package/dist/advanced/Crud/hooks/useColumns.js +111 -0
  21. package/dist/advanced/Crud/hooks/useList.d.ts +12 -0
  22. package/dist/advanced/Crud/hooks/useList.js +53 -0
  23. package/dist/advanced/Crud/hooks/useListFilters.d.ts +11 -0
  24. package/dist/advanced/Crud/hooks/useListFilters.js +159 -0
  25. package/dist/advanced/Crud/hooks/useOrderable.d.ts +15 -0
  26. package/dist/advanced/Crud/hooks/useOrderable.js +75 -0
  27. package/dist/advanced/Crud/hooks/useRequest.d.ts +13 -0
  28. package/dist/advanced/Crud/hooks/useRequest.js +27 -0
  29. package/dist/advanced/Crud/index.d.ts +3 -0
  30. package/dist/advanced/Crud/index.js +46 -0
  31. package/dist/advanced/Crud/types/index.d.ts +176 -0
  32. package/dist/advanced/Crud/types/index.js +1 -0
  33. package/dist/advanced/Crud/utils/index.d.ts +7 -0
  34. package/dist/advanced/Crud/utils/index.js +80 -0
  35. package/dist/advanced/Crud/utils/query.d.ts +3 -0
  36. package/dist/advanced/Crud/utils/query.js +34 -0
  37. package/dist/advanced/MindMap/context.d.ts +12 -0
  38. package/dist/advanced/MindMap/context.js +12 -0
  39. package/dist/advanced/MindMap/hooks/useAlignmentSnap.d.ts +15 -0
  40. package/dist/advanced/MindMap/hooks/useAlignmentSnap.js +164 -0
  41. package/dist/advanced/MindMap/hooks/useCopyPaste.d.ts +11 -0
  42. package/dist/advanced/MindMap/hooks/useCopyPaste.js +209 -0
  43. package/dist/advanced/MindMap/hooks/useDropToReparent.d.ts +21 -0
  44. package/dist/advanced/MindMap/hooks/useDropToReparent.js +216 -0
  45. package/dist/advanced/MindMap/hooks/useExpandCollapse.d.ts +18 -0
  46. package/dist/advanced/MindMap/hooks/useExpandCollapse.js +108 -0
  47. package/dist/advanced/MindMap/hooks/useMoveDescendants.d.ts +12 -0
  48. package/dist/advanced/MindMap/hooks/useMoveDescendants.js +98 -0
  49. package/dist/advanced/MindMap/hooks/useUndoRedo.d.ts +14 -0
  50. package/dist/advanced/MindMap/hooks/useUndoRedo.js +181 -0
  51. package/dist/advanced/MindMap/index.d.ts +29 -0
  52. package/dist/advanced/MindMap/index.js +52 -0
  53. package/dist/advanced/index.d.ts +5 -0
  54. package/dist/advanced/index.js +5 -0
  55. package/dist/antd/index.d.ts +6 -0
  56. package/dist/antd/index.js +5 -0
  57. package/dist/buttons/ButtonGroup/index.d.ts +8 -0
  58. package/dist/buttons/ButtonGroup/index.js +13 -0
  59. package/dist/buttons/ConfirmButton/index.d.ts +5 -0
  60. package/dist/buttons/ConfirmButton/index.js +9 -0
  61. package/dist/buttons/CopyButton/index.d.ts +6 -0
  62. package/dist/buttons/CopyButton/index.js +26 -0
  63. package/dist/buttons/DrawerButton/index.d.ts +6 -0
  64. package/dist/buttons/DrawerButton/index.js +13 -0
  65. package/dist/buttons/ProgressButton/index.css +63 -0
  66. package/dist/buttons/ProgressButton/index.d.ts +17 -0
  67. package/dist/buttons/ProgressButton/index.js +31 -0
  68. package/dist/buttons/SectorButton/index.d.ts +20 -0
  69. package/dist/buttons/SectorButton/index.js +130 -0
  70. package/dist/buttons/index.d.ts +6 -0
  71. package/dist/buttons/index.js +6 -0
  72. package/dist/display/CodeView/index.d.ts +26 -0
  73. package/dist/display/CodeView/index.js +60 -0
  74. package/dist/display/EnumTag/index.d.ts +12 -0
  75. package/dist/display/EnumTag/index.js +10 -0
  76. package/dist/display/HtmlDataRenderer/index.d.ts +6 -0
  77. package/dist/display/HtmlDataRenderer/index.js +15 -0
  78. package/dist/display/HtmlView/index.d.ts +6 -0
  79. package/dist/display/HtmlView/index.js +6 -0
  80. package/dist/display/IframePro/index.d.ts +8 -0
  81. package/dist/display/IframePro/index.js +24 -0
  82. package/dist/display/JsonSchemaRenderer/index.d.ts +11 -0
  83. package/dist/display/JsonSchemaRenderer/index.js +62 -0
  84. package/dist/display/JsonView/index.d.ts +3 -0
  85. package/dist/display/JsonView/index.js +7 -0
  86. package/dist/display/MarkdownView/index.d.ts +7 -0
  87. package/dist/display/MarkdownView/index.js +80 -0
  88. package/dist/display/MarkdownView/style.d.ts +1 -0
  89. package/{src/components/Markdown/style.ts → dist/display/MarkdownView/style.js} +1 -1
  90. package/dist/display/VideoPro/index.d.ts +9 -0
  91. package/dist/display/VideoPro/index.js +15 -0
  92. package/dist/display/index.d.ts +9 -0
  93. package/dist/display/index.js +9 -0
  94. package/dist/inputs/CheckboxButton/index.css +22 -0
  95. package/dist/inputs/CheckboxButton/index.d.ts +12 -0
  96. package/dist/inputs/CheckboxButton/index.js +9 -0
  97. package/dist/inputs/DateSwitcher/index.css +10 -0
  98. package/dist/inputs/DateSwitcher/index.d.ts +8 -0
  99. package/dist/inputs/DateSwitcher/index.js +29 -0
  100. package/dist/inputs/FetchSelect/index.d.ts +3 -0
  101. package/dist/inputs/FetchSelect/index.js +121 -0
  102. package/dist/inputs/FetchSelect/types.d.ts +33 -0
  103. package/dist/inputs/FetchSelect/types.js +1 -0
  104. package/dist/inputs/FetchSelect/utils.d.ts +21 -0
  105. package/dist/inputs/FetchSelect/utils.js +67 -0
  106. package/dist/inputs/FileUploader/index.d.ts +22 -0
  107. package/dist/inputs/FileUploader/index.js +79 -0
  108. package/dist/inputs/IconSelect/index.d.ts +89 -0
  109. package/dist/inputs/IconSelect/index.js +54 -0
  110. package/dist/inputs/ImageUploader/index.d.ts +12 -0
  111. package/dist/inputs/ImageUploader/index.js +192 -0
  112. package/dist/inputs/RadioButton/index.d.ts +15 -0
  113. package/dist/inputs/RadioButton/index.js +11 -0
  114. package/dist/inputs/RangeInput/index.d.ts +8 -0
  115. package/dist/inputs/RangeInput/index.js +17 -0
  116. package/dist/inputs/TextInput/index.d.ts +6 -0
  117. package/dist/inputs/TextInput/index.js +30 -0
  118. package/dist/inputs/index.d.ts +9 -0
  119. package/dist/inputs/index.js +9 -0
  120. package/dist/layout/DragSort/index.d.ts +16 -0
  121. package/dist/layout/DragSort/index.js +12 -0
  122. package/dist/layout/FoldCard/index.d.ts +9 -0
  123. package/dist/layout/FoldCard/index.js +69 -0
  124. package/dist/layout/PageBase/index.d.ts +6 -0
  125. package/dist/layout/PageBase/index.js +6 -0
  126. package/dist/layout/ResizableGridLayout/index.d.ts +11 -0
  127. package/dist/layout/ResizableGridLayout/index.js +13 -0
  128. package/dist/layout/SideMenu/index.d.ts +27 -0
  129. package/dist/layout/SideMenu/index.js +40 -0
  130. package/dist/layout/TabsPro/index.d.ts +9 -0
  131. package/dist/layout/TabsPro/index.js +87 -0
  132. package/dist/layout/index.d.ts +6 -0
  133. package/dist/layout/index.js +6 -0
  134. package/dist/web.d.ts +6 -0
  135. package/dist/web.js +6 -0
  136. package/package.json +28 -11
  137. package/src/antd/form/CheckboxButton/index.module.scss +0 -24
  138. package/src/antd/form/CheckboxButton/index.tsx +0 -31
  139. package/src/antd/form/FileUploader/index.tsx +0 -163
  140. package/src/antd/form/RadioButton/index.tsx +0 -32
  141. package/src/antd/form/Upload/index.tsx +0 -65
  142. package/src/antd/form/UploadImage/index.tsx +0 -338
  143. package/src/antd/form/index.ts +0 -6
  144. package/src/antd/index.ts +0 -46
  145. package/src/antd/pro/FoldCard/index.tsx +0 -131
  146. package/src/antd/pro/RangeInput/index.tsx +0 -46
  147. package/src/antd/pro/Tabs/index.tsx +0 -135
  148. package/src/antd/pro/Typography/components/String.tsx +0 -72
  149. package/src/antd/pro/Typography/index.tsx +0 -9
  150. package/src/antd/pro/buttons/ButtonGroup.tsx +0 -26
  151. package/src/antd/pro/buttons/ConfirmButton.tsx +0 -24
  152. package/src/antd/pro/buttons/CopyButton.tsx +0 -47
  153. package/src/antd/pro/buttons/DrawerButton.tsx +0 -37
  154. package/src/antd/pro/buttons/index.tsx +0 -4
  155. package/src/antd/pro/index.ts +0 -5
  156. package/src/components/BottomBar/index.tsx +0 -28
  157. package/src/components/CodeView/index.tsx +0 -85
  158. package/src/components/Collapse/index.tsx +0 -26
  159. package/src/components/Com2Canvas/index.tsx +0 -60
  160. package/src/components/CompileHtml/index.tsx +0 -26
  161. package/src/components/Crud/components/CardList/index.tsx +0 -174
  162. package/src/components/Crud/components/CreateUpdate/index.tsx +0 -179
  163. package/src/components/Crud/components/Provider/index.tsx +0 -83
  164. package/src/components/Crud/components/Remove/index.tsx +0 -56
  165. package/src/components/Crud/components/index.ts +0 -4
  166. package/src/components/Crud/hooks/index.ts +0 -4
  167. package/src/components/Crud/hooks/useColumns.tsx +0 -169
  168. package/src/components/Crud/hooks/useList.ts +0 -65
  169. package/src/components/Crud/hooks/useOrderable.tsx +0 -107
  170. package/src/components/Crud/hooks/useRequest.ts +0 -41
  171. package/src/components/Crud/index.tsx +0 -91
  172. package/src/components/Crud/types/index.ts +0 -188
  173. package/src/components/Crud/utils/index.ts +0 -87
  174. package/src/components/DateSwitcher/index.module.scss +0 -10
  175. package/src/components/DateSwitcher/index.tsx +0 -75
  176. package/src/components/DownloadLink/index.tsx +0 -36
  177. package/src/components/DragSort/index.tsx +0 -77
  178. package/src/components/DynamicSelect/index.tsx +0 -76
  179. package/src/components/DynamicSelect/types.ts +0 -8
  180. package/src/components/DynamicSelect/utils.ts +0 -47
  181. package/src/components/EnumTag/index.tsx +0 -24
  182. package/src/components/FetchSelect/index.tsx +0 -57
  183. package/src/components/FormPro/index.tsx +0 -28
  184. package/src/components/GroupLayout/index.tsx +0 -45
  185. package/src/components/HtmlPro/index.tsx +0 -18
  186. package/src/components/IframePro/index.tsx +0 -52
  187. package/src/components/JsonRenderer/index.tsx +0 -114
  188. package/src/components/JsonView/index.tsx +0 -21
  189. package/src/components/Markdown/index.tsx +0 -152
  190. package/src/components/MindMap/context.tsx +0 -29
  191. package/src/components/MindMap/hooks/useAlignmentSnap.ts +0 -220
  192. package/src/components/MindMap/hooks/useCopyPaste.ts +0 -272
  193. package/src/components/MindMap/hooks/useDropToReparent.ts +0 -288
  194. package/src/components/MindMap/hooks/useExpandCollapse.ts +0 -146
  195. package/src/components/MindMap/hooks/useMoveDescendants.ts +0 -136
  196. package/src/components/MindMap/hooks/useUndoRedo.ts +0 -232
  197. package/src/components/MindMap/index.tsx +0 -117
  198. package/src/components/MultiImageDisplay/index.tsx +0 -63
  199. package/src/components/ProgressButton/index.module.scss +0 -65
  200. package/src/components/ProgressButton/index.tsx +0 -96
  201. package/src/components/SectorButton/index.tsx +0 -247
  202. package/src/components/TextInput/index.tsx +0 -61
  203. package/src/components/TimelineBar/components/CurrentWeekHighlight/index.tsx +0 -64
  204. package/src/components/TimelineBar/components/Guides/index.tsx +0 -61
  205. package/src/components/TimelineBar/components/Ticks/index.tsx +0 -56
  206. package/src/components/TimelineBar/components/TodayIndicator/index.tsx +0 -54
  207. package/src/components/TimelineBar/components/index.ts +0 -4
  208. package/src/components/TimelineBar/const.ts +0 -3
  209. package/src/components/TimelineBar/hooks/index.ts +0 -5
  210. package/src/components/TimelineBar/hooks/useHighlightRange.ts +0 -21
  211. package/src/components/TimelineBar/hooks/useMonthGuides.ts +0 -40
  212. package/src/components/TimelineBar/hooks/useTickValues.ts +0 -18
  213. package/src/components/TimelineBar/hooks/useVisibleRange.ts +0 -43
  214. package/src/components/TimelineBar/hooks/useWeekGuides.ts +0 -39
  215. package/src/components/TimelineBar/index.tsx +0 -63
  216. package/src/components/TimelineBar/utils.ts +0 -27
  217. package/src/components/Video/index.tsx +0 -37
  218. package/src/components/index.ts +0 -26
  219. package/src/rn.ts +0 -1
  220. package/src/rns/index.ts +0 -0
  221. package/src/web.ts +0 -2
@@ -1,179 +0,0 @@
1
- 'use client'
2
-
3
- import { useMemo, useState } from 'react'
4
- import { Button, type DrawerProps, type ModalProps } from 'antd'
5
- import { PlusOutlined, EditOutlined } from '@ant-design/icons'
6
- import { BetaSchemaForm } from '@ant-design/pro-components'
7
-
8
- import type { CreateUpdateProps, ProColumnsPro } from '../../types'
9
-
10
- const isActionColumn = (column: ProColumnsPro) => (
11
- column.valueType === 'option'
12
- || column.key === 'option'
13
- || column.key === 'action'
14
- || column.title === '操作'
15
- )
16
-
17
- const getFormColumns = (columns: ProColumnsPro[]) => {
18
- return columns
19
- .filter(column => !column.hideInForm && !isActionColumn(column) && column.key !== '__drag_sort__')
20
- .map((column) => {
21
- const {
22
- fixed,
23
- sorter,
24
- sortOrder,
25
- defaultSortOrder,
26
- filters,
27
- onFilter,
28
- onCell,
29
- onHeaderCell,
30
- ellipsis,
31
- copyable,
32
- render,
33
- renderText,
34
- width,
35
- ...formColumn
36
- } = column as ProColumnsPro & Record<string, unknown>
37
-
38
- return formColumn as ProColumnsPro
39
- })
40
- }
41
-
42
- export const CreateUpdate = (props: CreateUpdateProps) => {
43
- const { crud, columns, config, record } = props
44
-
45
- const isEdit = !!record
46
- const [open, setOpen] = useState(false)
47
- const [formRendered, setFormRendered] = useState(false)
48
-
49
- const {
50
- mode = 'drawer',
51
- title = isEdit ? '编辑' : '新建',
52
- buttonProps = {},
53
- formProps = {},
54
- transformData,
55
- coverData,
56
- width,
57
- } = config
58
-
59
- const {
60
- drawerProps,
61
- modalProps,
62
- initialValues,
63
- onOpenChange,
64
- onVisibleChange,
65
- open: _open,
66
- visible: _visible,
67
- ...formSafeProps
68
- } = formProps as unknown as {
69
- drawerProps?: DrawerProps
70
- modalProps?: ModalProps
71
- initialValues?: Record<string, unknown>
72
- onOpenChange?: (open: boolean) => void
73
- onVisibleChange?: (open: boolean) => void
74
- open?: boolean
75
- visible?: boolean
76
- } & Record<string, unknown>
77
-
78
- const layoutType = mode === 'modal' ? 'ModalForm' : 'DrawerForm'
79
-
80
- const formColumns = useMemo(() => getFormColumns(columns), [columns])
81
-
82
- const handleOpenChange = (nextOpen: boolean) => {
83
- setOpen(nextOpen)
84
- if (nextOpen) {
85
- setFormRendered(true)
86
- }
87
- onOpenChange?.(nextOpen)
88
- onVisibleChange?.(nextOpen)
89
- }
90
-
91
- const openForm = (event: any) => {
92
- buttonProps.onClick?.(event)
93
- if (event.defaultPrevented) {
94
- return
95
- }
96
- setFormRendered(true)
97
- setOpen(true)
98
- }
99
-
100
- const onFinish = async (values: Record<string, unknown>) => {
101
- const finalValues = transformData ? await transformData(values, record) : values
102
-
103
- if (isEdit) {
104
- await crud.updateState.mutateAsync(record.id, finalValues)
105
- } else {
106
- await crud.createState.mutateAsync(finalValues)
107
- }
108
- return true
109
- }
110
-
111
- const formKey = (() => {
112
- if (isEdit && record) {
113
- return record.id
114
- }
115
-
116
- if (!initialValues) {
117
- return 'create'
118
- }
119
-
120
- if (typeof initialValues !== 'object') {
121
- return `create-${JSON.stringify(initialValues)}`
122
- }
123
-
124
- try {
125
- return `create-${JSON.stringify(initialValues)}`
126
- } catch {
127
- return 'create'
128
- }
129
- })()
130
-
131
- const finalInitialValues = {
132
- ...(record ?? {}),
133
- ...(initialValues ?? {}),
134
- ...(coverData ? coverData(record) : {}),
135
- }
136
-
137
- const trigger = isEdit ? (
138
- <Button
139
- type='link'
140
- size='small'
141
- icon={<EditOutlined />}
142
- {...buttonProps}
143
- onClick={openForm}
144
- />
145
- ) : (
146
- <Button
147
- type='primary'
148
- icon={<PlusOutlined />}
149
- {...buttonProps}
150
- onClick={openForm}
151
- >
152
- 新建
153
- </Button>
154
- )
155
-
156
- return (
157
- <>
158
- {trigger}
159
- {formRendered ? (
160
- <BetaSchemaForm
161
- key={formKey}
162
- layoutType={layoutType as any}
163
- title={title}
164
- width={width}
165
- columns={formColumns as any}
166
- onFinish={onFinish}
167
- layout='horizontal'
168
- labelCol={{ span: 4 }}
169
- initialValues={finalInitialValues}
170
- open={open}
171
- onOpenChange={handleOpenChange}
172
- {...(drawerProps ? { drawerProps } : {})}
173
- {...(modalProps ? { modalProps } : {})}
174
- {...formSafeProps}
175
- />
176
- ) : null}
177
- </>
178
- )
179
- }
@@ -1,83 +0,0 @@
1
- 'use client'
2
-
3
- import { type PropsWithChildren, useContext, useMemo } from 'react'
4
- import { Tag, Switch } from 'antd'
5
- import { ProProvider, ProFormSelect } from '@ant-design/pro-components'
6
- import type { ProRenderFieldPropsType } from '@ant-design/pro-provider'
7
-
8
- import type { Crud } from '../../types'
9
-
10
- interface ProviderProps extends PropsWithChildren {
11
- crud?: Crud
12
- }
13
-
14
- export const Provider = (props: ProviderProps) => {
15
- const { children, crud } = props
16
-
17
- const defaultContext = useContext(ProProvider)
18
-
19
- const onSwitchChange = (id: string, enabled: boolean) => {
20
- if (crud?.updateState) {
21
- crud.updateState.mutate(id, { enabled })
22
- }
23
- }
24
-
25
- const valueTypeMap = useMemo<Record<string, ProRenderFieldPropsType>>(() => ({
26
- ...defaultContext.valueTypeMap,
27
- tags: {
28
- renderFormItem: (_: unknown, props: any) => {
29
- const { options, ...restFieldProps } = props.fieldProps || {}
30
-
31
- let processedOptions = options
32
-
33
- if (Array.isArray(options) && options.length > 0 && typeof options[0] === 'string') {
34
- processedOptions = options.map((item: string) => ({
35
- label: item,
36
- value: item,
37
- }))
38
- }
39
-
40
- return (
41
- <ProFormSelect
42
- placeholder='请输入标签'
43
- mode='tags'
44
- options={processedOptions}
45
- {...restFieldProps}
46
- />
47
- )
48
- },
49
- render: (tags: string[]) => {
50
- return (
51
- <>
52
- {tags?.map((tag: string) => (
53
- <Tag key={tag}>{tag}</Tag>
54
- ))}
55
- </>
56
- )
57
- },
58
- },
59
- enabled: {
60
- render: (enabled: boolean, props: any) => {
61
- return (
62
- <Switch
63
- loading={crud?.updateState.isLoading}
64
- checked={enabled}
65
- onChange={enabled => onSwitchChange(props.record?.id, enabled)}
66
- disabled={!crud?.updateState}
67
- />
68
- )
69
- },
70
- },
71
- }), [crud?.updateState, defaultContext.valueTypeMap])
72
-
73
- return (
74
- <ProProvider.Provider
75
- value={{
76
- ...defaultContext,
77
- valueTypeMap,
78
- }}
79
- >
80
- {children}
81
- </ProProvider.Provider>
82
- )
83
- }
@@ -1,56 +0,0 @@
1
- import { Popconfirm, Button } from 'antd'
2
- import { DeleteOutlined } from '@ant-design/icons'
3
-
4
- import type { RemoveProps } from '../../types'
5
-
6
- export const Remove = (props: RemoveProps) => {
7
- const { crud, config, record } = props
8
-
9
- const {
10
- confirm = true,
11
- buttonProps = {},
12
- title = '确定要删除吗?',
13
- content,
14
- } = config
15
-
16
- const onConfirm = () => {
17
- crud.removeState.mutate(record.id)
18
- }
19
-
20
- // 如果不需要确认,直接执行删除
21
- if (!confirm) {
22
- return (
23
- <Button
24
- type='link'
25
- danger
26
- size='small'
27
- icon={<DeleteOutlined />}
28
- loading={crud.removeState.isLoading}
29
- onClick={onConfirm}
30
- {...buttonProps}
31
- />
32
- )
33
- }
34
-
35
- // 需要确认的删除按钮
36
- return (
37
- <Popconfirm
38
- title={title}
39
- description={content}
40
- onConfirm={onConfirm}
41
- okText='确定'
42
- cancelText='取消'
43
- okButtonProps={{
44
- loading: crud.removeState.isLoading,
45
- }}
46
- >
47
- <Button
48
- type='link'
49
- danger
50
- size='small'
51
- icon={<DeleteOutlined />}
52
- {...buttonProps}
53
- />
54
- </Popconfirm>
55
- )
56
- }
@@ -1,4 +0,0 @@
1
- export { CreateUpdate } from './CreateUpdate'
2
- export { Remove } from './Remove'
3
- export { CardList } from './CardList'
4
- export { Provider } from './Provider'
@@ -1,4 +0,0 @@
1
- export { useColumns } from './useColumns'
2
- export { useList } from './useList'
3
- export { useRequest } from './useRequest'
4
- export { useOrderable } from './useOrderable'
@@ -1,169 +0,0 @@
1
- import React, { useMemo } from 'react'
2
-
3
- import { Space } from 'antd'
4
- import { CreateUpdate, Remove } from '../components'
5
-
6
- import type { ProColumnsPro, CrudProps } from '../types'
7
-
8
- interface UseColumnsParams {
9
- columns: CrudProps['columns']
10
- crud: CrudProps['crud']
11
- update: CrudProps['update']
12
- remove: CrudProps['remove']
13
- }
14
-
15
- const normalizeCellDom = (dom: React.ReactNode): React.ReactNode => {
16
- if (!dom || typeof dom !== 'object') {
17
- return dom
18
- }
19
-
20
- if ('children' in dom && 'props' in dom) {
21
- return (dom as any).children
22
- }
23
-
24
- return dom
25
- }
26
-
27
- const normalizeRenderResult = (result: unknown) => {
28
- if (!result || typeof result !== 'object') {
29
- return result
30
- }
31
-
32
- if ('children' in result && 'props' in result) {
33
- return (result as any).children
34
- }
35
-
36
- return result
37
- }
38
-
39
- export const useColumns = ({ columns, crud, update, remove }: UseColumnsParams) => {
40
- // 检查是否需要显示操作列
41
- const hasActions = update !== false || remove !== false
42
-
43
- // 智能合并操作列
44
- const finalColumns: ProColumnsPro[] = useMemo(() => {
45
- // const proColumns = transformColumns(columns)
46
- const proColumns: ProColumnsPro[] = columns.map((col: ProColumnsPro) => {
47
- const isActionColumn: boolean = col.valueType === 'option'
48
- || col.key === 'option'
49
- || col.key === 'action'
50
- || col.title === '操作'
51
-
52
- if (col.render) {
53
- const originalRender = col.render
54
- return {
55
- ...col,
56
- render: (dom: any, record: any, index: any, action: any, schema: any) => {
57
- return normalizeRenderResult(originalRender(dom, record, index, action, schema)) as any
58
- },
59
- }
60
- }
61
-
62
- if (isActionColumn) {
63
- return col
64
- }
65
-
66
- return {
67
- ...col,
68
- // DragSortTable 需要包一层,不然有的字段不显示
69
- render: (dom: React.ReactNode): React.ReactNode => normalizeCellDom(dom),
70
- }
71
- })
72
-
73
- // 生成默认的操作按钮
74
- const generateDefaultActions = (record: any) => {
75
- const actions = []
76
-
77
- if (update !== false) {
78
- actions.push(
79
- <CreateUpdate
80
- key='update'
81
- crud={crud}
82
- columns={columns}
83
- config={update || {}}
84
- record={record}
85
- />,
86
- )
87
- }
88
-
89
- if (remove !== false) {
90
- actions.push(
91
- <Remove
92
- key='remove'
93
- crud={crud}
94
- config={remove || {}}
95
- record={record}
96
- />,
97
- )
98
- }
99
-
100
- return actions
101
- }
102
-
103
- // 查找是否已存在操作列
104
- const existingActionColumnIndex = proColumns.findIndex(
105
- col => col.key === 'option' || col.key === 'action' || col.title === '操作',
106
- )
107
-
108
- if (existingActionColumnIndex !== -1) {
109
- // 如果已存在操作列,合并操作
110
- const existingColumn = proColumns[existingActionColumnIndex]
111
- if (!existingColumn) return proColumns
112
-
113
- const originalRender = existingColumn.render
114
-
115
- const mergedColumns = [...proColumns]
116
- mergedColumns[existingActionColumnIndex] = {
117
- ...existingColumn,
118
- render: (text: any, record: any, index: number, action: any, schema: any) => {
119
- const defaultActions = hasActions ? generateDefaultActions(record) : []
120
-
121
- // 如果用户定义了自定义渲染,调用它
122
- if (originalRender) {
123
- const customActions = originalRender(text, record, index, action, schema)
124
-
125
- // 如果自定义渲染返回 ReactElement 或数组,合并操作
126
- if (React.isValidElement(customActions) || Array.isArray(customActions)) {
127
- return (
128
- <Space>
129
- {customActions}
130
- {defaultActions}
131
- </Space>
132
- )
133
- }
134
-
135
- // 如果自定义渲染返回其他内容,直接使用
136
- return customActions
137
- }
138
-
139
- // 没有自定义渲染时,只显示默认操作
140
- return <Space>{defaultActions}</Space>
141
- },
142
- }
143
-
144
- return mergedColumns
145
- } else {
146
- // 如果不存在操作列且需要操作,添加新的操作列
147
- return [
148
- ...proColumns,
149
- ...(hasActions ? [{
150
- title: '操作',
151
- dataIndex: 'action',
152
- key: 'action',
153
- fixed: 'right' as const,
154
- width: 120,
155
- search: false,
156
- render: (_: any, record: any) => (
157
- <Space>
158
- {generateDefaultActions(record)}
159
- </Space>
160
- ),
161
- }] : []),
162
- ]
163
- }
164
- }, [columns, hasActions, update, remove, crud])
165
-
166
- return {
167
- finalColumns,
168
- }
169
- }
@@ -1,65 +0,0 @@
1
- import { useState, useEffect, useMemo } from 'react'
2
- import type { CrudProps } from '../types'
3
-
4
- interface UseTabsStateParams {
5
- list: CrudProps['list']
6
- }
7
-
8
- export const useList = ({ list }: UseTabsStateParams) => {
9
- // 初始化 activeTabKey 状态
10
- const [activeTabKey, setTabActiveKey] = useState<string | undefined>(() => {
11
- const tabs = list?.toolbar?.tabs as any
12
- if (!tabs) {
13
- return
14
- }
15
- return tabs.activeKey ?? tabs.items?.[0]?.key
16
- })
17
-
18
- // 同步外部传入的 activeKey
19
- useEffect(() => {
20
- const tabs = list?.toolbar?.tabs as any
21
- if (tabs && tabs.activeKey !== undefined && tabs.activeKey !== activeTabKey) {
22
- setTabActiveKey(tabs.activeKey)
23
- }
24
- }, [list?.toolbar?.tabs])
25
-
26
- // 当 Tab 变化时,将最新的类型通过 onChangeQuery 回传给父组件
27
- useEffect(() => {
28
- if (activeTabKey !== undefined) {
29
- list?.onChangeQuery?.({
30
- where: { type: activeTabKey },
31
- })
32
- }
33
- }, [activeTabKey])
34
-
35
- // 构造最终传递给 ProTable 的 list 配置
36
- const finalList = useMemo(() => {
37
- if (!list?.toolbar?.tabs) return list ?? {}
38
-
39
- const originalTabs: any = list.toolbar.tabs
40
-
41
- const enhancedTabs = {
42
- ...originalTabs,
43
- activeKey: activeTabKey,
44
- onChange: (key: string) => {
45
- setTabActiveKey(key)
46
- originalTabs.onChange?.(key)
47
- },
48
- }
49
-
50
- return {
51
- ...list,
52
- toolbar: {
53
- ...list.toolbar,
54
- multipleLine: list.toolbar.multipleLine ?? !!list.toolbar.tabs.items?.length,
55
- tabs: enhancedTabs,
56
- },
57
- }
58
- }, [activeTabKey, list])
59
-
60
- return {
61
- activeTabKey,
62
- setTabActiveKey,
63
- finalList,
64
- }
65
- }
@@ -1,107 +0,0 @@
1
- import { useEffect, useMemo, useState } from 'react'
2
- import type { CrudProps, ProColumnsPro } from '../types'
3
-
4
- const dragSortKey = '__drag_sort__'
5
-
6
- const getOrderableConfig = (
7
- orderable: CrudProps['orderable'],
8
- ): Exclude<CrudProps['orderable'], boolean | undefined> => {
9
- if (orderable && typeof orderable === 'object') {
10
- return orderable
11
- }
12
- return {}
13
- }
14
-
15
- const sortByOrderField = <T extends Record<string, unknown>>(list: T[], orderField: string): T[] => {
16
- const indexed = list.map((item, index) => ({ item, index }))
17
- indexed.sort((a, b) => {
18
- const av = a.item[orderField] as number | undefined
19
- const bv = b.item[orderField] as number | undefined
20
-
21
- const an = typeof av === 'number' && Number.isFinite(av) ? av : Number.POSITIVE_INFINITY
22
- const bn = typeof bv === 'number' && Number.isFinite(bv) ? bv : Number.POSITIVE_INFINITY
23
-
24
- return an - bn
25
- })
26
- return indexed.map(i => i.item)
27
- }
28
-
29
- export const useOrderable = <T extends Record<string, unknown>>(params: {
30
- orderable: CrudProps['orderable']
31
- columns: ProColumnsPro<T>[]
32
- crud: CrudProps['crud']
33
- update: CrudProps['update']
34
- readonly?: boolean
35
- cardMode?: boolean
36
- }) => {
37
- const { orderable, columns, crud, update, readonly, cardMode } = params
38
-
39
- const enabledFeature = !!orderable && !cardMode
40
- const config = useMemo(() => getOrderableConfig(orderable), [orderable])
41
-
42
- const orderField = config.orderField ?? 'sort'
43
- const start = config.start ?? 0
44
-
45
- const canUpdate = enabledFeature && !readonly && update !== false && !!crud.updateState?.mutateAsync
46
-
47
- const [dataSource, setDataSource] = useState<T[]>([])
48
-
49
- useEffect(() => {
50
- if (!enabledFeature) return
51
- const list = (crud.listState.data as T[]) || []
52
- setDataSource(sortByOrderField(list, orderField))
53
- }, [enabledFeature, crud.listState.data, orderField])
54
-
55
- const tableColumns = useMemo((): ProColumnsPro<T>[] => {
56
- if (!enabledFeature) return columns
57
-
58
- return [
59
- {
60
- title: '',
61
- key: dragSortKey,
62
- dataIndex: dragSortKey,
63
- width: 48,
64
- fixed: 'left',
65
- hideInSearch: true,
66
- hideInForm: true,
67
- render: () => null,
68
- } as ProColumnsPro<T>,
69
- ...columns,
70
- ]
71
- }, [columns, enabledFeature])
72
-
73
- const onDragSortEnd = async (
74
- _beforeIndex: number,
75
- _afterIndex: number,
76
- newDataSource: T[],
77
- ) => {
78
- const next = newDataSource.map((row, index) => ({
79
- ...row,
80
- [orderField]: start + index,
81
- })) as T[]
82
-
83
- setDataSource(next)
84
-
85
- if (!canUpdate) return
86
-
87
- await Promise.allSettled(
88
- next.map((row) => {
89
- const id = row.id
90
- if (typeof id !== 'string' || !id) {
91
- return Promise.resolve()
92
- }
93
- return crud.updateState.mutateAsync(id, { [orderField]: row[orderField] })
94
- }),
95
- )
96
-
97
- await crud.listState.refetch()
98
- }
99
-
100
- return {
101
- enabledFeature,
102
- tableColumns,
103
- dragSortKey: enabledFeature ? dragSortKey : undefined,
104
- dataSource: enabledFeature ? dataSource : (crud.listState.data as T[] | undefined),
105
- onDragSortEnd: enabledFeature ? onDragSortEnd : undefined,
106
- }
107
- }
@@ -1,41 +0,0 @@
1
- import type { CrudProps, PaginationState } from '../types'
2
- import { transformOrder, transformPagination, transformWhere } from '../utils'
3
-
4
- interface UseRequest {
5
- columns: CrudProps['columns']
6
- list: CrudProps['list']
7
- }
8
-
9
- export const useRequest = ({ columns, list }: UseRequest) => {
10
- const request = async (params: PaginationState, sort: any, filter: any) => {
11
- const { current, pageSize, ...search } = params
12
-
13
- // 转换分页参数
14
- const pagination = transformPagination({ current, pageSize })
15
-
16
- // 转换排序参数
17
- const orderBy = transformOrder(sort)
18
-
19
- // 转换过滤参数
20
- const where = transformWhere(search, columns)
21
-
22
- const query = {
23
- ...pagination,
24
- ...(orderBy && { orderBy }),
25
- ...(where && { where }),
26
- }
27
- console.log(666, 35, params, sort, search, filter, where, query)
28
-
29
- list?.onChangeQuery?.(query)
30
-
31
- return {
32
- data: [],
33
- total: 0,
34
- success: true,
35
- }
36
- }
37
-
38
- return {
39
- request,
40
- }
41
- }