@nokecy/qc-ui 1.1.69 → 1.1.70

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.
@@ -4,7 +4,7 @@
4
4
  * @param params 导出参数
5
5
  * @param fileName 文件名
6
6
  */
7
- export declare const defaultHandleExport: (exportApi: (params: any) => Promise<Blob>, params: any, fileName: string) => Promise<void>;
7
+ export declare const defaultHandleExport: (exportApi: (params: any, options?: Record<string, any>) => Promise<Blob>, params: any, fileName: string) => Promise<void>;
8
8
  /**
9
9
  * 默认的删除处理器
10
10
  * @param deleteApi 删除API函数
@@ -9,6 +9,68 @@ var _antd = require("antd");
9
9
  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; }
10
10
  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); } }
11
11
  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); }); }; }
12
+ /**
13
+ * 按 blob 收的请求,后端的 JSON 错误体(无权限、业务校验等)也是 Blob,要读出来才能给出原因。@author nokecy
14
+ */
15
+ var readBlobErrorMessage = /*#__PURE__*/function () {
16
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data) {
17
+ var _JSON$parse;
18
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
19
+ while (1) switch (_context.prev = _context.next) {
20
+ case 0:
21
+ if (data instanceof Blob) {
22
+ _context.next = 2;
23
+ break;
24
+ }
25
+ return _context.abrupt("return", undefined);
26
+ case 2:
27
+ _context.prev = 2;
28
+ _context.t2 = JSON;
29
+ _context.next = 6;
30
+ return data.text();
31
+ case 6:
32
+ _context.t3 = _context.sent;
33
+ _context.t4 = _JSON$parse = _context.t2.parse.call(_context.t2, _context.t3);
34
+ _context.t1 = _context.t4 === null;
35
+ if (_context.t1) {
36
+ _context.next = 11;
37
+ break;
38
+ }
39
+ _context.t1 = _JSON$parse === void 0;
40
+ case 11:
41
+ _context.t0 = _context.t1;
42
+ if (_context.t0) {
43
+ _context.next = 14;
44
+ break;
45
+ }
46
+ _context.t0 = (_JSON$parse = _JSON$parse.error) === null || _JSON$parse === void 0;
47
+ case 14:
48
+ if (!_context.t0) {
49
+ _context.next = 18;
50
+ break;
51
+ }
52
+ _context.t5 = void 0;
53
+ _context.next = 19;
54
+ break;
55
+ case 18:
56
+ _context.t5 = _JSON$parse.message;
57
+ case 19:
58
+ return _context.abrupt("return", _context.t5);
59
+ case 22:
60
+ _context.prev = 22;
61
+ _context.t6 = _context["catch"](2);
62
+ return _context.abrupt("return", undefined);
63
+ case 25:
64
+ case "end":
65
+ return _context.stop();
66
+ }
67
+ }, _callee, null, [[2, 22]]);
68
+ }));
69
+ return function readBlobErrorMessage(_x) {
70
+ return _ref.apply(this, arguments);
71
+ };
72
+ }();
73
+
12
74
  /**
13
75
  * 默认的导出处理器
14
76
  * @param exportApi 导出API函数
@@ -16,26 +78,28 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
16
78
  * @param fileName 文件名
17
79
  */
18
80
  var defaultHandleExport = exports.defaultHandleExport = /*#__PURE__*/function () {
19
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(exportApi, params, fileName) {
20
- var hide, response, url, link, _error$response, errorMessage;
21
- return _regeneratorRuntime().wrap(function _callee$(_context) {
22
- while (1) switch (_context.prev = _context.next) {
81
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(exportApi, params, fileName) {
82
+ var hide, response, url, link, _error$response, _error$response2, errorMessage;
83
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
84
+ while (1) switch (_context2.prev = _context2.next) {
23
85
  case 0:
24
86
  hide = _antd.message.loading('正在导出,请稍后', 0);
25
- _context.prev = 1;
26
- _context.next = 4;
27
- return exportApi(params);
87
+ _context2.prev = 1;
88
+ _context2.next = 4;
89
+ return exportApi(params, {
90
+ responseType: 'blob'
91
+ });
28
92
  case 4:
29
- response = _context.sent;
93
+ response = _context2.sent;
30
94
  if (response instanceof Blob) {
31
- _context.next = 8;
95
+ _context2.next = 8;
32
96
  break;
33
97
  }
34
98
  console.error('导出API返回的不是Blob对象:', response);
35
99
  throw new Error('导出数据格式错误,请检查API配置');
36
100
  case 8:
37
101
  if (!(response.size === 0)) {
38
- _context.next = 10;
102
+ _context2.next = 10;
39
103
  break;
40
104
  }
41
105
  throw new Error('导出的文件为空');
@@ -52,27 +116,51 @@ var defaultHandleExport = exports.defaultHandleExport = /*#__PURE__*/function ()
52
116
  document.body.removeChild(link);
53
117
  window.URL.revokeObjectURL(url);
54
118
  _antd.message.success('导出成功');
55
- _context.next = 27;
119
+ _context2.next = 38;
56
120
  break;
57
121
  case 21:
58
- _context.prev = 21;
59
- _context.t0 = _context["catch"](1);
60
- console.error('导出失败:', _context.t0);
61
- 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 || '导出失败';
122
+ _context2.prev = 21;
123
+ _context2.t0 = _context2["catch"](1);
124
+ console.error('导出失败:', _context2.t0);
125
+ _context2.next = 26;
126
+ return readBlobErrorMessage((_error$response = _context2.t0.response) === null || _error$response === void 0 ? void 0 : _error$response.data);
127
+ case 26:
128
+ _context2.t3 = _context2.sent;
129
+ if (_context2.t3) {
130
+ _context2.next = 29;
131
+ break;
132
+ }
133
+ _context2.t3 = (_error$response2 = _context2.t0.response) === null || _error$response2 === void 0 || (_error$response2 = _error$response2.data) === null || _error$response2 === void 0 || (_error$response2 = _error$response2.error) === null || _error$response2 === void 0 ? void 0 : _error$response2.message;
134
+ case 29:
135
+ _context2.t2 = _context2.t3;
136
+ if (_context2.t2) {
137
+ _context2.next = 32;
138
+ break;
139
+ }
140
+ _context2.t2 = _context2.t0.message;
141
+ case 32:
142
+ _context2.t1 = _context2.t2;
143
+ if (_context2.t1) {
144
+ _context2.next = 35;
145
+ break;
146
+ }
147
+ _context2.t1 = '导出失败';
148
+ case 35:
149
+ errorMessage = _context2.t1;
62
150
  _antd.message.error("\u5BFC\u51FA\u5931\u8D25\uFF1A".concat(errorMessage));
63
- throw _context.t0;
64
- case 27:
65
- _context.prev = 27;
151
+ throw _context2.t0;
152
+ case 38:
153
+ _context2.prev = 38;
66
154
  hide();
67
- return _context.finish(27);
68
- case 30:
155
+ return _context2.finish(38);
156
+ case 41:
69
157
  case "end":
70
- return _context.stop();
158
+ return _context2.stop();
71
159
  }
72
- }, _callee, null, [[1, 21, 27, 30]]);
160
+ }, _callee2, null, [[1, 21, 38, 41]]);
73
161
  }));
74
- return function defaultHandleExport(_x, _x2, _x3) {
75
- return _ref.apply(this, arguments);
162
+ return function defaultHandleExport(_x2, _x3, _x4) {
163
+ return _ref2.apply(this, arguments);
76
164
  };
77
165
  }();
78
166
 
@@ -83,14 +171,14 @@ var defaultHandleExport = exports.defaultHandleExport = /*#__PURE__*/function ()
83
171
  * @param onSuccess 成功回调
84
172
  */
85
173
  var defaultHandleDelete = exports.defaultHandleDelete = /*#__PURE__*/function () {
86
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(deleteApi, id, onSuccess) {
87
- var hide, _error$response2, errorMessage;
88
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
89
- while (1) switch (_context2.prev = _context2.next) {
174
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(deleteApi, id, onSuccess) {
175
+ var hide, _error$response3, errorMessage;
176
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
177
+ while (1) switch (_context3.prev = _context3.next) {
90
178
  case 0:
91
179
  hide = _antd.message.loading('正在删除,请稍后', 0);
92
- _context2.prev = 1;
93
- _context2.next = 4;
180
+ _context3.prev = 1;
181
+ _context3.next = 4;
94
182
  return deleteApi({
95
183
  id: id
96
184
  });
@@ -99,27 +187,27 @@ var defaultHandleDelete = exports.defaultHandleDelete = /*#__PURE__*/function ()
99
187
  if (onSuccess) {
100
188
  onSuccess();
101
189
  }
102
- _context2.next = 14;
190
+ _context3.next = 14;
103
191
  break;
104
192
  case 8:
105
- _context2.prev = 8;
106
- _context2.t0 = _context2["catch"](1);
107
- console.error('删除失败:', _context2.t0);
108
- errorMessage = ((_error$response2 = _context2.t0.response) === null || _error$response2 === void 0 || (_error$response2 = _error$response2.data) === null || _error$response2 === void 0 || (_error$response2 = _error$response2.error) === null || _error$response2 === void 0 ? void 0 : _error$response2.message) || _context2.t0.message || '删除失败';
193
+ _context3.prev = 8;
194
+ _context3.t0 = _context3["catch"](1);
195
+ console.error('删除失败:', _context3.t0);
196
+ errorMessage = ((_error$response3 = _context3.t0.response) === null || _error$response3 === void 0 || (_error$response3 = _error$response3.data) === null || _error$response3 === void 0 || (_error$response3 = _error$response3.error) === null || _error$response3 === void 0 ? void 0 : _error$response3.message) || _context3.t0.message || '删除失败';
109
197
  _antd.message.error("\u5220\u9664\u5931\u8D25\uFF1A".concat(errorMessage));
110
- throw _context2.t0;
198
+ throw _context3.t0;
111
199
  case 14:
112
- _context2.prev = 14;
200
+ _context3.prev = 14;
113
201
  hide();
114
- return _context2.finish(14);
202
+ return _context3.finish(14);
115
203
  case 17:
116
204
  case "end":
117
- return _context2.stop();
205
+ return _context3.stop();
118
206
  }
119
- }, _callee2, null, [[1, 8, 14, 17]]);
207
+ }, _callee3, null, [[1, 8, 14, 17]]);
120
208
  }));
121
- return function defaultHandleDelete(_x4, _x5, _x6) {
122
- return _ref2.apply(this, arguments);
209
+ return function defaultHandleDelete(_x5, _x6, _x7) {
210
+ return _ref3.apply(this, arguments);
123
211
  };
124
212
  }();
125
213
 
@@ -77,8 +77,8 @@ export interface ApiConfig<T = any> {
77
77
  list: (params: ListParams) => Promise<PagedResult<T>>;
78
78
  /** 删除API */
79
79
  delete?: (params: DeleteParams) => Promise<void>;
80
- /** 导出API */
81
- export?: (params: ExportParams) => Promise<Blob>;
80
+ /** 导出API;第二参会传 `{ responseType: 'blob' }`,openapi 生成的函数直接透传给请求 */
81
+ export?: (params: ExportParams, options?: Record<string, any>) => Promise<Blob>;
82
82
  /** 获取导入模板API */
83
83
  getImportTemplate?: () => Promise<Blob>;
84
84
  /** 导入API */
@@ -4,7 +4,7 @@
4
4
  * @param params 导出参数
5
5
  * @param fileName 文件名
6
6
  */
7
- export declare const defaultHandleExport: (exportApi: (params: any) => Promise<Blob>, params: any, fileName: string) => Promise<void>;
7
+ export declare const defaultHandleExport: (exportApi: (params: any, options?: Record<string, any>) => Promise<Blob>, params: any, fileName: string) => Promise<void>;
8
8
  /**
9
9
  * 默认的删除处理器
10
10
  * @param deleteApi 删除API函数
@@ -4,6 +4,68 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try
4
4
  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); }); }; }
5
5
  import { message } from 'antd';
6
6
 
7
+ /**
8
+ * 按 blob 收的请求,后端的 JSON 错误体(无权限、业务校验等)也是 Blob,要读出来才能给出原因。@author nokecy
9
+ */
10
+ var readBlobErrorMessage = /*#__PURE__*/function () {
11
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(data) {
12
+ var _JSON$parse;
13
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
14
+ while (1) switch (_context.prev = _context.next) {
15
+ case 0:
16
+ if (data instanceof Blob) {
17
+ _context.next = 2;
18
+ break;
19
+ }
20
+ return _context.abrupt("return", undefined);
21
+ case 2:
22
+ _context.prev = 2;
23
+ _context.t2 = JSON;
24
+ _context.next = 6;
25
+ return data.text();
26
+ case 6:
27
+ _context.t3 = _context.sent;
28
+ _context.t4 = _JSON$parse = _context.t2.parse.call(_context.t2, _context.t3);
29
+ _context.t1 = _context.t4 === null;
30
+ if (_context.t1) {
31
+ _context.next = 11;
32
+ break;
33
+ }
34
+ _context.t1 = _JSON$parse === void 0;
35
+ case 11:
36
+ _context.t0 = _context.t1;
37
+ if (_context.t0) {
38
+ _context.next = 14;
39
+ break;
40
+ }
41
+ _context.t0 = (_JSON$parse = _JSON$parse.error) === null || _JSON$parse === void 0;
42
+ case 14:
43
+ if (!_context.t0) {
44
+ _context.next = 18;
45
+ break;
46
+ }
47
+ _context.t5 = void 0;
48
+ _context.next = 19;
49
+ break;
50
+ case 18:
51
+ _context.t5 = _JSON$parse.message;
52
+ case 19:
53
+ return _context.abrupt("return", _context.t5);
54
+ case 22:
55
+ _context.prev = 22;
56
+ _context.t6 = _context["catch"](2);
57
+ return _context.abrupt("return", undefined);
58
+ case 25:
59
+ case "end":
60
+ return _context.stop();
61
+ }
62
+ }, _callee, null, [[2, 22]]);
63
+ }));
64
+ return function readBlobErrorMessage(_x) {
65
+ return _ref.apply(this, arguments);
66
+ };
67
+ }();
68
+
7
69
  /**
8
70
  * 默认的导出处理器
9
71
  * @param exportApi 导出API函数
@@ -11,26 +73,28 @@ import { message } from 'antd';
11
73
  * @param fileName 文件名
12
74
  */
13
75
  export var defaultHandleExport = /*#__PURE__*/function () {
14
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(exportApi, params, fileName) {
15
- var hide, response, url, link, _error$response, errorMessage;
16
- return _regeneratorRuntime().wrap(function _callee$(_context) {
17
- while (1) switch (_context.prev = _context.next) {
76
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(exportApi, params, fileName) {
77
+ var hide, response, url, link, _error$response, _error$response2, errorMessage;
78
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
79
+ while (1) switch (_context2.prev = _context2.next) {
18
80
  case 0:
19
81
  hide = message.loading('正在导出,请稍后', 0);
20
- _context.prev = 1;
21
- _context.next = 4;
22
- return exportApi(params);
82
+ _context2.prev = 1;
83
+ _context2.next = 4;
84
+ return exportApi(params, {
85
+ responseType: 'blob'
86
+ });
23
87
  case 4:
24
- response = _context.sent;
88
+ response = _context2.sent;
25
89
  if (response instanceof Blob) {
26
- _context.next = 8;
90
+ _context2.next = 8;
27
91
  break;
28
92
  }
29
93
  console.error('导出API返回的不是Blob对象:', response);
30
94
  throw new Error('导出数据格式错误,请检查API配置');
31
95
  case 8:
32
96
  if (!(response.size === 0)) {
33
- _context.next = 10;
97
+ _context2.next = 10;
34
98
  break;
35
99
  }
36
100
  throw new Error('导出的文件为空');
@@ -47,27 +111,51 @@ export var defaultHandleExport = /*#__PURE__*/function () {
47
111
  document.body.removeChild(link);
48
112
  window.URL.revokeObjectURL(url);
49
113
  message.success('导出成功');
50
- _context.next = 27;
114
+ _context2.next = 38;
51
115
  break;
52
116
  case 21:
53
- _context.prev = 21;
54
- _context.t0 = _context["catch"](1);
55
- console.error('导出失败:', _context.t0);
56
- 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 || '导出失败';
117
+ _context2.prev = 21;
118
+ _context2.t0 = _context2["catch"](1);
119
+ console.error('导出失败:', _context2.t0);
120
+ _context2.next = 26;
121
+ return readBlobErrorMessage((_error$response = _context2.t0.response) === null || _error$response === void 0 ? void 0 : _error$response.data);
122
+ case 26:
123
+ _context2.t3 = _context2.sent;
124
+ if (_context2.t3) {
125
+ _context2.next = 29;
126
+ break;
127
+ }
128
+ _context2.t3 = (_error$response2 = _context2.t0.response) === null || _error$response2 === void 0 || (_error$response2 = _error$response2.data) === null || _error$response2 === void 0 || (_error$response2 = _error$response2.error) === null || _error$response2 === void 0 ? void 0 : _error$response2.message;
129
+ case 29:
130
+ _context2.t2 = _context2.t3;
131
+ if (_context2.t2) {
132
+ _context2.next = 32;
133
+ break;
134
+ }
135
+ _context2.t2 = _context2.t0.message;
136
+ case 32:
137
+ _context2.t1 = _context2.t2;
138
+ if (_context2.t1) {
139
+ _context2.next = 35;
140
+ break;
141
+ }
142
+ _context2.t1 = '导出失败';
143
+ case 35:
144
+ errorMessage = _context2.t1;
57
145
  message.error("\u5BFC\u51FA\u5931\u8D25\uFF1A".concat(errorMessage));
58
- throw _context.t0;
59
- case 27:
60
- _context.prev = 27;
146
+ throw _context2.t0;
147
+ case 38:
148
+ _context2.prev = 38;
61
149
  hide();
62
- return _context.finish(27);
63
- case 30:
150
+ return _context2.finish(38);
151
+ case 41:
64
152
  case "end":
65
- return _context.stop();
153
+ return _context2.stop();
66
154
  }
67
- }, _callee, null, [[1, 21, 27, 30]]);
155
+ }, _callee2, null, [[1, 21, 38, 41]]);
68
156
  }));
69
- return function defaultHandleExport(_x, _x2, _x3) {
70
- return _ref.apply(this, arguments);
157
+ return function defaultHandleExport(_x2, _x3, _x4) {
158
+ return _ref2.apply(this, arguments);
71
159
  };
72
160
  }();
73
161
 
@@ -78,14 +166,14 @@ export var defaultHandleExport = /*#__PURE__*/function () {
78
166
  * @param onSuccess 成功回调
79
167
  */
80
168
  export var defaultHandleDelete = /*#__PURE__*/function () {
81
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(deleteApi, id, onSuccess) {
82
- var hide, _error$response2, errorMessage;
83
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
84
- while (1) switch (_context2.prev = _context2.next) {
169
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(deleteApi, id, onSuccess) {
170
+ var hide, _error$response3, errorMessage;
171
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
172
+ while (1) switch (_context3.prev = _context3.next) {
85
173
  case 0:
86
174
  hide = message.loading('正在删除,请稍后', 0);
87
- _context2.prev = 1;
88
- _context2.next = 4;
175
+ _context3.prev = 1;
176
+ _context3.next = 4;
89
177
  return deleteApi({
90
178
  id: id
91
179
  });
@@ -94,27 +182,27 @@ export var defaultHandleDelete = /*#__PURE__*/function () {
94
182
  if (onSuccess) {
95
183
  onSuccess();
96
184
  }
97
- _context2.next = 14;
185
+ _context3.next = 14;
98
186
  break;
99
187
  case 8:
100
- _context2.prev = 8;
101
- _context2.t0 = _context2["catch"](1);
102
- console.error('删除失败:', _context2.t0);
103
- errorMessage = ((_error$response2 = _context2.t0.response) === null || _error$response2 === void 0 || (_error$response2 = _error$response2.data) === null || _error$response2 === void 0 || (_error$response2 = _error$response2.error) === null || _error$response2 === void 0 ? void 0 : _error$response2.message) || _context2.t0.message || '删除失败';
188
+ _context3.prev = 8;
189
+ _context3.t0 = _context3["catch"](1);
190
+ console.error('删除失败:', _context3.t0);
191
+ errorMessage = ((_error$response3 = _context3.t0.response) === null || _error$response3 === void 0 || (_error$response3 = _error$response3.data) === null || _error$response3 === void 0 || (_error$response3 = _error$response3.error) === null || _error$response3 === void 0 ? void 0 : _error$response3.message) || _context3.t0.message || '删除失败';
104
192
  message.error("\u5220\u9664\u5931\u8D25\uFF1A".concat(errorMessage));
105
- throw _context2.t0;
193
+ throw _context3.t0;
106
194
  case 14:
107
- _context2.prev = 14;
195
+ _context3.prev = 14;
108
196
  hide();
109
- return _context2.finish(14);
197
+ return _context3.finish(14);
110
198
  case 17:
111
199
  case "end":
112
- return _context2.stop();
200
+ return _context3.stop();
113
201
  }
114
- }, _callee2, null, [[1, 8, 14, 17]]);
202
+ }, _callee3, null, [[1, 8, 14, 17]]);
115
203
  }));
116
- return function defaultHandleDelete(_x4, _x5, _x6) {
117
- return _ref2.apply(this, arguments);
204
+ return function defaultHandleDelete(_x5, _x6, _x7) {
205
+ return _ref3.apply(this, arguments);
118
206
  };
119
207
  }();
120
208
 
@@ -77,8 +77,8 @@ export interface ApiConfig<T = any> {
77
77
  list: (params: ListParams) => Promise<PagedResult<T>>;
78
78
  /** 删除API */
79
79
  delete?: (params: DeleteParams) => Promise<void>;
80
- /** 导出API */
81
- export?: (params: ExportParams) => Promise<Blob>;
80
+ /** 导出API;第二参会传 `{ responseType: 'blob' }`,openapi 生成的函数直接透传给请求 */
81
+ export?: (params: ExportParams, options?: Record<string, any>) => Promise<Blob>;
82
82
  /** 获取导入模板API */
83
83
  getImportTemplate?: () => Promise<Blob>;
84
84
  /** 导入API */