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