@wzyjs/uis 0.3.29 → 0.3.31
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.css +363 -0
- package/dist/web.d.ts +7 -0
- package/dist/web.js +7 -0
- package/package.json +34 -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/FoldCard/index.tsx +0 -131
- package/src/antd/pro/RangeInput/index.tsx +0 -46
- 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/buttons/ButtonGroup.tsx +0 -26
- package/src/antd/pro/buttons/ConfirmButton.tsx +0 -24
- package/src/antd/pro/buttons/CopyButton.tsx +0 -47
- package/src/antd/pro/buttons/DrawerButton.tsx +0 -37
- package/src/antd/pro/buttons/index.tsx +0 -4
- package/src/antd/pro/index.ts +0 -5
- 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 -76
- package/src/components/DynamicSelect/types.ts +0 -8
- package/src/components/DynamicSelect/utils.ts +0 -47
- package/src/components/EnumTag/index.tsx +0 -24
- package/src/components/FetchSelect/index.tsx +0 -57
- 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 -26
- package/src/rn.ts +0 -1
- package/src/rns/index.ts +0 -0
- package/src/web.ts +0 -2
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import React, { useEffect, useRef, ReactNode } from 'react'
|
|
4
|
-
|
|
5
|
-
import html2canvas from 'html2canvas'
|
|
6
|
-
|
|
7
|
-
import { useDebounceFn } from '@wzyjs/hooks/web'
|
|
8
|
-
import { getRandomColor } from '@wzyjs/utils/web'
|
|
9
|
-
|
|
10
|
-
interface Com2CanvasProps {
|
|
11
|
-
children: ReactNode;
|
|
12
|
-
downloadName?: string;
|
|
13
|
-
onChange?: (url: string) => void;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const Com2Canvas = (props: Com2CanvasProps) => {
|
|
17
|
-
const { children, downloadName, onChange } = props
|
|
18
|
-
|
|
19
|
-
const random = useRef(getRandomColor())
|
|
20
|
-
const htmlId = `h2c_html_${random.current}`
|
|
21
|
-
const canvasId = `htc_canvas_${random.current}`
|
|
22
|
-
|
|
23
|
-
const { run } = useDebounceFn(() => {
|
|
24
|
-
const el = document.querySelector(`#${canvasId}`) as HTMLElement
|
|
25
|
-
if (!el) {
|
|
26
|
-
return
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
html2canvas(el, {
|
|
30
|
-
allowTaint: true, // 允许污染
|
|
31
|
-
useCORS: true, // 使用跨域(当allowTaint为true时这段代码没什么用)
|
|
32
|
-
scale: 2,
|
|
33
|
-
}).then((canvas: any) => {
|
|
34
|
-
el.innerHTML = ''
|
|
35
|
-
el.appendChild(canvas)
|
|
36
|
-
|
|
37
|
-
onChange?.(canvas.toDataURL('image/png'))
|
|
38
|
-
|
|
39
|
-
if (downloadName) {
|
|
40
|
-
el.onclick = () => {
|
|
41
|
-
const a = document.createElement('a')
|
|
42
|
-
a.download = downloadName
|
|
43
|
-
a.href = canvas.toDataURL('image/png')
|
|
44
|
-
document.body.appendChild(a)
|
|
45
|
-
a.click()
|
|
46
|
-
a.remove()
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
})
|
|
50
|
-
}, { wait: 500 })
|
|
51
|
-
|
|
52
|
-
useEffect(run, [children])
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<span style={{ position: 'relative' }}>
|
|
56
|
-
<span id={htmlId}>{children}</span>
|
|
57
|
-
<span id={canvasId} style={{ position: 'absolute', top: 0 }} />
|
|
58
|
-
</span>
|
|
59
|
-
)
|
|
60
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
|
|
3
|
-
import React, { useMemo } from 'react'
|
|
4
|
-
import Handlebars from 'handlebars'
|
|
5
|
-
|
|
6
|
-
interface Props {
|
|
7
|
-
template?: string
|
|
8
|
-
data: any
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default (props: Props) => {
|
|
12
|
-
const { template, data } = props
|
|
13
|
-
|
|
14
|
-
const html = useMemo(() => {
|
|
15
|
-
const html = Handlebars.compile(template || '')(data)
|
|
16
|
-
return html.replaceAll('\n', '').replaceAll('\t', '')
|
|
17
|
-
}, [template, data])
|
|
18
|
-
|
|
19
|
-
if (!html) {
|
|
20
|
-
return null
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return (
|
|
24
|
-
<div dangerouslySetInnerHTML={{ __html: html }} />
|
|
25
|
-
)
|
|
26
|
-
}
|
|
@@ -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
|
-
}
|