@fe-free/core 2.5.5 → 2.5.6

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,12 @@
1
1
  # @fe-free/core
2
2
 
3
+ ## 2.5.6
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: crud
8
+ - @fe-free/tool@2.5.6
9
+
3
10
  ## 2.5.5
4
11
 
5
12
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/core",
3
- "version": "2.5.5",
3
+ "version": "2.5.6",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -41,7 +41,7 @@
41
41
  "remark-gfm": "^4.0.1",
42
42
  "vanilla-jsoneditor": "^0.23.1",
43
43
  "zustand": "^4.5.4",
44
- "@fe-free/tool": "2.5.5"
44
+ "@fe-free/tool": "2.5.6"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@ant-design/pro-components": "2.8.9",
@@ -25,8 +25,7 @@ CRUDOfPure 组件。(更简洁的 CRUD 组件)
25
25
  export default meta;
26
26
  type Story = StoryObj<typeof CRUDOfPure>;
27
27
 
28
- // 基础用法
29
- export const Normal: Story = {
28
+ export const Basic: Story = {
30
29
  render: () => {
31
30
  const columns = [
32
31
  {
@@ -88,3 +87,117 @@ export const Normal: Story = {
88
87
  );
89
88
  },
90
89
  };
90
+
91
+ export const WithCreate: Story = {
92
+ render: () => {
93
+ const columns = [
94
+ {
95
+ title: 'id',
96
+ dataIndex: 'id',
97
+ search: true,
98
+ },
99
+ {
100
+ title: '名字(省略)',
101
+ dataIndex: 'name',
102
+ search: true,
103
+ ellipsis: true,
104
+ },
105
+ {
106
+ title: 'city',
107
+ dataIndex: 'city',
108
+ },
109
+ {
110
+ title: 'area',
111
+ dataIndex: 'area',
112
+ },
113
+ ];
114
+
115
+ return (
116
+ <CRUDOfPure
117
+ actions={['create', 'delete']}
118
+ tableProps={{
119
+ columns,
120
+ request: fakeRequest,
121
+ pagination: false,
122
+ search: {
123
+ optionRender: (_, __, dom) => {
124
+ return [
125
+ ...dom,
126
+ <Button key="1" type="primary" className="ml-2">
127
+ 额外的按钮
128
+ </Button>,
129
+ ];
130
+ },
131
+ },
132
+ }}
133
+ requestDeleteByRecord={fakeDeleteByRecord}
134
+ deleteProps={{
135
+ nameIndex: 'id',
136
+ }}
137
+ detailForm={() => (
138
+ <>
139
+ <ProFormText
140
+ name="name"
141
+ label="名字"
142
+ required
143
+ rules={[{ required: true }]}
144
+ extra="extra extra extra extra"
145
+ />
146
+ </>
147
+ )}
148
+ requestCreateByValues={fakeCreate}
149
+ />
150
+ );
151
+ },
152
+ };
153
+
154
+ export const NoSearch: Story = {
155
+ render: () => {
156
+ const columns = [
157
+ {
158
+ title: 'id',
159
+ dataIndex: 'id',
160
+ },
161
+ {
162
+ title: '名字(省略)',
163
+ dataIndex: 'name',
164
+ ellipsis: true,
165
+ },
166
+ {
167
+ title: 'city',
168
+ dataIndex: 'city',
169
+ },
170
+ {
171
+ title: 'area',
172
+ dataIndex: 'area',
173
+ },
174
+ ];
175
+
176
+ return (
177
+ <CRUDOfPure
178
+ actions={['create', 'delete']}
179
+ tableProps={{
180
+ columns,
181
+ request: fakeRequest,
182
+ pagination: false,
183
+ }}
184
+ requestDeleteByRecord={fakeDeleteByRecord}
185
+ deleteProps={{
186
+ nameIndex: 'id',
187
+ }}
188
+ detailForm={() => (
189
+ <>
190
+ <ProFormText
191
+ name="name"
192
+ label="名字"
193
+ required
194
+ rules={[{ required: true }]}
195
+ extra="extra extra extra extra"
196
+ />
197
+ </>
198
+ )}
199
+ requestCreateByValues={fakeCreate}
200
+ />
201
+ );
202
+ },
203
+ };
@@ -1,5 +1,5 @@
1
1
  import classNames from 'classnames';
2
- import { forwardRef } from 'react';
2
+ import { forwardRef, useMemo } from 'react';
3
3
  import type { CRUDMethods, CRUDProps } from '../crud';
4
4
  import { CRUD } from '../crud';
5
5
  import './style.scss';
@@ -33,8 +33,16 @@ function CRUDOfPureComponent(props: CRUDOfPureProps, ref: React.ForwardedRef<CRU
33
33
  return column;
34
34
  });
35
35
 
36
+ const noSearch = useMemo(() => {
37
+ return !props.tableProps.columns?.find((column) => column.search);
38
+ }, [props.tableProps.columns]);
39
+
36
40
  return (
37
- <div className={classNames('fec-crud-of-pure')}>
41
+ <div
42
+ className={classNames('fec-crud-of-pure', {
43
+ 'fec-crud-of-pure-no-search': noSearch,
44
+ })}
45
+ >
38
46
  <CRUD
39
47
  ref={ref}
40
48
  {...props}
@@ -40,7 +40,12 @@
40
40
  }
41
41
 
42
42
  .ant-pro-table-list-toolbar-container {
43
- padding-block: 0;
44
- padding-block-end: 8px;
43
+ padding-block: 0 8px;
44
+ }
45
+
46
+ &.fec-crud-of-pure-no-search {
47
+ .ant-pro-table-list-toolbar-container {
48
+ padding-block-start: 8px;
49
+ }
45
50
  }
46
51
  }
@@ -38,19 +38,28 @@ function Table<
38
38
  const hasSearch = !!newColumns?.find((column) => column.search);
39
39
 
40
40
  let newSearch: any = undefined;
41
+ // 如果有搜索,则使用 search 的配置
41
42
  if (hasSearch) {
42
43
  newSearch = {
43
44
  labelWidth: 'auto',
44
45
  defaultCollapsed: false,
45
46
  ...search,
46
47
  };
47
- } else if (search === false) {
48
- newSearch = false;
49
- } else {
48
+ }
49
+ // 如果是个对象
50
+ else if (typeof search === 'object') {
50
51
  newSearch = {
51
52
  ...search,
52
53
  };
53
54
  }
55
+ // 明确 search false 的情况,这样外部可以控制搜索的显示
56
+ else if (search === false) {
57
+ newSearch = false;
58
+ }
59
+ // 最后兜底 false
60
+ else {
61
+ newSearch = false;
62
+ }
54
63
 
55
64
  return (
56
65
  <ProTable<DataSource, Params>