@spacecorexdev/core 0.0.4 → 0.0.5
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/package.json +2 -36
- package/src/api/_base.ts +243 -0
- package/src/api/index.ts +17 -0
- package/src/api/project.ts +1345 -0
- package/src/api/user.ts +1174 -0
- package/src/contract.ts +50 -0
- package/src/hooks/index.ts +2 -0
- package/{dist/hooks/index.js → src/hooks/useLongPress.ts} +53 -49
- package/src/hooks/useOnlineStatus.ts +22 -0
- package/src/index.ts +14 -0
- package/src/types/id.ts +2 -0
- package/src/types/index.ts +5 -0
- package/src/types/project/base.ts +63 -0
- package/src/types/project/contract.ts +79 -0
- package/src/types/project/contractStatus.tsx +15 -0
- package/src/types/project/index.ts +5 -0
- package/src/types/project/member.ts +46 -0
- package/src/types/project/progress.ts +43 -0
- package/src/types/projectRole.ts +17 -0
- package/src/types/theme.ts +1 -0
- package/src/types/user/index.ts +1 -0
- package/src/types/user/role.ts +7 -0
- package/src/ui/CommentTimeline/index.tsx +330 -0
- package/src/ui/FileManager/FileContextMenu.tsx +628 -0
- package/src/ui/FileManager/FileGridView.tsx +529 -0
- package/src/ui/FileManager/FileTableView.tsx +405 -0
- package/src/ui/FileManager/FileToolbar.tsx +119 -0
- package/src/ui/FileManager/FileVersionHistoryModal.tsx +175 -0
- package/src/ui/FileManager/MoveCopyToProjectModal.tsx +119 -0
- package/src/ui/FileManager/ShareToWechatModal.tsx +419 -0
- package/src/ui/FileManager/hooks/useFileManagerActions.ts +2532 -0
- package/src/ui/FileManager/hooks/useFileManagerState.ts +419 -0
- package/src/ui/FileManager/index.tsx +580 -0
- package/src/ui/FileManager/projectFileManagerApi.ts +57 -0
- package/src/ui/FileManager/types.ts +184 -0
- package/src/ui/FileManager/utils/fileDeltaWorker.ts +193 -0
- package/src/ui/FileManager/utils/fileTree.ts +178 -0
- package/src/ui/FileManager/utils/fileUpload.ts +714 -0
- package/src/ui/FileManager/utils/fileUtils.ts +65 -0
- package/src/ui/InvoiceRecordsList/index.tsx +813 -0
- package/src/ui/MyFileSelectorModal.tsx +261 -0
- package/src/ui/ProjectSelector/index.tsx +472 -0
- package/src/ui/ProjectSelector/projectCache.ts +40 -0
- package/src/ui/RoleSelector/index.tsx +473 -0
- package/src/ui/RoleSelector/roleCache.ts +40 -0
- package/src/ui/UIAlert.tsx +399 -0
- package/src/ui/UIAlertExample.tsx +129 -0
- package/src/ui/UIConfirm.tsx +335 -0
- package/src/ui/UIConfirmExample.tsx +165 -0
- package/src/ui/UIDatePicker.tsx +146 -0
- package/src/ui/UIDateRangePicker.tsx +38 -0
- package/src/ui/UIFilePreview/ExcelEditor/index.tsx +617 -0
- package/src/ui/UIFilePreview/ExcelEditor/types.ts +24 -0
- package/src/ui/UIFilePreview/ExportDropdown.css +85 -0
- package/src/ui/UIFilePreview/ExportDropdown.tsx +109 -0
- package/src/ui/UIFilePreview/IndexedDBUtils.ts +564 -0
- package/src/ui/UIFilePreview/MarkdownEditor/exportMarkdownPdf.ts +576 -0
- package/src/ui/UIFilePreview/MarkdownEditor/index.tsx +677 -0
- package/src/ui/UIFilePreview/MarkdownEditor/markdownEditor.css +1005 -0
- package/src/ui/UIFilePreview/MarkdownEditor/types.ts +15 -0
- package/src/ui/UIFilePreview/PPTXEditor/index.tsx +602 -0
- package/src/ui/UIFilePreview/RichDocEditor/exportRDocMarkdown.ts +77 -0
- package/src/ui/UIFilePreview/RichDocEditor/exportRDocPdf.ts +374 -0
- package/src/ui/UIFilePreview/RichDocEditor/index.tsx +730 -0
- package/src/ui/UIFilePreview/RichDocEditor/richdoc-editor.css +59 -0
- package/src/ui/UIFilePreview/UIFilePreview.tsx +611 -0
- package/src/ui/UIFilePreview/WordEditor/index.tsx +3933 -0
- package/src/ui/UIFilePreview/WordEditor/style.ts +1213 -0
- package/src/ui/UIFilePreview/WordEditor/word-editor.css +999 -0
- package/src/ui/UIFilePreview/filePreview.css +193 -0
- package/src/ui/UIFilePreview/filetypes/archive.tsx +66 -0
- package/src/ui/UIFilePreview/filetypes/cad.tsx +287 -0
- package/src/ui/UIFilePreview/filetypes/excel.tsx +355 -0
- package/src/ui/UIFilePreview/filetypes/image.tsx +20 -0
- package/src/ui/UIFilePreview/filetypes/imageLoader.ts +63 -0
- package/src/ui/UIFilePreview/filetypes/pdf.tsx +156 -0
- package/src/ui/UIFilePreview/filetypes/ppt.tsx +535 -0
- package/src/ui/UIFilePreview/filetypes/pptExportPdf.ts +523 -0
- package/src/ui/UIFilePreview/filetypes/video.tsx +482 -0
- package/src/ui/UIFilePreview/filetypes/word.tsx +245 -0
- package/src/ui/UIFilePreview/filetypes/wordExportMarkdown.ts +86 -0
- package/src/ui/UIFilePreview/filetypes/wordExportPdf.tsx +427 -0
- package/src/ui/UIFilePreview/index.ts +35 -0
- package/src/ui/UIFilePreview/pdfPagination.ts +143 -0
- package/src/ui/UIFilePreview/previewUtils.tsx +531 -0
- package/src/ui/UIFileUpload.tsx +382 -0
- package/src/ui/UIImageUpload.tsx +195 -0
- package/src/ui/UILoading.tsx +255 -0
- package/src/ui/UILoadingExample.tsx +139 -0
- package/src/ui/UISelect.tsx +105 -0
- package/src/ui/UIToast.tsx +381 -0
- package/src/ui/UIToastExample.tsx +69 -0
- package/src/ui/UIToastSingle.tsx +279 -0
- package/src/ui/UIViewToggle.tsx +64 -0
- package/src/ui/UserSelector/index.tsx +583 -0
- package/src/ui/index.ts +84 -0
- package/src/ui/upload/image.ts +135 -0
- package/src/ui/upload/index.ts +73 -0
- package/src/ui/upload/submitFile.ts +106 -0
- package/src/ui/upload/submitForm.ts +124 -0
- package/src/ui/upload/upload.err.ts +15 -0
- package/src/ui/upload/upload.ts +250 -0
- package/src/utils/CacheDepartmentInfo.ts +372 -0
- package/src/utils/CacheFileContent.ts +315 -0
- package/src/utils/CachePermissionInfo.ts +235 -0
- package/src/utils/CacheRoleInfo.ts +303 -0
- package/src/utils/CacheUserInfo.ts +818 -0
- package/src/utils/CacheViewToggleInfo.ts +182 -0
- package/src/utils/MessageContentUtils.ts +268 -0
- package/src/utils/clipboard.ts +70 -0
- package/src/utils/companyEmail.ts +19 -0
- package/src/utils/forbidDebugger.ts +59 -0
- package/src/utils/formatters.ts +94 -0
- package/src/utils/htmlUtils.tsx +59 -0
- package/src/utils/index.ts +18 -0
- package/src/utils/keyboard.ts +114 -0
- package/src/utils/mammothApi.ts +16 -0
- package/src/utils/polyfills.ts +928 -0
- package/src/utils/regex.ts +14 -0
- package/src/utils/storage.ts +95 -0
- package/src/utils/workerBootstrap.ts +87 -0
- package/dist/api/index.js +0 -1553
- package/dist/contract.js +0 -5
- package/dist/index.js +0 -4492
- package/dist/types/index.js +0 -49
- package/dist/ui/index.css +0 -1876
- package/dist/ui/index.js +0 -22245
- package/dist/utils/index.js +0 -4296
- /package/{dist → src}/styles/ant-modal.css +0 -0
- /package/{dist → src}/styles/ant-spin.css +0 -0
- /package/{dist → src}/styles/ant-table.css +0 -0
- /package/{dist → src}/styles/index.css +0 -0
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
/* eslint-disable react-refresh/only-export-components */
|
|
2
|
+
/**
|
|
3
|
+
* UIAlert - 全局警告/提示对话框组件
|
|
4
|
+
*
|
|
5
|
+
* 使用示例:
|
|
6
|
+
*
|
|
7
|
+
* 1. 直接调用 API(推荐):
|
|
8
|
+
* import uiAlert from './UIAlert';
|
|
9
|
+
*
|
|
10
|
+
* // 简单提示
|
|
11
|
+
* const close = uiAlert.success('操作成功');
|
|
12
|
+
* const close = uiAlert.error('操作失败');
|
|
13
|
+
* const close = uiAlert.warning('警告信息');
|
|
14
|
+
* const close = uiAlert.info('提示信息');
|
|
15
|
+
*
|
|
16
|
+
* // 手动关闭
|
|
17
|
+
* close();
|
|
18
|
+
* // 或使用全局关闭
|
|
19
|
+
* uiAlert.close();
|
|
20
|
+
*
|
|
21
|
+
* // 完整配置
|
|
22
|
+
* uiAlert.success({
|
|
23
|
+
* title: '成功',
|
|
24
|
+
* content: '数据保存成功!',
|
|
25
|
+
* okText: '确定',
|
|
26
|
+
* okType: 'primary',
|
|
27
|
+
* onOk: () => console.log('用户点击了确定'),
|
|
28
|
+
* autoClose: 3000, // 3秒后自动关闭(毫秒)
|
|
29
|
+
* showIcon: true
|
|
30
|
+
* });
|
|
31
|
+
*
|
|
32
|
+
* // 确认对话框
|
|
33
|
+
* uiAlert.confirm({
|
|
34
|
+
* title: '确认',
|
|
35
|
+
* content: '确定要删除吗?',
|
|
36
|
+
* onOk: () => console.log('用户点击了确定'),
|
|
37
|
+
* onCancel: () => console.log('用户点击了取消')
|
|
38
|
+
* });
|
|
39
|
+
*
|
|
40
|
+
* // 自定义按钮
|
|
41
|
+
* uiAlert.custom({
|
|
42
|
+
* title: '选择操作',
|
|
43
|
+
* content: '请选择您的操作',
|
|
44
|
+
* buttons: [
|
|
45
|
+
* { text: '删除', type: 'danger', onClick: () => console.log('删除') },
|
|
46
|
+
* { text: '修改', type: 'primary', onClick: () => console.log('修改') },
|
|
47
|
+
* { text: '取消', onClick: () => console.log('取消') }
|
|
48
|
+
* ]
|
|
49
|
+
* });
|
|
50
|
+
*
|
|
51
|
+
* 特点:
|
|
52
|
+
* - 支持多种类型:success, error, warning, info, confirm
|
|
53
|
+
* - 支持自定义按钮
|
|
54
|
+
* - 支持自动关闭
|
|
55
|
+
* - 返回关闭方法,可以手动调用
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
import React from 'react';
|
|
59
|
+
import { Modal, Button, Space, Typography } from 'antd';
|
|
60
|
+
import { CheckCircleFilled, CloseCircleFilled, ExclamationCircleFilled, InfoCircleFilled, QuestionCircleFilled } from '@ant-design/icons';
|
|
61
|
+
import { createRoot, Root } from 'react-dom/client';
|
|
62
|
+
import type { ButtonProps } from 'antd/es/button';
|
|
63
|
+
|
|
64
|
+
const { Text, Title } = Typography;
|
|
65
|
+
|
|
66
|
+
// Alert类型定义
|
|
67
|
+
export type UIAlertType = 'success' | 'error' | 'warning' | 'info' | 'confirm';
|
|
68
|
+
|
|
69
|
+
// Alert按钮定义
|
|
70
|
+
export interface UIAlertButton {
|
|
71
|
+
text: string;
|
|
72
|
+
type?: ButtonProps['type'];
|
|
73
|
+
onClick?: () => void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Alert选项接口
|
|
77
|
+
export interface UIAlertOptions {
|
|
78
|
+
type?: UIAlertType;
|
|
79
|
+
title?: React.ReactNode;
|
|
80
|
+
content?: React.ReactNode;
|
|
81
|
+
width?: number | string;
|
|
82
|
+
centered?: boolean;
|
|
83
|
+
closable?: boolean;
|
|
84
|
+
maskClosable?: boolean;
|
|
85
|
+
okText?: string;
|
|
86
|
+
okType?: ButtonProps['type'];
|
|
87
|
+
cancelText?: string;
|
|
88
|
+
buttons?: UIAlertButton[];
|
|
89
|
+
onOk?: () => void | Promise<void>;
|
|
90
|
+
onCancel?: () => void;
|
|
91
|
+
afterClose?: () => void;
|
|
92
|
+
className?: string;
|
|
93
|
+
autoClose?: number; // 自动关闭时间(毫秒),0表示不自动关闭
|
|
94
|
+
showIcon?: boolean;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 默认选项
|
|
98
|
+
const defaultOptions: UIAlertOptions = {
|
|
99
|
+
type: 'info',
|
|
100
|
+
title: '提示',
|
|
101
|
+
content: '',
|
|
102
|
+
width: 420,
|
|
103
|
+
centered: true,
|
|
104
|
+
closable: true,
|
|
105
|
+
maskClosable: true,
|
|
106
|
+
okText: '确定',
|
|
107
|
+
okType: 'primary',
|
|
108
|
+
cancelText: '取消',
|
|
109
|
+
autoClose: 0,
|
|
110
|
+
showIcon: false,
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
// 单例管理
|
|
114
|
+
let alertInstance: HTMLDivElement | null = null;
|
|
115
|
+
let rootInstance: Root | null = null;
|
|
116
|
+
let autoCloseTimer: number | null = null;
|
|
117
|
+
|
|
118
|
+
// Alert组件
|
|
119
|
+
const AlertComponent: React.FC<UIAlertOptions & { open: boolean; onClose: () => void }> = (props) => {
|
|
120
|
+
const {
|
|
121
|
+
type = 'info',
|
|
122
|
+
title,
|
|
123
|
+
content,
|
|
124
|
+
width,
|
|
125
|
+
centered,
|
|
126
|
+
closable,
|
|
127
|
+
maskClosable,
|
|
128
|
+
okText,
|
|
129
|
+
okType,
|
|
130
|
+
cancelText,
|
|
131
|
+
buttons,
|
|
132
|
+
onOk,
|
|
133
|
+
onCancel,
|
|
134
|
+
open,
|
|
135
|
+
onClose,
|
|
136
|
+
className,
|
|
137
|
+
showIcon
|
|
138
|
+
} = props;
|
|
139
|
+
|
|
140
|
+
// 图标映射
|
|
141
|
+
const iconMap = {
|
|
142
|
+
success: <CheckCircleFilled style={{ color: '#52c41a', fontSize: 24, marginRight: 8 }} />,
|
|
143
|
+
error: <CloseCircleFilled style={{ color: '#ff4d4f', fontSize: 24, marginRight: 8 }} />,
|
|
144
|
+
warning: <ExclamationCircleFilled style={{ color: '#faad14', fontSize: 24, marginRight: 8 }} />,
|
|
145
|
+
info: <InfoCircleFilled style={{ color: '#1677ff', fontSize: 24, marginRight: 8 }} />,
|
|
146
|
+
confirm: <QuestionCircleFilled style={{ color: '#1677ff', fontSize: 24, marginRight: 8 }} />
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// 处理确定按钮点击
|
|
150
|
+
const handleOk = async () => {
|
|
151
|
+
if (onOk) {
|
|
152
|
+
await onOk();
|
|
153
|
+
}
|
|
154
|
+
onClose();
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// 处理取消按钮点击
|
|
158
|
+
const handleCancel = () => {
|
|
159
|
+
if (onCancel) {
|
|
160
|
+
onCancel();
|
|
161
|
+
}
|
|
162
|
+
onClose();
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
// 渲染自定义按钮
|
|
166
|
+
const renderFooter = () => {
|
|
167
|
+
if (buttons && buttons.length > 0) {
|
|
168
|
+
return (
|
|
169
|
+
<Space style={{ display: 'flex', justifyContent: 'flex-end' }}>
|
|
170
|
+
{buttons.map((btn, index) => (
|
|
171
|
+
<Button
|
|
172
|
+
key={index}
|
|
173
|
+
type={btn.type || 'default'}
|
|
174
|
+
onClick={() => {
|
|
175
|
+
if (btn.onClick) {
|
|
176
|
+
btn.onClick();
|
|
177
|
+
}
|
|
178
|
+
onClose();
|
|
179
|
+
}}
|
|
180
|
+
>
|
|
181
|
+
{btn.text}
|
|
182
|
+
</Button>
|
|
183
|
+
))}
|
|
184
|
+
</Space>
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// 不同类型的默认按钮
|
|
189
|
+
if (type === 'confirm') {
|
|
190
|
+
return (
|
|
191
|
+
<Space style={{ display: 'flex', justifyContent: 'flex-end' }}>
|
|
192
|
+
<Button onClick={handleCancel}>{cancelText}</Button>
|
|
193
|
+
<Button type={okType} onClick={handleOk}>{okText}</Button>
|
|
194
|
+
</Space>
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<Button type={okType} onClick={handleOk}>{okText}</Button>
|
|
200
|
+
);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
// 渲染标题
|
|
204
|
+
const renderTitle = () => {
|
|
205
|
+
if (!title) return null;
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<div style={{ display: 'flex', alignItems: 'center' }}>
|
|
209
|
+
{showIcon && iconMap[type]}
|
|
210
|
+
<Title level={4} style={{ margin: 0 }}>{title}</Title>
|
|
211
|
+
</div>
|
|
212
|
+
);
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
return (
|
|
216
|
+
<Modal
|
|
217
|
+
title={renderTitle()}
|
|
218
|
+
open={open}
|
|
219
|
+
width={width}
|
|
220
|
+
centered={centered}
|
|
221
|
+
closable={closable}
|
|
222
|
+
maskClosable={maskClosable}
|
|
223
|
+
onCancel={handleCancel}
|
|
224
|
+
footer={renderFooter()}
|
|
225
|
+
className={className ? className + ' ant-modal-nofull' : 'ant-modal-nofull'}
|
|
226
|
+
>
|
|
227
|
+
<div style={{ marginLeft: showIcon ? 32 : 0 }}>
|
|
228
|
+
{typeof content === 'string' ? <Text>{content}</Text> : content}
|
|
229
|
+
</div>
|
|
230
|
+
</Modal>
|
|
231
|
+
);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// 创建Alert实例
|
|
235
|
+
const createAlertInstance = (options: UIAlertOptions, open: boolean = true) => {
|
|
236
|
+
// 清除自动关闭计时器
|
|
237
|
+
if (autoCloseTimer) {
|
|
238
|
+
window.clearTimeout(autoCloseTimer);
|
|
239
|
+
autoCloseTimer = null;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// 合并选项
|
|
243
|
+
const mergedOptions = { ...defaultOptions, ...options };
|
|
244
|
+
|
|
245
|
+
// 关闭Alert的方法
|
|
246
|
+
const closeAlert = () => {
|
|
247
|
+
if (alertInstance && rootInstance) {
|
|
248
|
+
rootInstance.render(
|
|
249
|
+
<AlertComponent
|
|
250
|
+
{...mergedOptions}
|
|
251
|
+
open={false}
|
|
252
|
+
onClose={() => {
|
|
253
|
+
if (mergedOptions.afterClose) {
|
|
254
|
+
mergedOptions.afterClose();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (alertInstance && rootInstance) {
|
|
258
|
+
setTimeout(() => {
|
|
259
|
+
rootInstance?.unmount();
|
|
260
|
+
document.body.removeChild(alertInstance!);
|
|
261
|
+
alertInstance = null;
|
|
262
|
+
rootInstance = null;
|
|
263
|
+
}, 300); // 等待动画结束
|
|
264
|
+
}
|
|
265
|
+
}}
|
|
266
|
+
/>
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
// 如果已存在实例,则更新内容
|
|
272
|
+
if (alertInstance && rootInstance) {
|
|
273
|
+
rootInstance.render(
|
|
274
|
+
<AlertComponent
|
|
275
|
+
{...mergedOptions}
|
|
276
|
+
open={open}
|
|
277
|
+
onClose={closeAlert}
|
|
278
|
+
/>
|
|
279
|
+
);
|
|
280
|
+
} else {
|
|
281
|
+
// 创建新实例
|
|
282
|
+
alertInstance = document.createElement('div');
|
|
283
|
+
document.body.appendChild(alertInstance);
|
|
284
|
+
rootInstance = createRoot(alertInstance);
|
|
285
|
+
rootInstance.render(
|
|
286
|
+
<AlertComponent
|
|
287
|
+
{...mergedOptions}
|
|
288
|
+
open={open}
|
|
289
|
+
onClose={closeAlert}
|
|
290
|
+
/>
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// 如果设置了自动关闭
|
|
295
|
+
if (mergedOptions.autoClose && mergedOptions.autoClose > 0) {
|
|
296
|
+
autoCloseTimer = window.setTimeout(() => {
|
|
297
|
+
closeAlert();
|
|
298
|
+
autoCloseTimer = null;
|
|
299
|
+
}, mergedOptions.autoClose);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// 返回关闭方法
|
|
303
|
+
return closeAlert;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// 全局Alert API
|
|
307
|
+
const uiAlert = {
|
|
308
|
+
// 成功提示
|
|
309
|
+
success: (options: string | UIAlertOptions) => {
|
|
310
|
+
const config = typeof options === 'string'
|
|
311
|
+
? { content: options }
|
|
312
|
+
: options;
|
|
313
|
+
|
|
314
|
+
return createAlertInstance({
|
|
315
|
+
...config,
|
|
316
|
+
type: 'success',
|
|
317
|
+
title: config.title || '成功',
|
|
318
|
+
});
|
|
319
|
+
},
|
|
320
|
+
|
|
321
|
+
// 错误提示
|
|
322
|
+
error: (options: string | UIAlertOptions) => {
|
|
323
|
+
const config = typeof options === 'string'
|
|
324
|
+
? { content: options }
|
|
325
|
+
: options;
|
|
326
|
+
|
|
327
|
+
return createAlertInstance({
|
|
328
|
+
...config,
|
|
329
|
+
type: 'error',
|
|
330
|
+
title: config.title || '错误',
|
|
331
|
+
});
|
|
332
|
+
},
|
|
333
|
+
|
|
334
|
+
// 警告提示
|
|
335
|
+
warning: (options: string | UIAlertOptions) => {
|
|
336
|
+
const config = typeof options === 'string'
|
|
337
|
+
? { content: options }
|
|
338
|
+
: options;
|
|
339
|
+
|
|
340
|
+
return createAlertInstance({
|
|
341
|
+
...config,
|
|
342
|
+
type: 'warning',
|
|
343
|
+
title: config.title || '警告',
|
|
344
|
+
});
|
|
345
|
+
},
|
|
346
|
+
|
|
347
|
+
// 信息提示
|
|
348
|
+
info: (options: string | UIAlertOptions) => {
|
|
349
|
+
const config = typeof options === 'string'
|
|
350
|
+
? { content: options }
|
|
351
|
+
: options;
|
|
352
|
+
|
|
353
|
+
return createAlertInstance({
|
|
354
|
+
...config,
|
|
355
|
+
type: 'info',
|
|
356
|
+
title: config.title || '提示',
|
|
357
|
+
});
|
|
358
|
+
},
|
|
359
|
+
|
|
360
|
+
// 确认提示
|
|
361
|
+
confirm: (options: string | UIAlertOptions) => {
|
|
362
|
+
const config = typeof options === 'string'
|
|
363
|
+
? { content: options }
|
|
364
|
+
: options;
|
|
365
|
+
|
|
366
|
+
return createAlertInstance({
|
|
367
|
+
...config,
|
|
368
|
+
type: 'confirm',
|
|
369
|
+
title: config.title || '确认',
|
|
370
|
+
});
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
// 自定义提示
|
|
374
|
+
custom: (options: UIAlertOptions) => {
|
|
375
|
+
return createAlertInstance(options);
|
|
376
|
+
},
|
|
377
|
+
|
|
378
|
+
// 关闭当前显示的Alert
|
|
379
|
+
close: () => {
|
|
380
|
+
if (alertInstance && rootInstance) {
|
|
381
|
+
rootInstance.render(
|
|
382
|
+
<AlertComponent
|
|
383
|
+
{...defaultOptions}
|
|
384
|
+
open={false}
|
|
385
|
+
onClose={() => {
|
|
386
|
+
if (alertInstance && rootInstance) {
|
|
387
|
+
rootInstance.unmount();
|
|
388
|
+
document.body.removeChild(alertInstance);
|
|
389
|
+
alertInstance = null;
|
|
390
|
+
rootInstance = null;
|
|
391
|
+
}
|
|
392
|
+
}}
|
|
393
|
+
/>
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
export default uiAlert;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Button, Space, Card, Divider } from 'antd';
|
|
3
|
+
import uiAlert from './UIAlert';
|
|
4
|
+
|
|
5
|
+
const AlertExample: React.FC = () => {
|
|
6
|
+
// 成功提示
|
|
7
|
+
const showSuccessAlert = () => {
|
|
8
|
+
uiAlert.success('操作已成功完成');
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// 错误提示
|
|
12
|
+
const showErrorAlert = () => {
|
|
13
|
+
uiAlert.error({
|
|
14
|
+
title: '操作失败',
|
|
15
|
+
content: '服务器连接超时,请稍后再试',
|
|
16
|
+
okText: '我知道了'
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// 警告提示
|
|
21
|
+
const showWarningAlert = () => {
|
|
22
|
+
uiAlert.warning({
|
|
23
|
+
content: '此操作将删除所选项目,是否继续?',
|
|
24
|
+
onOk: () => console.log('用户确认删除')
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// 信息提示
|
|
29
|
+
const showInfoAlert = () => {
|
|
30
|
+
uiAlert.info('系统将于今晚22:00进行维护,届时服务将暂停使用');
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// 确认对话框
|
|
34
|
+
const showConfirmAlert = () => {
|
|
35
|
+
uiAlert.confirm({
|
|
36
|
+
title: '确认操作',
|
|
37
|
+
content: '您确定要提交这些更改吗?提交后将不可撤销',
|
|
38
|
+
onOk: () => console.log('用户确认提交'),
|
|
39
|
+
onCancel: () => console.log('用户取消提交')
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// 自定义按钮提示
|
|
44
|
+
const showCustomButtonsAlert = () => {
|
|
45
|
+
uiAlert.custom({
|
|
46
|
+
type: 'info',
|
|
47
|
+
title: '选择操作',
|
|
48
|
+
content: '请选择要执行的操作:',
|
|
49
|
+
buttons: [
|
|
50
|
+
{ text: '保存', type: 'primary', onClick: () => console.log('保存操作') },
|
|
51
|
+
{ text: '保存并发布', type: 'default', onClick: () => console.log('保存并发布') },
|
|
52
|
+
{ text: '取消', type: 'dashed', onClick: () => console.log('取消操作') }
|
|
53
|
+
],
|
|
54
|
+
closable: true
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// 自动关闭提示
|
|
59
|
+
const showAutoCloseAlert = () => {
|
|
60
|
+
uiAlert.success({
|
|
61
|
+
title: '上传成功',
|
|
62
|
+
content: '文件已成功上传到服务器',
|
|
63
|
+
autoClose: 3000, // 3秒后自动关闭
|
|
64
|
+
onOk: () => console.log('用户点击了确定')
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// 复杂内容示例
|
|
69
|
+
const showComplexContentAlert = () => {
|
|
70
|
+
uiAlert.custom({
|
|
71
|
+
type: 'info',
|
|
72
|
+
title: '用户信息',
|
|
73
|
+
content: (
|
|
74
|
+
<div>
|
|
75
|
+
<p>以下是您的账户信息摘要:</p>
|
|
76
|
+
<ul style={{ marginBottom: 0 }}>
|
|
77
|
+
<li>用户名:admin</li>
|
|
78
|
+
<li>注册时间:2023-05-01</li>
|
|
79
|
+
<li>上次登录:2023-06-15</li>
|
|
80
|
+
<li>账户状态:<span style={{ color: '#52c41a' }}>正常</span></li>
|
|
81
|
+
</ul>
|
|
82
|
+
</div>
|
|
83
|
+
),
|
|
84
|
+
width: 500
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
return (
|
|
89
|
+
<Card title="Alert 提示示例" style={{ width: '100%', maxWidth: 600, margin: '20px auto' }}>
|
|
90
|
+
<Space direction="vertical" style={{ width: '100%' }}>
|
|
91
|
+
<Button type="primary" block onClick={showSuccessAlert}>
|
|
92
|
+
显示成功提示
|
|
93
|
+
</Button>
|
|
94
|
+
|
|
95
|
+
<Button danger block onClick={showErrorAlert}>
|
|
96
|
+
显示错误提示
|
|
97
|
+
</Button>
|
|
98
|
+
|
|
99
|
+
<Button type="default" block onClick={showWarningAlert}>
|
|
100
|
+
显示警告提示
|
|
101
|
+
</Button>
|
|
102
|
+
|
|
103
|
+
<Button type="dashed" block onClick={showInfoAlert}>
|
|
104
|
+
显示信息提示
|
|
105
|
+
</Button>
|
|
106
|
+
|
|
107
|
+
<Divider>高级用法</Divider>
|
|
108
|
+
|
|
109
|
+
<Button type="primary" ghost block onClick={showConfirmAlert}>
|
|
110
|
+
显示确认对话框
|
|
111
|
+
</Button>
|
|
112
|
+
|
|
113
|
+
<Button block onClick={showCustomButtonsAlert}>
|
|
114
|
+
显示自定义按钮提示
|
|
115
|
+
</Button>
|
|
116
|
+
|
|
117
|
+
<Button type="default" block onClick={showAutoCloseAlert}>
|
|
118
|
+
显示自动关闭提示(3秒)
|
|
119
|
+
</Button>
|
|
120
|
+
|
|
121
|
+
<Button type="dashed" block onClick={showComplexContentAlert}>
|
|
122
|
+
显示复杂内容提示
|
|
123
|
+
</Button>
|
|
124
|
+
</Space>
|
|
125
|
+
</Card>
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
export default AlertExample;
|