@fe-free/core 1.4.6 → 1.4.8

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.8
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: crud
8
+ - @fe-free/tool@1.4.8
9
+
10
+ ## 1.4.7
11
+
12
+ ### Patch Changes
13
+
14
+ - fix: crud
15
+ - @fe-free/tool@1.4.7
16
+
3
17
  ## 1.4.6
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.6",
3
+ "version": "1.4.8",
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.6"
38
+ "@fe-free/tool": "1.4.8"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@ant-design/pro-components": "^2.8.7",
package/src/crud/crud.tsx CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { ActionType } from '@ant-design/pro-components';
2
- import { Button, Space } from 'antd';
2
+ import { Button, message, Space } from 'antd';
3
+ import { isString } from 'lodash-es';
3
4
  import { forwardRef, useCallback, useImperativeHandle, useMemo, useRef } from 'react';
4
5
  import type { TableProps } from '../table';
5
6
  import { Table } from '../table';
@@ -73,7 +74,17 @@ function CRUDComponent<
73
74
  (record) => {
74
75
  return () => {
75
76
  if (requestDeleteByRecord) {
77
+ let content = '删除成功';
78
+ if (deleteProps?.successText) {
79
+ content = isString(deleteProps.successText)
80
+ ? deleteProps.successText
81
+ : deleteProps.successText();
82
+ }
76
83
  return requestDeleteByRecord(record).then(() => {
84
+ message.open({
85
+ type: 'success',
86
+ content,
87
+ });
77
88
  actionRef.current?.reload();
78
89
  });
79
90
  }
@@ -81,7 +92,7 @@ function CRUDComponent<
81
92
  throw new Error('没有传 requestDeleteByRecord');
82
93
  };
83
94
  },
84
- [requestDeleteByRecord],
95
+ [deleteProps, requestDeleteByRecord],
85
96
  );
86
97
 
87
98
  const handleReload = useCallback(() => {
@@ -89,6 +100,8 @@ function CRUDComponent<
89
100
  }, []);
90
101
 
91
102
  const newColumns = useMemo(() => {
103
+ const idField = tableProps.rowKey || 'id';
104
+
92
105
  const operateColumn = {
93
106
  title: '操作',
94
107
  fixed: 'right',
@@ -99,7 +112,7 @@ function CRUDComponent<
99
112
  {operateColumnProps?.moreOperator && operateColumnProps.moreOperator(record)}
100
113
  {actions.includes('read') && (
101
114
  <CRUDDetail
102
- id={record.id}
115
+ id={record[idField]}
103
116
  record={record}
104
117
  onSuccess={handleReload}
105
118
  trigger={<a>{readProps?.operateText || '查看'}</a>}
@@ -117,7 +130,7 @@ function CRUDComponent<
117
130
  )}
118
131
  {actions.includes('update') && (
119
132
  <CRUDDetail
120
- id={record.id}
133
+ id={record[idField]}
121
134
  record={record}
122
135
  onSuccess={handleReload}
123
136
  trigger={<a>{updateProps?.operateText || '编辑'}</a>}
@@ -155,9 +168,10 @@ function CRUDComponent<
155
168
 
156
169
  return tableProps.columns as TableProps['columns'];
157
170
  }, [
171
+ tableProps.rowKey,
172
+ tableProps.columns,
158
173
  operateColumnProps,
159
174
  actions,
160
- tableProps.columns,
161
175
  handleReload,
162
176
  readProps?.operateText,
163
177
  readProps?.target,
@@ -98,6 +98,8 @@ interface CRUDProps<DataSource = any, Key = string> {
98
98
  desc?: string;
99
99
  /** 文本 */
100
100
  operateText?: string;
101
+ /** 成功文案 */
102
+ successText?: string | (() => string);
101
103
  };
102
104
 
103
105
  // *** 批量操作 ***
@@ -77,6 +77,13 @@ export const ProFormSwitchNumberComponent: Story = {
77
77
  render: () => (
78
78
  <ProFormBase>
79
79
  <ProFormSwitchNumber name="switchNumber" />
80
+ <ProFormSwitchNumber
81
+ name="switchNumber"
82
+ fieldProps={{
83
+ checkedChildren: '开启',
84
+ unCheckedChildren: '关闭',
85
+ }}
86
+ />
80
87
  </ProFormBase>
81
88
  ),
82
89
  };
@@ -1,6 +1,10 @@
1
- export { ProFormSwitchNumber, SwitchNumber, type SwitchNumberProps } from './form_switch_number';
2
1
  export { ProFormJavascript } from './pro_form_javascript';
3
2
  export { ProFormJSON } from './pro_form_json';
3
+ export {
4
+ ProFormSwitchNumber,
5
+ SwitchNumber,
6
+ type SwitchNumberProps,
7
+ } from './pro_form_switch_number';
4
8
  import { pinyinMatch } from '@fe-free/tool';
5
9
 
6
10
  /** ProFromSelect 搜索相关 props。 支持 1 搜索 2 拼音过滤 */
@@ -12,7 +12,6 @@ function JavascriptItem(props: EditorJavascriptProps) {
12
12
  }
13
13
 
14
14
  function ProFormJavascript(props: ProFormItemProps<EditorJavascriptProps>) {
15
- // 没搞明白 cacheFormSwr, proFieldKey, onBlur,先这样处理
16
15
  /* eslint-disable-next-line */
17
16
  const { fieldProps, readonly, ...rest } = props;
18
17
 
@@ -12,7 +12,6 @@ function JSONItem(props: EditorJSONProps) {
12
12
  }
13
13
 
14
14
  function ProFormJSON(props: ProFormItemProps<EditorJSONProps>) {
15
- // 没搞明白 cacheFormSwr, proFieldKey, onBlur,先这样处理
16
15
  /* eslint-disable-next-line */
17
16
  const { fieldProps, readonly, ...rest } = props;
18
17
 
@@ -25,7 +25,6 @@ function SwitchNumber(props: SwitchNumberProps) {
25
25
  }
26
26
 
27
27
  function ProFormSwitchNumber(props: ProFormItemProps<SwitchNumberProps>) {
28
- // 没搞明白 cacheFormSwr, proFieldKey, onBlur,先这样处理
29
28
  /* eslint-disable-next-line */
30
29
  const { fieldProps, readonly, ...rest } = props;
31
30