@fe-free/core 1.2.3 → 1.3.0

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.
@@ -1,46 +0,0 @@
1
- ---
2
- group: 'core'
3
- toc: content
4
- ---
5
-
6
- # Button
7
-
8
- ## LoadingButton
9
-
10
- ```tsx
11
- import { LoadingButton } from '@fe-free/core';
12
-
13
- export default () => {
14
- return (
15
- <div>
16
- <LoadingButton
17
- onClick={() => {
18
- return;
19
- }}
20
- >
21
- 点击
22
- </LoadingButton>
23
-
24
- <LoadingButton
25
- onClick={() =>
26
- new Promise((resolve) => {
27
- setTimeout(resolve, 1000);
28
- })
29
- }
30
- >
31
- 点击 1000ms resolve
32
- </LoadingButton>
33
-
34
- <LoadingButton
35
- onClick={() =>
36
- new Promise((_, reject) => {
37
- setTimeout(reject, 1000);
38
- })
39
- }
40
- >
41
- 点击 1000ms reject
42
- </LoadingButton>
43
- </div>
44
- );
45
- };
46
- ```
@@ -1,342 +0,0 @@
1
- import React, { useRef } from 'react';
2
- import type { CRUDProps } from '@fe-free/core';
3
- import { CRUD, proFormSelectSearchProps } from '@fe-free/core';
4
- import { Button } from 'antd';
5
- import { ProForm, ProFormSwitch, ProFormText } from '@ant-design/pro-components';
6
- import {
7
- fakeRequest,
8
- fakeDeleteByRecord,
9
- fakeCreate,
10
- fakeGetByRecord,
11
- fakeUpdateById,
12
- fakeRequestCity,
13
- fakeRequestArea,
14
- levels,
15
- fakeRequestSchool,
16
- } from './data';
17
-
18
- const Normal = () => {
19
- const columns = [
20
- {
21
- title: 'id',
22
- dataIndex: 'id',
23
- search: true,
24
- },
25
- {
26
- title: '名字(省略)',
27
- dataIndex: 'name',
28
- search: true,
29
- ellipsis: true,
30
- },
31
- {
32
- title: 'city',
33
- dataIndex: 'city',
34
- },
35
- {
36
- title: 'area',
37
- dataIndex: 'area',
38
- },
39
- ];
40
-
41
- return (
42
- <CRUD
43
- actions={['create', 'read', 'delete', 'update']}
44
- tableProps={{
45
- columns,
46
- request: fakeRequest,
47
- }}
48
- requestDeleteByRecord={fakeDeleteByRecord}
49
- deleteProps={{
50
- nameIndex: 'name',
51
- }}
52
- detailForm={(formProps) => (
53
- <>
54
- <ProFormText
55
- {...formProps}
56
- name="name"
57
- label="名字"
58
- required
59
- rules={[{ required: true }]}
60
- extra="extra extra extra extra"
61
- />
62
- </>
63
- )}
64
- requestGetByRecord={fakeGetByRecord}
65
- requestCreateByValues={fakeCreate}
66
- requestUpdateById={fakeUpdateById}
67
- />
68
- );
69
- };
70
-
71
- function ReadDetail() {
72
- const columns = [
73
- {
74
- title: 'id',
75
- dataIndex: 'id',
76
- search: true,
77
- },
78
- {
79
- title: '名字',
80
- dataIndex: 'name',
81
- search: true,
82
- },
83
- ];
84
-
85
- return (
86
- <CRUD
87
- actions={['read_detail']}
88
- tableProps={{
89
- columns,
90
- request: fakeRequest,
91
- }}
92
- />
93
- );
94
- }
95
-
96
- function Ref() {
97
- const formRef = useRef<any>();
98
- const [detailFormInstance] = ProForm.useForm();
99
-
100
- // @ts-ignore
101
- window._detailFormInstance = detailFormInstance;
102
-
103
- const name = ProForm.useWatch('name', formRef.current);
104
- const detailName = ProForm.useWatch('name', detailFormInstance);
105
-
106
- // 不知道为啥这里 name 不生效,但是项目里是生效的。先忽略
107
- console.log('useWatch', name, detailName);
108
-
109
- const columns = [
110
- {
111
- title: 'id',
112
- dataIndex: 'id',
113
- search: true,
114
- },
115
- {
116
- title: '名字',
117
- dataIndex: 'name',
118
- search: true,
119
- },
120
- ];
121
-
122
- return (
123
- <CRUD
124
- actions={['create', 'read', 'update']}
125
- tableProps={{
126
- formRef,
127
- columns,
128
- request: fakeRequest,
129
- }}
130
- detailFormInstance={detailFormInstance}
131
- detailForm={(formProps) => (
132
- <>
133
- <ProFormText
134
- {...formProps}
135
- name="name"
136
- label="名字"
137
- required
138
- rules={[{ required: true }]}
139
- initialValue={'default'}
140
- />
141
- <ProFormSwitch {...formProps} name="status" label="开启" initialValue={false} />
142
- </>
143
- )}
144
- requestGetByRecord={fakeGetByRecord}
145
- requestCreateByValues={fakeCreate}
146
- requestUpdateById={fakeUpdateById}
147
- />
148
- );
149
- }
150
-
151
- function ActionRef() {
152
- const ref = useRef<any>();
153
-
154
- const columns = [
155
- {
156
- title: 'id',
157
- dataIndex: 'id',
158
- search: true,
159
- },
160
- {
161
- title: '名字',
162
- dataIndex: 'name',
163
- search: true,
164
- },
165
- ];
166
-
167
- return (
168
- <>
169
- <Button onClick={() => ref.current.getActionRef().current?.reload()}>reload</Button>
170
- <CRUD
171
- ref={ref}
172
- actions={[]}
173
- tableProps={{
174
- columns,
175
- request: fakeRequest,
176
- }}
177
- />
178
- </>
179
- );
180
- }
181
-
182
- function RemoteData() {
183
- const columns: CRUDProps['tableProps']['columns'] = [
184
- {
185
- title: 'id',
186
- dataIndex: 'id',
187
- search: true,
188
- },
189
- {
190
- title: '名字',
191
- dataIndex: 'name',
192
- search: true,
193
- },
194
- {
195
- title: '等级(本地数据)',
196
- dataIndex: 'level',
197
- search: true,
198
- valueEnum: levels,
199
- ...proFormSelectSearchProps,
200
- },
201
- {
202
- title: 'city(远端数据)',
203
- dataIndex: 'city',
204
- search: true,
205
- request: async () => {
206
- console.log('request');
207
- const res = await fakeRequestCity();
208
-
209
- return (
210
- res.map((item) => ({
211
- label: item,
212
- value: item,
213
- })) || []
214
- );
215
- },
216
- ...proFormSelectSearchProps,
217
- },
218
- {
219
- title: 'area(联动 city)',
220
- dataIndex: 'area',
221
- search: true,
222
- request: async (params) => {
223
- console.log('params', params);
224
- const res = await fakeRequestArea(params);
225
-
226
- return (
227
- res.map((item) => ({
228
- label: item,
229
- value: item,
230
- })) || []
231
- );
232
- },
233
- dependencies: ['city'],
234
- ...proFormSelectSearchProps,
235
- },
236
- {
237
- title: '学校(远端数据 label value)',
238
- dataIndex: 'school',
239
- search: true,
240
- valueType: 'select',
241
- request: () => fakeRequestSchool(),
242
- ...proFormSelectSearchProps,
243
- },
244
- ];
245
-
246
- return (
247
- <CRUD
248
- actions={[]}
249
- tableProps={{
250
- columns,
251
- request: fakeRequest,
252
- }}
253
- />
254
- );
255
- }
256
-
257
- function NoSearch() {
258
- const ref = useRef<any>();
259
-
260
- const columns = [
261
- {
262
- title: 'id',
263
- dataIndex: 'id',
264
- },
265
- {
266
- title: '名字',
267
- dataIndex: 'name',
268
- },
269
- ];
270
-
271
- return (
272
- <CRUD
273
- ref={ref}
274
- actions={[]}
275
- tableProps={{
276
- columns,
277
- request: fakeRequest,
278
- }}
279
- />
280
- );
281
- }
282
-
283
- const CustomText = () => {
284
- const columns = [
285
- {
286
- title: 'id',
287
- dataIndex: 'id',
288
- search: true,
289
- },
290
- {
291
- title: '名字',
292
- dataIndex: 'name',
293
- search: true,
294
- ellipsis: true,
295
- },
296
- ];
297
-
298
- return (
299
- <CRUD
300
- actions={['create', 'read', 'delete', 'update']}
301
- tableProps={{
302
- columns,
303
- request: fakeRequest,
304
- }}
305
- operateColumnProps={{
306
- width: 230,
307
- moreOperator: () => <div>custom</div>,
308
- }}
309
- readProps={{
310
- operateText: '查看啦',
311
- }}
312
- requestDeleteByRecord={fakeDeleteByRecord}
313
- deleteProps={{
314
- nameIndex: 'name',
315
- operateText: '删除啦',
316
- }}
317
- detailForm={(formProps) => (
318
- <>
319
- <ProFormText
320
- {...formProps}
321
- name="name"
322
- label="名字"
323
- required
324
- rules={[{ required: true }]}
325
- />
326
- </>
327
- )}
328
- requestGetByRecord={fakeGetByRecord}
329
- requestCreateByValues={fakeCreate}
330
- createProps={{
331
- successText: '新建成功啦',
332
- }}
333
- updateProps={{
334
- operateText: '更新啦',
335
- successText: '更新成功啦',
336
- }}
337
- requestUpdateById={fakeUpdateById}
338
- />
339
- );
340
- };
341
-
342
- export { Normal, ReadDetail, Ref, ActionRef, RemoteData, NoSearch, CustomText };
package/src/crud/index.md DELETED
@@ -1,158 +0,0 @@
1
- ---
2
- nav:
3
- title: '组件'
4
- order: 10
5
- group: 'core'
6
- toc: content
7
- ---
8
-
9
- # CRUD
10
-
11
- > 需要了解 ant pro-components ProForm ProTable
12
-
13
- 基于 ant pro-components 通用的 CRUD 组件,同时保留扩展性。
14
-
15
- ## 代码演示
16
-
17
- ### 常规
18
-
19
- ```tsx
20
- import { Normal } from './demo';
21
-
22
- export default Normal;
23
- ```
24
-
25
- ### 详情页查看
26
-
27
- 调整 actions 为 `['read_detail']`,点击<查看>跳转到 `xxx/detail/[id]`,
28
-
29
- ```tsx
30
- import { ReadDetail } from './demo';
31
-
32
- export default ReadDetail;
33
- ```
34
-
35
- ### 数据 本地&远程&依赖
36
-
37
- ```tsx
38
- import { RemoteData } from './demo';
39
-
40
- export default RemoteData;
41
- ```
42
-
43
- ### 表格表单和详情表单 ref
44
-
45
- 获取 ProTable 的 actionRef
46
-
47
- ```tsx
48
- import { Ref } from './demo';
49
-
50
- export default Ref;
51
- ```
52
-
53
- ### ref.current.getActionRef
54
-
55
- 通过 ref 你可以做更多操作
56
-
57
- ```tsx
58
- import { ActionRef } from './demo';
59
-
60
- export default ActionRef;
61
- ```
62
-
63
- ### 没有搜索
64
-
65
- ```tsx
66
- import { NoSearch } from './demo';
67
-
68
- export default NoSearch;
69
- ```
70
-
71
- ### 自定义文案
72
-
73
- ```tsx
74
- import { CustomText } from './demo';
75
-
76
- export default CustomText;
77
- ```
78
-
79
- ## API
80
-
81
- ```tsx | pure
82
- import type { ReactNode } from 'react';
83
- import type { TableProps } from '../table';
84
- import type { ProFormInstance, ActionType } from '@ant-design/pro-components';
85
-
86
- /**
87
- * create 创建
88
- * read 查看
89
- * read_detail 详情页查看
90
- * update 编辑
91
- * delete 删除
92
- */
93
- type CrudAction = 'create' | 'read' | 'read_detail' | 'update' | 'delete';
94
-
95
- interface CRUDProps {
96
- actions: CrudAction[];
97
-
98
- /** 新建按钮,默认新建 */
99
- createButton?: ReactNode;
100
-
101
- /** 表格相关 */
102
- tableProps: TableProps;
103
- operateColumnProps?: {
104
- width?: number;
105
- /** 扩展操作区域 */
106
- moreOperator?: (record) => ReactNode;
107
- };
108
- readProps?: {
109
- /** 文本 */
110
- operateText?: string;
111
- /** 打开方式, action 为 read_detail 有效 */
112
- target?: '_blank';
113
- };
114
-
115
- /** 删除接口 */
116
- requestDeleteByRecord?: (record) => Promise<any>;
117
- /** 删除相关 */
118
- deleteProps?: {
119
- /** 显示名称索引 */
120
- nameIndex: string;
121
- /** 删除确认描述 */
122
- desc?: string;
123
- /** 文本 */
124
- operateText?: string;
125
- };
126
-
127
- /** 弹窗表单 */
128
- detailForm?: (formProps: { readonly: boolean }, info: { action: CrudAction }) => ReactNode;
129
- /** detailForm 的 formRef */
130
- detailFormInstance?: ProFormInstance;
131
-
132
- /** 新增接口 */
133
- requestCreateByValues?: (values) => Promise<any>;
134
- createProps?: {
135
- /** 成功文案 */
136
- successText?: string | (() => string);
137
- };
138
-
139
- /** 更新接口 */
140
- requestUpdateById?: (values) => Promise<any>;
141
- updateProps?: {
142
- /** 文本 */
143
- operateText?: string;
144
- /** 成功文案 */
145
- successText?: string | (() => string);
146
- };
147
-
148
- /** 获取详情接口 */
149
- requestGetByRecord?: (record) => Promise<any>;
150
-
151
- /** 跳转到详情的索引 ,默认 id */
152
- detailIdIndex?: string;
153
- }
154
-
155
- interface CRUDMethods {
156
- getActionRef: () => React.MutableRefObject<ActionType | undefined>;
157
- }
158
- ```
@@ -1,48 +0,0 @@
1
- ---
2
- group: 'core'
3
- toc: content
4
- ---
5
-
6
- # EditorLogs
7
-
8
- `LogViewer` 是一个用于显示日志内容的 React 组件。它使用 CodeMirror 编辑器来呈现日志,提供了语法高亮和主题支持。
9
-
10
- ## 代码演示
11
-
12
- ### 常规
13
-
14
- ```tsx
15
- import { EditorLogs } from '@fe-free/core';
16
-
17
- function Demo() {
18
- return (
19
- <EditorLogs
20
- logs={[
21
- {
22
- timestamp: '2023-01-01 12:00:00',
23
- level: 'info',
24
- message: 'This is an info log message.',
25
- },
26
- {
27
- timestamp: '2023-01-01 12:00:00',
28
- level: 'warn',
29
- message: 'This is a warning log message.',
30
- },
31
- {
32
- timestamp: '2023-01-01 12:00:00',
33
- level: 'error',
34
- message: 'This is an error log message.',
35
- },
36
- {
37
- timestamp: '2023-01-01 12:00:00',
38
- level: 'system',
39
- message:
40
- 'This is a debug log message. This is a debug log message This is a debug log message This is a debug log message This is a debug log message',
41
- },
42
- ]}
43
- />
44
- );
45
- }
46
-
47
- export default Demo;
48
- ```
@@ -1,40 +0,0 @@
1
- ---
2
- group: 'core'
3
- toc: content
4
- ---
5
-
6
- # EditorMarkdown
7
-
8
- ## 代码演示
9
-
10
- ### 常规
11
-
12
- ```tsx
13
- import { useState } from 'react';
14
- import { EditorMarkdown } from '@fe-free/core';
15
-
16
- function Demo() {
17
- const [value] = useState(
18
- `# hello
19
-
20
- world
21
- `
22
- );
23
-
24
- return (
25
- <div style={{ width: '500px', height: '500px' }}>
26
- <EditorMarkdown value={value} />
27
- </div>
28
- );
29
- }
30
-
31
- export default Demo;
32
- ```
33
-
34
- ## API
35
-
36
- ```tsx | pure
37
- interface EditorMarkdownProps {
38
- value: string;
39
- }
40
- ```
package/src/form/index.md DELETED
@@ -1,96 +0,0 @@
1
- ---
2
- group: 'core'
3
- toc: content
4
- ---
5
-
6
- # Form
7
-
8
- ## ProFormJSON
9
-
10
- JSON
11
-
12
- ```tsx
13
- import { ProForm } from '@ant-design/pro-components';
14
- import { ProFormJSON } from '@fe-free/core';
15
-
16
- function Demo() {
17
- return (
18
- <ProForm>
19
- <ProFormJSON name="json" initialValue={JSON.stringify({ name: 'world' }, null, 2)} />
20
- </ProForm>
21
- );
22
- }
23
-
24
- export default Demo;
25
- ```
26
-
27
- readonly
28
-
29
- ```tsx
30
- import { ProForm } from '@ant-design/pro-components';
31
- import { ProFormJSON } from '@fe-free/core';
32
-
33
- function Demo() {
34
- return (
35
- <ProForm>
36
- <ProFormJSON
37
- name="json"
38
- readonly
39
- initialValue={JSON.stringify({ name: 'world' }, null, 2)}
40
- fieldProps={{
41
- mainMenuBar: false,
42
- }}
43
- />
44
- </ProForm>
45
- );
46
- }
47
-
48
- export default Demo;
49
- ```
50
-
51
- ## ProFormJavascript
52
-
53
- JSON
54
-
55
- ```tsx
56
- import { ProForm } from '@ant-design/pro-components';
57
- import { ProFormJavascript } from '@fe-free/core';
58
-
59
- function Demo() {
60
- return (
61
- <ProForm>
62
- <ProFormJavascript
63
- name="json"
64
- initialValue={`const name = 'world';
65
- console.log('hello', name);
66
- `}
67
- />
68
- </ProForm>
69
- );
70
- }
71
-
72
- export default Demo;
73
- ```
74
-
75
- readonly
76
-
77
- ```tsx
78
- import { ProForm } from '@ant-design/pro-components';
79
- import { ProFormJavascript } from '@fe-free/core';
80
-
81
- function Demo() {
82
- return (
83
- <ProForm>
84
- <ProFormJavascript
85
- name="json"
86
- readonly
87
- initialValue={`const name = 'world';
88
- console.log('hello', name);
89
- `}
90
- />
91
- </ProForm>
92
- );
93
- }
94
-
95
- export default Demo;
96
- ```