@fe-free/core 1.4.2 → 1.4.4

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @fe-free/core
2
2
 
3
+ ## 1.4.4
4
+
5
+ ### Patch Changes
6
+
7
+ - fix: crud types
8
+ - @fe-free/tool@1.4.4
9
+
10
+ ## 1.4.3
11
+
12
+ ### Patch Changes
13
+
14
+ - feat: crud
15
+ - @fe-free/tool@1.4.3
16
+
3
17
  ## 1.4.2
4
18
 
5
19
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/core",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -35,7 +35,7 @@
35
35
  "react-syntax-highlighter": "^15.5.0",
36
36
  "vanilla-jsoneditor": "^0.23.1",
37
37
  "zustand": "^4.5.4",
38
- "@fe-free/tool": "1.4.2"
38
+ "@fe-free/tool": "1.4.4"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@ant-design/pro-components": "^2.8.7",
@@ -387,7 +387,13 @@ export const CustomText: Story = {
387
387
  request: fakeRequest,
388
388
  }}
389
389
  createButton={<Button type="primary">新建</Button>}
390
+ createProps={{
391
+ submitText: '自定义新建确定',
392
+ resetText: '自定义新建取消',
393
+ }}
390
394
  readProps={{
395
+ submitText: '自定义查看确定',
396
+ resetText: '自定义查看取消',
391
397
  operateText: '查看',
392
398
  }}
393
399
  deleteProps={{
@@ -397,6 +403,8 @@ export const CustomText: Story = {
397
403
  }}
398
404
  updateProps={{
399
405
  operateText: '编辑',
406
+ submitText: '自定义编辑确定',
407
+ resetText: '自定义编辑取消',
400
408
  successText: '编辑成功',
401
409
  }}
402
410
  requestDeleteByRecord={fakeDeleteByRecord}
package/src/crud/crud.tsx CHANGED
@@ -54,6 +54,7 @@ function CRUDComponent<
54
54
  requestUpdateById,
55
55
  detailFormInstance,
56
56
  createProps,
57
+ readProps,
57
58
  updateProps,
58
59
  }),
59
60
  [
@@ -63,6 +64,7 @@ function CRUDComponent<
63
64
  requestUpdateById,
64
65
  detailFormInstance,
65
66
  createProps,
67
+ readProps,
66
68
  updateProps,
67
69
  ],
68
70
  );
@@ -3,7 +3,7 @@ import { message, Spin } from 'antd';
3
3
  import classNames from 'classnames';
4
4
  import { isString } from 'lodash-es';
5
5
  import { useCallback, useMemo, useState } from 'react';
6
- import type { CRUDProps } from './crud';
6
+ import type { CRUDProps } from './types';
7
7
 
8
8
  /**
9
9
  * create 创建
@@ -20,6 +20,7 @@ interface CRUDDetailProps
20
20
  CRUDProps,
21
21
  | 'requestGetByRecord'
22
22
  | 'createProps'
23
+ | 'readProps'
23
24
  | 'requestCreateByValues'
24
25
  | 'updateProps'
25
26
  | 'requestUpdateById'
@@ -44,6 +45,7 @@ function CRUDDetail(props: CRUDDetailProps) {
44
45
  detailForm,
45
46
  requestGetByRecord,
46
47
  createProps,
48
+ readProps,
47
49
  requestCreateByValues,
48
50
  updateProps,
49
51
  requestUpdateById,
@@ -170,6 +172,61 @@ function CRUDDetail(props: CRUDDetailProps) {
170
172
  };
171
173
  }, []);
172
174
 
175
+ const title = useMemo(() => {
176
+ if (action === 'create') {
177
+ return '新建';
178
+ }
179
+ if (action === 'read') {
180
+ return '查看';
181
+ }
182
+ if (action === 'update') {
183
+ return '编辑';
184
+ }
185
+
186
+ return '';
187
+ }, [action]);
188
+
189
+ const submitter = useMemo(() => {
190
+ const result = {
191
+ searchConfig: {
192
+ submitText: '确定',
193
+ resetText: '取消',
194
+ },
195
+ };
196
+ if (action === 'create') {
197
+ if (createProps?.submitText) {
198
+ result.searchConfig.submitText = createProps.submitText;
199
+ }
200
+ if (createProps?.resetText) {
201
+ result.searchConfig.resetText = createProps.resetText;
202
+ }
203
+ } else if (action === 'read') {
204
+ if (readProps?.submitText) {
205
+ result.searchConfig.submitText = readProps.submitText;
206
+ }
207
+ if (readProps?.resetText) {
208
+ result.searchConfig.resetText = readProps.resetText;
209
+ }
210
+ } else if (action === 'update') {
211
+ if (updateProps?.submitText) {
212
+ result.searchConfig.submitText = updateProps.submitText;
213
+ }
214
+ if (updateProps?.resetText) {
215
+ result.searchConfig.resetText = updateProps.resetText;
216
+ }
217
+ }
218
+
219
+ return result;
220
+ }, [
221
+ action,
222
+ createProps?.resetText,
223
+ createProps?.submitText,
224
+ readProps?.resetText,
225
+ readProps?.submitText,
226
+ updateProps?.resetText,
227
+ updateProps?.submitText,
228
+ ]);
229
+
173
230
  return (
174
231
  <DrawerForm
175
232
  form={form}
@@ -181,6 +238,8 @@ function CRUDDetail(props: CRUDDetailProps) {
181
238
  readonly={action === 'read' && !!id}
182
239
  // 关闭销毁,否则会有很奇怪的 onFinish 闭包问题,怀疑 pro components bug
183
240
  drawerProps={drawerProps}
241
+ title={title}
242
+ submitter={submitter}
184
243
  >
185
244
  {children}
186
245
  </DrawerForm>
@@ -25,11 +25,15 @@ interface CRUDProps<DataSource = any, Key = string> {
25
25
  // *** Create 新建 ***
26
26
 
27
27
  /** 新增接口 */
28
- requestCreateByValues?: (values: Partial<DataSource>) => Promise<any>;
28
+ requestCreateByValues?: (values: Partial<DataSource>) => Promise<false | void>;
29
29
  /** 新建按钮,默认新建 */
30
30
  createButton?: ReactNode;
31
31
  /** create 更多设置 */
32
32
  createProps?: {
33
+ /** 保存按钮文本 */
34
+ submitText?: string;
35
+ /** 重置按钮文本 */
36
+ resetText?: string;
33
37
  /** 成功文案 */
34
38
  successText?: string | (() => string);
35
39
  };
@@ -50,7 +54,7 @@ interface CRUDProps<DataSource = any, Key = string> {
50
54
  // *** Read 详情 ***
51
55
 
52
56
  /** 获取详情接口 */
53
- requestGetByRecord?: (record: DataSource) => Promise<any>;
57
+ requestGetByRecord?: (record: DataSource) => Promise<DataSource>;
54
58
  /** 跳转到详情的索引 ,默认 id */
55
59
  detailIdIndex?: string;
56
60
  /** read 更多设置 */
@@ -59,17 +63,25 @@ interface CRUDProps<DataSource = any, Key = string> {
59
63
  operateText?: string;
60
64
  /** 打开方式, action 为 read_detail 有效 */
61
65
  target?: '_blank';
66
+ /** 保存按钮文本 */
67
+ submitText?: string;
68
+ /** 重置按钮文本 */
69
+ resetText?: string;
62
70
  };
63
71
 
64
72
  // *** Update 更新 ***
65
73
 
66
- /** 更新接口 */
67
- requestUpdateByValues?: (values: Partial<DataSource>) => Promise<any>;
74
+ /** 更新接口,返回 false 则不关闭弹窗 */
75
+ requestUpdateByValues?: (values: Partial<DataSource>) => Promise<false | void>;
68
76
  /** @deprecated 请使用 requestUpdateByValues 替代 */
69
- requestUpdateById?: (values: Partial<DataSource>) => Promise<any>;
77
+ requestUpdateById?: (values: Partial<DataSource>) => Promise<false | void>;
70
78
  updateProps?: {
71
79
  /** 文本 */
72
80
  operateText?: string;
81
+ /** 保存按钮文本 */
82
+ submitText?: string;
83
+ /** 重置按钮文本 */
84
+ resetText?: string;
73
85
  /** 成功文案 */
74
86
  successText?: string | (() => string);
75
87
  };
@@ -77,7 +89,7 @@ interface CRUDProps<DataSource = any, Key = string> {
77
89
  // *** Delete 删除 ***
78
90
 
79
91
  /** 删除接口 */
80
- requestDeleteByRecord?: (record: DataSource) => Promise<any>;
92
+ requestDeleteByRecord?: (record: DataSource) => Promise<void>;
81
93
  /** 删除相关 */
82
94
  deleteProps?: {
83
95
  /** 显示名称索引 */
@@ -100,7 +112,7 @@ interface CRUDProps<DataSource = any, Key = string> {
100
112
  onClick: (
101
113
  event: React.MouseEvent<HTMLElement>,
102
114
  options: { selectedRowKeys: Key[]; selectedRows: DataSource[] },
103
- ) => Promise<any>;
115
+ ) => Promise<void>;
104
116
  }[];
105
117
  }
106
118