@fe-free/core 3.0.16 → 3.0.18

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
+ ## 3.0.18
4
+
5
+ ### Patch Changes
6
+
7
+ - feat: rules
8
+ - @fe-free/tool@3.0.18
9
+
10
+ ## 3.0.17
11
+
12
+ ### Patch Changes
13
+
14
+ - feat: upload
15
+ - @fe-free/tool@3.0.17
16
+
3
17
  ## 3.0.16
4
18
 
5
19
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/core",
3
- "version": "3.0.16",
3
+ "version": "3.0.18",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -41,7 +41,7 @@
41
41
  "safe-stable-stringify": "^2.5.0",
42
42
  "vanilla-jsoneditor": "^0.23.1",
43
43
  "zustand": "^4.5.4",
44
- "@fe-free/tool": "3.0.16"
44
+ "@fe-free/tool": "3.0.18"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@ant-design/pro-components": "2.8.9",
package/src/crud/crud.tsx CHANGED
@@ -5,11 +5,11 @@ import classNames from 'classnames';
5
5
  import { isString } from 'lodash-es';
6
6
  import { useCallback, useImperativeHandle, useMemo, useRef } from 'react';
7
7
  import { Link } from 'react-router-dom';
8
- import type { TableProps } from '../table';
9
- import { getTableScroll, Table } from '../table';
10
8
  import { OperateDelete } from './crud_delete';
11
9
  import { CRUDDetail } from './crud_detail';
12
10
  import './style.scss';
11
+ import type { TableProps } from './table';
12
+ import { getTableScroll, Table } from './table';
13
13
  import type { CRUDProps } from './types';
14
14
  import { useRowSelection } from './use_row_selection';
15
15
  import { useTips } from './use_tips';
@@ -1,6 +1,6 @@
1
1
  import type { ActionType, ProFormInstance } from '@ant-design/pro-components';
2
2
  import type { MouseEvent, ReactNode, Ref, RefObject } from 'react';
3
- import type { TableProps } from '../table';
3
+ import type { TableProps } from './table';
4
4
 
5
5
  /**
6
6
  * create 创建
@@ -16,6 +16,7 @@ import {
16
16
  ProFormUpload,
17
17
  ProFormUploadDragger,
18
18
  } from '@fe-free/core';
19
+ import { sleep } from '@fe-free/tool';
19
20
  import type { Meta, StoryObj } from '@storybook/react-vite';
20
21
  import { useState } from 'react';
21
22
 
@@ -191,31 +192,19 @@ export const ProFormListBooleanComponent: Story = {
191
192
  };
192
193
 
193
194
  function customRequest(option: any) {
194
- const { file, onProgress, onSuccess } = option;
195
-
196
- // 模拟上传进度
197
- let percent = 0;
198
- const interval = setInterval(() => {
199
- percent += 10;
200
- onProgress({ percent });
201
-
202
- if (percent >= 100) {
203
- clearInterval(interval);
204
- // 模拟上传成功
205
- onSuccess({
206
- data: {
207
- url: `https://picsum.photos/200/300?random=${Date.now()}`,
208
- name: file.name,
209
- uid: file.uid,
210
- },
211
- });
212
- }
213
- }, 1000);
195
+ const { onSuccess } = option;
196
+ // fake request
197
+ sleep(1000).then(() => {
198
+ onSuccess({
199
+ data: {
200
+ url: `https://picsum.photos/200/300?random=${Date.now()}`,
201
+ },
202
+ });
203
+ });
214
204
 
215
205
  // 返回 abort 方法,用于取消上传
216
206
  return {
217
207
  abort: () => {
218
- clearInterval(interval);
219
208
  console.log('上传已取消');
220
209
  },
221
210
  };
@@ -243,7 +232,8 @@ export const ProFormUploadComponent: Story = {
243
232
  label="knowledge_files_dragger"
244
233
  name="knowledge_files_dragger"
245
234
  fieldProps={{
246
- accept: '.doc,.docx,.pdf,.ppt,.jpg, jpeg,.png,.mp3,.mp4,.txt,.markdown,.excel',
235
+ directory: true,
236
+ accept: '.doc,.docx,.pdf,.ppt,.jpg,.jpeg,.png,.mp3,.mp4,.txt,.markdown,.excel',
247
237
  multiple: true,
248
238
  maxCount: 100,
249
239
  customRequest,
@@ -2,6 +2,7 @@ import type { ProFormItemProps } from '@ant-design/pro-components';
2
2
  import { ProForm } from '@ant-design/pro-components';
3
3
  import { Input, InputNumber, Switch } from 'antd';
4
4
 
5
+ import { uniq, uniqBy } from 'lodash-es';
5
6
  import { ProFormListHelper } from './form_list_helper';
6
7
 
7
8
  interface ListTextProps {
@@ -104,10 +105,18 @@ function ProFormListBase(props) {
104
105
  if (value?.some((item) => item.value === undefined)) {
105
106
  return Promise.reject('每个选项都不能为空');
106
107
  }
108
+ // 不能有重复的 value
109
+ if (uniqBy(value, 'value').length !== value.length) {
110
+ return Promise.reject('不能有重复');
111
+ }
107
112
  } else {
108
113
  if (value?.some((item) => item === undefined)) {
109
114
  return Promise.reject('每个选项都不能为空');
110
115
  }
116
+ // 不能有重复的 value
117
+ if (uniq(value).length !== value.length) {
118
+ return Promise.reject('不能有重复');
119
+ }
111
120
  }
112
121
  return Promise.resolve();
113
122
  },
package/src/index.ts CHANGED
@@ -57,8 +57,6 @@ export type { RecordArrayProps, RecordProps } from './record';
57
57
  export { routeTool } from './route';
58
58
  export { NumberSlider, PercentageSlider } from './slider';
59
59
  export type { NumberSliderProps, PercentageSliderProps } from './slider';
60
- export { Table } from './table';
61
- export type { TableProps } from './table';
62
60
  export { Tabs } from './tabs';
63
61
  export type { TabsProps } from './tabs';
64
62
  export { themeVariables } from './theme';
@@ -16,6 +16,7 @@ interface UploadBaseProps {
16
16
  customRequest?: AntdUploadProps['customRequest'];
17
17
  listType?: AntdUploadProps['listType'];
18
18
  accept?: string;
19
+ directory?: AntdUploadProps['directory'];
19
20
  }
20
21
 
21
22
  interface UploadProps extends UploadBaseProps {
@@ -40,7 +41,7 @@ function useUpload(
40
41
  const [fileList, setFileList] = useState<UploadFile[]>(defaultFileList);
41
42
 
42
43
  // 找到真正上传成功的。
43
- const successList = fileList.map((item) => item.url || item.response?.data.url).filter(Boolean);
44
+ const successList = fileList.map((item) => item.url || item.response?.data?.url).filter(Boolean);
44
45
 
45
46
  const handleChange = useCallback(
46
47
  (info) => {
@@ -48,7 +49,7 @@ function useUpload(
48
49
 
49
50
  // 找到真正上传成功的。
50
51
  const newValue = info.fileList
51
- .map((item) => item.url || item.response?.data.url)
52
+ .map((item) => item.url || item.response?.data?.url)
52
53
  .filter(Boolean);
53
54
 
54
55
  onChange?.(multiple ? newValue : newValue[0]);
@@ -92,7 +93,8 @@ function useUpload(
92
93
  }
93
94
 
94
95
  function Upload(props: ImageUploadProps) {
95
- const { multiple, maxCount, showCount, action, customRequest, listType, accept } = props;
96
+ const { multiple, maxCount, showCount, action, customRequest, listType, accept, directory } =
97
+ props;
96
98
  const { onChange, beforeUpload, isDisabled, fileList } = useUpload(props);
97
99
 
98
100
  return (
@@ -106,6 +108,7 @@ function Upload(props: ImageUploadProps) {
106
108
  maxCount={multiple ? maxCount : 1}
107
109
  multiple={multiple}
108
110
  beforeUpload={beforeUpload}
111
+ directory={directory}
109
112
  // 不可,否则会没法删除
110
113
  // disabled={isDisabled}
111
114
  >
@@ -140,6 +143,7 @@ function UploadDragger(props: UploadDraggerProps) {
140
143
  title,
141
144
  description,
142
145
  showStatus,
146
+ directory,
143
147
  } = props;
144
148
  const { onChange, beforeUpload, isDisabled, fileList, successList } = useUpload(props);
145
149
 
@@ -174,6 +178,7 @@ function UploadDragger(props: UploadDraggerProps) {
174
178
  maxCount={multiple ? maxCount : 1}
175
179
  multiple={multiple}
176
180
  beforeUpload={beforeUpload}
181
+ directory={directory}
177
182
  // 不可,否则会没法删除
178
183
  // disabled={isDisabled}
179
184
  className={classNames('fec-upload-dragger', {
@@ -240,7 +245,7 @@ function AvatarImageUpload(props: AvatarImageUploadProps) {
240
245
  action={action}
241
246
  customRequest={customRequest}
242
247
  onChange={(info) => {
243
- const url = info.file.response?.data.url;
248
+ const url = info.file.response?.data?.url;
244
249
  if (url) {
245
250
  onChange?.(url);
246
251
  }
@@ -1,95 +0,0 @@
1
- import type { ProColumns } from '@ant-design/pro-components';
2
- import { Table } from '@fe-free/core';
3
- import type { Meta, StoryObj } from '@storybook/react-vite';
4
- import { fakeData } from '../crud/demo/data';
5
-
6
- const meta: Meta<typeof Table> = {
7
- title: '@fe-free/core/Table',
8
- component: Table,
9
- tags: ['autodocs'],
10
- parameters: {
11
- docs: {
12
- description: {
13
- component: `Table 基于 ProTable 做了一些封装:<br>
14
- - props column 需要显示的提供 search: true;
15
- - 列宽默认 120,和滚动条
16
- - 搜索样式做了默认设置,具体见代码
17
- - 页码做了默认设置,具体见代码
18
- `,
19
- },
20
- },
21
- },
22
- };
23
-
24
- export default meta;
25
- type Story = StoryObj<typeof Table>;
26
-
27
- // 定义列配置
28
- const columns: ProColumns[] = [
29
- {
30
- title: 'id',
31
- dataIndex: 'id',
32
- search: true,
33
- },
34
- {
35
- title: '名字(省略)',
36
- dataIndex: 'name',
37
- search: true,
38
- ellipsis: true,
39
- },
40
- {
41
- title: 'city',
42
- dataIndex: 'city',
43
- },
44
- {
45
- title: 'area',
46
- dataIndex: 'area',
47
- },
48
- ];
49
-
50
- export const Basic: Story = {
51
- render: () => (
52
- <Table
53
- rowKey="id"
54
- columns={columns}
55
- request={async (params) => {
56
- console.log(params);
57
- return {
58
- data: fakeData,
59
- success: true,
60
- total: fakeData.length,
61
- };
62
- }}
63
- />
64
- ),
65
- };
66
-
67
- export const ScrollX: Story = {
68
- render: () => (
69
- <div className="w-[400px]">
70
- <Table
71
- rowKey="id"
72
- columns={[
73
- {
74
- title: 'id',
75
- dataIndex: 'id',
76
- },
77
- {
78
- title: '名字(省略)',
79
- dataIndex: 'name',
80
-
81
- ellipsis: true,
82
- },
83
- {
84
- title: 'city',
85
- dataIndex: 'city',
86
- },
87
- {
88
- title: 'area',
89
- dataIndex: 'area',
90
- },
91
- ]}
92
- />
93
- </div>
94
- ),
95
- };
File without changes
File without changes