@noah-libjs/request 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helper.d.ts +1 -1
- package/dist/index.js +22 -11
- package/package.json +3 -3
package/dist/helper.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ICommonOption } from "@noah-libjs/utils";
|
|
2
2
|
import { FormInstance } from "antd";
|
|
3
3
|
export type T_FETCH_OPTIONS = ((f?: FormInstance) => (Promise<ICommonOption[]> | ICommonOption[])) | {
|
|
4
|
-
url: string;
|
|
4
|
+
url: string | (() => string);
|
|
5
5
|
labelKey?: string;
|
|
6
6
|
valueKey?: string;
|
|
7
7
|
method?: 'get' | 'post';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
1
2
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
4
|
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
@@ -8,7 +9,7 @@ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstruct
|
|
|
8
9
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
|
|
9
10
|
import axios, { Axios } from 'axios';
|
|
10
11
|
import utils from 'axios/lib/utils';
|
|
11
|
-
import { MyLog, EventEmitter, isFunction, safe_async_call, expect_array, cache_fetch, get } from '@noah-libjs/utils';
|
|
12
|
+
import { MyLog, EventEmitter, getSearchParamsAll, isFunction, safe_async_call, expect_array, isString, cache_fetch, get } from '@noah-libjs/utils';
|
|
12
13
|
import bind from 'axios/lib/helpers/bind';
|
|
13
14
|
var codeMessage = {
|
|
14
15
|
200: '服务器成功返回请求的数据。',
|
|
@@ -134,9 +135,18 @@ var Request = /*#__PURE__*/function (_EventEmitter) {
|
|
|
134
135
|
return onRejected(e);
|
|
135
136
|
};
|
|
136
137
|
ins.interceptors.request.use(function (config) {
|
|
138
|
+
var _a;
|
|
139
|
+
var args = getSearchParamsAll();
|
|
140
|
+
var headers = (_a = config.headers) !== null && _a !== void 0 ? _a : config.headers = {};
|
|
141
|
+
Object.entries(args).forEach(function (_ref) {
|
|
142
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
143
|
+
k = _ref2[0],
|
|
144
|
+
v = _ref2[1];
|
|
145
|
+
headers["X-Arg-".concat(k)] = encodeURI(v);
|
|
146
|
+
});
|
|
137
147
|
_this2.emit('request', config);
|
|
138
148
|
// TODO: remove
|
|
139
|
-
|
|
149
|
+
headers.Authorization = headers.Authorization || _this2.token || '';
|
|
140
150
|
// params.pathname = location.pathname
|
|
141
151
|
return onRequest(config);
|
|
142
152
|
});
|
|
@@ -221,11 +231,11 @@ var Request = /*#__PURE__*/function (_EventEmitter) {
|
|
|
221
231
|
key: "getMsg",
|
|
222
232
|
value: function getMsg(res) {
|
|
223
233
|
if (!res) return '';
|
|
224
|
-
var
|
|
225
|
-
|
|
226
|
-
showMsg =
|
|
227
|
-
successText =
|
|
228
|
-
errText =
|
|
234
|
+
var _ref3 = res === null || res === void 0 ? void 0 : res.config,
|
|
235
|
+
_ref3$showMsg = _ref3.showMsg,
|
|
236
|
+
showMsg = _ref3$showMsg === void 0 ? true : _ref3$showMsg,
|
|
237
|
+
successText = _ref3.successText,
|
|
238
|
+
errText = _ref3.errText;
|
|
229
239
|
var remoteMsg = showMsg ? Request.getRemoteMessage(res) : '';
|
|
230
240
|
var isSuccessful = Request.checkRTCode(res);
|
|
231
241
|
var configMsg = isSuccessful ? successText : errText;
|
|
@@ -319,7 +329,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
319
329
|
};
|
|
320
330
|
function safe_fetch_options(cb, f) {
|
|
321
331
|
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
322
|
-
var arr, _cb$method, method, _cb$valueKey, valueKey, _cb$labelKey, labelKey, url;
|
|
332
|
+
var arr, _cb$method, method, _cb$valueKey, valueKey, _cb$labelKey, labelKey, url, _url;
|
|
323
333
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
324
334
|
while (1) switch (_context.prev = _context.next) {
|
|
325
335
|
case 0:
|
|
@@ -334,10 +344,11 @@ function safe_fetch_options(cb, f) {
|
|
|
334
344
|
return _context.abrupt("return", expect_array(arr));
|
|
335
345
|
case 7:
|
|
336
346
|
_cb$method = cb.method, method = _cb$method === void 0 ? 'get' : _cb$method, _cb$valueKey = cb.valueKey, valueKey = _cb$valueKey === void 0 ? 'value' : _cb$valueKey, _cb$labelKey = cb.labelKey, labelKey = _cb$labelKey === void 0 ? 'label' : _cb$labelKey, url = cb.url;
|
|
337
|
-
|
|
347
|
+
_url = isString(url) ? url : url();
|
|
348
|
+
return _context.abrupt("return", cache_fetch(_url, function () {
|
|
338
349
|
return request.ins({
|
|
339
350
|
method: method,
|
|
340
|
-
url:
|
|
351
|
+
url: _url
|
|
341
352
|
});
|
|
342
353
|
}).then(function (res) {
|
|
343
354
|
return expect_array(res.data).map(function (_) {
|
|
@@ -347,7 +358,7 @@ function safe_fetch_options(cb, f) {
|
|
|
347
358
|
};
|
|
348
359
|
});
|
|
349
360
|
}));
|
|
350
|
-
case
|
|
361
|
+
case 10:
|
|
351
362
|
case "end":
|
|
352
363
|
return _context.stop();
|
|
353
364
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@noah-libjs/request",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "echo \"Error: no test specified\" && exit 1",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"access": "public"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@noah-libjs/utils": "0.0.
|
|
24
|
+
"@noah-libjs/utils": "0.0.9",
|
|
25
25
|
"axios": "^0.26.1",
|
|
26
26
|
"store": "2.x"
|
|
27
27
|
},
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"keywords": [],
|
|
33
33
|
"author": "",
|
|
34
34
|
"license": "MIT",
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "bb49d078600e65d77b842887c63be3b254faf999"
|
|
36
36
|
}
|