@hzab/form-render 1.7.7 → 1.7.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,3 +1,7 @@
1
+ # @hzab/form-render@1.7.8
2
+
3
+ fix: upload onRemove 数据处理
4
+
1
5
  # @hzab/form-render@1.7.7
2
6
 
3
7
  feat: scenario form-render
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/form-render",
3
- "version": "1.7.7",
3
+ "version": "1.7.8",
4
4
  "description": "",
5
5
  "main": "src",
6
6
  "scripts": {
@@ -54,7 +54,6 @@ export interface IFile {
54
54
  /** 最后更新时间戳 */
55
55
  lastModified?: number;
56
56
  thumbUrl?: string;
57
-
58
57
  }
59
58
 
60
59
  /**
@@ -69,9 +68,12 @@ export interface IHandlerOpt {
69
68
  itemMode: "object" | "file" | "url" | "jsonStr";
70
69
  /** 预览配置参数 */
71
70
  previewConfig?: Object;
72
- thumbnailParams?: string,
73
- selfUrlList?: string[]
74
-
71
+ thumbnailParams?: string;
72
+ selfUrlList?: string[];
73
+ /** maxCount === 1 时是否去除数组,直接返回内容 */
74
+ isResRemoveArr: boolean;
75
+ /** 最大文件数量 */
76
+ maxCount: number;
75
77
  }
76
78
 
77
79
  /** 内部文件格式 */
@@ -128,7 +130,9 @@ export const objStrToObj = function (objStr) {
128
130
  if (/^\[.*\]$|^\{.*\}$/.test(_objStr)) {
129
131
  try {
130
132
  _objStr = JSON.parse(_objStr);
131
- } catch (error) { }
133
+ } catch (error) {
134
+ console.error(error);
135
+ }
132
136
  }
133
137
  }
134
138
  return _objStr;
@@ -191,7 +195,7 @@ export const handleInputItem = (data, opt: IHandlerOpt) => {
191
195
  console.warn("Upload handleInputData 请传入正确的数据");
192
196
  return data;
193
197
  }
194
- const { thumbnailParams, selfUrlList } = opt
198
+ const { thumbnailParams, selfUrlList } = opt;
195
199
 
196
200
  let file = {
197
201
  ...fileTpl,
@@ -307,8 +311,6 @@ export const handleInputFileList = (fileList, opt: IHandlerOpt) => {
307
311
  return _fileList;
308
312
  };
309
313
 
310
- export const handleFileName = function () { };
311
-
312
314
  /**
313
315
  * 子项数据归一化
314
316
  * @param data
@@ -404,8 +406,15 @@ export const handleOutputFileList = function (fileList, opt: IHandlerOpt) {
404
406
 
405
407
  // 数组
406
408
  if (listMode === "array") {
407
- return _fileList?.map((it) => handleUploadItem(it, opt));
409
+ const { isResRemoveArr, maxCount } = opt || {};
410
+ let _files = _fileList?.map((it) => handleUploadItem(it, opt));
411
+ if (isResRemoveArr && maxCount === 1) {
412
+ // maxCount 为 1 的时候返回结果去除数组包裹
413
+ _files = _files[0];
414
+ }
415
+ return _files;
408
416
  }
417
+
409
418
  // 序列化后的字符串
410
419
  if (listMode === "jsonStr") {
411
420
  return JSON.stringify(_fileList?.map((it) => handleUploadItem(it, opt)));
@@ -65,7 +65,7 @@ export function Uploader({ onChange, ...props }) {
65
65
  isFileJson = false,
66
66
  thumbnailParams = "image_process=resize,p_30",
67
67
  selfUrlList = ["https://self-oss.abt.hzabjt.com"],
68
- readPretty
68
+ readPretty,
69
69
  } = props;
70
70
  const isPrivateStore =
71
71
  props.uploadParams?.fileAcl === "private" || props.ossOpt?.signatureParams?.fileAcl === "private";
@@ -109,12 +109,12 @@ export function Uploader({ onChange, ...props }) {
109
109
  let _file = _files[i]?.originFileObj || _files[i];
110
110
  if (!_file.url) {
111
111
  const promiseRes = await _file.ossPromise;
112
- _file.url =
113
- typeof promiseRes === "object"
114
- ? promiseRes.url
115
- : promiseRes || _file.ossUrl || typeof _file === "string"
116
- ? _file
117
- : "";
112
+ _file.url = "";
113
+ if (typeof promiseRes === "object") {
114
+ _file.url = promiseRes.url;
115
+ } else if (promiseRes || _file.ossUrl || typeof _file === "string") {
116
+ _file.url = _file;
117
+ }
118
118
 
119
119
  if (typeof _file.url === "string") {
120
120
  _files[i].url = _file.url;
@@ -127,14 +127,11 @@ export function Uploader({ onChange, ...props }) {
127
127
 
128
128
  // 处理出参格式
129
129
  _files = handleOutputFileList(_files, {
130
+ isResRemoveArr,
131
+ maxCount,
130
132
  ...fileListConf,
131
133
  });
132
134
 
133
- if (isResRemoveArr && maxCount === 1 && Array.isArray(_files)) {
134
- // maxCount 为 1 的时候返回结果去除数组
135
- _files = _files[0];
136
- }
137
-
138
135
  onChange && onChange?.(_files);
139
136
  };
140
137
 
@@ -158,7 +155,11 @@ export function Uploader({ onChange, ...props }) {
158
155
 
159
156
  const onRemove = (file) => {
160
157
  const files = (fileList || []).filter((v) => v.url !== file.url);
161
- onChange && onChange(files);
158
+ // 处理出参格式
159
+ const _files = handleOutputFileList(files, {
160
+ ...fileListConf,
161
+ });
162
+ onChange && onChange(_files);
162
163
  };
163
164
 
164
165
  // 自定义请求逻辑
@@ -285,9 +286,9 @@ export function Uploader({ onChange, ...props }) {
285
286
  };
286
287
  const isShowUploadBtn = useMemo(() => {
287
288
  if (disabled || readOnly || readPretty) {
288
- return null
289
+ return null;
289
290
  }
290
- return (maxCount && maxCount > fileList.length ? (
291
+ return maxCount && maxCount > fileList.length ? (
291
292
  listType === "picture-card" ? (
292
293
  checking ? (
293
294
  "检测中"
@@ -299,8 +300,8 @@ export function Uploader({ onChange, ...props }) {
299
300
  {btnText}
300
301
  </Button>
301
302
  )
302
- ) : null)
303
- }, [maxCount, fileList, disabled, readOnly, readPretty, checking, btnText, listType])
303
+ ) : null;
304
+ }, [maxCount, fileList, disabled, readOnly, readPretty, checking, btnText, listType]);
304
305
  return (
305
306
  <>
306
307
  <AUpload className="oss-uploader" {..._uploadProps}>