im-ui-mobile 0.0.60 → 0.0.62
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/package.json +1 -1
- package/types/utils/requester.d.ts +2 -1
- package/utils/requester.js +10 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="@dcloudio/types" />
|
|
2
2
|
import type { Response } from '../libs/index';
|
|
3
|
-
|
|
3
|
+
declare class Requester {
|
|
4
4
|
private baseURL;
|
|
5
5
|
private options;
|
|
6
6
|
private timeout;
|
|
@@ -14,3 +14,4 @@ export default class Requester {
|
|
|
14
14
|
put<T = any>(url: string, data?: any, options?: Partial<UniApp.RequestOptions>): Promise<Response<T>>;
|
|
15
15
|
delete<T = any>(url: string, data?: any, options?: Partial<UniApp.RequestOptions>): Promise<Response<T>>;
|
|
16
16
|
}
|
|
17
|
+
export default Requester;
|
package/utils/requester.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
class Requester {
|
|
1
|
+
export default class Requester {
|
|
2
2
|
constructor(baseURL, options = {}) {
|
|
3
3
|
this.baseURL = baseURL;
|
|
4
4
|
this.options = options;
|
|
5
5
|
this.timeout = options.timeout || 10000;
|
|
6
|
-
|
|
7
|
-
this.headers = {
|
|
6
|
+
this.header = {
|
|
8
7
|
'Content-Type': 'application/json',
|
|
9
8
|
// 'Authorization': `Bearer ${this.accessToken}`,
|
|
10
9
|
// 'AccessToken': this.accessToken,
|
|
@@ -14,19 +13,21 @@ class Requester {
|
|
|
14
13
|
|
|
15
14
|
// 设置 token
|
|
16
15
|
setToken(token) {
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
16
|
+
this.header['Authorization'] = `Bearer ${token}`;
|
|
17
|
+
this.header['AccessToken'] = token;
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
// 基础请求方法
|
|
22
21
|
async request(options) {
|
|
23
|
-
this.options = { ...this.options, ...options };
|
|
24
22
|
this.options.url = this.baseURL + this.options.url;
|
|
23
|
+
this.options.header = this.header
|
|
24
|
+
this.options.timeout = this.timeout
|
|
25
|
+
this.options = {
|
|
26
|
+
...options
|
|
27
|
+
};
|
|
25
28
|
|
|
26
29
|
return new Promise((resolve, reject) => {
|
|
27
30
|
uni.request({
|
|
28
|
-
timeout: this.timeout,
|
|
29
|
-
header: this.headers,
|
|
30
31
|
...this.options,
|
|
31
32
|
success: (res) => {
|
|
32
33
|
const data = res.data;
|
|
@@ -79,6 +80,4 @@ class Requester {
|
|
|
79
80
|
delete(url, data, options) {
|
|
80
81
|
return this.request({ url, method: 'DELETE', data, ...options });
|
|
81
82
|
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export default { Requester }
|
|
83
|
+
}
|