venus-design 1.0.75 → 1.0.77

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.
@@ -132,6 +132,12 @@ export declare const VenusFormSlider: (props: any) => React.JSX.Element;
132
132
  * @returns
133
133
  */
134
134
  export declare const VenusFormUploadPro: (props: any) => React.JSX.Element;
135
+ /**
136
+ * 上传组件
137
+ * @param props
138
+ * @returns
139
+ */
140
+ export declare const VenusFormEditor: (props: any) => React.JSX.Element;
135
141
  /**
136
142
  * 新上传组件
137
143
  */
@@ -66,13 +66,14 @@ var _excluded = ["children", "pageLoading", "pageFormClassName", "submitter", "s
66
66
  _excluded38 = ["comAttr", "placeholder", "disabled", "isDuo"],
67
67
  _excluded39 = ["comAttr", "placeholder", "disabled", "isDuo"],
68
68
  _excluded40 = ["comAttr", "placeholder", "disabled", "isDuo"],
69
- _excluded41 = ["comAttr", "placeholder", "disabled", "isDuo"];
69
+ _excluded41 = ["comAttr", "placeholder", "disabled", "isDuo"],
70
+ _excluded42 = ["comAttr", "placeholder", "disabled", "isDuo"];
70
71
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
71
72
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
72
73
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
73
74
  import React from 'react';
74
75
  import classnames from 'classnames';
75
- import { CheckBoxInput, NumberPercent, NumberUnit, RadioAndInput, Search, TreeSelect, UploadImage, VenusUploadSecLevelForm, Upload, VenusUploadSecLevel } from "./..";
76
+ import { CheckBoxInput, NumberPercent, NumberUnit, RadioAndInput, Search, TreeSelect, UploadImage, VenusUploadSecLevelForm, Upload, VenusUploadSecLevel, VenusEditor } from "./..";
76
77
  import "./styles.less";
77
78
  import { StyleProvider, legacyLogicalPropertiesTransformer } from "@ant-design/cssinjs";
78
79
  var ProForm = function ProForm(props) {
@@ -905,17 +906,32 @@ export var VenusFormUploadPro = function VenusFormUploadPro(props) {
905
906
  disabled: disabled
906
907
  }, comAttr)));
907
908
  };
908
-
909
909
  /**
910
- * 新上传组件
910
+ * 上传组件
911
+ * @param props
912
+ * @returns
911
913
  */
912
- export var VenusFormUploadSecLevel = function VenusFormUploadSecLevel(props) {
914
+ export var VenusFormEditor = function VenusFormEditor(props) {
913
915
  var _props$comAttr36 = props.comAttr,
914
916
  comAttr = _props$comAttr36 === void 0 ? {} : _props$comAttr36,
915
917
  placeholder = props.placeholder,
916
918
  disabled = props.disabled,
917
919
  isDuo = props.isDuo,
918
920
  others = _objectWithoutProperties(props, _excluded41);
921
+ return /*#__PURE__*/React.createElement(FormItem2, others, /*#__PURE__*/React.createElement(VenusEditor, _extends({
922
+ disabled: disabled
923
+ }, comAttr)));
924
+ };
925
+ /**
926
+ * 新上传组件
927
+ */
928
+ export var VenusFormUploadSecLevel = function VenusFormUploadSecLevel(props) {
929
+ var _props$comAttr37 = props.comAttr,
930
+ comAttr = _props$comAttr37 === void 0 ? {} : _props$comAttr37,
931
+ placeholder = props.placeholder,
932
+ disabled = props.disabled,
933
+ isDuo = props.isDuo,
934
+ others = _objectWithoutProperties(props, _excluded42);
919
935
  return /*#__PURE__*/React.createElement(FormItem2, others, /*#__PURE__*/React.createElement(VenusUploadSecLevel, _extends({
920
936
  placeholder: placeholder,
921
937
  isDuo: isDuo,
@@ -17,7 +17,6 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
17
17
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
18
18
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
19
19
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
20
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
21
20
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
22
21
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
23
22
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -45,80 +44,84 @@ var VenusUploadSecLevel = function VenusUploadSecLevel(props) {
45
44
  var downNode = useRef(null);
46
45
  var _useState3 = useState(false),
47
46
  _useState4 = _slicedToArray(_useState3, 2),
48
- isup = _useState4[0],
49
- setisup = _useState4[1];
50
- var _useState5 = useState(false),
47
+ load = _useState4[0],
48
+ setload = _useState4[1];
49
+ var _useState5 = useState(undefined),
51
50
  _useState6 = _slicedToArray(_useState5, 2),
52
- load = _useState6[0],
53
- setload = _useState6[1];
54
- var _useState7 = useState(undefined),
55
- _useState8 = _slicedToArray(_useState7, 2),
56
- level = _useState8[0],
57
- setLevel = _useState8[1];
51
+ level = _useState6[0],
52
+ setLevel = _useState6[1];
53
+ // 外部只给“已完成”数据,用 map 快速索引
58
54
  useEffect(function () {
59
- var value = (props.value || []).map(function (ls) {
60
- return _objectSpread(_objectSpread({
61
- fileId: ls.response != undefined && ls.response.data != undefined && ls.response.data.fileId != undefined ? ls.response.data.fileId : ls.fileId
62
- }, ls), {}, {
63
- status: 'done',
64
- uid: ls.uid || ls.fileId
55
+ var outerMap = new Map(
56
+ //@ts-ignore
57
+ (props.value || []).map(function (f) {
58
+ return [f.fileId || f.uid, f];
59
+ }));
60
+
61
+ // 回显层只更新“已完成”部分的信息,不动正在上传的
62
+ setFileList(function (prev) {
63
+ return prev.map(function (file) {
64
+ var key = file.fileId || file.uid;
65
+ var target = outerMap.get(key);
66
+ return target ? _objectSpread(_objectSpread(_objectSpread({}, file), target), {}, {
67
+ status: 'done'
68
+ }) : file;
65
69
  });
66
70
  });
67
- setFileList(value);
68
- if (props.isDuo != undefined && props.isDuo == false) {
69
- if (fileList.length > 0) {
70
- setisup(true);
71
- }
72
- if (fileList.length < 1) {
73
- setisup(false);
74
- }
75
- }
76
- }, [props.value]);
77
- /**
78
- * 上传文件
79
- */
71
+ }, [props.value, level]);
72
+ // 上传完成后,更新 fileList 里的信息
80
73
  var onChange = function onChange(info) {
81
- var files = [];
82
74
  var dataLevel = [];
83
- (props.value || []).map(function (v, n) {
75
+ (props.value || []).forEach(function (v) {
84
76
  dataLevel[v.id] = v.secId;
85
77
  });
86
- var _iterator = _createForOfIteratorHelper(info.fileList),
87
- _step;
88
- try {
89
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
90
- var file = _step.value;
91
- if (file.response && file.response.success) {
92
- file.id = file.response.data.id;
93
- file.secId = dataLevel[file.fileId] != undefined ? {
94
- label: dataLevel[file.fileId].label,
95
- value: dataLevel[file.fileId].value
96
- } : level && level[file.fileId] != undefined ? {
97
- label: level[file.fileId].label,
98
- value: level[file.fileId].value
99
- } : undefined;
100
- files.push(file);
101
- }
102
- if (file.response == undefined) {
103
- files.push(file);
104
- }
105
- if (file.response && !file.response.success) {
106
- _message.warning("文件上传失败!请重新上传!");
107
- }
78
+
79
+ /* ---------- 1. 收集本次失败的 uid ---------- */
80
+ var failedUids = [];
81
+ info.fileList.forEach(function (f) {
82
+ if (f.response && !f.response.success) {
83
+ failedUids.push(f.uid);
108
84
  }
109
- } catch (err) {
110
- _iterator.e(err);
111
- } finally {
112
- _iterator.f();
85
+ });
86
+ if (failedUids.length) {
87
+ _message.warning('文件上传失败!请重新上传');
113
88
  }
114
- setFileList(files);
115
- // 保留:已有 fileId 或 新上传成功
116
- var doneFiles = files.filter(function (f) {
89
+
90
+ /* ---------- 2. 双键 Map:优先 fileId,其次 uid ---------- */
91
+ var fileMap = new Map();
92
+ fileList.forEach(function (f) {
93
+ var key = f.fileId || f.uid;
94
+ fileMap.set(key, f);
95
+ });
96
+ // 上传完成后,更新 fileList 里的信息
97
+ info.fileList.forEach(function (f) {
117
98
  var _f$response;
118
- return f.fileId || ((_f$response = f.response) === null || _f$response === void 0 ? void 0 : _f$response.success);
99
+ var key = f.fileId || f.uid;
100
+ var target = _objectSpread({}, f);
101
+ if ((_f$response = f.response) !== null && _f$response !== void 0 && _f$response.success) {
102
+ var _ref, _dataLevel$target$fil;
103
+ target.fileId = f.response.data.fileId;
104
+ target.secId = (_ref = (_dataLevel$target$fil = dataLevel[target.fileId]) !== null && _dataLevel$target$fil !== void 0 ? _dataLevel$target$fil : level && level[target.fileId]) !== null && _ref !== void 0 ? _ref : undefined;
105
+ }
106
+ fileMap.set(key, target);
119
107
  });
120
- propsOnChange(doneFiles);
108
+
109
+ /* ---------- 3. 把失败项从 Map 里删掉 ---------- */
110
+ failedUids.forEach(function (uid) {
111
+ var key = uid; // 失败文件一定没有 fileId,直接用 uid
112
+ fileMap.delete(key);
113
+ });
114
+ // 4. 合并 Map 里的项
115
+ var merged = Array.from(fileMap.values());
116
+ setFileList(merged);
117
+
118
+ /* ---------- 4. 写给表单的依旧是“已完成” ---------- */
119
+ propsOnChange(merged.filter(function (f) {
120
+ var _f$response2;
121
+ return f.fileId || ((_f$response2 = f.response) === null || _f$response2 === void 0 ? void 0 : _f$response2.success);
122
+ }));
121
123
  };
124
+ // 上传完成后,调用表单的 onChange 回调
122
125
  var propsOnChange = function propsOnChange(files) {
123
126
  if (props.onChange) {
124
127
  props.onChange(files);
@@ -126,7 +129,7 @@ var VenusUploadSecLevel = function VenusUploadSecLevel(props) {
126
129
  };
127
130
  //删除文件
128
131
  var onRemove = /*#__PURE__*/function () {
129
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file) {
132
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file) {
130
133
  var res;
131
134
  return _regeneratorRuntime().wrap(function _callee$(_context) {
132
135
  while (1) switch (_context.prev = _context.next) {
@@ -137,9 +140,11 @@ var VenusUploadSecLevel = function VenusUploadSecLevel(props) {
137
140
  res = _context.sent;
138
141
  if (res && res.success) {
139
142
  _message.success(res.message);
140
- setFileList(fileList.filter(function (f) {
141
- return f.fileId !== file.fileId;
142
- }));
143
+ setFileList(function (prev) {
144
+ return prev.filter(function (f) {
145
+ return (f.fileId || f.uid) !== (file.fileId || file.uid);
146
+ });
147
+ });
143
148
  }
144
149
  case 4:
145
150
  case "end":
@@ -148,7 +153,7 @@ var VenusUploadSecLevel = function VenusUploadSecLevel(props) {
148
153
  }, _callee);
149
154
  }));
150
155
  return function onRemove(_x) {
151
- return _ref.apply(this, arguments);
156
+ return _ref2.apply(this, arguments);
152
157
  };
153
158
  }();
154
159
  /*
@@ -156,34 +161,25 @@ var VenusUploadSecLevel = function VenusUploadSecLevel(props) {
156
161
  * @param info
157
162
  */
158
163
  var onSelectLevelChange = function onSelectLevelChange() {
159
- var files = [];
160
164
  var dataLevel = [];
161
- (props.value || []).map(function (v, n) {
165
+ (props.value || []).forEach(function (v) {
162
166
  dataLevel[v.id] = v.secId;
163
167
  });
164
- var _iterator2 = _createForOfIteratorHelper(fileList),
165
- _step2;
166
- try {
167
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
168
- var file = _step2.value;
169
- file.secId = dataLevel[file.fileId] != undefined ? {
170
- label: dataLevel[file.fileId].label,
171
- value: dataLevel[file.fileId].value
172
- } : level && level[file.fileId] != undefined ? {
173
- label: level[file.fileId].label,
174
- value: level[file.fileId].value
175
- } : undefined;
176
- files.push(file);
177
- }
178
- } catch (err) {
179
- _iterator2.e(err);
180
- } finally {
181
- _iterator2.f();
182
- }
183
- setFileList(files);
184
- propsOnChange(files.filter(function (f) {
185
- var _f$response2;
186
- return f.fileId || ((_f$response2 = f.response) === null || _f$response2 === void 0 ? void 0 : _f$response2.success);
168
+
169
+ /* 1. 双键 Map 去重:优先 fileId,其次 uid */
170
+ var fileMap = new Map();
171
+ fileList.forEach(function (f) {
172
+ var _ref3, _dataLevel$f$fileId;
173
+ var key = f.fileId || f.uid;
174
+ // 更新 secId
175
+ f.secId = (_ref3 = (_dataLevel$f$fileId = dataLevel[f.fileId]) !== null && _dataLevel$f$fileId !== void 0 ? _dataLevel$f$fileId : level && level[f.fileId]) !== null && _ref3 !== void 0 ? _ref3 : undefined;
176
+ fileMap.set(key, f);
177
+ });
178
+ var merged = Array.from(fileMap.values());
179
+ setFileList(merged);
180
+ propsOnChange(merged.filter(function (f) {
181
+ var _f$response3;
182
+ return f.fileId || ((_f$response3 = f.response) === null || _f$response3 === void 0 ? void 0 : _f$response3.success);
187
183
  }));
188
184
  };
189
185
  // 密级改变时,更新文件密级
@@ -197,28 +193,34 @@ var VenusUploadSecLevel = function VenusUploadSecLevel(props) {
197
193
  * 选择密级
198
194
  */
199
195
  var onSelectLevel = /*#__PURE__*/function () {
200
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(v, file) {
201
- var fileId;
196
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(v, file) {
197
+ var _file$response;
198
+ var key, fileId;
202
199
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
203
200
  while (1) switch (_context2.prev = _context2.next) {
204
201
  case 0:
205
- //设置表单属性
206
- setLevel(_objectSpread(_objectSpread({}, level), {}, _defineProperty({}, file.uid, v)));
207
- if (!(file.fileId || file.response != undefined && file.response.code == 200)) {
208
- _context2.next = 5;
202
+ // 1. 函数式更新,用参数 prev 而不是外部 level
203
+ key = file.fileId || file.uid; //@ts-ignore
204
+ setLevel(function (prev) {
205
+ return _objectSpread(_objectSpread({}, prev), {}, _defineProperty({}, key, v));
206
+ });
207
+
208
+ // 2. 调接口依旧用 fileId
209
+ if (!(file.fileId || (_file$response = file.response) !== null && _file$response !== void 0 && _file$response.success)) {
210
+ _context2.next = 6;
209
211
  break;
210
212
  }
211
213
  fileId = file.fileId || file.response.data.fileId;
212
- _context2.next = 5;
214
+ _context2.next = 6;
213
215
  return updateFileSecLevelNew(fileId, v.value);
214
- case 5:
216
+ case 6:
215
217
  case "end":
216
218
  return _context2.stop();
217
219
  }
218
220
  }, _callee2);
219
221
  }));
220
222
  return function onSelectLevel(_x2, _x3) {
221
- return _ref2.apply(this, arguments);
223
+ return _ref4.apply(this, arguments);
222
224
  };
223
225
  }();
224
226
  //上传前的控制
@@ -256,7 +258,7 @@ var VenusUploadSecLevel = function VenusUploadSecLevel(props) {
256
258
  },
257
259
  itemRender: function itemRender(originNode, file, fileList, actions) {
258
260
  return /*#__PURE__*/React.createElement(FileCard, {
259
- key: file.fileId,
261
+ key: "".concat(file.fileId || file.uid),
260
262
  style: {
261
263
  backgroundColor: props.disabled ? "#f5f5f5" : ""
262
264
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "venus-design",
3
- "version": "1.0.75",
3
+ "version": "1.0.77",
4
4
  "description": "venus all compoments",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",