@hzab/form-render 1.1.0 → 1.1.2

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.
@@ -11,7 +11,7 @@ import React, { useEffect, useState } from "react";
11
11
  import { nanoid } from "nanoid";
12
12
 
13
13
  import { handleInputFileList, getFileName, getFileType } from "./common/utils";
14
- import UploadOss from "./common/ossUpload";
14
+ import LUploadOss from "./common/ossUpload";
15
15
 
16
16
  import PreviewModal, { hasPreviewRender, hasPreviewMedium } from "./components/PreviewModal";
17
17
 
@@ -43,6 +43,9 @@ export function Uploader({ onChange, ...props }) {
43
43
  templateUrl,
44
44
  beforeUploadCheck,
45
45
  templateDownloadText = "模板下载",
46
+ isFileObj = false,
47
+ isFileJson = false,
48
+ UploadOss,
46
49
  } = props;
47
50
 
48
51
  const [fileList, setFileList] = useState([]);
@@ -60,8 +63,14 @@ export function Uploader({ onChange, ...props }) {
60
63
  _file = _file?.originFileObj;
61
64
  }
62
65
  // 从文件对象中获取 url,ossPromise 为上传中的文件,兼容 file 为字符串的情况
63
- let str = (await _file.ossPromise) || _file.url || _file.ossUrl || _file;
64
- _files[i] = str;
66
+
67
+ if (isFileObj) {
68
+ let { ossUrl, url, uid, name, type } = (await _file.ossPromise) || _file;
69
+ _files[i] = { ossUrl, url, uid, name, type };
70
+ } else {
71
+ let str = (await _file.ossPromise) || _file.url || _file.ossUrl || _file;
72
+ _files[i] = str;
73
+ }
65
74
  }
66
75
  }
67
76
  // 处理空数据情况
@@ -71,17 +80,25 @@ export function Uploader({ onChange, ...props }) {
71
80
  // maxCount 为 1 的时候返回结果去除数组
72
81
  _files = _files[0];
73
82
  }
74
- onChange && onChange?.(_files);
83
+ onChange && onChange?.(isFileJson ? JSON.stringify(_files) : _files);
75
84
  };
76
85
 
77
86
  useEffect(() => {
78
87
  if (!value) {
79
88
  return;
80
89
  }
81
- let _list = value;
90
+
91
+ let _list = [];
92
+ try {
93
+ _list = JSON.parse(value);
94
+ } catch (e) {
95
+ _list = value;
96
+ }
97
+
82
98
  if (typeof _list === "string") {
83
99
  _list = value.split(",");
84
100
  }
101
+
85
102
  if (Array.isArray(_list)) {
86
103
  _list = _list.map((res) => {
87
104
  if (typeof res === "string") {
@@ -173,7 +190,8 @@ export function Uploader({ onChange, ...props }) {
173
190
  },
174
191
  customRequest: isOssUpload
175
192
  ? function customRequest({ action, data, file, filename, headers, method, onSuccess, onProgress, onError }) {
176
- const ossUpload = new UploadOss({
193
+ const _UploadOss = UploadOss || LUploadOss;
194
+ const ossUpload = new _UploadOss({
177
195
  serverUrl: ossUrl,
178
196
  ...ossOpt,
179
197
  });
@@ -188,7 +206,7 @@ export function Uploader({ onChange, ...props }) {
188
206
  file.url = res?.data?.data?.fileUrl ?? res?.data?.fileUrl ?? res?.fileUrl;
189
207
  file.ossUrl = file.url;
190
208
  onSuccess(file);
191
- return file.ossUrl;
209
+ return isFileObj ? file : file.ossUrl;
192
210
  })
193
211
  .catch(onError);
194
212
  }