uniapp-request-sdk 1.4.11 → 1.5.0
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/README.md +1067 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.esm.js +436 -71
- package/dist/index.umd.js +436 -71
- package/package.json +2 -1
package/dist/index.umd.js
CHANGED
|
@@ -4,6 +4,337 @@
|
|
|
4
4
|
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.UniappRequestSdk = {}));
|
|
5
5
|
})(this, (function (exports) { 'use strict';
|
|
6
6
|
|
|
7
|
+
function _regeneratorRuntime() {
|
|
8
|
+
_regeneratorRuntime = function () {
|
|
9
|
+
return exports;
|
|
10
|
+
};
|
|
11
|
+
var exports = {},
|
|
12
|
+
Op = Object.prototype,
|
|
13
|
+
hasOwn = Op.hasOwnProperty,
|
|
14
|
+
defineProperty = Object.defineProperty || function (obj, key, desc) {
|
|
15
|
+
obj[key] = desc.value;
|
|
16
|
+
},
|
|
17
|
+
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
|
18
|
+
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
|
19
|
+
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
|
20
|
+
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
21
|
+
function define(obj, key, value) {
|
|
22
|
+
return Object.defineProperty(obj, key, {
|
|
23
|
+
value: value,
|
|
24
|
+
enumerable: !0,
|
|
25
|
+
configurable: !0,
|
|
26
|
+
writable: !0
|
|
27
|
+
}), obj[key];
|
|
28
|
+
}
|
|
29
|
+
try {
|
|
30
|
+
define({}, "");
|
|
31
|
+
} catch (err) {
|
|
32
|
+
define = function (obj, key, value) {
|
|
33
|
+
return obj[key] = value;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
37
|
+
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
38
|
+
generator = Object.create(protoGenerator.prototype),
|
|
39
|
+
context = new Context(tryLocsList || []);
|
|
40
|
+
return defineProperty(generator, "_invoke", {
|
|
41
|
+
value: makeInvokeMethod(innerFn, self, context)
|
|
42
|
+
}), generator;
|
|
43
|
+
}
|
|
44
|
+
function tryCatch(fn, obj, arg) {
|
|
45
|
+
try {
|
|
46
|
+
return {
|
|
47
|
+
type: "normal",
|
|
48
|
+
arg: fn.call(obj, arg)
|
|
49
|
+
};
|
|
50
|
+
} catch (err) {
|
|
51
|
+
return {
|
|
52
|
+
type: "throw",
|
|
53
|
+
arg: err
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.wrap = wrap;
|
|
58
|
+
var ContinueSentinel = {};
|
|
59
|
+
function Generator() {}
|
|
60
|
+
function GeneratorFunction() {}
|
|
61
|
+
function GeneratorFunctionPrototype() {}
|
|
62
|
+
var IteratorPrototype = {};
|
|
63
|
+
define(IteratorPrototype, iteratorSymbol, function () {
|
|
64
|
+
return this;
|
|
65
|
+
});
|
|
66
|
+
var getProto = Object.getPrototypeOf,
|
|
67
|
+
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
68
|
+
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
69
|
+
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
70
|
+
function defineIteratorMethods(prototype) {
|
|
71
|
+
["next", "throw", "return"].forEach(function (method) {
|
|
72
|
+
define(prototype, method, function (arg) {
|
|
73
|
+
return this._invoke(method, arg);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function AsyncIterator(generator, PromiseImpl) {
|
|
78
|
+
function invoke(method, arg, resolve, reject) {
|
|
79
|
+
var record = tryCatch(generator[method], generator, arg);
|
|
80
|
+
if ("throw" !== record.type) {
|
|
81
|
+
var result = record.arg,
|
|
82
|
+
value = result.value;
|
|
83
|
+
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
84
|
+
invoke("next", value, resolve, reject);
|
|
85
|
+
}, function (err) {
|
|
86
|
+
invoke("throw", err, resolve, reject);
|
|
87
|
+
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
88
|
+
result.value = unwrapped, resolve(result);
|
|
89
|
+
}, function (error) {
|
|
90
|
+
return invoke("throw", error, resolve, reject);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
reject(record.arg);
|
|
94
|
+
}
|
|
95
|
+
var previousPromise;
|
|
96
|
+
defineProperty(this, "_invoke", {
|
|
97
|
+
value: function (method, arg) {
|
|
98
|
+
function callInvokeWithMethodAndArg() {
|
|
99
|
+
return new PromiseImpl(function (resolve, reject) {
|
|
100
|
+
invoke(method, arg, resolve, reject);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function makeInvokeMethod(innerFn, self, context) {
|
|
108
|
+
var state = "suspendedStart";
|
|
109
|
+
return function (method, arg) {
|
|
110
|
+
if ("executing" === state) throw new Error("Generator is already running");
|
|
111
|
+
if ("completed" === state) {
|
|
112
|
+
if ("throw" === method) throw arg;
|
|
113
|
+
return doneResult();
|
|
114
|
+
}
|
|
115
|
+
for (context.method = method, context.arg = arg;;) {
|
|
116
|
+
var delegate = context.delegate;
|
|
117
|
+
if (delegate) {
|
|
118
|
+
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
119
|
+
if (delegateResult) {
|
|
120
|
+
if (delegateResult === ContinueSentinel) continue;
|
|
121
|
+
return delegateResult;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
|
125
|
+
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
|
126
|
+
context.dispatchException(context.arg);
|
|
127
|
+
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
128
|
+
state = "executing";
|
|
129
|
+
var record = tryCatch(innerFn, self, context);
|
|
130
|
+
if ("normal" === record.type) {
|
|
131
|
+
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
132
|
+
return {
|
|
133
|
+
value: record.arg,
|
|
134
|
+
done: context.done
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function maybeInvokeDelegate(delegate, context) {
|
|
142
|
+
var methodName = context.method,
|
|
143
|
+
method = delegate.iterator[methodName];
|
|
144
|
+
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
|
145
|
+
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
146
|
+
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
147
|
+
var info = record.arg;
|
|
148
|
+
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
|
|
149
|
+
}
|
|
150
|
+
function pushTryEntry(locs) {
|
|
151
|
+
var entry = {
|
|
152
|
+
tryLoc: locs[0]
|
|
153
|
+
};
|
|
154
|
+
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
155
|
+
}
|
|
156
|
+
function resetTryEntry(entry) {
|
|
157
|
+
var record = entry.completion || {};
|
|
158
|
+
record.type = "normal", delete record.arg, entry.completion = record;
|
|
159
|
+
}
|
|
160
|
+
function Context(tryLocsList) {
|
|
161
|
+
this.tryEntries = [{
|
|
162
|
+
tryLoc: "root"
|
|
163
|
+
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
164
|
+
}
|
|
165
|
+
function values(iterable) {
|
|
166
|
+
if (iterable) {
|
|
167
|
+
var iteratorMethod = iterable[iteratorSymbol];
|
|
168
|
+
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
169
|
+
if ("function" == typeof iterable.next) return iterable;
|
|
170
|
+
if (!isNaN(iterable.length)) {
|
|
171
|
+
var i = -1,
|
|
172
|
+
next = function next() {
|
|
173
|
+
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
174
|
+
return next.value = undefined, next.done = !0, next;
|
|
175
|
+
};
|
|
176
|
+
return next.next = next;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
next: doneResult
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function doneResult() {
|
|
184
|
+
return {
|
|
185
|
+
value: undefined,
|
|
186
|
+
done: !0
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", {
|
|
190
|
+
value: GeneratorFunctionPrototype,
|
|
191
|
+
configurable: !0
|
|
192
|
+
}), defineProperty(GeneratorFunctionPrototype, "constructor", {
|
|
193
|
+
value: GeneratorFunction,
|
|
194
|
+
configurable: !0
|
|
195
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) {
|
|
196
|
+
var ctor = "function" == typeof genFun && genFun.constructor;
|
|
197
|
+
return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name));
|
|
198
|
+
}, exports.mark = function (genFun) {
|
|
199
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun;
|
|
200
|
+
}, exports.awrap = function (arg) {
|
|
201
|
+
return {
|
|
202
|
+
__await: arg
|
|
203
|
+
};
|
|
204
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
|
|
205
|
+
return this;
|
|
206
|
+
}), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
|
|
207
|
+
void 0 === PromiseImpl && (PromiseImpl = Promise);
|
|
208
|
+
var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
|
|
209
|
+
return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) {
|
|
210
|
+
return result.done ? result.value : iter.next();
|
|
211
|
+
});
|
|
212
|
+
}, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () {
|
|
213
|
+
return this;
|
|
214
|
+
}), define(Gp, "toString", function () {
|
|
215
|
+
return "[object Generator]";
|
|
216
|
+
}), exports.keys = function (val) {
|
|
217
|
+
var object = Object(val),
|
|
218
|
+
keys = [];
|
|
219
|
+
for (var key in object) keys.push(key);
|
|
220
|
+
return keys.reverse(), function next() {
|
|
221
|
+
for (; keys.length;) {
|
|
222
|
+
var key = keys.pop();
|
|
223
|
+
if (key in object) return next.value = key, next.done = !1, next;
|
|
224
|
+
}
|
|
225
|
+
return next.done = !0, next;
|
|
226
|
+
};
|
|
227
|
+
}, exports.values = values, Context.prototype = {
|
|
228
|
+
constructor: Context,
|
|
229
|
+
reset: function (skipTempReset) {
|
|
230
|
+
if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined);
|
|
231
|
+
},
|
|
232
|
+
stop: function () {
|
|
233
|
+
this.done = !0;
|
|
234
|
+
var rootRecord = this.tryEntries[0].completion;
|
|
235
|
+
if ("throw" === rootRecord.type) throw rootRecord.arg;
|
|
236
|
+
return this.rval;
|
|
237
|
+
},
|
|
238
|
+
dispatchException: function (exception) {
|
|
239
|
+
if (this.done) throw exception;
|
|
240
|
+
var context = this;
|
|
241
|
+
function handle(loc, caught) {
|
|
242
|
+
return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught;
|
|
243
|
+
}
|
|
244
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
245
|
+
var entry = this.tryEntries[i],
|
|
246
|
+
record = entry.completion;
|
|
247
|
+
if ("root" === entry.tryLoc) return handle("end");
|
|
248
|
+
if (entry.tryLoc <= this.prev) {
|
|
249
|
+
var hasCatch = hasOwn.call(entry, "catchLoc"),
|
|
250
|
+
hasFinally = hasOwn.call(entry, "finallyLoc");
|
|
251
|
+
if (hasCatch && hasFinally) {
|
|
252
|
+
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
253
|
+
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
254
|
+
} else if (hasCatch) {
|
|
255
|
+
if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0);
|
|
256
|
+
} else {
|
|
257
|
+
if (!hasFinally) throw new Error("try statement without catch or finally");
|
|
258
|
+
if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
abrupt: function (type, arg) {
|
|
264
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
265
|
+
var entry = this.tryEntries[i];
|
|
266
|
+
if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
|
|
267
|
+
var finallyEntry = entry;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null);
|
|
272
|
+
var record = finallyEntry ? finallyEntry.completion : {};
|
|
273
|
+
return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record);
|
|
274
|
+
},
|
|
275
|
+
complete: function (record, afterLoc) {
|
|
276
|
+
if ("throw" === record.type) throw record.arg;
|
|
277
|
+
return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel;
|
|
278
|
+
},
|
|
279
|
+
finish: function (finallyLoc) {
|
|
280
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
281
|
+
var entry = this.tryEntries[i];
|
|
282
|
+
if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel;
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
catch: function (tryLoc) {
|
|
286
|
+
for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
|
287
|
+
var entry = this.tryEntries[i];
|
|
288
|
+
if (entry.tryLoc === tryLoc) {
|
|
289
|
+
var record = entry.completion;
|
|
290
|
+
if ("throw" === record.type) {
|
|
291
|
+
var thrown = record.arg;
|
|
292
|
+
resetTryEntry(entry);
|
|
293
|
+
}
|
|
294
|
+
return thrown;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
throw new Error("illegal catch attempt");
|
|
298
|
+
},
|
|
299
|
+
delegateYield: function (iterable, resultName, nextLoc) {
|
|
300
|
+
return this.delegate = {
|
|
301
|
+
iterator: values(iterable),
|
|
302
|
+
resultName: resultName,
|
|
303
|
+
nextLoc: nextLoc
|
|
304
|
+
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
305
|
+
}
|
|
306
|
+
}, exports;
|
|
307
|
+
}
|
|
308
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
309
|
+
try {
|
|
310
|
+
var info = gen[key](arg);
|
|
311
|
+
var value = info.value;
|
|
312
|
+
} catch (error) {
|
|
313
|
+
reject(error);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (info.done) {
|
|
317
|
+
resolve(value);
|
|
318
|
+
} else {
|
|
319
|
+
Promise.resolve(value).then(_next, _throw);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function _asyncToGenerator(fn) {
|
|
323
|
+
return function () {
|
|
324
|
+
var self = this,
|
|
325
|
+
args = arguments;
|
|
326
|
+
return new Promise(function (resolve, reject) {
|
|
327
|
+
var gen = fn.apply(self, args);
|
|
328
|
+
function _next(value) {
|
|
329
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
330
|
+
}
|
|
331
|
+
function _throw(err) {
|
|
332
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
333
|
+
}
|
|
334
|
+
_next(undefined);
|
|
335
|
+
});
|
|
336
|
+
};
|
|
337
|
+
}
|
|
7
338
|
function _classCallCheck(instance, Constructor) {
|
|
8
339
|
if (!(instance instanceof Constructor)) {
|
|
9
340
|
throw new TypeError("Cannot call a class as a function");
|
|
@@ -145,78 +476,112 @@
|
|
|
145
476
|
var requestedToken = false;
|
|
146
477
|
var retryCount = 0;
|
|
147
478
|
return new Promise(function (res, rej) {
|
|
148
|
-
var retryFucntion = function
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
timeout: params.timeout || _this3.timeout
|
|
161
|
-
})).then(function (resData) {
|
|
162
|
-
var statusCode = resData.statusCode,
|
|
163
|
-
data = resData.data;
|
|
164
|
-
if (statusCode === 200) {
|
|
165
|
-
if (!data.errno) {
|
|
166
|
-
var jsonData = data;
|
|
167
|
-
/** 如果是上传API的话,返回的结果需要解析成json对象 */
|
|
168
|
-
if (Object.prototype.toString.call(data) !== '[object Object]' && callbackPromise === uploadFilePromise) {
|
|
169
|
-
try {
|
|
170
|
-
jsonData = JSON.parse(data);
|
|
171
|
-
} catch (error) {
|
|
172
|
-
console.error(error);
|
|
173
|
-
_this3.rejectHandler(rej, resData);
|
|
479
|
+
var retryFucntion = /*#__PURE__*/function () {
|
|
480
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
481
|
+
var finalHeader, processedHeader;
|
|
482
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
483
|
+
while (1) switch (_context.prev = _context.next) {
|
|
484
|
+
case 0:
|
|
485
|
+
/** 因为token需要动态获取,因此放入这里 */
|
|
486
|
+
header[_this3.tokenHeader] = "".concat(_this3.tokenPrefix).concat(_this3.token);
|
|
487
|
+
/** 针对h5调试的时候,因为塞入cookie是不安全的,因此无需塞入cookie,使用登录页后,后端塞入的cookie */
|
|
488
|
+
// #ifdef H5
|
|
489
|
+
if (_this3.tokenHeader === 'cookie') {
|
|
490
|
+
delete header[_this3.tokenHeader];
|
|
174
491
|
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
492
|
+
// #endif
|
|
493
|
+
/** 执行请求头预处理 */
|
|
494
|
+
finalHeader = header;
|
|
495
|
+
if (!_this3.headerProcessor) {
|
|
496
|
+
_context.next = 15;
|
|
497
|
+
break;
|
|
498
|
+
}
|
|
499
|
+
_context.prev = 4;
|
|
500
|
+
_context.next = 7;
|
|
501
|
+
return _this3.headerProcessor(header);
|
|
502
|
+
case 7:
|
|
503
|
+
processedHeader = _context.sent;
|
|
504
|
+
finalHeader = Object.assign(Object.assign({}, header), processedHeader);
|
|
505
|
+
_context.next = 15;
|
|
506
|
+
break;
|
|
507
|
+
case 11:
|
|
508
|
+
_context.prev = 11;
|
|
509
|
+
_context.t0 = _context["catch"](4);
|
|
510
|
+
_this3.rejectHandler(rej, _context.t0);
|
|
511
|
+
return _context.abrupt("return");
|
|
512
|
+
case 15:
|
|
513
|
+
callbackPromise(Object.assign(Object.assign({}, params), {
|
|
514
|
+
header: finalHeader,
|
|
515
|
+
url: url,
|
|
516
|
+
timeout: params.timeout || _this3.timeout
|
|
517
|
+
})).then(function (resData) {
|
|
518
|
+
var statusCode = resData.statusCode,
|
|
519
|
+
data = resData.data;
|
|
520
|
+
if (statusCode === 200) {
|
|
521
|
+
if (!data.errno) {
|
|
522
|
+
var jsonData = data;
|
|
523
|
+
/** 如果是上传API的话,返回的结果需要解析成json对象 */
|
|
524
|
+
if (Object.prototype.toString.call(data) !== '[object Object]' && callbackPromise === uploadFilePromise) {
|
|
525
|
+
try {
|
|
526
|
+
jsonData = JSON.parse(data);
|
|
527
|
+
} catch (error) {
|
|
528
|
+
console.error(error);
|
|
529
|
+
_this3.rejectHandler(rej, resData);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
res(jsonData.data);
|
|
533
|
+
} else {
|
|
534
|
+
_this3.rejectHandler(rej, resData);
|
|
535
|
+
}
|
|
536
|
+
/** 针对小网关进行的处理,历史遗留问题,需要兼容 */
|
|
537
|
+
} else if (403 === statusCode && !requestedToken) {
|
|
538
|
+
// #ifndef H5
|
|
539
|
+
(_this3.getTokenFun ? _this3.getTokenFun() : getToken(_this3.tokenEventName)).then(function (token) {
|
|
540
|
+
_this3.token = token;
|
|
541
|
+
requestedToken = true;
|
|
542
|
+
/** 获取token应该立马请求,不需要延迟 */
|
|
543
|
+
retryFucntion();
|
|
544
|
+
})["catch"](function () {
|
|
545
|
+
if (_this3.maxRetryCount > retryCount && !requestedToken) {
|
|
546
|
+
delayRetryFcuntion();
|
|
547
|
+
} else {
|
|
548
|
+
_this3.rejectHandler(rej, resData);
|
|
549
|
+
}
|
|
550
|
+
});
|
|
551
|
+
// #endif
|
|
552
|
+
// #ifdef H5
|
|
553
|
+
_this3.rejectHandler(rej, resData);
|
|
554
|
+
// #endif
|
|
555
|
+
/** 最新无权限处理方案,直接调用客户端logout事件,退出到登录页 */
|
|
556
|
+
} else if (401 === statusCode) {
|
|
557
|
+
_this3.rejectHandler(rej, resData);
|
|
558
|
+
uni.sendNativeEvent(EVENT_NAME.LOGOUT, {}, function () {
|
|
559
|
+
console.log('用户无权限,调用logout事件,退出到登录页');
|
|
560
|
+
});
|
|
561
|
+
} else {
|
|
562
|
+
if (_this3.maxRetryCount > retryCount && !requestedToken) {
|
|
563
|
+
delayRetryFcuntion();
|
|
564
|
+
} else {
|
|
565
|
+
_this3.rejectHandler(rej, resData);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
})["catch"](function (rejData) {
|
|
569
|
+
if (_this3.maxRetryCount > retryCount && !requestedToken) {
|
|
570
|
+
delayRetryFcuntion();
|
|
571
|
+
} else {
|
|
572
|
+
_this3.rejectHandler(rej, rejData);
|
|
573
|
+
}
|
|
574
|
+
});
|
|
575
|
+
case 16:
|
|
576
|
+
case "end":
|
|
577
|
+
return _context.stop();
|
|
210
578
|
}
|
|
211
|
-
}
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
}
|
|
218
|
-
});
|
|
219
|
-
};
|
|
579
|
+
}, _callee, null, [[4, 11]]);
|
|
580
|
+
}));
|
|
581
|
+
return function retryFucntion() {
|
|
582
|
+
return _ref.apply(this, arguments);
|
|
583
|
+
};
|
|
584
|
+
}();
|
|
220
585
|
var delayRetryFcuntion = function delayRetryFcuntion() {
|
|
221
586
|
setTimeout(function () {
|
|
222
587
|
retryCount++;
|
|
@@ -302,7 +667,7 @@
|
|
|
302
667
|
name: name,
|
|
303
668
|
header: header,
|
|
304
669
|
timeout: this.uploadTimeout,
|
|
305
|
-
method: '
|
|
670
|
+
method: 'POST'
|
|
306
671
|
}, uploadFilePromise);
|
|
307
672
|
}
|
|
308
673
|
}]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uniapp-request-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "用于uniapp小程序的请求库的sdk",
|
|
5
5
|
"main": "dist/index.umd.js",
|
|
6
6
|
"module": " dist/index.esm.js",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"dev": "rimraf dist typings && tsc --emitDeclarationOnly && cross-env NODE_ENV=development rollup -c --watch",
|
|
20
20
|
"build": "rimraf dist typings && tsc --emitDeclarationOnly && cross-env NODE_ENV=production rollup -c",
|
|
21
21
|
"prepublish": "npm run build",
|
|
22
|
+
"preinstall": "patch-package",
|
|
22
23
|
"c": "git-cz"
|
|
23
24
|
},
|
|
24
25
|
"author": "yaojun",
|