uniapp-request-sdk 1.3.9 → 1.4.1
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/index.d.ts +20 -1
- package/dist/index.esm.js +57 -3
- package/dist/index.umd.js +298 -0
- package/package.json +16 -2
package/dist/index.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ interface IParams {
|
|
|
11
11
|
maxRetryCount?: number;
|
|
12
12
|
/** 请求超时时间默认10s,ms为单位 */
|
|
13
13
|
timeout?: number;
|
|
14
|
+
/** 上传文件的请求超时时间,ms为单位 */
|
|
15
|
+
uploadTimeout?: number;
|
|
14
16
|
/** 请求尝试延迟时间默认3s,ms为单位 */
|
|
15
17
|
retryDelay?: number;
|
|
16
18
|
/** token,APP初始化给到小程序的token */
|
|
@@ -24,6 +26,9 @@ interface IParams {
|
|
|
24
26
|
/** 自定义得到token的函数,默认使用从客户端获取token的方式 */
|
|
25
27
|
getTokenFun?: () => Promise<string>;
|
|
26
28
|
}
|
|
29
|
+
declare function requestPromise(options?: RequestOptions & {
|
|
30
|
+
timeout: number;
|
|
31
|
+
}): Promise<RequestSuccessCallbackResult>;
|
|
27
32
|
declare class UniRequest {
|
|
28
33
|
/** 基准路径 */
|
|
29
34
|
private baseUrl;
|
|
@@ -34,6 +39,8 @@ declare class UniRequest {
|
|
|
34
39
|
private maxRetryCount;
|
|
35
40
|
/** 超时时间 */
|
|
36
41
|
private timeout;
|
|
42
|
+
/** 上传文件的超时时间 */
|
|
43
|
+
private uploadTimeout;
|
|
37
44
|
private retryDelay;
|
|
38
45
|
private token?;
|
|
39
46
|
private tokenEventName;
|
|
@@ -51,7 +58,9 @@ declare class UniRequest {
|
|
|
51
58
|
method: RequestOptions['method'];
|
|
52
59
|
data?: RequestOptions['data'];
|
|
53
60
|
header?: RequestOptions['header'];
|
|
54
|
-
|
|
61
|
+
/** 超时时间 */
|
|
62
|
+
timeout?: number;
|
|
63
|
+
} & RequestOptions & UploadFileOption, callbackPromise?: typeof requestPromise): Promise<T>;
|
|
55
64
|
/**
|
|
56
65
|
* post请求
|
|
57
66
|
* @param url
|
|
@@ -63,6 +72,16 @@ declare class UniRequest {
|
|
|
63
72
|
get<T>(url: string, data?: {}, header?: Record<string, string>): Promise<T>;
|
|
64
73
|
delete<T>(url: string, data?: {}, header?: Record<string, string>): Promise<T>;
|
|
65
74
|
put<T>(url: string, data?: {}, header?: Record<string, string>): Promise<T>;
|
|
75
|
+
/**
|
|
76
|
+
* 文件上传
|
|
77
|
+
* @param url 上传的url
|
|
78
|
+
* @param filePath 文件路径
|
|
79
|
+
* @param formData HTTP 请求中其他额外的 form data
|
|
80
|
+
* @param name 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容,默认key为file
|
|
81
|
+
* @param header
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
uploadFile<T>(url: string, filePath: string, formData?: Record<string, any>, name?: string, header?: Record<string, string>): Promise<T>;
|
|
66
85
|
}
|
|
67
86
|
|
|
68
87
|
export { IParams, UniRequest as default };
|
package/dist/index.esm.js
CHANGED
|
@@ -35,6 +35,10 @@ function _toPropertyKey(arg) {
|
|
|
35
35
|
return typeof key === "symbol" ? key : String(key);
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/** 客户端交互内置事件名称 */
|
|
39
|
+
var EVENT_NAME = {
|
|
40
|
+
LOGOUT: 'logout'
|
|
41
|
+
};
|
|
38
42
|
function requestPromise(options) {
|
|
39
43
|
return new Promise(function (res, rej) {
|
|
40
44
|
uni.request(Object.assign(Object.assign({}, options), {
|
|
@@ -43,6 +47,14 @@ function requestPromise(options) {
|
|
|
43
47
|
}));
|
|
44
48
|
});
|
|
45
49
|
}
|
|
50
|
+
function uploadFilePromise(options) {
|
|
51
|
+
return new Promise(function (res, rej) {
|
|
52
|
+
uni.uploadFile(Object.assign(Object.assign({}, options), {
|
|
53
|
+
success: res,
|
|
54
|
+
fail: rej
|
|
55
|
+
}));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
46
58
|
/** 得到小程序的token */
|
|
47
59
|
function getToken(eventName) {
|
|
48
60
|
return new Promise(function (res, rej) {
|
|
@@ -66,6 +78,8 @@ var UniRequest = /*#__PURE__*/function () {
|
|
|
66
78
|
this.maxRetryCount = 3;
|
|
67
79
|
/** 超时时间 */
|
|
68
80
|
this.timeout = 10000;
|
|
81
|
+
/** 上传文件的超时时间 */
|
|
82
|
+
this.uploadTimeout = 5000;
|
|
69
83
|
this.retryDelay = 3000;
|
|
70
84
|
this.tokenEventName = 'getToken';
|
|
71
85
|
/** token的header名称,默认Authorization */
|
|
@@ -103,6 +117,7 @@ var UniRequest = /*#__PURE__*/function () {
|
|
|
103
117
|
key: "request",
|
|
104
118
|
value: function request(params) {
|
|
105
119
|
var _this3 = this;
|
|
120
|
+
var callbackPromise = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : requestPromise;
|
|
106
121
|
var url = params.url;
|
|
107
122
|
/** 如果是http开头的,则不需要加入baseUrl */
|
|
108
123
|
if (!/^https?:\/\//.test(url)) {
|
|
@@ -116,11 +131,19 @@ var UniRequest = /*#__PURE__*/function () {
|
|
|
116
131
|
return new Promise(function (res, rej) {
|
|
117
132
|
var retryFucntion = function retryFucntion() {
|
|
118
133
|
/** 因为token需要动态获取,因此放入这里 */
|
|
134
|
+
// #ifndef H5
|
|
119
135
|
header[_this3.tokenHeader] = "".concat(_this3.tokenPrefix).concat(_this3.token);
|
|
120
|
-
|
|
136
|
+
// #endif
|
|
137
|
+
/** 针对h5调试的时候,因为塞入cookie是不安全的,因此无需塞入cookie,使用登录页后,后端塞入的cookie */
|
|
138
|
+
// #ifdef H5
|
|
139
|
+
if (!['cookie'].includes(_this3.tokenHeader)) {
|
|
140
|
+
header[_this3.tokenHeader] = "".concat(_this3.tokenPrefix).concat(_this3.token);
|
|
141
|
+
}
|
|
142
|
+
// #endif
|
|
143
|
+
callbackPromise(Object.assign(Object.assign({}, params), {
|
|
121
144
|
header: header,
|
|
122
145
|
url: url,
|
|
123
|
-
timeout: _this3.timeout
|
|
146
|
+
timeout: params.timeout || _this3.timeout
|
|
124
147
|
})).then(function (resData) {
|
|
125
148
|
var statusCode = resData.statusCode,
|
|
126
149
|
data = resData.data;
|
|
@@ -130,7 +153,8 @@ var UniRequest = /*#__PURE__*/function () {
|
|
|
130
153
|
} else {
|
|
131
154
|
_this3.rejectHandler(rej, resData);
|
|
132
155
|
}
|
|
133
|
-
|
|
156
|
+
/** 针对小网关进行的处理,历史遗留问题,需要兼容 */
|
|
157
|
+
} else if ('403' === statusCode && !requestedToken) {
|
|
134
158
|
// #ifndef H5
|
|
135
159
|
(_this3.getTokenFun ? _this3.getTokenFun() : getToken(_this3.tokenEventName)).then(function (token) {
|
|
136
160
|
_this3.token = token;
|
|
@@ -148,6 +172,12 @@ var UniRequest = /*#__PURE__*/function () {
|
|
|
148
172
|
// #ifdef H5
|
|
149
173
|
_this3.rejectHandler(rej, resData);
|
|
150
174
|
// #endif
|
|
175
|
+
/** 最新无权限处理方案,直接调用客户端logout事件,退出到登录页 */
|
|
176
|
+
} else if ('401' === statusCode) {
|
|
177
|
+
_this3.rejectHandler(rej, resData);
|
|
178
|
+
uni.sendNativeEvent(EVENT_NAME.LOGOUT, {}, function () {
|
|
179
|
+
console.log('用户无权限,调用logout事件,退出到登录页');
|
|
180
|
+
});
|
|
151
181
|
} else {
|
|
152
182
|
if (_this3.maxRetryCount > retryCount) {
|
|
153
183
|
delayRetryFcuntion();
|
|
@@ -227,6 +257,30 @@ var UniRequest = /*#__PURE__*/function () {
|
|
|
227
257
|
method: 'PUT'
|
|
228
258
|
});
|
|
229
259
|
}
|
|
260
|
+
/**
|
|
261
|
+
* 文件上传
|
|
262
|
+
* @param url 上传的url
|
|
263
|
+
* @param filePath 文件路径
|
|
264
|
+
* @param formData HTTP 请求中其他额外的 form data
|
|
265
|
+
* @param name 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容,默认key为file
|
|
266
|
+
* @param header
|
|
267
|
+
* @returns
|
|
268
|
+
*/
|
|
269
|
+
}, {
|
|
270
|
+
key: "uploadFile",
|
|
271
|
+
value: function uploadFile(url, filePath, formData) {
|
|
272
|
+
var name = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'file';
|
|
273
|
+
var header = arguments.length > 4 ? arguments[4] : undefined;
|
|
274
|
+
return this.request({
|
|
275
|
+
url: url,
|
|
276
|
+
filePath: filePath,
|
|
277
|
+
formData: formData,
|
|
278
|
+
name: name,
|
|
279
|
+
header: header,
|
|
280
|
+
timeout: this.uploadTimeout,
|
|
281
|
+
method: 'PUT'
|
|
282
|
+
}, uploadFilePromise);
|
|
283
|
+
}
|
|
230
284
|
}]);
|
|
231
285
|
return UniRequest;
|
|
232
286
|
}();
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.UniappRequestSdk = {}));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
function _classCallCheck(instance, Constructor) {
|
|
8
|
+
if (!(instance instanceof Constructor)) {
|
|
9
|
+
throw new TypeError("Cannot call a class as a function");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function _defineProperties(target, props) {
|
|
13
|
+
for (var i = 0; i < props.length; i++) {
|
|
14
|
+
var descriptor = props[i];
|
|
15
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
16
|
+
descriptor.configurable = true;
|
|
17
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
18
|
+
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
22
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
23
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
24
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
25
|
+
writable: false
|
|
26
|
+
});
|
|
27
|
+
return Constructor;
|
|
28
|
+
}
|
|
29
|
+
function _toPrimitive(input, hint) {
|
|
30
|
+
if (typeof input !== "object" || input === null) return input;
|
|
31
|
+
var prim = input[Symbol.toPrimitive];
|
|
32
|
+
if (prim !== undefined) {
|
|
33
|
+
var res = prim.call(input, hint || "default");
|
|
34
|
+
if (typeof res !== "object") return res;
|
|
35
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
36
|
+
}
|
|
37
|
+
return (hint === "string" ? String : Number)(input);
|
|
38
|
+
}
|
|
39
|
+
function _toPropertyKey(arg) {
|
|
40
|
+
var key = _toPrimitive(arg, "string");
|
|
41
|
+
return typeof key === "symbol" ? key : String(key);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** 客户端交互内置事件名称 */
|
|
45
|
+
var EVENT_NAME = {
|
|
46
|
+
LOGOUT: 'logout'
|
|
47
|
+
};
|
|
48
|
+
function requestPromise(options) {
|
|
49
|
+
return new Promise(function (res, rej) {
|
|
50
|
+
uni.request(Object.assign(Object.assign({}, options), {
|
|
51
|
+
success: res,
|
|
52
|
+
fail: rej
|
|
53
|
+
}));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
function uploadFilePromise(options) {
|
|
57
|
+
return new Promise(function (res, rej) {
|
|
58
|
+
uni.uploadFile(Object.assign(Object.assign({}, options), {
|
|
59
|
+
success: res,
|
|
60
|
+
fail: rej
|
|
61
|
+
}));
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/** 得到小程序的token */
|
|
65
|
+
function getToken(eventName) {
|
|
66
|
+
return new Promise(function (res, rej) {
|
|
67
|
+
var timeout = setTimeout(rej, 5000);
|
|
68
|
+
uni.sendNativeEvent(eventName, {}, function (resData) {
|
|
69
|
+
clearTimeout(timeout);
|
|
70
|
+
res(resData);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
var UniRequest = /*#__PURE__*/function () {
|
|
75
|
+
function UniRequest(params) {
|
|
76
|
+
var _this = this;
|
|
77
|
+
_classCallCheck(this, UniRequest);
|
|
78
|
+
/** 基准路径 */
|
|
79
|
+
this.baseUrl = '';
|
|
80
|
+
/** 错误处理函数 */
|
|
81
|
+
this.onErrorHandler = function (error) {
|
|
82
|
+
console.error(error);
|
|
83
|
+
};
|
|
84
|
+
this.maxRetryCount = 3;
|
|
85
|
+
/** 超时时间 */
|
|
86
|
+
this.timeout = 10000;
|
|
87
|
+
/** 上传文件的超时时间 */
|
|
88
|
+
this.uploadTimeout = 5000;
|
|
89
|
+
this.retryDelay = 3000;
|
|
90
|
+
this.tokenEventName = 'getToken';
|
|
91
|
+
/** token的header名称,默认Authorization */
|
|
92
|
+
this.tokenHeader = 'Authorization';
|
|
93
|
+
/** 传入的token前缀,默认Bearer ,注意Bearer有个空字符串*/
|
|
94
|
+
this.tokenPrefix = 'Bearer ';
|
|
95
|
+
if (params) {
|
|
96
|
+
Object.keys(params).forEach(function (key) {
|
|
97
|
+
if (params[key] !== void 0) {
|
|
98
|
+
_this[key] = params[key];
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
_createClass(UniRequest, [{
|
|
104
|
+
key: "rejectHandler",
|
|
105
|
+
value: function rejectHandler(rej, data) {
|
|
106
|
+
var _a;
|
|
107
|
+
rej(data);
|
|
108
|
+
(_a = this.onErrorHandler) === null || _a === void 0 ? void 0 : _a.call(this, data);
|
|
109
|
+
}
|
|
110
|
+
}, {
|
|
111
|
+
key: "setParams",
|
|
112
|
+
value: function setParams(params) {
|
|
113
|
+
var _this2 = this;
|
|
114
|
+
if (params) {
|
|
115
|
+
Object.keys(params).forEach(function (key) {
|
|
116
|
+
if (params[key] !== void 0) {
|
|
117
|
+
_this2[key] = params[key];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}, {
|
|
123
|
+
key: "request",
|
|
124
|
+
value: function request(params) {
|
|
125
|
+
var _this3 = this;
|
|
126
|
+
var callbackPromise = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : requestPromise;
|
|
127
|
+
var url = params.url;
|
|
128
|
+
/** 如果是http开头的,则不需要加入baseUrl */
|
|
129
|
+
if (!/^https?:\/\//.test(url)) {
|
|
130
|
+
url = "".concat(this.baseUrl.replace(/\/$/, ''), "/").concat(params.url.replace(/^\//, ''), "?t=").concat(Date.now());
|
|
131
|
+
} else {
|
|
132
|
+
url = "".concat(params.url, "?t=").concat(Date.now());
|
|
133
|
+
}
|
|
134
|
+
var header = Object.assign(Object.assign({}, this.header), params.header);
|
|
135
|
+
var requestedToken = false;
|
|
136
|
+
var retryCount = 0;
|
|
137
|
+
return new Promise(function (res, rej) {
|
|
138
|
+
var retryFucntion = function retryFucntion() {
|
|
139
|
+
/** 因为token需要动态获取,因此放入这里 */
|
|
140
|
+
// #ifndef H5
|
|
141
|
+
header[_this3.tokenHeader] = "".concat(_this3.tokenPrefix).concat(_this3.token);
|
|
142
|
+
// #endif
|
|
143
|
+
/** 针对h5调试的时候,因为塞入cookie是不安全的,因此无需塞入cookie,使用登录页后,后端塞入的cookie */
|
|
144
|
+
// #ifdef H5
|
|
145
|
+
if (!['cookie'].includes(_this3.tokenHeader)) {
|
|
146
|
+
header[_this3.tokenHeader] = "".concat(_this3.tokenPrefix).concat(_this3.token);
|
|
147
|
+
}
|
|
148
|
+
// #endif
|
|
149
|
+
callbackPromise(Object.assign(Object.assign({}, params), {
|
|
150
|
+
header: header,
|
|
151
|
+
url: url,
|
|
152
|
+
timeout: params.timeout || _this3.timeout
|
|
153
|
+
})).then(function (resData) {
|
|
154
|
+
var statusCode = resData.statusCode,
|
|
155
|
+
data = resData.data;
|
|
156
|
+
if (statusCode === 200) {
|
|
157
|
+
if (!data.errno) {
|
|
158
|
+
res(data.data);
|
|
159
|
+
} else {
|
|
160
|
+
_this3.rejectHandler(rej, resData);
|
|
161
|
+
}
|
|
162
|
+
/** 针对小网关进行的处理,历史遗留问题,需要兼容 */
|
|
163
|
+
} else if ('403' === statusCode && !requestedToken) {
|
|
164
|
+
// #ifndef H5
|
|
165
|
+
(_this3.getTokenFun ? _this3.getTokenFun() : getToken(_this3.tokenEventName)).then(function (token) {
|
|
166
|
+
_this3.token = token;
|
|
167
|
+
requestedToken = true;
|
|
168
|
+
/** 获取token应该立马请求,不需要延迟 */
|
|
169
|
+
retryFucntion();
|
|
170
|
+
})["catch"](function () {
|
|
171
|
+
if (_this3.maxRetryCount > retryCount) {
|
|
172
|
+
delayRetryFcuntion();
|
|
173
|
+
} else {
|
|
174
|
+
_this3.rejectHandler(rej, resData);
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
// #endif
|
|
178
|
+
// #ifdef H5
|
|
179
|
+
_this3.rejectHandler(rej, resData);
|
|
180
|
+
// #endif
|
|
181
|
+
/** 最新无权限处理方案,直接调用客户端logout事件,退出到登录页 */
|
|
182
|
+
} else if ('401' === statusCode) {
|
|
183
|
+
_this3.rejectHandler(rej, resData);
|
|
184
|
+
uni.sendNativeEvent(EVENT_NAME.LOGOUT, {}, function () {
|
|
185
|
+
console.log('用户无权限,调用logout事件,退出到登录页');
|
|
186
|
+
});
|
|
187
|
+
} else {
|
|
188
|
+
if (_this3.maxRetryCount > retryCount) {
|
|
189
|
+
delayRetryFcuntion();
|
|
190
|
+
} else {
|
|
191
|
+
_this3.rejectHandler(rej, resData);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
})["catch"](function (rejData) {
|
|
195
|
+
if (_this3.maxRetryCount > retryCount) {
|
|
196
|
+
delayRetryFcuntion();
|
|
197
|
+
} else {
|
|
198
|
+
_this3.rejectHandler(rej, rejData);
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
};
|
|
202
|
+
var delayRetryFcuntion = function delayRetryFcuntion() {
|
|
203
|
+
setTimeout(function () {
|
|
204
|
+
retryCount++;
|
|
205
|
+
retryFucntion();
|
|
206
|
+
}, _this3.retryDelay);
|
|
207
|
+
};
|
|
208
|
+
retryFucntion();
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* post请求
|
|
213
|
+
* @param url
|
|
214
|
+
* @param data 可传可不传
|
|
215
|
+
* @param header
|
|
216
|
+
* @returns
|
|
217
|
+
*/
|
|
218
|
+
}, {
|
|
219
|
+
key: "post",
|
|
220
|
+
value: function post(url) {
|
|
221
|
+
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
222
|
+
var header = arguments.length > 2 ? arguments[2] : undefined;
|
|
223
|
+
return this.request({
|
|
224
|
+
url: url,
|
|
225
|
+
data: data,
|
|
226
|
+
header: header,
|
|
227
|
+
method: 'POST'
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
}, {
|
|
231
|
+
key: "get",
|
|
232
|
+
value: function get(url) {
|
|
233
|
+
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
234
|
+
var header = arguments.length > 2 ? arguments[2] : undefined;
|
|
235
|
+
return this.request({
|
|
236
|
+
url: url,
|
|
237
|
+
data: data,
|
|
238
|
+
header: header,
|
|
239
|
+
method: 'GET'
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}, {
|
|
243
|
+
key: "delete",
|
|
244
|
+
value: function _delete(url) {
|
|
245
|
+
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
246
|
+
var header = arguments.length > 2 ? arguments[2] : undefined;
|
|
247
|
+
return this.request({
|
|
248
|
+
url: url,
|
|
249
|
+
data: data,
|
|
250
|
+
header: header,
|
|
251
|
+
method: 'DELETE'
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}, {
|
|
255
|
+
key: "put",
|
|
256
|
+
value: function put(url) {
|
|
257
|
+
var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
258
|
+
var header = arguments.length > 2 ? arguments[2] : undefined;
|
|
259
|
+
return this.request({
|
|
260
|
+
url: url,
|
|
261
|
+
data: data,
|
|
262
|
+
header: header,
|
|
263
|
+
method: 'PUT'
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* 文件上传
|
|
268
|
+
* @param url 上传的url
|
|
269
|
+
* @param filePath 文件路径
|
|
270
|
+
* @param formData HTTP 请求中其他额外的 form data
|
|
271
|
+
* @param name 文件对应的 key , 开发者在服务器端通过这个 key 可以获取到文件二进制内容,默认key为file
|
|
272
|
+
* @param header
|
|
273
|
+
* @returns
|
|
274
|
+
*/
|
|
275
|
+
}, {
|
|
276
|
+
key: "uploadFile",
|
|
277
|
+
value: function uploadFile(url, filePath, formData) {
|
|
278
|
+
var name = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'file';
|
|
279
|
+
var header = arguments.length > 4 ? arguments[4] : undefined;
|
|
280
|
+
return this.request({
|
|
281
|
+
url: url,
|
|
282
|
+
filePath: filePath,
|
|
283
|
+
formData: formData,
|
|
284
|
+
name: name,
|
|
285
|
+
header: header,
|
|
286
|
+
timeout: this.uploadTimeout,
|
|
287
|
+
method: 'PUT'
|
|
288
|
+
}, uploadFilePromise);
|
|
289
|
+
}
|
|
290
|
+
}]);
|
|
291
|
+
return UniRequest;
|
|
292
|
+
}();
|
|
293
|
+
|
|
294
|
+
exports["default"] = UniRequest;
|
|
295
|
+
|
|
296
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
297
|
+
|
|
298
|
+
}));
|
package/package.json
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uniapp-request-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "用于uniapp小程序的请求库的sdk",
|
|
5
|
-
"main": "dist/index.
|
|
5
|
+
"main": "dist/index.umd.js",
|
|
6
|
+
"module": " dist/index.esm.js",
|
|
6
7
|
"typings": "dist/index.d.ts",
|
|
7
8
|
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"require": "./dist/index.umd.js",
|
|
12
|
+
"import": "./dist/index.esm.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
8
15
|
"files": [
|
|
9
16
|
"dist"
|
|
10
17
|
],
|
|
@@ -50,5 +57,12 @@
|
|
|
50
57
|
"rollup-plugin-terser": "^7.0.2",
|
|
51
58
|
"rollup-plugin-typescript2": "^0.27.2",
|
|
52
59
|
"typescript": "^4.0.2"
|
|
60
|
+
},
|
|
61
|
+
"buildOptions": {
|
|
62
|
+
"name": "UniappRequestSdk",
|
|
63
|
+
"formats": [
|
|
64
|
+
"umd",
|
|
65
|
+
"esm"
|
|
66
|
+
]
|
|
53
67
|
}
|
|
54
68
|
}
|