xydata-tools 1.1.16 → 1.1.18

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.
@@ -100,35 +100,6 @@ var SMSConfig = function SMSConfig() {
100
100
  return _ref2.apply(this, arguments);
101
101
  };
102
102
  }();
103
- var handleSwitchChange = /*#__PURE__*/function () {
104
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(checked, record) {
105
- var res;
106
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
107
- while (1) switch (_context3.prev = _context3.next) {
108
- case 0:
109
- _context3.next = 2;
110
- return saveSmsProperty({
111
- id: record.id,
112
- value: checked.toString()
113
- });
114
- case 2:
115
- res = _context3.sent;
116
- if (res && res.rspCode === '000000') {
117
- message.success("".concat(record.propertyName, " \u5DF2").concat(checked ? '开启' : '关闭'));
118
- fetchData();
119
- } else {
120
- message.error((res === null || res === void 0 ? void 0 : res.rspMsg) || '操作失败');
121
- }
122
- case 4:
123
- case "end":
124
- return _context3.stop();
125
- }
126
- }, _callee3);
127
- }));
128
- return function handleSwitchChange(_x2, _x3) {
129
- return _ref3.apply(this, arguments);
130
- };
131
- }();
132
103
 
133
104
  // 数据按 groupName 分组
134
105
  var groupedData = dataSource.reduce(function (acc, item) {
@@ -210,7 +181,8 @@ var SMSConfig = function SMSConfig() {
210
181
  onCancel: function onCancel() {
211
182
  setModalVisible(false);
212
183
  setEditingRecord(null);
213
- }
184
+ },
185
+ onOk: handleEditSave
214
186
  }));
215
187
  };
216
188
  export default SMSConfig;
@@ -1,27 +1,13 @@
1
+ export default doRequest;
1
2
  /**
2
- * 统一请求封装函数
3
- * 支持 GET、POST、PUT、DELETE 等方法
4
- * 自动处理认证、错误提示、响应解析等
5
- *
3
+ * 配置request请求时的默认参数
4
+ */
5
+ export const request: import("umi-request").RequestMethod<false>;
6
+ /**
7
+ * 封装后的 doRequest 函数,保持与原有项目的参数兼容性
6
8
  * @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
- * });
9
+ * @param {string} method - 请求方法
10
+ * @param {Object} data - 请求体数据
11
+ * @param {Object} options - 额外配置
26
12
  */
27
- export default function doRequest(url: string, method: string, data?: any, params?: any, options?: any): Promise<any>;
13
+ export function doRequest(url: string, method: string, data?: any, options?: any): Promise<any>;
@@ -1,215 +1,208 @@
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; }
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; }
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; }
4
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
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
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); }
7
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; }
8
3
  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
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); }); }; }
10
- import { request } from 'umi';
11
- import { message } from 'antd';
5
+ /**
6
+ * request 网络请求工具
7
+ * api 文档: https://github.com/umijs/umi-request/blob/master/README_zh-CN.md
8
+ */
9
+ import { extend } from 'umi-request';
10
+ import { notification, message } from 'antd';
12
11
  import { getSessionStorage } from "./token.js";
13
12
  import { handleUnauthorized } from "../components";
14
13
 
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
- };
14
+ /* ********************************************************************************************************************************* */
15
+ /* ********************************************************************************************************************************* */
16
+ /* ********************************************************************************************************************************* */
17
+ // 无需TOKEN验证的接口,例如AAA登录接口
18
+ var NO_TOKEN_URLS = [];
19
+
20
+ // 需要在业务层处理的状态编码,例如需要判断当接口返回999999时需要弹窗提示,那么可在下方加上999999,未配置的会进入错误回调
21
+ var PROCESS_RESPONSE_CODES = ['000000'];
22
+
23
+ /* ********************************************************************************************************************************* */
24
+ /* ********************************************************************************************************************************* */
25
+ /* ********************************************************************************************************************************* */
26
+
27
+ // 服务器状态中文映射
28
+ var CODE_MESSAGE = {
29
+ 200: '服务器成功返回请求的数据。',
30
+ 201: '新建或修改数据成功。',
31
+ 202: '一个请求已经进入后台排队(异步任务)。',
32
+ 204: '删除数据成功。',
33
+ 400: '发出的请求有错误,服务器没有进行新建或修改数据的操作。',
34
+ 401: '用户没有权限(令牌、用户名、密码错误)。',
35
+ 403: '用户得到授权,但是访问是被禁止的。',
36
+ 404: '发出的请求针对的是不存在的记录,服务器没有进行操作。',
37
+ 406: '请求的格式不可得。',
38
+ 410: '请求的资源被永久删除,且不会再得到的。',
39
+ 422: '当创建一个对象时,发生一个验证错误。',
40
+ 429: '太火爆了,请稍后再试。',
41
+ 500: '服务器发生错误,请检查服务器。',
42
+ 502: '网关错误。',
43
+ 503: '服务不可用,服务器暂时过载或维护。',
44
+ 504: '网关超时。'
31
45
  };
32
46
 
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) {
47
+ // 请求异常处理程序。进入错误回调的,只会返回false。
48
+ var errorHandler = /*#__PURE__*/function () {
49
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(error) {
50
+ var response, errorText, status, url, errorData, rspMsg;
40
51
  return _regeneratorRuntime().wrap(function _callee$(_context) {
41
52
  while (1) switch (_context.prev = _context.next) {
42
53
  case 0:
43
- _context.prev = 0;
44
- _context.next = 3;
54
+ response = error.response;
55
+ if (!(response && response.status)) {
56
+ _context.next = 23;
57
+ break;
58
+ }
59
+ errorText = CODE_MESSAGE[response.status] || response.statusText;
60
+ status = response.status, url = response.url;
61
+ _context.prev = 4;
62
+ _context.next = 7;
45
63
  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:
64
+ case 7:
65
+ errorData = _context.sent;
66
+ rspMsg = errorData.rspMsg;
67
+ if (rspMsg) {
68
+ message.error(rspMsg);
69
+ }
70
+ if (!(status == 401)) {
71
+ _context.next = 14;
72
+ break;
73
+ }
74
+ handleUnauthorized(ENV_DATA);
75
+ _context.next = 16;
76
+ break;
77
+ case 14:
78
+ if (!(status !== 200)) {
79
+ _context.next = 16;
80
+ break;
81
+ }
82
+ throw new Error();
83
+ case 16:
84
+ _context.next = 21;
85
+ break;
86
+ case 18:
87
+ _context.prev = 18;
88
+ _context.t0 = _context["catch"](4);
89
+ notification.error({
90
+ message: "\u8BF7\u6C42\u9519\u8BEF ".concat(status, ": ").concat(url),
91
+ description: errorText
92
+ });
93
+ case 21:
94
+ _context.next = 24;
95
+ break;
96
+ case 23:
97
+ if (!response) {
98
+ console.error(error);
99
+ notification.error({
100
+ message: '网络异常',
101
+ description: '您的网络发生异常,无法连接服务器'
102
+ });
103
+ }
104
+ case 24:
105
+ return _context.abrupt("return", false);
106
+ case 25:
54
107
  case "end":
55
108
  return _context.stop();
56
109
  }
57
- }, _callee, null, [[0, 6]]);
110
+ }, _callee, null, [[4, 18]]);
58
111
  }));
59
- return function safeParseJSON(_x) {
112
+ return function errorHandler(_x) {
60
113
  return _ref.apply(this, arguments);
61
114
  };
62
115
  }();
63
116
 
64
117
  /**
65
- * 处理成功响应
66
- * @param {Object} responseData - 响应数据对象,包含 data 和 response
67
- * @returns {any} 处理后的数据
118
+ * 配置request请求时的默认参数
68
119
  */
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
- }
120
+ var request = extend({
121
+ errorHandler: errorHandler
122
+ });
76
123
 
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;
124
+ // request拦截器
125
+ request.interceptors.request.use(function (url, options) {
126
+ options.headers = {
127
+ 'Content-Type': 'application/json; charset=utf-8',
128
+ Accept: 'application/json',
129
+ UserId: getSessionStorage('userId'),
130
+ OrgId: getSessionStorage('orgId'),
131
+ service: getSessionStorage('service') || 'unknown',
132
+ SID: SID
133
+ };
134
+ // 过滤不需要TOKEN的请求,统一加上Authorization
135
+ if (!NO_TOKEN_URLS.includes(url)) {
136
+ // TOKEN在每次调用的时候获取最新值
137
+ var token = getSessionStorage('Token');
138
+ options.headers.Authorization = token ? "Bearer ".concat(token) : '';
87
139
  }
140
+ return {
141
+ url: url,
142
+ options: options
143
+ };
144
+ });
88
145
 
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;
146
+ // response拦截器
147
+ request.interceptors.response.use( /*#__PURE__*/function () {
148
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(response, options) {
149
+ var data, rspCode;
101
150
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
102
151
  while (1) switch (_context2.prev = _context2.next) {
103
152
  case 0:
104
- if (error.response) {
105
- _context2.next = 4;
153
+ if (!response.ok) {
154
+ _context2.next = 7;
106
155
  break;
107
156
  }
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;
157
+ _context2.next = 3;
158
+ return response.clone().json();
159
+ case 3:
160
+ data = _context2.sent;
161
+ rspCode = data.rspCode; // 状态编码只有在已定义的,需要处理的编码里才会返回响应,否则会进入错误回调
162
+ if (!(rspCode && PROCESS_RESPONSE_CODES.includes(rspCode))) {
163
+ _context2.next = 7;
119
164
  break;
120
165
  }
121
- handleUnauthorized(ENV_DATA);
122
- return _context2.abrupt("return");
166
+ return _context2.abrupt("return", data);
167
+ case 7:
168
+ throw {
169
+ response: response
170
+ };
123
171
  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
172
  case "end":
157
173
  return _context2.stop();
158
174
  }
159
175
  }, _callee2);
160
176
  }));
161
- return function handleErrorResponse(_x2) {
162
- return _ref3.apply(this, arguments);
177
+ return function (_x2, _x3) {
178
+ return _ref2.apply(this, arguments);
163
179
  };
164
- }();
180
+ }());
165
181
 
166
182
  /**
167
- * 统一请求封装函数
168
- * 支持 GET、POST、PUT、DELETE 等方法
169
- * 自动处理认证、错误提示、响应解析等
170
- *
183
+ * 封装后的 doRequest 函数,保持与原有项目的参数兼容性
171
184
  * @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
- * });
185
+ * @param {string} method - 请求方法
186
+ * @param {Object} data - 请求体数据
187
+ * @param {Object} options - 额外配置
191
188
  */
192
- export default function doRequest(_x3, _x4, _x5, _x6) {
189
+ function doRequest(_x4, _x5) {
193
190
  return _doRequest.apply(this, arguments);
194
191
  }
195
192
  function _doRequest() {
196
- _doRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(url, method, data, params) {
197
- var options,
198
- headers,
193
+ _doRequest = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(url, method) {
194
+ var data,
195
+ options,
199
196
  _args3 = arguments;
200
197
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
201
198
  while (1) switch (_context3.prev = _context3.next) {
202
199
  case 0:
203
- options = _args3.length > 4 && _args3[4] !== undefined ? _args3[4] : {};
204
- headers = buildHeaders();
205
- return _context3.abrupt("return", request(url, _objectSpread({
200
+ data = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {};
201
+ options = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : {};
202
+ return _context3.abrupt("return", request(url, {
206
203
  method: method,
207
- params: params,
208
- data: data,
209
- headers: _objectSpread(_objectSpread({}, headers), options.headers),
210
- getResponse: true,
211
- skipErrorHandler: true
212
- }, options)).then(handleSuccessResponse).catch(handleErrorResponse));
204
+ data: data
205
+ }));
213
206
  case 3:
214
207
  case "end":
215
208
  return _context3.stop();
@@ -217,4 +210,6 @@ function _doRequest() {
217
210
  }, _callee3);
218
211
  }));
219
212
  return _doRequest.apply(this, arguments);
220
- }
213
+ }
214
+ export { request, doRequest };
215
+ export default doRequest;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xydata-tools",
3
- "version": "1.1.16",
3
+ "version": "1.1.18",
4
4
  "description": "xydata tools",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
@@ -65,6 +65,7 @@
65
65
  "compressorjs": "1.2.1",
66
66
  "querystring": "0.2.1",
67
67
  "react-json-view": "^1.21.3",
68
- "styled-components": "4.4.1"
68
+ "styled-components": "4.4.1",
69
+ "umi-request": "^1.4.0"
69
70
  }
70
71
  }