@wzyjs/uis 0.3.28 → 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.
- package/dist/advanced/Com2Canvas/index.d.ts +8 -0
- package/dist/advanced/Com2Canvas/index.js +39 -0
- package/dist/advanced/Crud/components/CardList/index.d.ts +2 -0
- package/dist/advanced/Crud/components/CardList/index.js +90 -0
- package/dist/advanced/Crud/components/CreateUpdate/index.d.ts +2 -0
- package/dist/advanced/Crud/components/CreateUpdate/index.js +78 -0
- package/dist/advanced/Crud/components/ListTabs/index.d.ts +8 -0
- package/dist/advanced/Crud/components/ListTabs/index.js +7 -0
- package/dist/advanced/Crud/components/Provider/index.d.ts +7 -0
- package/dist/advanced/Crud/components/Provider/index.js +42 -0
- package/dist/advanced/Crud/components/QuickFilters/index.d.ts +8 -0
- package/dist/advanced/Crud/components/QuickFilters/index.js +20 -0
- package/dist/advanced/Crud/components/Remove/index.d.ts +2 -0
- package/dist/advanced/Crud/components/Remove/index.js +18 -0
- package/dist/advanced/Crud/components/index.d.ts +6 -0
- package/dist/advanced/Crud/components/index.js +6 -0
- package/dist/advanced/Crud/hooks/index.d.ts +5 -0
- package/dist/advanced/Crud/hooks/index.js +5 -0
- package/dist/advanced/Crud/hooks/useColumns.d.ts +11 -0
- package/dist/advanced/Crud/hooks/useColumns.js +111 -0
- package/dist/advanced/Crud/hooks/useList.d.ts +12 -0
- package/dist/advanced/Crud/hooks/useList.js +53 -0
- package/dist/advanced/Crud/hooks/useListFilters.d.ts +11 -0
- package/dist/advanced/Crud/hooks/useListFilters.js +159 -0
- package/dist/advanced/Crud/hooks/useOrderable.d.ts +15 -0
- package/dist/advanced/Crud/hooks/useOrderable.js +75 -0
- package/dist/advanced/Crud/hooks/useRequest.d.ts +13 -0
- package/dist/advanced/Crud/hooks/useRequest.js +27 -0
- package/dist/advanced/Crud/index.d.ts +3 -0
- package/dist/advanced/Crud/index.js +46 -0
- package/dist/advanced/Crud/types/index.d.ts +176 -0
- package/dist/advanced/Crud/types/index.js +1 -0
- package/dist/advanced/Crud/utils/index.d.ts +7 -0
- package/dist/advanced/Crud/utils/index.js +80 -0
- package/dist/advanced/Crud/utils/query.d.ts +3 -0
- package/dist/advanced/Crud/utils/query.js +34 -0
- package/dist/advanced/MindMap/context.d.ts +12 -0
- package/dist/advanced/MindMap/context.js +12 -0
- package/dist/advanced/MindMap/hooks/useAlignmentSnap.d.ts +15 -0
- package/dist/advanced/MindMap/hooks/useAlignmentSnap.js +164 -0
- package/dist/advanced/MindMap/hooks/useCopyPaste.d.ts +11 -0
- package/dist/advanced/MindMap/hooks/useCopyPaste.js +209 -0
- package/dist/advanced/MindMap/hooks/useDropToReparent.d.ts +21 -0
- package/dist/advanced/MindMap/hooks/useDropToReparent.js +216 -0
- package/dist/advanced/MindMap/hooks/useExpandCollapse.d.ts +18 -0
- package/dist/advanced/MindMap/hooks/useExpandCollapse.js +108 -0
- package/dist/advanced/MindMap/hooks/useMoveDescendants.d.ts +12 -0
- package/dist/advanced/MindMap/hooks/useMoveDescendants.js +98 -0
- package/dist/advanced/MindMap/hooks/useUndoRedo.d.ts +14 -0
- package/dist/advanced/MindMap/hooks/useUndoRedo.js +181 -0
- package/dist/advanced/MindMap/index.d.ts +29 -0
- package/dist/advanced/MindMap/index.js +52 -0
- package/dist/advanced/index.d.ts +5 -0
- package/dist/advanced/index.js +5 -0
- package/dist/antd/index.d.ts +6 -0
- package/dist/antd/index.js +5 -0
- package/dist/buttons/ButtonGroup/index.d.ts +8 -0
- package/dist/buttons/ButtonGroup/index.js +13 -0
- package/dist/buttons/ConfirmButton/index.d.ts +5 -0
- package/dist/buttons/ConfirmButton/index.js +9 -0
- package/dist/buttons/CopyButton/index.d.ts +6 -0
- package/dist/buttons/CopyButton/index.js +26 -0
- package/dist/buttons/DrawerButton/index.d.ts +6 -0
- package/dist/buttons/DrawerButton/index.js +13 -0
- package/dist/buttons/ProgressButton/index.css +63 -0
- package/dist/buttons/ProgressButton/index.d.ts +17 -0
- package/dist/buttons/ProgressButton/index.js +31 -0
- package/dist/buttons/SectorButton/index.d.ts +20 -0
- package/dist/buttons/SectorButton/index.js +130 -0
- package/dist/buttons/index.d.ts +6 -0
- package/dist/buttons/index.js +6 -0
- package/dist/display/CodeView/index.d.ts +26 -0
- package/dist/display/CodeView/index.js +60 -0
- package/dist/display/EnumTag/index.d.ts +12 -0
- package/dist/display/EnumTag/index.js +10 -0
- package/dist/display/HtmlDataRenderer/index.d.ts +6 -0
- package/dist/display/HtmlDataRenderer/index.js +15 -0
- package/dist/display/HtmlView/index.d.ts +6 -0
- package/dist/display/HtmlView/index.js +6 -0
- package/dist/display/IframePro/index.d.ts +8 -0
- package/dist/display/IframePro/index.js +24 -0
- package/dist/display/JsonSchemaRenderer/index.d.ts +11 -0
- package/dist/display/JsonSchemaRenderer/index.js +62 -0
- package/dist/display/JsonView/index.d.ts +3 -0
- package/dist/display/JsonView/index.js +7 -0
- package/dist/display/MarkdownView/index.d.ts +7 -0
- package/dist/display/MarkdownView/index.js +80 -0
- package/dist/display/MarkdownView/style.d.ts +1 -0
- package/{src/components/Markdown/style.ts → dist/display/MarkdownView/style.js} +1 -1
- package/dist/display/VideoPro/index.d.ts +9 -0
- package/dist/display/VideoPro/index.js +15 -0
- package/dist/display/index.d.ts +9 -0
- package/dist/display/index.js +9 -0
- package/dist/inputs/CheckboxButton/index.css +22 -0
- package/dist/inputs/CheckboxButton/index.d.ts +12 -0
- package/dist/inputs/CheckboxButton/index.js +9 -0
- package/dist/inputs/DateSwitcher/index.css +10 -0
- package/dist/inputs/DateSwitcher/index.d.ts +8 -0
- package/dist/inputs/DateSwitcher/index.js +29 -0
- package/dist/inputs/FetchSelect/index.d.ts +3 -0
- package/dist/inputs/FetchSelect/index.js +121 -0
- package/dist/inputs/FetchSelect/types.d.ts +33 -0
- package/dist/inputs/FetchSelect/types.js +1 -0
- package/dist/inputs/FetchSelect/utils.d.ts +21 -0
- package/dist/inputs/FetchSelect/utils.js +67 -0
- package/dist/inputs/FileUploader/index.d.ts +22 -0
- package/dist/inputs/FileUploader/index.js +79 -0
- package/dist/inputs/IconSelect/index.d.ts +89 -0
- package/dist/inputs/IconSelect/index.js +54 -0
- package/dist/inputs/ImageUploader/index.d.ts +12 -0
- package/dist/inputs/ImageUploader/index.js +192 -0
- package/dist/inputs/RadioButton/index.d.ts +15 -0
- package/dist/inputs/RadioButton/index.js +11 -0
- package/dist/inputs/RangeInput/index.d.ts +8 -0
- package/dist/inputs/RangeInput/index.js +17 -0
- package/dist/inputs/TextInput/index.d.ts +6 -0
- package/dist/inputs/TextInput/index.js +30 -0
- package/dist/inputs/index.d.ts +9 -0
- package/dist/inputs/index.js +9 -0
- package/dist/layout/DragSort/index.d.ts +16 -0
- package/dist/layout/DragSort/index.js +12 -0
- package/dist/layout/FoldCard/index.d.ts +9 -0
- package/dist/layout/FoldCard/index.js +69 -0
- package/dist/layout/PageBase/index.d.ts +6 -0
- package/dist/layout/PageBase/index.js +6 -0
- package/dist/layout/ResizableGridLayout/index.d.ts +11 -0
- package/dist/layout/ResizableGridLayout/index.js +13 -0
- package/dist/layout/SideMenu/index.d.ts +27 -0
- package/dist/layout/SideMenu/index.js +40 -0
- package/dist/layout/TabsPro/index.d.ts +9 -0
- package/dist/layout/TabsPro/index.js +87 -0
- package/dist/layout/index.d.ts +6 -0
- package/dist/layout/index.js +6 -0
- package/dist/web.d.ts +6 -0
- package/dist/web.js +6 -0
- package/package.json +28 -12
- package/src/antd/form/CheckboxButton/index.module.scss +0 -24
- package/src/antd/form/CheckboxButton/index.tsx +0 -31
- package/src/antd/form/FileUploader/index.tsx +0 -163
- package/src/antd/form/RadioButton/index.tsx +0 -32
- package/src/antd/form/Upload/index.tsx +0 -65
- package/src/antd/form/UploadImage/index.tsx +0 -338
- package/src/antd/form/index.ts +0 -6
- package/src/antd/index.ts +0 -46
- package/src/antd/pro/Alert/index.tsx +0 -24
- package/src/antd/pro/Button/components/Confirm.tsx +0 -24
- package/src/antd/pro/Button/components/Copy.tsx +0 -47
- package/src/antd/pro/Button/components/Drawer.tsx +0 -37
- package/src/antd/pro/Button/components/Group.tsx +0 -26
- package/src/antd/pro/Button/index.tsx +0 -11
- package/src/antd/pro/Card/index.tsx +0 -92
- package/src/antd/pro/Collapse/components/Item.tsx +0 -30
- package/src/antd/pro/Collapse/index.tsx +0 -27
- package/src/antd/pro/Image/index.tsx +0 -17
- package/src/antd/pro/Input/components/Range.tsx +0 -46
- package/src/antd/pro/Input/index.tsx +0 -61
- package/src/antd/pro/Popconfirm/index.tsx +0 -16
- package/src/antd/pro/Radio/components/Cancel.tsx +0 -30
- package/src/antd/pro/Radio/index.tsx +0 -7
- package/src/antd/pro/Space/index.tsx +0 -15
- package/src/antd/pro/Tabs/index.tsx +0 -135
- package/src/antd/pro/Typography/components/String.tsx +0 -72
- package/src/antd/pro/Typography/index.tsx +0 -9
- package/src/antd/pro/index.ts +0 -11
- package/src/components/BottomBar/index.tsx +0 -28
- package/src/components/CodeView/index.tsx +0 -85
- package/src/components/Collapse/index.tsx +0 -26
- package/src/components/Com2Canvas/index.tsx +0 -60
- package/src/components/CompileHtml/index.tsx +0 -26
- package/src/components/Crud/components/CardList/index.tsx +0 -174
- package/src/components/Crud/components/CreateUpdate/index.tsx +0 -179
- package/src/components/Crud/components/Provider/index.tsx +0 -83
- package/src/components/Crud/components/Remove/index.tsx +0 -56
- package/src/components/Crud/components/index.ts +0 -4
- package/src/components/Crud/hooks/index.ts +0 -4
- package/src/components/Crud/hooks/useColumns.tsx +0 -169
- package/src/components/Crud/hooks/useList.ts +0 -65
- package/src/components/Crud/hooks/useOrderable.tsx +0 -107
- package/src/components/Crud/hooks/useRequest.ts +0 -41
- package/src/components/Crud/index.tsx +0 -91
- package/src/components/Crud/types/index.ts +0 -188
- package/src/components/Crud/utils/index.ts +0 -87
- package/src/components/DateSwitcher/index.module.scss +0 -10
- package/src/components/DateSwitcher/index.tsx +0 -75
- package/src/components/DownloadLink/index.tsx +0 -36
- package/src/components/DragSort/index.tsx +0 -77
- package/src/components/DynamicSelect/index.tsx +0 -74
- package/src/components/DynamicSelect/utils.ts +0 -45
- package/src/components/EnumTag/index.tsx +0 -24
- package/src/components/FetchSelect/index.tsx +0 -57
- package/src/components/Fold/index.tsx +0 -52
- package/src/components/FormPro/index.tsx +0 -28
- package/src/components/GroupLayout/index.tsx +0 -45
- package/src/components/HtmlPro/index.tsx +0 -18
- package/src/components/IframePro/index.tsx +0 -52
- package/src/components/JsonRenderer/index.tsx +0 -114
- package/src/components/JsonView/index.tsx +0 -21
- package/src/components/Markdown/index.tsx +0 -152
- package/src/components/MindMap/context.tsx +0 -29
- package/src/components/MindMap/hooks/useAlignmentSnap.ts +0 -220
- package/src/components/MindMap/hooks/useCopyPaste.ts +0 -272
- package/src/components/MindMap/hooks/useDropToReparent.ts +0 -288
- package/src/components/MindMap/hooks/useExpandCollapse.ts +0 -146
- package/src/components/MindMap/hooks/useMoveDescendants.ts +0 -136
- package/src/components/MindMap/hooks/useUndoRedo.ts +0 -232
- package/src/components/MindMap/index.tsx +0 -117
- package/src/components/MultiImageDisplay/index.tsx +0 -63
- package/src/components/ProgressButton/index.module.scss +0 -65
- package/src/components/ProgressButton/index.tsx +0 -96
- package/src/components/SectorButton/index.tsx +0 -247
- package/src/components/TextInput/index.tsx +0 -61
- package/src/components/TimelineBar/components/CurrentWeekHighlight/index.tsx +0 -64
- package/src/components/TimelineBar/components/Guides/index.tsx +0 -61
- package/src/components/TimelineBar/components/Ticks/index.tsx +0 -56
- package/src/components/TimelineBar/components/TodayIndicator/index.tsx +0 -54
- package/src/components/TimelineBar/components/index.ts +0 -4
- package/src/components/TimelineBar/const.ts +0 -3
- package/src/components/TimelineBar/hooks/index.ts +0 -5
- package/src/components/TimelineBar/hooks/useHighlightRange.ts +0 -21
- package/src/components/TimelineBar/hooks/useMonthGuides.ts +0 -40
- package/src/components/TimelineBar/hooks/useTickValues.ts +0 -18
- package/src/components/TimelineBar/hooks/useVisibleRange.ts +0 -43
- package/src/components/TimelineBar/hooks/useWeekGuides.ts +0 -39
- package/src/components/TimelineBar/index.tsx +0 -63
- package/src/components/TimelineBar/utils.ts +0 -27
- package/src/components/Video/index.tsx +0 -37
- package/src/components/index.ts +0 -27
- package/src/rn.ts +0 -1
- package/src/rns/index.ts +0 -0
- package/src/web.ts +0 -2
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import React, { type ReactNode } from 'react'
|
|
4
|
-
|
|
5
|
-
import { Card, Col, Row, Avatar } from 'antd'
|
|
6
|
-
import { Remove } from '../Remove'
|
|
7
|
-
import { CreateUpdate } from '../CreateUpdate'
|
|
8
|
-
|
|
9
|
-
import type { ListProps } from '../../types'
|
|
10
|
-
|
|
11
|
-
export const CardList = (props: ListProps) => {
|
|
12
|
-
const { crud, columns, list, update, remove } = props
|
|
13
|
-
|
|
14
|
-
const cardConfig = list.cardConfig!
|
|
15
|
-
const {
|
|
16
|
-
gutter = [16, 16],
|
|
17
|
-
col = { xs: 24, md: 8, lg: 6 },
|
|
18
|
-
height = 'calc(100vh - 210px)',
|
|
19
|
-
render: customRender,
|
|
20
|
-
card,
|
|
21
|
-
} = cardConfig
|
|
22
|
-
|
|
23
|
-
const dataSource = crud.listState.data || []
|
|
24
|
-
|
|
25
|
-
// 默认操作按钮生成函数
|
|
26
|
-
const getDefaultActions = (record: any): ReactNode[] => {
|
|
27
|
-
const actions: ReactNode[] = []
|
|
28
|
-
|
|
29
|
-
if (update !== false) {
|
|
30
|
-
actions.push(
|
|
31
|
-
<CreateUpdate
|
|
32
|
-
key='edit'
|
|
33
|
-
crud={crud}
|
|
34
|
-
columns={columns}
|
|
35
|
-
config={update || {}}
|
|
36
|
-
record={record}
|
|
37
|
-
/>
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (remove !== false) {
|
|
42
|
-
actions.push(
|
|
43
|
-
<Remove
|
|
44
|
-
key='delete'
|
|
45
|
-
crud={crud}
|
|
46
|
-
config={remove || {}}
|
|
47
|
-
record={record}
|
|
48
|
-
/>
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return actions
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// 解析卡片字段值
|
|
56
|
-
const parseFieldValue = (field: any, record: any): any => {
|
|
57
|
-
if (typeof field === 'string') {
|
|
58
|
-
return record[field]
|
|
59
|
-
}
|
|
60
|
-
return field
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
// 渲染单个卡片项
|
|
64
|
-
const renderCardItem = (record: any, index: number) => {
|
|
65
|
-
const defaultActions = getDefaultActions(record)
|
|
66
|
-
|
|
67
|
-
// 如果有完全自定义渲染函数,直接使用
|
|
68
|
-
if (customRender) {
|
|
69
|
-
return customRender(record, index, defaultActions)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 获取卡片配置(支持函数和对象两种形式)
|
|
73
|
-
const cardConfig = typeof card === 'function' ? card(record, index) : card
|
|
74
|
-
const {
|
|
75
|
-
title,
|
|
76
|
-
extra,
|
|
77
|
-
content,
|
|
78
|
-
cover,
|
|
79
|
-
meta,
|
|
80
|
-
actions: configActions,
|
|
81
|
-
props: cardProps = {},
|
|
82
|
-
} = cardConfig
|
|
83
|
-
|
|
84
|
-
// 渲染封面
|
|
85
|
-
const renderCover = () => {
|
|
86
|
-
if (!cover) return undefined
|
|
87
|
-
return parseFieldValue(cover, record)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// 渲染标题
|
|
91
|
-
const renderTitle = () => {
|
|
92
|
-
if (title !== undefined) {
|
|
93
|
-
return parseFieldValue(title, record)
|
|
94
|
-
}
|
|
95
|
-
// 默认标题逻辑
|
|
96
|
-
return record.title || record.name || record.id
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// 渲染右上角
|
|
100
|
-
const renderExtra = () => {
|
|
101
|
-
if (extra !== undefined) {
|
|
102
|
-
return parseFieldValue(extra, record)
|
|
103
|
-
}
|
|
104
|
-
return null
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// 渲染内容
|
|
108
|
-
const renderContent = () => {
|
|
109
|
-
if (content !== undefined) {
|
|
110
|
-
return parseFieldValue(content, record)
|
|
111
|
-
}
|
|
112
|
-
return null
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
// 渲染操作按钮
|
|
116
|
-
const renderActions = () => {
|
|
117
|
-
if (configActions && configActions.length > 0) {
|
|
118
|
-
return configActions.map(action => parseFieldValue(action, record))
|
|
119
|
-
}
|
|
120
|
-
return defaultActions
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// 渲染元数据
|
|
124
|
-
const renderMeta = () => {
|
|
125
|
-
if (!meta) return undefined
|
|
126
|
-
|
|
127
|
-
const metaTitle = meta.title ? parseFieldValue(meta.title, record) : undefined
|
|
128
|
-
const metaDescription = meta.description ? parseFieldValue(meta.description, record) : undefined
|
|
129
|
-
const metaAvatar = meta.avatar ? parseFieldValue(meta.avatar, record) : undefined
|
|
130
|
-
|
|
131
|
-
if (!metaTitle && !metaDescription && !metaAvatar) {
|
|
132
|
-
return undefined
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return (
|
|
136
|
-
<Card.Meta
|
|
137
|
-
title={metaTitle}
|
|
138
|
-
description={metaDescription}
|
|
139
|
-
avatar={metaAvatar && (
|
|
140
|
-
typeof metaAvatar === 'string' ? (
|
|
141
|
-
<Avatar src={metaAvatar} />
|
|
142
|
-
) : (
|
|
143
|
-
metaAvatar
|
|
144
|
-
)
|
|
145
|
-
)}
|
|
146
|
-
/>
|
|
147
|
-
)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return (
|
|
151
|
-
<Card
|
|
152
|
-
size='small'
|
|
153
|
-
title={renderTitle()}
|
|
154
|
-
extra={renderExtra()}
|
|
155
|
-
cover={renderCover()}
|
|
156
|
-
actions={renderActions()}
|
|
157
|
-
{...cardProps}
|
|
158
|
-
>
|
|
159
|
-
{renderMeta()}
|
|
160
|
-
{renderContent()}
|
|
161
|
-
</Card>
|
|
162
|
-
)
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return (
|
|
166
|
-
<Row gutter={gutter} style={{ overflow: 'auto', height }}>
|
|
167
|
-
{dataSource.map((record, index) => (
|
|
168
|
-
<Col key={record.id || index} {...col}>
|
|
169
|
-
{renderCardItem(record, index)}
|
|
170
|
-
</Col>
|
|
171
|
-
))}
|
|
172
|
-
</Row>
|
|
173
|
-
)
|
|
174
|
-
}
|
|
@@ -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,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
|
-
}
|