@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
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
interface Com2CanvasProps {
|
|
3
|
+
children: ReactNode;
|
|
4
|
+
downloadName?: string;
|
|
5
|
+
onChange?: (url: string) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const Com2Canvas: (props: Com2CanvasProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from 'react';
|
|
4
|
+
import html2canvas from 'html2canvas';
|
|
5
|
+
import { useDebounceFn } from '@wzyjs/hooks/web';
|
|
6
|
+
import { getRandomColor } from '@wzyjs/utils/web';
|
|
7
|
+
export const Com2Canvas = (props) => {
|
|
8
|
+
const { children, downloadName, onChange } = props;
|
|
9
|
+
const random = useRef(getRandomColor());
|
|
10
|
+
const htmlId = `h2c_html_${random.current}`;
|
|
11
|
+
const canvasId = `htc_canvas_${random.current}`;
|
|
12
|
+
const { run } = useDebounceFn(() => {
|
|
13
|
+
const el = document.querySelector(`#${canvasId}`);
|
|
14
|
+
if (!el) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
html2canvas(el, {
|
|
18
|
+
allowTaint: true, // 允许污染
|
|
19
|
+
useCORS: true, // 使用跨域(当allowTaint为true时这段代码没什么用)
|
|
20
|
+
scale: 2,
|
|
21
|
+
}).then((canvas) => {
|
|
22
|
+
el.innerHTML = '';
|
|
23
|
+
el.appendChild(canvas);
|
|
24
|
+
onChange?.(canvas.toDataURL('image/png'));
|
|
25
|
+
if (downloadName) {
|
|
26
|
+
el.onclick = () => {
|
|
27
|
+
const a = document.createElement('a');
|
|
28
|
+
a.download = downloadName;
|
|
29
|
+
a.href = canvas.toDataURL('image/png');
|
|
30
|
+
document.body.appendChild(a);
|
|
31
|
+
a.click();
|
|
32
|
+
a.remove();
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}, { wait: 500 });
|
|
37
|
+
useEffect(run, [children]);
|
|
38
|
+
return (_jsxs("span", { style: { position: 'relative' }, children: [_jsx("span", { id: htmlId, children: children }), _jsx("span", { id: canvasId, style: { position: 'absolute', top: 0 } })] }));
|
|
39
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Fragment } from 'react';
|
|
4
|
+
import { Card, Col, Row, Avatar } from 'antd';
|
|
5
|
+
import { Remove } from '../Remove';
|
|
6
|
+
import { CreateUpdate } from '../CreateUpdate';
|
|
7
|
+
export const CardList = (props) => {
|
|
8
|
+
const { crud, columns, list, update, remove } = props;
|
|
9
|
+
const cardConfig = list.cardConfig;
|
|
10
|
+
const { gutter = [16, 16], col = { xs: 24, md: 8, lg: 6 }, height = 'calc(100vh - 210px)', render: customRender, card, } = cardConfig;
|
|
11
|
+
const dataSource = crud.listState.data || [];
|
|
12
|
+
// 默认操作按钮生成函数
|
|
13
|
+
const getDefaultActions = (record) => {
|
|
14
|
+
const actions = [];
|
|
15
|
+
if (update !== false) {
|
|
16
|
+
actions.push(_jsx(Fragment, { children: _jsx(CreateUpdate, { crud: crud, columns: columns, config: update || {}, record: record }) }, 'edit'));
|
|
17
|
+
}
|
|
18
|
+
if (remove !== false) {
|
|
19
|
+
actions.push(_jsx(Fragment, { children: _jsx(Remove, { crud: crud, config: remove || {}, record: record }) }, 'delete'));
|
|
20
|
+
}
|
|
21
|
+
return actions;
|
|
22
|
+
};
|
|
23
|
+
// 解析卡片字段值
|
|
24
|
+
const parseFieldValue = (field, record) => {
|
|
25
|
+
if (typeof field === 'string') {
|
|
26
|
+
return record[field];
|
|
27
|
+
}
|
|
28
|
+
return field;
|
|
29
|
+
};
|
|
30
|
+
// 渲染单个卡片项
|
|
31
|
+
const renderCardItem = (record, index) => {
|
|
32
|
+
const defaultActions = getDefaultActions(record);
|
|
33
|
+
// 如果有完全自定义渲染函数,直接使用
|
|
34
|
+
if (customRender) {
|
|
35
|
+
return customRender(record, index, defaultActions);
|
|
36
|
+
}
|
|
37
|
+
// 获取卡片配置(支持函数和对象两种形式)
|
|
38
|
+
const cardConfig = typeof card === 'function' ? card(record, index) : card;
|
|
39
|
+
const { title, extra, content, cover, meta, actions: configActions, props: cardProps = {}, } = cardConfig;
|
|
40
|
+
// 渲染封面
|
|
41
|
+
const renderCover = () => {
|
|
42
|
+
if (!cover)
|
|
43
|
+
return undefined;
|
|
44
|
+
return parseFieldValue(cover, record);
|
|
45
|
+
};
|
|
46
|
+
// 渲染标题
|
|
47
|
+
const renderTitle = () => {
|
|
48
|
+
if (title !== undefined) {
|
|
49
|
+
return parseFieldValue(title, record);
|
|
50
|
+
}
|
|
51
|
+
// 默认标题逻辑
|
|
52
|
+
return record.title || record.name || record.id;
|
|
53
|
+
};
|
|
54
|
+
// 渲染右上角
|
|
55
|
+
const renderExtra = () => {
|
|
56
|
+
if (extra !== undefined) {
|
|
57
|
+
return parseFieldValue(extra, record);
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
};
|
|
61
|
+
// 渲染内容
|
|
62
|
+
const renderContent = () => {
|
|
63
|
+
if (content !== undefined) {
|
|
64
|
+
return parseFieldValue(content, record);
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
};
|
|
68
|
+
// 渲染操作按钮
|
|
69
|
+
const renderActions = () => {
|
|
70
|
+
if (configActions && configActions.length > 0) {
|
|
71
|
+
return configActions.map(action => parseFieldValue(action, record));
|
|
72
|
+
}
|
|
73
|
+
return defaultActions;
|
|
74
|
+
};
|
|
75
|
+
// 渲染元数据
|
|
76
|
+
const renderMeta = () => {
|
|
77
|
+
if (!meta)
|
|
78
|
+
return undefined;
|
|
79
|
+
const metaTitle = meta.title ? parseFieldValue(meta.title, record) : undefined;
|
|
80
|
+
const metaDescription = meta.description ? parseFieldValue(meta.description, record) : undefined;
|
|
81
|
+
const metaAvatar = meta.avatar ? parseFieldValue(meta.avatar, record) : undefined;
|
|
82
|
+
if (!metaTitle && !metaDescription && !metaAvatar) {
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
return (_jsx(Card.Meta, { title: metaTitle, description: metaDescription, avatar: metaAvatar && (typeof metaAvatar === 'string' ? (_jsx(Avatar, { src: metaAvatar })) : (metaAvatar)) }));
|
|
86
|
+
};
|
|
87
|
+
return (_jsxs(Card, { size: 'small', title: renderTitle(), extra: renderExtra(), cover: renderCover(), actions: renderActions(), ...cardProps, children: [renderMeta(), renderContent()] }));
|
|
88
|
+
};
|
|
89
|
+
return (_jsx(Row, { gutter: gutter, style: { overflow: 'auto', height }, children: dataSource.map((record, index) => (_jsx(Col, { ...col, children: renderCardItem(record, index) }, record.id || index))) }));
|
|
90
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo, useState } from 'react';
|
|
4
|
+
import { Button } from 'antd';
|
|
5
|
+
import { PlusOutlined, EditOutlined } from '@ant-design/icons';
|
|
6
|
+
import { BetaSchemaForm } from '@ant-design/pro-components';
|
|
7
|
+
const isActionColumn = (column) => (column.valueType === 'option'
|
|
8
|
+
|| column.key === 'option'
|
|
9
|
+
|| column.key === 'action'
|
|
10
|
+
|| column.title === '操作');
|
|
11
|
+
const getFormColumns = (columns) => {
|
|
12
|
+
return columns
|
|
13
|
+
.filter(column => !column.hideInForm && !isActionColumn(column) && column.key !== '__drag_sort__')
|
|
14
|
+
.map((column) => {
|
|
15
|
+
const { fixed, sorter, sortOrder, defaultSortOrder, filters, onFilter, onCell, onHeaderCell, ellipsis, copyable, render, renderText, width, ...formColumn } = column;
|
|
16
|
+
return formColumn;
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
export const CreateUpdate = (props) => {
|
|
20
|
+
const { crud, columns, config, record } = props;
|
|
21
|
+
const isEdit = !!record;
|
|
22
|
+
const [open, setOpen] = useState(false);
|
|
23
|
+
const [formRendered, setFormRendered] = useState(false);
|
|
24
|
+
const { mode = 'drawer', title = isEdit ? '编辑' : '新建', buttonProps = {}, formProps = {}, transformData, coverData, width, } = config;
|
|
25
|
+
const { drawerProps, modalProps, initialValues, onOpenChange, onVisibleChange, open: _open, visible: _visible, ...formSafeProps } = formProps;
|
|
26
|
+
const layoutType = mode === 'modal' ? 'ModalForm' : 'DrawerForm';
|
|
27
|
+
const formColumns = useMemo(() => getFormColumns(columns), [columns]);
|
|
28
|
+
const handleOpenChange = (nextOpen) => {
|
|
29
|
+
setOpen(nextOpen);
|
|
30
|
+
if (nextOpen) {
|
|
31
|
+
setFormRendered(true);
|
|
32
|
+
}
|
|
33
|
+
onOpenChange?.(nextOpen);
|
|
34
|
+
onVisibleChange?.(nextOpen);
|
|
35
|
+
};
|
|
36
|
+
const openForm = (event) => {
|
|
37
|
+
buttonProps.onClick?.(event);
|
|
38
|
+
if (event.defaultPrevented) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
setFormRendered(true);
|
|
42
|
+
setOpen(true);
|
|
43
|
+
};
|
|
44
|
+
const onFinish = async (values) => {
|
|
45
|
+
const finalValues = transformData ? await transformData(values, record) : values;
|
|
46
|
+
if (isEdit) {
|
|
47
|
+
await crud.updateState.mutateAsync(record.id, finalValues);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
await crud.createState.mutateAsync(finalValues);
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
};
|
|
54
|
+
const formKey = (() => {
|
|
55
|
+
if (isEdit && record) {
|
|
56
|
+
return record.id;
|
|
57
|
+
}
|
|
58
|
+
if (!initialValues) {
|
|
59
|
+
return 'create';
|
|
60
|
+
}
|
|
61
|
+
if (typeof initialValues !== 'object') {
|
|
62
|
+
return `create-${JSON.stringify(initialValues)}`;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
return `create-${JSON.stringify(initialValues)}`;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return 'create';
|
|
69
|
+
}
|
|
70
|
+
})();
|
|
71
|
+
const finalInitialValues = {
|
|
72
|
+
...(record ?? {}),
|
|
73
|
+
...(initialValues ?? {}),
|
|
74
|
+
...(coverData ? coverData(record) : {}),
|
|
75
|
+
};
|
|
76
|
+
const trigger = isEdit ? (_jsx(Button, { type: 'link', size: 'small', icon: _jsx(EditOutlined, {}), ...buttonProps, onClick: openForm })) : (_jsx(Button, { type: 'primary', icon: _jsx(PlusOutlined, {}), ...buttonProps, onClick: openForm, children: "\u65B0\u5EFA" }));
|
|
77
|
+
return (_jsxs(_Fragment, { children: [trigger, formRendered ? (_jsx(BetaSchemaForm, { layoutType: layoutType, title: title, width: width, columns: formColumns, onFinish: onFinish, layout: 'horizontal', labelCol: { span: 4 }, initialValues: finalInitialValues, open: open, onOpenChange: handleOpenChange, ...(drawerProps ? { drawerProps } : {}), ...(modalProps ? { modalProps } : {}), ...formSafeProps }, formKey)) : null] }));
|
|
78
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CrudListTabs } from '../../types';
|
|
2
|
+
interface ListTabsProps {
|
|
3
|
+
tabs: CrudListTabs;
|
|
4
|
+
activeKey?: string;
|
|
5
|
+
onChange: (key: string) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const ListTabs: (props: ListTabsProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { TabsPro } from '../../../../layout/TabsPro';
|
|
4
|
+
export const ListTabs = (props) => {
|
|
5
|
+
const { tabs, activeKey, onChange } = props;
|
|
6
|
+
return (_jsx(TabsPro, { type: tabs.type ?? 'card', activeKey: activeKey, onChange: onChange, items: tabs.items }));
|
|
7
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useContext, useMemo } from 'react';
|
|
4
|
+
import { Tag, Switch } from 'antd';
|
|
5
|
+
import { ProProvider, ProFormSelect } from '@ant-design/pro-components';
|
|
6
|
+
export const Provider = (props) => {
|
|
7
|
+
const { children, crud } = props;
|
|
8
|
+
const defaultContext = useContext(ProProvider);
|
|
9
|
+
const onSwitchChange = (id, enabled) => {
|
|
10
|
+
if (crud?.updateState) {
|
|
11
|
+
crud.updateState.mutate(id, { enabled });
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
const valueTypeMap = useMemo(() => ({
|
|
15
|
+
...defaultContext.valueTypeMap,
|
|
16
|
+
tags: {
|
|
17
|
+
renderFormItem: (_, props) => {
|
|
18
|
+
const { options, ...restFieldProps } = props.fieldProps || {};
|
|
19
|
+
let processedOptions = options;
|
|
20
|
+
if (Array.isArray(options) && options.length > 0 && typeof options[0] === 'string') {
|
|
21
|
+
processedOptions = options.map((item) => ({
|
|
22
|
+
label: item,
|
|
23
|
+
value: item,
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
return (_jsx(ProFormSelect, { placeholder: '\u8BF7\u8F93\u5165\u6807\u7B7E', mode: 'tags', options: processedOptions, ...restFieldProps }));
|
|
27
|
+
},
|
|
28
|
+
render: (tags) => {
|
|
29
|
+
return (_jsx(_Fragment, { children: tags?.map((tag) => (_jsx(Tag, { children: tag }, tag))) }));
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
enabled: {
|
|
33
|
+
render: (enabled, props) => {
|
|
34
|
+
return (_jsx(Switch, { loading: crud?.updateState.isLoading, checked: enabled, onChange: enabled => onSwitchChange(props.record?.id, enabled), disabled: !crud?.updateState }));
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
}), [crud?.updateState, defaultContext.valueTypeMap]);
|
|
38
|
+
return (_jsx(ProProvider.Provider, { value: {
|
|
39
|
+
...defaultContext,
|
|
40
|
+
valueTypeMap,
|
|
41
|
+
}, children: children }));
|
|
42
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CrudQuickFilter } from '../../types';
|
|
2
|
+
interface QuickFiltersProps {
|
|
3
|
+
filters: CrudQuickFilter[];
|
|
4
|
+
values: Record<string, any>;
|
|
5
|
+
onChange: (key: string, value: any) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare const QuickFilters: (props: QuickFiltersProps) => import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { Space } from 'antd';
|
|
4
|
+
import { RadioButton } from '../../../../inputs/RadioButton';
|
|
5
|
+
const normalizeOptions = (options = []) => {
|
|
6
|
+
if (Array.isArray(options) && typeof options[0] === 'string') {
|
|
7
|
+
return options.map(option => ({
|
|
8
|
+
label: option,
|
|
9
|
+
value: option,
|
|
10
|
+
}));
|
|
11
|
+
}
|
|
12
|
+
return options;
|
|
13
|
+
};
|
|
14
|
+
export const QuickFilters = (props) => {
|
|
15
|
+
const { filters, values, onChange } = props;
|
|
16
|
+
if (filters.length === 0) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
return (_jsx(Space, { wrap: true, children: filters.map(filter => (_jsxs(Space, { children: [filter.label ? _jsx("span", { className: 'text-sm text-gray-500 whitespace-nowrap', children: filter.label }) : null, _jsx(RadioButton, { value: values[filter.key], options: normalizeOptions(filter.options), buttonStyle: filter.buttonStyle, allowClear: true, onChange: value => onChange(filter.key, value) })] }, filter.key))) }));
|
|
20
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Popconfirm, Button } from 'antd';
|
|
3
|
+
import { DeleteOutlined } from '@ant-design/icons';
|
|
4
|
+
export const Remove = (props) => {
|
|
5
|
+
const { crud, config, record } = props;
|
|
6
|
+
const { confirm = true, buttonProps = {}, title = '确定要删除吗?', content, } = config;
|
|
7
|
+
const onConfirm = () => {
|
|
8
|
+
crud.removeState.mutate(record.id);
|
|
9
|
+
};
|
|
10
|
+
// 如果不需要确认,直接执行删除
|
|
11
|
+
if (!confirm) {
|
|
12
|
+
return (_jsx(Button, { type: 'link', danger: true, size: 'small', icon: _jsx(DeleteOutlined, {}), loading: crud.removeState.isLoading, onClick: onConfirm, ...buttonProps }));
|
|
13
|
+
}
|
|
14
|
+
// 需要确认的删除按钮
|
|
15
|
+
return (_jsx(Popconfirm, { title: title, description: content, onConfirm: onConfirm, okText: '\u786E\u5B9A', cancelText: '\u53D6\u6D88', okButtonProps: {
|
|
16
|
+
loading: crud.removeState.isLoading,
|
|
17
|
+
}, children: _jsx(Button, { type: 'link', danger: true, size: 'small', icon: _jsx(DeleteOutlined, {}), ...buttonProps }) }));
|
|
18
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ProColumnsPro, CrudProps } from '../types';
|
|
2
|
+
interface UseColumnsParams {
|
|
3
|
+
columns: CrudProps['columns'];
|
|
4
|
+
crud: CrudProps['crud'];
|
|
5
|
+
update: CrudProps['update'];
|
|
6
|
+
remove: CrudProps['remove'];
|
|
7
|
+
}
|
|
8
|
+
export declare const useColumns: ({ columns, crud, update, remove }: UseColumnsParams) => {
|
|
9
|
+
finalColumns: ProColumnsPro[];
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React, { Fragment, useMemo } from 'react';
|
|
3
|
+
import { Space } from 'antd';
|
|
4
|
+
import { CreateUpdate, Remove } from '../components';
|
|
5
|
+
const normalizeCellDom = (dom) => {
|
|
6
|
+
if (!dom || typeof dom !== 'object') {
|
|
7
|
+
return dom;
|
|
8
|
+
}
|
|
9
|
+
if ('children' in dom && 'props' in dom) {
|
|
10
|
+
return dom.children;
|
|
11
|
+
}
|
|
12
|
+
return dom;
|
|
13
|
+
};
|
|
14
|
+
const normalizeRenderResult = (result) => {
|
|
15
|
+
if (!result || typeof result !== 'object') {
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
if ('children' in result && 'props' in result) {
|
|
19
|
+
return result.children;
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
};
|
|
23
|
+
export const useColumns = ({ columns, crud, update, remove }) => {
|
|
24
|
+
// 检查是否需要显示操作列
|
|
25
|
+
const hasActions = update !== false || remove !== false;
|
|
26
|
+
// 智能合并操作列
|
|
27
|
+
const finalColumns = useMemo(() => {
|
|
28
|
+
// const proColumns = transformColumns(columns)
|
|
29
|
+
const proColumns = columns.map((col) => {
|
|
30
|
+
const isActionColumn = col.valueType === 'option'
|
|
31
|
+
|| col.key === 'option'
|
|
32
|
+
|| col.key === 'action'
|
|
33
|
+
|| col.title === '操作';
|
|
34
|
+
if (col.render) {
|
|
35
|
+
const originalRender = col.render;
|
|
36
|
+
return {
|
|
37
|
+
...col,
|
|
38
|
+
render: (dom, record, index, action, schema) => {
|
|
39
|
+
return normalizeRenderResult(originalRender(dom, record, index, action, schema));
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (isActionColumn) {
|
|
44
|
+
return col;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
...col,
|
|
48
|
+
// DragSortTable 需要包一层,不然有的字段不显示
|
|
49
|
+
render: (dom) => normalizeCellDom(dom),
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
// 生成默认的操作按钮
|
|
53
|
+
const generateDefaultActions = (record) => {
|
|
54
|
+
const actions = [];
|
|
55
|
+
if (update !== false) {
|
|
56
|
+
actions.push(_jsx(Fragment, { children: _jsx(CreateUpdate, { crud: crud, columns: columns, config: update || {}, record: record }) }, 'update'));
|
|
57
|
+
}
|
|
58
|
+
if (remove !== false) {
|
|
59
|
+
actions.push(_jsx(Fragment, { children: _jsx(Remove, { crud: crud, config: remove || {}, record: record }) }, 'remove'));
|
|
60
|
+
}
|
|
61
|
+
return actions;
|
|
62
|
+
};
|
|
63
|
+
// 查找是否已存在操作列
|
|
64
|
+
const existingActionColumnIndex = proColumns.findIndex(col => col.key === 'option' || col.key === 'action' || col.title === '操作');
|
|
65
|
+
if (existingActionColumnIndex !== -1) {
|
|
66
|
+
// 如果已存在操作列,合并操作
|
|
67
|
+
const existingColumn = proColumns[existingActionColumnIndex];
|
|
68
|
+
if (!existingColumn)
|
|
69
|
+
return proColumns;
|
|
70
|
+
const originalRender = existingColumn.render;
|
|
71
|
+
const mergedColumns = [...proColumns];
|
|
72
|
+
mergedColumns[existingActionColumnIndex] = {
|
|
73
|
+
...existingColumn,
|
|
74
|
+
render: (text, record, index, action, schema) => {
|
|
75
|
+
const defaultActions = hasActions ? generateDefaultActions(record) : [];
|
|
76
|
+
// 如果用户定义了自定义渲染,调用它
|
|
77
|
+
if (originalRender) {
|
|
78
|
+
const customActions = normalizeRenderResult(originalRender(text, record, index, action, schema));
|
|
79
|
+
// 如果自定义渲染返回 ReactElement 或数组,合并操作
|
|
80
|
+
if (React.isValidElement(customActions) || Array.isArray(customActions)) {
|
|
81
|
+
return (_jsxs(Space, { children: [customActions, defaultActions] }));
|
|
82
|
+
}
|
|
83
|
+
// 如果自定义渲染返回其他内容,直接使用
|
|
84
|
+
return customActions;
|
|
85
|
+
}
|
|
86
|
+
// 没有自定义渲染时,只显示默认操作
|
|
87
|
+
return _jsx(Space, { children: defaultActions });
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
return mergedColumns;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
// 如果不存在操作列且需要操作,添加新的操作列
|
|
94
|
+
return [
|
|
95
|
+
...proColumns,
|
|
96
|
+
...(hasActions ? [{
|
|
97
|
+
title: '操作',
|
|
98
|
+
dataIndex: 'action',
|
|
99
|
+
key: 'action',
|
|
100
|
+
fixed: 'right',
|
|
101
|
+
width: 120,
|
|
102
|
+
search: false,
|
|
103
|
+
render: (_, record) => (_jsx(Space, { children: generateDefaultActions(record) })),
|
|
104
|
+
}] : []),
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
}, [columns, hasActions, update, remove, crud]);
|
|
108
|
+
return {
|
|
109
|
+
finalColumns,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import type { CrudProps } from '../types';
|
|
3
|
+
interface UseTabsStateParams {
|
|
4
|
+
list: CrudProps['list'];
|
|
5
|
+
}
|
|
6
|
+
interface UseListResult {
|
|
7
|
+
activeTabKey: string | undefined;
|
|
8
|
+
setTabActiveKey: Dispatch<SetStateAction<string | undefined>>;
|
|
9
|
+
finalList: any;
|
|
10
|
+
}
|
|
11
|
+
export declare const useList: ({ list }: UseTabsStateParams) => UseListResult;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useState, useEffect, useMemo } from 'react';
|
|
2
|
+
export const useList = ({ list }) => {
|
|
3
|
+
// 初始化 activeTabKey 状态
|
|
4
|
+
const [activeTabKey, setTabActiveKey] = useState(() => {
|
|
5
|
+
const tabs = list?.toolbar?.tabs;
|
|
6
|
+
if (!tabs) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
return tabs.activeKey ?? tabs.items?.[0]?.key;
|
|
10
|
+
});
|
|
11
|
+
// 同步外部传入的 activeKey
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
const tabs = list?.toolbar?.tabs;
|
|
14
|
+
if (tabs && tabs.activeKey !== undefined && tabs.activeKey !== activeTabKey) {
|
|
15
|
+
setTabActiveKey(tabs.activeKey);
|
|
16
|
+
}
|
|
17
|
+
}, [list?.toolbar?.tabs]);
|
|
18
|
+
// 当 Tab 变化时,将最新的类型通过 onChangeQuery 回传给父组件
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (activeTabKey !== undefined) {
|
|
21
|
+
list?.onChangeQuery?.({
|
|
22
|
+
where: { type: activeTabKey },
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}, [activeTabKey]);
|
|
26
|
+
// 构造最终传递给 ProTable 的 list 配置
|
|
27
|
+
const finalList = useMemo(() => {
|
|
28
|
+
if (!list?.toolbar?.tabs)
|
|
29
|
+
return list ?? {};
|
|
30
|
+
const originalTabs = list.toolbar.tabs;
|
|
31
|
+
const enhancedTabs = {
|
|
32
|
+
...originalTabs,
|
|
33
|
+
activeKey: activeTabKey,
|
|
34
|
+
onChange: (key) => {
|
|
35
|
+
setTabActiveKey(key);
|
|
36
|
+
originalTabs.onChange?.(key);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
...list,
|
|
41
|
+
toolbar: {
|
|
42
|
+
...list.toolbar,
|
|
43
|
+
multipleLine: list.toolbar.multipleLine ?? !!list.toolbar.tabs.items?.length,
|
|
44
|
+
tabs: enhancedTabs,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}, [activeTabKey, list]);
|
|
48
|
+
return {
|
|
49
|
+
activeTabKey,
|
|
50
|
+
setTabActiveKey,
|
|
51
|
+
finalList,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CrudProps } from '../types';
|
|
2
|
+
interface UseListFiltersParams {
|
|
3
|
+
list: CrudProps['list'];
|
|
4
|
+
}
|
|
5
|
+
interface UseListFiltersResult {
|
|
6
|
+
activeTabKey: string | undefined;
|
|
7
|
+
handleTabChange: (key: string) => void;
|
|
8
|
+
preparedList: any;
|
|
9
|
+
}
|
|
10
|
+
export declare const useListFilters: ({ list }: UseListFiltersParams) => UseListFiltersResult;
|
|
11
|
+
export {};
|