xydata-tools 1.1.4 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ export { default as OrganizationFront } from "./organization";
3
3
  export { default as Sso } from "./sso";
4
4
  export { default as Aaa } from "./aaa";
5
5
  export { default as BothSecurityLayout } from "./both";
6
- export { default as XyAuthLayout, logout } from "./xyAuthLayout";
6
+ export { default as XyAuthLayout, logout, handleUnauthorized } from "./xyAuthLayout";
7
7
  export { default as UploadFile } from "./uploadFile";
8
8
  export { default as DownloadFile } from "./downloadFile";
9
9
  export { default as Version } from "./tools/version";
@@ -387,7 +387,7 @@ export var logout = /*#__PURE__*/function () {
387
387
  console.error('AAA 退出登录失败:', _context5.t0);
388
388
  case 13:
389
389
  window.location.href = "".concat(window.publicPath || '/', "user/login");
390
- _context5.next = 27;
390
+ _context5.next = 29;
391
391
  break;
392
392
  case 16:
393
393
  _context5.prev = 16;
@@ -396,16 +396,24 @@ export var logout = /*#__PURE__*/function () {
396
396
  case 19:
397
397
  res = _context5.sent;
398
398
  removeSessionData();
399
- if (res) {
399
+ // 检查响应是否有效
400
+ if (res && typeof res === 'string') {
400
401
  window.location.href = res;
402
+ } else {
403
+ // 如果没有返回跳转地址,则跳转到默认登录页
404
+ console.warn('SSO 退出登录未返回跳转地址,使用默认登录页');
405
+ window.location.href = "".concat(window.publicPath || '/', "user/login");
401
406
  }
402
- _context5.next = 27;
407
+ _context5.next = 29;
403
408
  break;
404
409
  case 24:
405
410
  _context5.prev = 24;
406
411
  _context5.t1 = _context5["catch"](16);
407
412
  console.error('SSO 退出登录失败:', _context5.t1);
408
- case 27:
413
+ // 即使退出失败,也清理本地数据并跳转到登录页
414
+ removeSessionData();
415
+ window.location.href = "".concat(window.publicPath || '/', "user/login");
416
+ case 29:
409
417
  case "end":
410
418
  return _context5.stop();
411
419
  }
@@ -7,4 +7,4 @@ export { default as UploadFile } from "./uploadFile";
7
7
  export { default as DownloadFile } from "./downloadFile";
8
8
  export { default as Version } from "./tools/version";
9
9
  export { default as MaterialCard } from "./materialCard";
10
- export { default as XyAuthLayout, logout } from "./xyAuthLayout";
10
+ export { default as XyAuthLayout, logout, handleUnauthorized } from "./xyAuthLayout";
@@ -1 +1,27 @@
1
- export default function doRequest(url: any, method: any, data: any, params: any): Promise<any>;
1
+ /**
2
+ * 统一请求封装函数
3
+ * 支持 GET、POST、PUT、DELETE 等方法
4
+ * 自动处理认证、错误提示、响应解析等
5
+ *
6
+ * @param {string} url - 请求地址
7
+ * @param {string} method - 请求方法 (GET, POST, PUT, DELETE 等)
8
+ * @param {Object} [data] - 请求体数据 (POST, PUT 等)
9
+ * @param {Object} [params] - URL 查询参数 (GET 等)
10
+ * @param {Object} [options] - 额外的请求配置
11
+ * @returns {Promise<any>} 响应数据
12
+ *
13
+ * @example
14
+ * // GET 请求
15
+ * const users = await doRequest('/api/users', 'GET', null, { page: 1 });
16
+ *
17
+ * @example
18
+ * // POST 请求
19
+ * const result = await doRequest('/api/login', 'POST', { username, password });
20
+ *
21
+ * @example
22
+ * // 自定义配置
23
+ * const data = await doRequest('/api/upload', 'POST', formData, null, {
24
+ * headers: { 'Content-Type': 'multipart/form-data' }
25
+ * });
26
+ */
27
+ export default function doRequest(url: string, method: string, data?: any, params?: any, options?: any): Promise<any>;
@@ -1,81 +1,220 @@
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; }
3
1
  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; }
4
2
  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; }
5
3
  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; }
6
4
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
5
  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); }
6
+ 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); }
7
+ 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; }
8
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
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
- import { request, history } from 'umi';
10
+ import { request } from 'umi';
11
11
  import { message } from 'antd';
12
12
  import { getSessionStorage } from "./token.js";
13
- export default function doRequest(_x, _x2, _x3, _x4) {
13
+ import { handleUnauthorized } from "../components";
14
+
15
+ /**
16
+ * 构建请求头
17
+ * @returns {Object} 请求头对象
18
+ */
19
+ var buildHeaders = function buildHeaders() {
20
+ var token = getSessionStorage('Token');
21
+ var userId = getSessionStorage('userId');
22
+ var orgId = getSessionStorage('orgId');
23
+ var service = getSessionStorage('service') || 'unknown';
24
+ return {
25
+ SID: SID,
26
+ Authorization: token ? "Bearer ".concat(token) : '',
27
+ UserId: userId || '',
28
+ OrgId: orgId || '',
29
+ service: service
30
+ };
31
+ };
32
+
33
+ /**
34
+ * 安全解析 JSON 响应
35
+ * @param {Response} response - 响应对象
36
+ * @returns {Promise<any>} 解析后的数据,失败时返回 null
37
+ */
38
+ var safeParseJSON = /*#__PURE__*/function () {
39
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(response) {
40
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
41
+ while (1) switch (_context.prev = _context.next) {
42
+ case 0:
43
+ _context.prev = 0;
44
+ _context.next = 3;
45
+ return response.json();
46
+ case 3:
47
+ return _context.abrupt("return", _context.sent);
48
+ case 6:
49
+ _context.prev = 6;
50
+ _context.t0 = _context["catch"](0);
51
+ console.error('JSON 解析失败:', _context.t0);
52
+ return _context.abrupt("return", null);
53
+ case 10:
54
+ case "end":
55
+ return _context.stop();
56
+ }
57
+ }, _callee, null, [[0, 6]]);
58
+ }));
59
+ return function safeParseJSON(_x) {
60
+ return _ref.apply(this, arguments);
61
+ };
62
+ }();
63
+
64
+ /**
65
+ * 处理成功响应
66
+ * @param {Object} responseData - 响应数据对象,包含 data 和 response
67
+ * @returns {any} 处理后的数据
68
+ */
69
+ var handleSuccessResponse = function handleSuccessResponse(_ref2) {
70
+ var data = _ref2.data,
71
+ response = _ref2.response;
72
+ // 如果是字符串类型(如 text/plain),直接返回
73
+ if (typeof data === 'string') {
74
+ return data;
75
+ }
76
+
77
+ // 如果是对象类型(JSON 响应)
78
+ if (data && _typeof(data) === 'object') {
79
+ // 检查业务错误码
80
+ if (data.rspCode && data.rspCode !== '000000') {
81
+ // 业务逻辑错误
82
+ if (data.rspMsg) {
83
+ message.error(data.rspMsg);
84
+ }
85
+ }
86
+ return data;
87
+ }
88
+
89
+ // 其他类型(如 null, undefined, number 等)直接返回
90
+ return data;
91
+ };
92
+
93
+ /**
94
+ * 处理错误响应
95
+ * @param {Error} error - 错误对象
96
+ * @returns {Promise<any>} 处理后的响应或 null
97
+ */
98
+ var handleErrorResponse = /*#__PURE__*/function () {
99
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(error) {
100
+ var status, data, _error$request;
101
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
102
+ while (1) switch (_context2.prev = _context2.next) {
103
+ case 0:
104
+ if (error.response) {
105
+ _context2.next = 4;
106
+ break;
107
+ }
108
+ console.error('网络请求失败:', {
109
+ message: error.message,
110
+ stack: error.stack,
111
+ error: error
112
+ });
113
+ message.error('网络请求失败,请检查网络连接');
114
+ return _context2.abrupt("return", null);
115
+ case 4:
116
+ status = error.response.status;
117
+ if (!(status === 401)) {
118
+ _context2.next = 8;
119
+ break;
120
+ }
121
+ handleUnauthorized(ENV_DATA);
122
+ return _context2.abrupt("return");
123
+ case 8:
124
+ if (!(status >= 400 && status < 500)) {
125
+ _context2.next = 15;
126
+ break;
127
+ }
128
+ _context2.next = 11;
129
+ return safeParseJSON(error.response);
130
+ case 11:
131
+ data = _context2.sent;
132
+ if (data !== null && data !== void 0 && data.rspMsg) {
133
+ message.error(data.rspMsg);
134
+ } else {
135
+ message.error("\u8BF7\u6C42\u9519\u8BEF (".concat(status, ")"));
136
+ }
137
+ _context2.next = 16;
138
+ break;
139
+ case 15:
140
+ if (status >= 500) {
141
+ // 服务器错误
142
+ console.error('服务器错误:', {
143
+ status: status,
144
+ url: (_error$request = error.request) === null || _error$request === void 0 ? void 0 : _error$request.url,
145
+ error: error
146
+ });
147
+ message.error('服务器异常,请稍后重试');
148
+ } else {
149
+ // 其他未知错误
150
+ console.error('未知错误:', error);
151
+ message.error('请求失败,请稍后重试');
152
+ }
153
+ case 16:
154
+ return _context2.abrupt("return", error.response);
155
+ case 17:
156
+ case "end":
157
+ return _context2.stop();
158
+ }
159
+ }, _callee2);
160
+ }));
161
+ return function handleErrorResponse(_x2) {
162
+ return _ref3.apply(this, arguments);
163
+ };
164
+ }();
165
+
166
+ /**
167
+ * 统一请求封装函数
168
+ * 支持 GET、POST、PUT、DELETE 等方法
169
+ * 自动处理认证、错误提示、响应解析等
170
+ *
171
+ * @param {string} url - 请求地址
172
+ * @param {string} method - 请求方法 (GET, POST, PUT, DELETE 等)
173
+ * @param {Object} [data] - 请求体数据 (POST, PUT 等)
174
+ * @param {Object} [params] - URL 查询参数 (GET 等)
175
+ * @param {Object} [options] - 额外的请求配置
176
+ * @returns {Promise<any>} 响应数据
177
+ *
178
+ * @example
179
+ * // GET 请求
180
+ * const users = await doRequest('/api/users', 'GET', null, { page: 1 });
181
+ *
182
+ * @example
183
+ * // POST 请求
184
+ * const result = await doRequest('/api/login', 'POST', { username, password });
185
+ *
186
+ * @example
187
+ * // 自定义配置
188
+ * const data = await doRequest('/api/upload', 'POST', formData, null, {
189
+ * headers: { 'Content-Type': 'multipart/form-data' }
190
+ * });
191
+ */
192
+ export default function doRequest(_x3, _x4, _x5, _x6) {
14
193
  return _doRequest.apply(this, arguments);
15
194
  }
16
195
  function _doRequest() {
17
- _doRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(url, method, data, params) {
18
- var headers;
19
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
20
- while (1) switch (_context2.prev = _context2.next) {
196
+ _doRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(url, method, data, params) {
197
+ var options,
198
+ headers,
199
+ _args3 = arguments;
200
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
201
+ while (1) switch (_context3.prev = _context3.next) {
21
202
  case 0:
22
- headers = {
23
- SID: SID,
24
- Authorization: 'Bearer ' + getSessionStorage(),
25
- UserId: getSessionStorage('userId'),
26
- OrgId: getSessionStorage('orgId')
27
- };
28
- return _context2.abrupt("return", request(url, {
203
+ options = _args3.length > 4 && _args3[4] !== undefined ? _args3[4] : {};
204
+ headers = buildHeaders();
205
+ return _context3.abrupt("return", request(url, _objectSpread({
29
206
  method: method,
30
207
  params: params,
31
208
  data: data,
32
- headers: _objectSpread(_objectSpread({}, headers), {}, {
33
- service: getSessionStorage('service') || 'unknow'
34
- }),
209
+ headers: _objectSpread(_objectSpread({}, headers), options.headers),
35
210
  getResponse: true,
36
211
  skipErrorHandler: true
37
- }).then(function (_ref) {
38
- var data = _ref.data;
39
- if (data.rspCode !== '000000' && data.rspMsg) {
40
- message.error(data.rspMsg);
41
- }
42
- return data;
43
- }).catch( /*#__PURE__*/function () {
44
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(error) {
45
- var _data;
46
- return _regeneratorRuntime().wrap(function _callee$(_context) {
47
- while (1) switch (_context.prev = _context.next) {
48
- case 0:
49
- if (!(error.response.status === 401 || error.response.status === 402 || error.response.status === 403)) {
50
- _context.next = 7;
51
- break;
52
- }
53
- _context.next = 3;
54
- return error.response.json();
55
- case 3:
56
- _data = _context.sent;
57
- _data.rspMsg && message.error(_data.rspMsg);
58
- _context.next = 8;
59
- break;
60
- case 7:
61
- message.error('服务器异常');
62
- case 8:
63
- return _context.abrupt("return", error.response);
64
- case 9:
65
- case "end":
66
- return _context.stop();
67
- }
68
- }, _callee);
69
- }));
70
- return function (_x5) {
71
- return _ref2.apply(this, arguments);
72
- };
73
- }()));
74
- case 2:
212
+ }, options)).then(handleSuccessResponse).catch(handleErrorResponse));
213
+ case 3:
75
214
  case "end":
76
- return _context2.stop();
215
+ return _context3.stop();
77
216
  }
78
- }, _callee2);
217
+ }, _callee3);
79
218
  }));
80
219
  return _doRequest.apply(this, arguments);
81
220
  }
@@ -4,7 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
4
  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
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  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); }
7
- import { message } from "antd";
7
+ import { message } from 'antd';
8
8
 
9
9
  /**
10
10
  * 设置页面中接口回调
@@ -16,8 +16,8 @@ export var asyncCallback = function asyncCallback(res, isTip) {
16
16
  if (!res) return;
17
17
  var rspCode = res.rspCode,
18
18
  rspMsg = res.rspMsg;
19
- if (rspCode === "000000") {
20
- if (isTip) message.success(rspMsg);
19
+ if (rspCode === '000000') {
20
+ if (isTip && rspMsg) message.success(rspMsg);
21
21
  return true;
22
22
  } else {
23
23
  message.error(rspMsg);
@@ -32,9 +32,9 @@ export var asyncCallback = function asyncCallback(res, isTip) {
32
32
  */
33
33
  export function getQueryVariable(variable) {
34
34
  var query = window.location.search.substring(1);
35
- var vars = query.split("&");
35
+ var vars = query.split('&');
36
36
  for (var i = 0; i < vars.length; i++) {
37
- var pair = vars[i].split("=");
37
+ var pair = vars[i].split('=');
38
38
  if (pair[0] == variable) {
39
39
  return pair[1];
40
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xydata-tools",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "xydata tools",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",