@fe-free/core 3.0.17 → 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,12 @@
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
+
3
10
  ## 3.0.17
4
11
 
5
12
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fe-free/core",
3
- "version": "3.0.17",
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.17"
44
+ "@fe-free/tool": "3.0.18"
45
45
  },
46
46
  "peerDependencies": {
47
47
  "@ant-design/pro-components": "2.8.9",
@@ -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
  };
@@ -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
  },
@@ -41,7 +41,7 @@ function useUpload(
41
41
  const [fileList, setFileList] = useState<UploadFile[]>(defaultFileList);
42
42
 
43
43
  // 找到真正上传成功的。
44
- 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);
45
45
 
46
46
  const handleChange = useCallback(
47
47
  (info) => {
@@ -49,7 +49,7 @@ function useUpload(
49
49
 
50
50
  // 找到真正上传成功的。
51
51
  const newValue = info.fileList
52
- .map((item) => item.url || item.response?.data.url)
52
+ .map((item) => item.url || item.response?.data?.url)
53
53
  .filter(Boolean);
54
54
 
55
55
  onChange?.(multiple ? newValue : newValue[0]);
@@ -245,7 +245,7 @@ function AvatarImageUpload(props: AvatarImageUploadProps) {
245
245
  action={action}
246
246
  customRequest={customRequest}
247
247
  onChange={(info) => {
248
- const url = info.file.response?.data.url;
248
+ const url = info.file.response?.data?.url;
249
249
  if (url) {
250
250
  onChange?.(url);
251
251
  }