zmdms-webui 0.0.73 → 0.0.74

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.
@@ -3,6 +3,7 @@ import { useCallback, useState, useEffect, useMemo } from 'react';
3
3
  import { flushSync } from 'react-dom';
4
4
  import { getFileExtension, isImageExtension, createDownloadLink, createUploadFileLink, getToken, exactRound, times, divide } from 'zmdms-utils';
5
5
  import MemoUploadList from './uploadList.js';
6
+ import { useLatest } from 'ahooks';
6
7
  import { message } from 'antd';
7
8
 
8
9
  // 默认限制的文件类型
@@ -11,17 +12,24 @@ var NO_ACCEPT = ["exe"];
11
12
  * 附件上传前的控制
12
13
  */
13
14
  function useBeforeUpload(props) {
14
- var acceptList = props.acceptList, maxSize = props.maxSize, maxSizeStr = props.maxSizeStr, beforeUpload = props.beforeUpload, isImage = props.isImage;
15
+ var acceptList = props.acceptList, maxSize = props.maxSize, maxSizeStr = props.maxSizeStr, beforeUpload = props.beforeUpload, isImage = props.isImage, disAllowDuplicateFile = props.disAllowDuplicateFile, fileList = props.fileList;
16
+ var fileListRef = useLatest(fileList);
15
17
  return useCallback(function (file, fileList) {
18
+ var _a, _b;
16
19
  var fileName = file.name, fileSize = file.size;
17
20
  // 获取文件后缀
18
- var _a = getFileExtension(fileName), fileExtension = _a[1];
21
+ var _c = getFileExtension(fileName), fileExtension = _c[1];
19
22
  if (beforeUpload) {
20
23
  var result = beforeUpload(file, fileList);
21
24
  if (result) {
22
25
  return result;
23
26
  }
24
27
  }
28
+ if (disAllowDuplicateFile &&
29
+ ((_b = (_a = fileListRef.current) === null || _a === void 0 ? void 0 : _a.find) === null || _b === void 0 ? void 0 : _b.call(_a, function (item) { return item.name === fileName || item.attachName === fileName; }))) {
30
+ message.warning("不能上传同名附件!");
31
+ return MemoUploadList.LIST_IGNORE;
32
+ }
25
33
  // 文件大小
26
34
  if (fileSize === 0) {
27
35
  message.warning("不能上传空文件!");
@@ -49,7 +57,15 @@ function useBeforeUpload(props) {
49
57
  return MemoUploadList.LIST_IGNORE;
50
58
  }
51
59
  return Promise.resolve(file);
52
- }, [acceptList, maxSize, maxSizeStr, beforeUpload, isImage]);
60
+ }, [
61
+ acceptList,
62
+ maxSize,
63
+ maxSizeStr,
64
+ beforeUpload,
65
+ isImage,
66
+ fileListRef,
67
+ disAllowDuplicateFile,
68
+ ]);
53
69
  }
54
70
  /**
55
71
  * 文件改变触发事件
@@ -142,13 +158,18 @@ function useOnChange(props) {
142
158
  innerFileList: innerFileList,
143
159
  setInnerFileList: function (c) {
144
160
  setInnerFileList(c);
145
- if (typeof c === "function") {
146
- var result = c(innerFileList);
147
- onChange && onChange({ file: null, fileList: result });
148
- }
149
- else {
150
- onChange && onChange({ file: null, fileList: c });
151
- }
161
+ // 当删除附加时,需要手动触发这些操作
162
+ var newFileList = typeof c === "function" ? c(innerFileList) : c;
163
+ var successFileList = newFileList.filter(function (item) { return item.status === "done" || !item.status; });
164
+ var errorFileList = newFileList.filter(function (item) { return item.status === "error"; });
165
+ onChange &&
166
+ onChange({
167
+ file: null,
168
+ isComplete: true,
169
+ fileList: newFileList,
170
+ successFileList: successFileList,
171
+ errorFileList: errorFileList,
172
+ });
152
173
  },
153
174
  onChangeHandle: onChangeHandle,
154
175
  };
@@ -43,6 +43,8 @@ interface IUploadListProps extends Omit<UploadProps, "onChange"> {
43
43
  isImage?: boolean;
44
44
  /** 自定义按钮 */
45
45
  customRenderBtn?: React.ReactNode;
46
+ /** 不允许同名附件 */
47
+ disAllowDuplicateFile?: boolean;
46
48
  }
47
49
  interface UploadListComponent extends React.ForwardRefExoticComponent<IUploadListProps & React.RefAttributes<unknown>> {
48
50
  Dragger: typeof Upload.Dragger;
@@ -27,7 +27,7 @@ var MAXSIZE = 104857600; // 100 * 1024 * 1024
27
27
  * 附件大小 attachSize
28
28
  */
29
29
  var UploadList = function (props, ref) {
30
- var children = props.children, btnText = props.btnText, className = props.className, _a = props.showTip, showTip = _a === void 0 ? true : _a, _b = props.maxSize, maxSize = _b === void 0 ? MAXSIZE : _b, showTable = props.showTable, acceptList = props.acceptList, beforeUpload = props.beforeUpload, onChange = props.onChange, PROPS_API_BASEURL = props.API_BASEURL, PROPS_FILE_API_BASEURL = props.FILE_API_BASEURL, action = props.action, headers = props.headers, data = props.data, userName = props.userName, fileList = props.fileList, isPublic = props.isPublic, _c = props.maxPreviewSize, maxPreviewSize = _c === void 0 ? MAX_PREVIEW_SIZE : _c, isPreview = props.isPreview, isDownload = props.isDownload, isDelete = props.isDelete, _d = props.zipName, zipName = _d === void 0 ? "\u6279\u91CF\u4E0B\u8F7D-".concat(Date.now(), ".zip") : _d, isImage = props.isImage, customRenderBtn = props.customRenderBtn, resetProps = __rest(props, ["children", "btnText", "className", "showTip", "maxSize", "showTable", "acceptList", "beforeUpload", "onChange", "API_BASEURL", "FILE_API_BASEURL", "action", "headers", "data", "userName", "fileList", "isPublic", "maxPreviewSize", "isPreview", "isDownload", "isDelete", "zipName", "isImage", "customRenderBtn"]);
30
+ var children = props.children, btnText = props.btnText, className = props.className, _a = props.showTip, showTip = _a === void 0 ? true : _a, _b = props.maxSize, maxSize = _b === void 0 ? MAXSIZE : _b, showTable = props.showTable, acceptList = props.acceptList, beforeUpload = props.beforeUpload, onChange = props.onChange, PROPS_API_BASEURL = props.API_BASEURL, PROPS_FILE_API_BASEURL = props.FILE_API_BASEURL, action = props.action, headers = props.headers, data = props.data, userName = props.userName, fileList = props.fileList, isPublic = props.isPublic, _c = props.maxPreviewSize, maxPreviewSize = _c === void 0 ? MAX_PREVIEW_SIZE : _c, isPreview = props.isPreview, isDownload = props.isDownload, isDelete = props.isDelete, _d = props.zipName, zipName = _d === void 0 ? "\u6279\u91CF\u4E0B\u8F7D-".concat(Date.now(), ".zip") : _d, isImage = props.isImage, customRenderBtn = props.customRenderBtn, disAllowDuplicateFile = props.disAllowDuplicateFile, resetProps = __rest(props, ["children", "btnText", "className", "showTip", "maxSize", "showTable", "acceptList", "beforeUpload", "onChange", "API_BASEURL", "FILE_API_BASEURL", "action", "headers", "data", "userName", "fileList", "isPublic", "maxPreviewSize", "isPreview", "isDownload", "isDelete", "zipName", "isImage", "customRenderBtn", "disAllowDuplicateFile"]);
31
31
  var maxCount = resetProps.maxCount, listType = resetProps.listType, method = resetProps.method;
32
32
  var classes = classNames("ztxk-upload", className, {});
33
33
  var maxSizeStr = formatUnit(maxSize);
@@ -46,6 +46,8 @@ var UploadList = function (props, ref) {
46
46
  maxSizeStr: maxSizeStr,
47
47
  beforeUpload: beforeUpload,
48
48
  isImage: isImage,
49
+ disAllowDuplicateFile: disAllowDuplicateFile,
50
+ fileList: fileList,
49
51
  });
50
52
  // 文件改变逻辑
51
53
  var _g = useOnChange({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-webui",
3
- "version": "0.0.73",
3
+ "version": "0.0.74",
4
4
  "private": false,
5
5
  "main": "dist/index.es.js",
6
6
  "module": "dist/index.es.js",