@hzab/form-render 1.7.1 → 1.7.2-beta

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,4 +1,9 @@
1
+ # @hzab/form-render@1.7.2
2
+
3
+ feat: 上传图片列表支持缩略图
4
+
1
5
  # @hzab/form-render@1.7.1
6
+
2
7
  feat: 文件上传组件删除后重走数据处理逻辑
3
8
 
4
9
  # @hzab/form-render@1.7.0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/form-render",
3
- "version": "1.7.1",
3
+ "version": "1.7.2-beta",
4
4
  "description": "",
5
5
  "main": "src",
6
6
  "scripts": {
@@ -42,8 +42,8 @@ export const RichEditor = observer(function (props: PropsType, parentRef) {
42
42
  offlineServerUrl = "",
43
43
  uploadParams = {},
44
44
  // ossUrl = "https://test-abt.hzabjt.com:18091/api/v1/user/oss/getWebOssConfig",
45
- ossServerUrl = "/api/v1/user/oss/getWebOssConfig",
46
- ossUrl = "/api/v1/user/oss/getWebOssConfig",
45
+ ossServerUrl = "/api/v1/common/oss/getWebOssConfig",
46
+ ossUrl = "/api/v1/common/oss/getWebOssConfig",
47
47
  zIndex = 9999,
48
48
  } = props;
49
49
  const isPrivateStore =
@@ -52,6 +52,8 @@ export interface IFile {
52
52
  createTime?: string;
53
53
  /** 最后更新时间戳 */
54
54
  lastModified?: number;
55
+ thumbUrl?: string;
56
+
55
57
  }
56
58
 
57
59
  /**
@@ -66,6 +68,9 @@ export interface IHandlerOpt {
66
68
  itemMode: "object" | "file" | "url" | "jsonStr";
67
69
  /** 预览配置参数 */
68
70
  previewConfig?: Object;
71
+ thumbnailParams?: string,
72
+ selfUrlList?: string[]
73
+
69
74
  }
70
75
 
71
76
  /** 内部文件格式 */
@@ -122,7 +127,7 @@ export const objStrToObj = function (objStr) {
122
127
  if (/^\[.*\]$|^\{.*\}$/.test(_objStr)) {
123
128
  try {
124
129
  _objStr = JSON.parse(_objStr);
125
- } catch (error) {}
130
+ } catch (error) { }
126
131
  }
127
132
  }
128
133
  return _objStr;
@@ -164,7 +169,16 @@ export function mergePreviewConfig(uri, previewConfig) {
164
169
 
165
170
  return _uri;
166
171
  }
167
-
172
+ /**判断是否私有 */
173
+ const isSelf = (selfUrlList, fileUrl) => {
174
+ let flag = "?";
175
+ selfUrlList?.forEach((el) => {
176
+ if (fileUrl?.startsWith(el)) {
177
+ flag = "&";
178
+ }
179
+ });
180
+ return flag;
181
+ };
168
182
  /**
169
183
  * 子项数据归一化
170
184
  * 字符串:url、base64
@@ -176,6 +190,8 @@ export const handleInputItem = (data, opt: IHandlerOpt) => {
176
190
  console.warn("Upload handleInputData 请传入正确的数据");
177
191
  return data;
178
192
  }
193
+ const { thumbnailParams, selfUrlList } = opt
194
+
179
195
  let file = {
180
196
  ...fileTpl,
181
197
  };
@@ -184,7 +200,7 @@ export const handleInputItem = (data, opt: IHandlerOpt) => {
184
200
  if (typeof _data === "string") {
185
201
  const obj = getFileNameObj(_data);
186
202
  file.id = obj?.id;
187
- file.uid = file.id || nanoidNumALetters();
203
+ file.uid = file.id;
188
204
  file.url = _data;
189
205
  file.storeUrl = _data;
190
206
  file.name = getFullFileName(file.url);
@@ -192,10 +208,12 @@ export const handleInputItem = (data, opt: IHandlerOpt) => {
192
208
  file.originalFilename = getFullFileName(file.url);
193
209
  file.type = getFileType(file.url);
194
210
  file.ext = getFileExt(file.url);
211
+ file.thumbUrl = `${_data}${thumbnailParams ? isSelf(selfUrlList, _data) + thumbnailParams : ""}`;
195
212
  } else if (typeof _data === "object") {
196
213
  const sourceData = _data.originFileObj || _data;
197
214
  file.id = _data.id || _data.uid;
198
215
  file.url = sourceData.url || sourceData.ossUrl;
216
+ file.thumbUrl = `${file.url}${thumbnailParams ? isSelf(selfUrlList, file.url) + thumbnailParams : ""}`;
199
217
  file.storeUrl = file.url;
200
218
  file.originalFilename = _data.originalFilename || getFullFileName(file.url) || _data.name;
201
219
  file.name = _data.filename || _data.name || getFullFileName(file.url);
@@ -284,7 +302,7 @@ export const handleInputFileList = (fileList, opt: IHandlerOpt) => {
284
302
  return _fileList;
285
303
  };
286
304
 
287
- export const handleFileName = function () {};
305
+ export const handleFileName = function () { };
288
306
 
289
307
  /**
290
308
  * 子项数据归一化
@@ -13,7 +13,7 @@ export async function handleOssUpload(files, opt) {
13
13
  ...opt,
14
14
  axios: opt.axios,
15
15
  axiosConf: axiosConf,
16
- serverUrl: ossUrl || "/api/v1/user/oss/getWebOssConfig",
16
+ serverUrl: ossUrl || "/api/v1/common/oss/getWebOssConfig",
17
17
  });
18
18
 
19
19
  const promise = [];
@@ -47,7 +47,7 @@ export function Uploader({ onChange, ...props }) {
47
47
  listType = "text",
48
48
  disabled = false,
49
49
  readOnly = false,
50
- ossServerUrl = "/api/v1/user/oss/getWebOssConfig",
50
+ ossServerUrl = "/api/v1/common/oss/getWebOssConfig",
51
51
  // 是否使用 oss 上传文件
52
52
  isOssUpload = true,
53
53
  // 是否使用字符串结果
@@ -62,6 +62,8 @@ export function Uploader({ onChange, ...props }) {
62
62
  templateDownloadText = "模板下载",
63
63
  isFileObj = false,
64
64
  isFileJson = false,
65
+ thumbnailParams = "image_process=resize,p_30",
66
+ selfUrlList = ["https://self-oss.abt.hzabjt.com"]
65
67
  } = props;
66
68
  const isPrivateStore =
67
69
  props.uploadParams?.fileAcl === "private" || props.ossOpt?.signatureParams?.fileAcl === "private";
@@ -109,8 +111,8 @@ export function Uploader({ onChange, ...props }) {
109
111
  typeof promiseRes === "object"
110
112
  ? promiseRes.url
111
113
  : promiseRes || _file.ossUrl || typeof _file === "string"
112
- ? _file
113
- : "";
114
+ ? _file
115
+ : "";
114
116
 
115
117
  if (typeof _file.url === "string") {
116
118
  _files[i].url = _file.url;
@@ -135,7 +137,7 @@ export function Uploader({ onChange, ...props }) {
135
137
  };
136
138
 
137
139
  useEffect(() => {
138
- const list = handleInputFileList(value, { ...fileListConf, maxCount, previewConfig });
140
+ const list = handleInputFileList(value, { ...fileListConf, maxCount, previewConfig, thumbnailParams, selfUrlList });
139
141
 
140
142
  async function handlePreview() {
141
143
  await handlePreviewUrls(list, {
@@ -153,13 +155,8 @@ export function Uploader({ onChange, ...props }) {
153
155
  }, [value]);
154
156
 
155
157
  const onRemove = (file) => {
156
- const files = (fileList || []).filter((v) => v.uid !== file.uid);
157
- let _files = [...files];
158
- // 处理出参格式
159
- _files = handleOutputFileList(_files, {
160
- ...fileListConf,
161
- });
162
- onChange && onChange(_files);
158
+ const files = (fileList || []).filter((v) => v.url !== file.url);
159
+ onChange && onChange(files);
163
160
  };
164
161
 
165
162
  // 自定义请求逻辑