@nokecy/qc-ui 1.1.63 → 1.1.64
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/dist/cjs/deleteConfirm/index.js +56 -38
- package/dist/cjs/generatedListPage/OptionsColumn.js +4 -2
- package/dist/cjs/standardFormDialog/StandardFormDialog.js +118 -120
- package/dist/esm/deleteConfirm/index.js +55 -37
- package/dist/esm/generatedListPage/OptionsColumn.js +4 -2
- package/dist/esm/standardFormDialog/StandardFormDialog.js +121 -123
- package/dist/umd/qc-ui.min.js +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
|
4
5
|
value: true
|
|
5
6
|
});
|
|
@@ -8,13 +9,20 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
8
9
|
var _antd = require("antd");
|
|
9
10
|
var _icons = require("@ant-design/icons");
|
|
10
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
function
|
|
12
|
+
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; }
|
|
12
13
|
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; }
|
|
13
14
|
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; }
|
|
14
15
|
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; }
|
|
15
16
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
16
17
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
17
|
-
var
|
|
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
|
+
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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
21
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
22
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
23
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
24
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
25
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
26
|
/**
|
|
19
27
|
* DeleteConfirm 删除确认组件
|
|
20
28
|
*
|
|
@@ -41,44 +49,54 @@ var DeleteConfirm = function DeleteConfirm(props) {
|
|
|
41
49
|
_props$danger = props.danger,
|
|
42
50
|
danger = _props$danger === void 0 ? true : _props$danger,
|
|
43
51
|
children = props.children;
|
|
44
|
-
var showPromiseConfirm = function showPromiseConfirm(event) {
|
|
45
|
-
// 智能转换 title:支持字符串、ReactNode 或使用默认值
|
|
46
|
-
var titleText = title || '确认操作';
|
|
47
52
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
53
|
+
// 保留宿主主题,并让 antd 接管异步提交的加载与失败恢复。@author nokecy
|
|
54
|
+
var _Modal$useModal = _antd.Modal.useModal(),
|
|
55
|
+
_Modal$useModal2 = _slicedToArray(_Modal$useModal, 2),
|
|
56
|
+
modal = _Modal$useModal2[0],
|
|
57
|
+
contextHolder = _Modal$useModal2[1];
|
|
58
|
+
var showPromiseConfirm = /*#__PURE__*/function () {
|
|
59
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
60
|
+
var titleText, contentText;
|
|
61
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
62
|
+
while (1) switch (_context.prev = _context.next) {
|
|
63
|
+
case 0:
|
|
64
|
+
// 智能转换 title:支持字符串、ReactNode 或使用默认值
|
|
65
|
+
titleText = title || '确认操作'; // 正文要说清动的是哪条、几条,这只有调用方知道,所以 content 交给调用方。
|
|
66
|
+
// 不传时的兜底只承诺「不可撤销」:原来的默认正文是把 title 拼进去,
|
|
67
|
+
// 拼出来是一句病句,而且始终没告诉用户动的是哪条数据。@author nokecy
|
|
68
|
+
contentText = content || '该操作不可撤销,请确认后继续。';
|
|
69
|
+
_context.next = 4;
|
|
70
|
+
return modal.confirm(_objectSpread(_objectSpread({
|
|
71
|
+
title: titleText,
|
|
72
|
+
icon: /*#__PURE__*/_react.default.createElement(_icons.ExclamationCircleFilled, null),
|
|
73
|
+
content: contentText,
|
|
74
|
+
okButtonProps: {
|
|
75
|
+
danger: danger
|
|
76
|
+
}
|
|
77
|
+
}, okText ? {
|
|
78
|
+
okText: okText
|
|
79
|
+
} : {}), {}, {
|
|
80
|
+
onOk: function onOk() {
|
|
81
|
+
// 同步异常与异步失败均交回确认框,失败不关闭,可继续重试。
|
|
82
|
+
// @author nokecy
|
|
83
|
+
return Promise.resolve().then(function () {
|
|
84
|
+
return onConfirm(event);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}));
|
|
88
|
+
case 4:
|
|
89
|
+
case "end":
|
|
90
|
+
return _context.stop();
|
|
91
|
+
}
|
|
92
|
+
}, _callee);
|
|
78
93
|
}));
|
|
79
|
-
|
|
80
|
-
|
|
94
|
+
return function showPromiseConfirm(_x) {
|
|
95
|
+
return _ref.apply(this, arguments);
|
|
96
|
+
};
|
|
97
|
+
}();
|
|
98
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, contextHolder, /*#__PURE__*/_react.default.createElement("span", {
|
|
81
99
|
onClick: showPromiseConfirm
|
|
82
|
-
}, children);
|
|
100
|
+
}, children));
|
|
83
101
|
};
|
|
84
102
|
var _default = exports.default = DeleteConfirm;
|
|
@@ -58,13 +58,15 @@ var OptionsColumn = function OptionsColumn(props) {
|
|
|
58
58
|
_context.next = 6;
|
|
59
59
|
return (0, _defaultHandlers.defaultHandleDelete)(deleteApi, id, refresh);
|
|
60
60
|
case 6:
|
|
61
|
-
_context.next =
|
|
61
|
+
_context.next = 12;
|
|
62
62
|
break;
|
|
63
63
|
case 8:
|
|
64
64
|
_context.prev = 8;
|
|
65
65
|
_context.t0 = _context["catch"](3);
|
|
66
66
|
console.error('删除失败:', _context.t0);
|
|
67
|
-
|
|
67
|
+
// 让确认框结束加载并保留失败状态,避免失败被当作成功关闭。@author nokecy
|
|
68
|
+
throw _context.t0;
|
|
69
|
+
case 12:
|
|
68
70
|
case "end":
|
|
69
71
|
return _context.stop();
|
|
70
72
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -14,6 +13,7 @@ var _react2 = require("@formily/react");
|
|
|
14
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
16
15
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
17
17
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
18
18
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
19
19
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
@@ -33,12 +33,6 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
33
33
|
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; }
|
|
34
34
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
35
35
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
36
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
37
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
38
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
39
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
40
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
41
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
42
36
|
// 创建默认的 SchemaField,包含基本组件和装饰器
|
|
43
37
|
var SchemaFieldComponents = (0, _react2.createSchemaField)({
|
|
44
38
|
components: {
|
|
@@ -81,6 +75,7 @@ var defaultUseSchemaField = function defaultUseSchemaField(config) {
|
|
|
81
75
|
* - 灵活的Schema支持
|
|
82
76
|
* - 性能优化和加载状态管理
|
|
83
77
|
*
|
|
78
|
+
* @author nokecy
|
|
84
79
|
* @param props 组件属性
|
|
85
80
|
*/
|
|
86
81
|
var StandardFormDialog = function StandardFormDialog(props) {
|
|
@@ -110,15 +105,11 @@ var StandardFormDialog = function StandardFormDialog(props) {
|
|
|
110
105
|
_props$useSchemaField = props.useSchemaField,
|
|
111
106
|
useSchemaFieldHook = _props$useSchemaField === void 0 ? defaultUseSchemaField : _props$useSchemaField;
|
|
112
107
|
|
|
113
|
-
//
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
var _useState3 = (0, _react.useState)(false),
|
|
119
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
120
|
-
submitting = _useState4[0],
|
|
121
|
-
setSubmitting = _useState4[1];
|
|
108
|
+
// 直接观察弹窗表单,避免打开时的 React 状态快照覆盖实时状态。
|
|
109
|
+
// @author nokecy
|
|
110
|
+
var formRef = (0, _react.useRef)();
|
|
111
|
+
var confirmingRef = (0, _react.useRef)(false);
|
|
112
|
+
var loadingRef = (0, _react.useRef)(false);
|
|
122
113
|
|
|
123
114
|
// 组件挂载状态追踪 - 防止内存泄漏
|
|
124
115
|
var isMountedRef = (0, _react.useRef)(true);
|
|
@@ -170,78 +161,81 @@ var StandardFormDialog = function StandardFormDialog(props) {
|
|
|
170
161
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
171
162
|
while (1) switch (_context.prev = _context.next) {
|
|
172
163
|
case 0:
|
|
173
|
-
|
|
174
|
-
|
|
164
|
+
formRef.current = form;
|
|
165
|
+
if (!(entityId !== undefined && entityId !== null)) {
|
|
166
|
+
_context.next = 32;
|
|
175
167
|
break;
|
|
176
168
|
}
|
|
177
169
|
// 创建新的 AbortController
|
|
178
170
|
controller = new AbortController();
|
|
179
171
|
abortControllerRef.current = controller;
|
|
180
172
|
if (isMountedRef.current) {
|
|
181
|
-
_context.next =
|
|
173
|
+
_context.next = 6;
|
|
182
174
|
break;
|
|
183
175
|
}
|
|
184
176
|
return _context.abrupt("return");
|
|
185
|
-
case
|
|
186
|
-
|
|
187
|
-
|
|
177
|
+
case 6:
|
|
178
|
+
loadingRef.current = true;
|
|
179
|
+
form.setLoading(true);
|
|
180
|
+
_context.prev = 8;
|
|
188
181
|
if (!customInitializer) {
|
|
189
|
-
_context.next =
|
|
182
|
+
_context.next = 14;
|
|
190
183
|
break;
|
|
191
184
|
}
|
|
192
|
-
_context.next =
|
|
185
|
+
_context.next = 12;
|
|
193
186
|
return customInitializer(form, entityId);
|
|
194
|
-
case 10:
|
|
195
|
-
_context.next = 20;
|
|
196
|
-
break;
|
|
197
187
|
case 12:
|
|
188
|
+
_context.next = 22;
|
|
189
|
+
break;
|
|
190
|
+
case 14:
|
|
198
191
|
if (!apiConfig.get) {
|
|
199
|
-
_context.next =
|
|
192
|
+
_context.next = 21;
|
|
200
193
|
break;
|
|
201
194
|
}
|
|
202
|
-
_context.next =
|
|
195
|
+
_context.next = 17;
|
|
203
196
|
return apiConfig.get({
|
|
204
197
|
id: entityId
|
|
205
198
|
});
|
|
206
|
-
case
|
|
199
|
+
case 17:
|
|
207
200
|
data = _context.sent;
|
|
208
201
|
// 检查组件是否已卸载或请求是否已取消
|
|
209
202
|
if (!controller.signal.aborted && isMountedRef.current) {
|
|
210
203
|
form.setInitialValues(data);
|
|
211
204
|
}
|
|
212
|
-
_context.next =
|
|
205
|
+
_context.next = 22;
|
|
213
206
|
break;
|
|
214
|
-
case
|
|
207
|
+
case 21:
|
|
215
208
|
console.warn('编辑模式但未提供get API或自定义初始化函数');
|
|
216
|
-
case 20:
|
|
217
|
-
_context.next = 27;
|
|
218
|
-
break;
|
|
219
209
|
case 22:
|
|
220
|
-
_context.
|
|
221
|
-
|
|
210
|
+
_context.next = 29;
|
|
211
|
+
break;
|
|
212
|
+
case 24:
|
|
213
|
+
_context.prev = 24;
|
|
214
|
+
_context.t0 = _context["catch"](8);
|
|
222
215
|
if (!controller.signal.aborted) {
|
|
223
|
-
_context.next =
|
|
216
|
+
_context.next = 28;
|
|
224
217
|
break;
|
|
225
218
|
}
|
|
226
219
|
return _context.abrupt("return");
|
|
227
|
-
case
|
|
220
|
+
case 28:
|
|
228
221
|
if (isMountedRef.current) {
|
|
229
222
|
console.error('加载数据失败:', _context.t0);
|
|
230
223
|
errorMessage = ((_error$response = _context.t0.response) === null || _error$response === void 0 || (_error$response = _error$response.data) === null || _error$response === void 0 || (_error$response = _error$response.error) === null || _error$response === void 0 ? void 0 : _error$response.message) || _context.t0.message || '加载数据失败';
|
|
231
224
|
_antd.message.error(errorMessage);
|
|
232
225
|
}
|
|
233
|
-
case
|
|
234
|
-
_context.prev =
|
|
226
|
+
case 29:
|
|
227
|
+
_context.prev = 29;
|
|
235
228
|
// 只在组件仍挂载且请求未取消时更新状态
|
|
236
229
|
if (!controller.signal.aborted && isMountedRef.current) {
|
|
237
|
-
|
|
230
|
+
loadingRef.current = false;
|
|
231
|
+
form.setLoading(false);
|
|
238
232
|
}
|
|
239
|
-
return _context.finish(
|
|
240
|
-
case
|
|
233
|
+
return _context.finish(29);
|
|
234
|
+
case 32:
|
|
241
235
|
case "end":
|
|
242
236
|
return _context.stop();
|
|
243
237
|
}
|
|
244
|
-
}, _callee, null, [[
|
|
238
|
+
}, _callee, null, [[8, 24, 29, 32]]);
|
|
245
239
|
}));
|
|
246
240
|
return function (_x) {
|
|
247
241
|
return _ref.apply(this, arguments);
|
|
@@ -288,7 +282,13 @@ var StandardFormDialog = function StandardFormDialog(props) {
|
|
|
288
282
|
return {
|
|
289
283
|
effects: function effects() {
|
|
290
284
|
(0, _core.onFormInit)(initializeForm);
|
|
291
|
-
(0, _core.onFormValidateFailed)(
|
|
285
|
+
(0, _core.onFormValidateFailed)(function (form) {
|
|
286
|
+
confirmingRef.current = false;
|
|
287
|
+
handleValidationFailed(form);
|
|
288
|
+
});
|
|
289
|
+
(0, _core.onFormSubmitEnd)(function () {
|
|
290
|
+
confirmingRef.current = false;
|
|
291
|
+
});
|
|
292
292
|
}
|
|
293
293
|
};
|
|
294
294
|
}, [initializeForm, handleValidationFailed]);
|
|
@@ -296,7 +296,7 @@ var StandardFormDialog = function StandardFormDialog(props) {
|
|
|
296
296
|
// 提交处理函数
|
|
297
297
|
var handleSubmit = (0, _react.useCallback)( /*#__PURE__*/function () {
|
|
298
298
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(payload, next) {
|
|
299
|
-
var values, isEdit, _error$response2, errorMessage;
|
|
299
|
+
var values, isEdit, _values$id, _error$response2, errorMessage;
|
|
300
300
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
301
301
|
while (1) switch (_context2.prev = _context2.next) {
|
|
302
302
|
case 0:
|
|
@@ -306,79 +306,82 @@ var StandardFormDialog = function StandardFormDialog(props) {
|
|
|
306
306
|
}
|
|
307
307
|
return _context2.abrupt("return");
|
|
308
308
|
case 2:
|
|
309
|
-
|
|
310
|
-
_context2.prev = 3;
|
|
309
|
+
_context2.prev = 2;
|
|
311
310
|
values = payload.values;
|
|
312
|
-
isEdit =
|
|
311
|
+
isEdit = values.id != null || entityId != null; // FormDialog已经在内部处理了验证,无需手动调用validate
|
|
313
312
|
// Formily的FormDialog.forConfirm会自动验证表单
|
|
314
313
|
if (!customSubmitHandler) {
|
|
315
|
-
_context2.next =
|
|
314
|
+
_context2.next = 10;
|
|
316
315
|
break;
|
|
317
316
|
}
|
|
318
|
-
_context2.next =
|
|
317
|
+
_context2.next = 8;
|
|
319
318
|
return customSubmitHandler(values, isEdit);
|
|
320
|
-
case
|
|
321
|
-
_context2.next =
|
|
319
|
+
case 8:
|
|
320
|
+
_context2.next = 23;
|
|
322
321
|
break;
|
|
323
|
-
case
|
|
322
|
+
case 10:
|
|
324
323
|
if (!isEdit) {
|
|
325
|
-
_context2.next =
|
|
324
|
+
_context2.next = 18;
|
|
326
325
|
break;
|
|
327
326
|
}
|
|
328
327
|
if (apiConfig.update) {
|
|
329
|
-
_context2.next =
|
|
328
|
+
_context2.next = 13;
|
|
330
329
|
break;
|
|
331
330
|
}
|
|
332
331
|
throw new Error('更新API未配置');
|
|
333
|
-
case
|
|
334
|
-
_context2.next =
|
|
332
|
+
case 13:
|
|
333
|
+
_context2.next = 15;
|
|
335
334
|
return apiConfig.update({
|
|
336
|
-
id: values.id
|
|
335
|
+
id: (_values$id = values.id) !== null && _values$id !== void 0 ? _values$id : entityId
|
|
337
336
|
}, values);
|
|
338
|
-
case
|
|
337
|
+
case 15:
|
|
339
338
|
// 只在组件仍挂载时显示消息
|
|
340
339
|
if (isMountedRef.current) {
|
|
341
340
|
_antd.message.success('更新成功');
|
|
342
341
|
}
|
|
343
|
-
_context2.next =
|
|
342
|
+
_context2.next = 23;
|
|
344
343
|
break;
|
|
345
|
-
case
|
|
344
|
+
case 18:
|
|
346
345
|
if (apiConfig.create) {
|
|
347
|
-
_context2.next =
|
|
346
|
+
_context2.next = 20;
|
|
348
347
|
break;
|
|
349
348
|
}
|
|
350
349
|
throw new Error('创建API未配置');
|
|
351
|
-
case
|
|
352
|
-
_context2.next =
|
|
350
|
+
case 20:
|
|
351
|
+
_context2.next = 22;
|
|
353
352
|
return apiConfig.create(values);
|
|
354
|
-
case
|
|
353
|
+
case 22:
|
|
355
354
|
// 只在组件仍挂载时显示消息
|
|
356
355
|
if (isMountedRef.current) {
|
|
357
356
|
_antd.message.success('创建成功');
|
|
358
357
|
}
|
|
359
|
-
case
|
|
358
|
+
case 23:
|
|
360
359
|
// 调用成功回调
|
|
361
360
|
if (isMountedRef.current && onAfterSubmit) {
|
|
362
361
|
onAfterSubmit();
|
|
363
362
|
}
|
|
364
363
|
|
|
365
364
|
// 关闭对话框
|
|
366
|
-
if (isMountedRef.current) {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
next(payload);
|
|
365
|
+
if (!isMountedRef.current) {
|
|
366
|
+
_context2.next = 28;
|
|
367
|
+
break;
|
|
370
368
|
}
|
|
371
|
-
|
|
372
|
-
|
|
369
|
+
// 标记 Portal 为已关闭
|
|
370
|
+
_PortalManager.default.markAsClosed(portalId);
|
|
371
|
+
_context2.next = 28;
|
|
372
|
+
return next(payload);
|
|
373
373
|
case 28:
|
|
374
|
-
_context2.
|
|
375
|
-
|
|
374
|
+
_context2.next = 37;
|
|
375
|
+
break;
|
|
376
|
+
case 30:
|
|
377
|
+
_context2.prev = 30;
|
|
378
|
+
_context2.t0 = _context2["catch"](2);
|
|
376
379
|
if (isMountedRef.current) {
|
|
377
|
-
_context2.next =
|
|
380
|
+
_context2.next = 34;
|
|
378
381
|
break;
|
|
379
382
|
}
|
|
380
383
|
return _context2.abrupt("return");
|
|
381
|
-
case
|
|
384
|
+
case 34:
|
|
382
385
|
console.error('提交失败:', _context2.t0);
|
|
383
386
|
if (useUnifiedErrorHandling) {
|
|
384
387
|
// 使用统一错误处理
|
|
@@ -389,24 +392,19 @@ var StandardFormDialog = function StandardFormDialog(props) {
|
|
|
389
392
|
_antd.message.error('操作失败:' + (_context2.t0.message || '未知错误'));
|
|
390
393
|
}
|
|
391
394
|
|
|
392
|
-
//
|
|
393
|
-
|
|
394
|
-
_context2.
|
|
395
|
-
// 只在组件仍挂载时更新状态
|
|
396
|
-
if (isMountedRef.current) {
|
|
397
|
-
setSubmitting(false);
|
|
398
|
-
}
|
|
399
|
-
return _context2.finish(34);
|
|
395
|
+
// 拒绝中间件链,让 Formily 结束提交状态并保留弹窗供重试。
|
|
396
|
+
// @author nokecy
|
|
397
|
+
throw _context2.t0;
|
|
400
398
|
case 37:
|
|
401
399
|
case "end":
|
|
402
400
|
return _context2.stop();
|
|
403
401
|
}
|
|
404
|
-
}, _callee2, null, [[
|
|
402
|
+
}, _callee2, null, [[2, 30]]);
|
|
405
403
|
}));
|
|
406
404
|
return function (_x2, _x3) {
|
|
407
405
|
return _ref2.apply(this, arguments);
|
|
408
406
|
};
|
|
409
|
-
}(), [entityId, customSubmitHandler, apiConfig, onAfterSubmit, useUnifiedErrorHandling]);
|
|
407
|
+
}(), [entityId, customSubmitHandler, apiConfig, onAfterSubmit, useUnifiedErrorHandling, portalId]);
|
|
410
408
|
|
|
411
409
|
// 点击处理函数
|
|
412
410
|
var handleClick = (0, _react.useCallback)(function () {
|
|
@@ -415,42 +413,42 @@ var StandardFormDialog = function StandardFormDialog(props) {
|
|
|
415
413
|
var formDialog = (0, _antdV.FormDialog)({
|
|
416
414
|
title: title,
|
|
417
415
|
width: width,
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
416
|
+
// 不设置静态 loading,使用 FormDialog 自带的 form.submitting。
|
|
417
|
+
// @author nokecy
|
|
418
|
+
maskClosable: false,
|
|
419
|
+
onOk: function onOk() {
|
|
420
|
+
if (confirmingRef.current || loadingRef.current) return false;
|
|
421
|
+
confirmingRef.current = true;
|
|
421
422
|
},
|
|
422
|
-
|
|
423
|
-
|
|
423
|
+
onCancel: function onCancel() {
|
|
424
|
+
return !confirmingRef.current && !loadingRef.current;
|
|
424
425
|
},
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
})), /*#__PURE__*/_react.default.createElement(_antdV.FormLayout, schema.form, /*#__PURE__*/_react.default.createElement(SchemaField, {
|
|
449
|
-
schema: schema.schema
|
|
450
|
-
})));
|
|
426
|
+
footer: function footer(_, _ref3) {
|
|
427
|
+
var OkBtn = _ref3.OkBtn,
|
|
428
|
+
CancelBtn = _ref3.CancelBtn;
|
|
429
|
+
return /*#__PURE__*/_react.default.createElement(_react2.Observer, null, function () {
|
|
430
|
+
var _formRef$current, _formRef$current2, _formRef$current3;
|
|
431
|
+
return /*#__PURE__*/_react.default.createElement(_antd.ConfigProvider, {
|
|
432
|
+
componentDisabled: ((_formRef$current = formRef.current) === null || _formRef$current === void 0 ? void 0 : _formRef$current.loading) || ((_formRef$current2 = formRef.current) === null || _formRef$current2 === void 0 ? void 0 : _formRef$current2.validating) || ((_formRef$current3 = formRef.current) === null || _formRef$current3 === void 0 ? void 0 : _formRef$current3.submitting)
|
|
433
|
+
}, /*#__PURE__*/_react.default.createElement(CancelBtn, null), /*#__PURE__*/_react.default.createElement(OkBtn, null));
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
}, portalId, function (form) {
|
|
437
|
+
return /*#__PURE__*/_react.default.createElement(_react2.Observer, null, function () {
|
|
438
|
+
return /*#__PURE__*/_react.default.createElement(_antd.Spin, {
|
|
439
|
+
spinning: form.loading,
|
|
440
|
+
tip: "\u52A0\u8F7D\u6570\u636E\u4E2D..."
|
|
441
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
442
|
+
style: {
|
|
443
|
+
minHeight: 200
|
|
444
|
+
}
|
|
445
|
+
}, /*#__PURE__*/_react.default.createElement(_antdV.FormLayout, schema.form, /*#__PURE__*/_react.default.createElement(SchemaField, {
|
|
446
|
+
schema: schema.schema
|
|
447
|
+
}))));
|
|
448
|
+
});
|
|
451
449
|
});
|
|
452
450
|
formDialog.forConfirm(handleSubmit).open(formProps);
|
|
453
|
-
}, [title, width, portalId, schema, formProps, handleSubmit
|
|
451
|
+
}, [title, width, portalId, schema, SchemaField, formProps, handleSubmit]);
|
|
454
452
|
return /*#__PURE__*/_react.default.createElement(_antdV.FormDialog.Portal, {
|
|
455
453
|
id: portalId
|
|
456
454
|
}, /*#__PURE__*/_react.default.createElement(_antd.Button, _extends({
|