@fairys/taro-tools-react 1.0.10 → 1.0.12
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/esm/utils/request.d.ts +4 -0
- package/esm/utils/request.js +3 -1
- package/esm/utils/valtio/index.d.ts +4 -0
- package/esm/utils/valtio/index.js +11 -2
- package/lib/utils/request.d.ts +4 -0
- package/lib/utils/request.js +3 -1
- package/lib/utils/valtio/index.d.ts +4 -0
- package/lib/utils/valtio/index.js +14 -1
- package/package.json +1 -1
- package/src/utils/request.ts +7 -1
- package/src/utils/valtio/index.ts +10 -1
package/esm/utils/request.d.ts
CHANGED
|
@@ -46,8 +46,12 @@ export interface RequestInstanceCreateOptions {
|
|
|
46
46
|
pathRewrite: Record<string, string>;
|
|
47
47
|
}>;
|
|
48
48
|
};
|
|
49
|
+
/**启用token校验*/
|
|
50
|
+
isEnableTokenAuth?: boolean;
|
|
49
51
|
}
|
|
50
52
|
export declare class RequestInstance {
|
|
53
|
+
/**启用token校验*/
|
|
54
|
+
isEnableTokenAuth?: boolean;
|
|
51
55
|
/**请求IP地址*/
|
|
52
56
|
IP?: string | ((url: string, module?: string, env?: string) => string);
|
|
53
57
|
/**简单的代理配置*/
|
package/esm/utils/request.js
CHANGED
|
@@ -41,6 +41,7 @@ const requestResponseHandle = (result, options)=>{
|
|
|
41
41
|
});
|
|
42
42
|
};
|
|
43
43
|
class RequestInstance {
|
|
44
|
+
isEnableTokenAuth = true;
|
|
44
45
|
IP;
|
|
45
46
|
proxy;
|
|
46
47
|
commonOptions = {};
|
|
@@ -58,6 +59,7 @@ class RequestInstance {
|
|
|
58
59
|
...this.commonOptions,
|
|
59
60
|
...options.commonOptions
|
|
60
61
|
};
|
|
62
|
+
this.isEnableTokenAuth = 'boolean' == typeof options.isEnableTokenAuth ? options.isEnableTokenAuth : true;
|
|
61
63
|
return this;
|
|
62
64
|
};
|
|
63
65
|
getHttpPath = (url, module)=>{
|
|
@@ -115,7 +117,7 @@ class RequestInstance {
|
|
|
115
117
|
...header
|
|
116
118
|
};
|
|
117
119
|
if (token) newHeader[globalSettingDataInstance.store.headerTokenName || 'token'] = token;
|
|
118
|
-
else if (true !== isIgnoreToken) {
|
|
120
|
+
else if (true !== isIgnoreToken && this.isEnableTokenAuth) {
|
|
119
121
|
if (false !== isShowErrorMessage) if (globalSettingDataInstance.store.isUseTaroToast) taro.showToast({
|
|
120
122
|
title: "\u672A\u767B\u5F55",
|
|
121
123
|
duration: 3000,
|
|
@@ -7,3 +7,7 @@ export declare const useValtioInstaceState: <T extends object = any, K extends P
|
|
|
7
7
|
} = {
|
|
8
8
|
new (...args: any[]): K;
|
|
9
9
|
}>(Instance: M) => readonly [import("valtio").Snapshot<T>, K, any];
|
|
10
|
+
/**
|
|
11
|
+
* 创建valtio proxy 状态管理
|
|
12
|
+
*/
|
|
13
|
+
export declare const useValtioProxyState: <T extends object>(inital?: T) => readonly [import("valtio").Snapshot<T>, T, any];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useRef } from "react";
|
|
2
|
-
import { useSnapshot } from "valtio";
|
|
2
|
+
import { proxy, useSnapshot } from "valtio";
|
|
3
3
|
import { ProxyInstanceObjectBase } from "./instance.js";
|
|
4
4
|
export * from "./instance.js";
|
|
5
5
|
const useValtioState = (inital)=>{
|
|
@@ -20,4 +20,13 @@ const useValtioInstaceState = (Instance)=>{
|
|
|
20
20
|
state.__defaultValue
|
|
21
21
|
];
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
const useValtioProxyState = (inital)=>{
|
|
24
|
+
const instance = useRef(proxy(inital || {})).current;
|
|
25
|
+
const state = useSnapshot(instance);
|
|
26
|
+
return [
|
|
27
|
+
state,
|
|
28
|
+
instance,
|
|
29
|
+
state.__defaultValue
|
|
30
|
+
];
|
|
31
|
+
};
|
|
32
|
+
export { useValtioInstaceState, useValtioProxyState, useValtioState };
|
package/lib/utils/request.d.ts
CHANGED
|
@@ -46,8 +46,12 @@ export interface RequestInstanceCreateOptions {
|
|
|
46
46
|
pathRewrite: Record<string, string>;
|
|
47
47
|
}>;
|
|
48
48
|
};
|
|
49
|
+
/**启用token校验*/
|
|
50
|
+
isEnableTokenAuth?: boolean;
|
|
49
51
|
}
|
|
50
52
|
export declare class RequestInstance {
|
|
53
|
+
/**启用token校验*/
|
|
54
|
+
isEnableTokenAuth?: boolean;
|
|
51
55
|
/**请求IP地址*/
|
|
52
56
|
IP?: string | ((url: string, module?: string, env?: string) => string);
|
|
53
57
|
/**简单的代理配置*/
|
package/lib/utils/request.js
CHANGED
|
@@ -81,6 +81,7 @@ const requestResponseHandle = (result, options)=>{
|
|
|
81
81
|
});
|
|
82
82
|
};
|
|
83
83
|
class RequestInstance {
|
|
84
|
+
isEnableTokenAuth = true;
|
|
84
85
|
IP;
|
|
85
86
|
proxy;
|
|
86
87
|
commonOptions = {};
|
|
@@ -98,6 +99,7 @@ class RequestInstance {
|
|
|
98
99
|
...this.commonOptions,
|
|
99
100
|
...options.commonOptions
|
|
100
101
|
};
|
|
102
|
+
this.isEnableTokenAuth = 'boolean' == typeof options.isEnableTokenAuth ? options.isEnableTokenAuth : true;
|
|
101
103
|
return this;
|
|
102
104
|
};
|
|
103
105
|
getHttpPath = (url, module)=>{
|
|
@@ -155,7 +157,7 @@ class RequestInstance {
|
|
|
155
157
|
...header
|
|
156
158
|
};
|
|
157
159
|
if (token) newHeader[global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.headerTokenName || 'token'] = token;
|
|
158
|
-
else if (true !== isIgnoreToken) {
|
|
160
|
+
else if (true !== isIgnoreToken && this.isEnableTokenAuth) {
|
|
159
161
|
if (false !== isShowErrorMessage) if (global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.isUseTaroToast) taro_default().showToast({
|
|
160
162
|
title: "\u672A\u767B\u5F55",
|
|
161
163
|
duration: 3000,
|
|
@@ -7,3 +7,7 @@ export declare const useValtioInstaceState: <T extends object = any, K extends P
|
|
|
7
7
|
} = {
|
|
8
8
|
new (...args: any[]): K;
|
|
9
9
|
}>(Instance: M) => readonly [import("valtio").Snapshot<T>, K, any];
|
|
10
|
+
/**
|
|
11
|
+
* 创建valtio proxy 状态管理
|
|
12
|
+
*/
|
|
13
|
+
export declare const useValtioProxyState: <T extends object>(inital?: T) => readonly [import("valtio").Snapshot<T>, T, any];
|
|
@@ -55,6 +55,7 @@ var __webpack_exports__ = {};
|
|
|
55
55
|
__webpack_require__.r(__webpack_exports__);
|
|
56
56
|
__webpack_require__.d(__webpack_exports__, {
|
|
57
57
|
useValtioInstaceState: ()=>useValtioInstaceState,
|
|
58
|
+
useValtioProxyState: ()=>useValtioProxyState,
|
|
58
59
|
useValtioState: ()=>useValtioState
|
|
59
60
|
});
|
|
60
61
|
var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("react");
|
|
@@ -62,8 +63,9 @@ var __webpack_exports__ = {};
|
|
|
62
63
|
var _instance__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./instance");
|
|
63
64
|
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
64
65
|
for(var __WEBPACK_IMPORT_KEY__ in _instance__WEBPACK_IMPORTED_MODULE_2__)if ([
|
|
65
|
-
"
|
|
66
|
+
"useValtioProxyState",
|
|
66
67
|
"default",
|
|
68
|
+
"useValtioInstaceState",
|
|
67
69
|
"useValtioState"
|
|
68
70
|
].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
69
71
|
return _instance__WEBPACK_IMPORTED_MODULE_2__[key];
|
|
@@ -87,11 +89,22 @@ var __webpack_exports__ = {};
|
|
|
87
89
|
state.__defaultValue
|
|
88
90
|
];
|
|
89
91
|
};
|
|
92
|
+
const useValtioProxyState = (inital)=>{
|
|
93
|
+
const instance = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)((0, valtio__WEBPACK_IMPORTED_MODULE_1__.proxy)(inital || {})).current;
|
|
94
|
+
const state = (0, valtio__WEBPACK_IMPORTED_MODULE_1__.useSnapshot)(instance);
|
|
95
|
+
return [
|
|
96
|
+
state,
|
|
97
|
+
instance,
|
|
98
|
+
state.__defaultValue
|
|
99
|
+
];
|
|
100
|
+
};
|
|
90
101
|
})();
|
|
91
102
|
exports.useValtioInstaceState = __webpack_exports__.useValtioInstaceState;
|
|
103
|
+
exports.useValtioProxyState = __webpack_exports__.useValtioProxyState;
|
|
92
104
|
exports.useValtioState = __webpack_exports__.useValtioState;
|
|
93
105
|
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
|
|
94
106
|
"useValtioInstaceState",
|
|
107
|
+
"useValtioProxyState",
|
|
95
108
|
"useValtioState"
|
|
96
109
|
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
97
110
|
Object.defineProperty(exports, '__esModule', {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"author": "SunLxy <1011771396@qq.com>",
|
|
4
4
|
"description": "框架组件库",
|
|
5
5
|
"homepage": "https://github.com/autumn-fairy-tales/fairys-taro-react",
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.12",
|
|
7
7
|
"main": "esm/index.js",
|
|
8
8
|
"types": "esm/index.d.ts",
|
|
9
9
|
"module": "esm/index.js",
|
package/src/utils/request.ts
CHANGED
|
@@ -102,9 +102,14 @@ export interface RequestInstanceCreateOptions {
|
|
|
102
102
|
dev: Record<string, string | { target: string; pathRewrite: Record<string, string> }>;
|
|
103
103
|
pro: Record<string, string | { target: string; pathRewrite: Record<string, string> }>;
|
|
104
104
|
};
|
|
105
|
+
/**启用token校验*/
|
|
106
|
+
isEnableTokenAuth?: boolean;
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
export class RequestInstance {
|
|
110
|
+
/**启用token校验*/
|
|
111
|
+
public isEnableTokenAuth?: boolean = true;
|
|
112
|
+
|
|
108
113
|
/**请求IP地址*/
|
|
109
114
|
public IP?: string | ((url: string, module?: string, env?: string) => string);
|
|
110
115
|
/**简单的代理配置*/
|
|
@@ -128,6 +133,7 @@ export class RequestInstance {
|
|
|
128
133
|
this.IP = options.IP || this.IP;
|
|
129
134
|
this.proxy = options.proxy || this.proxy;
|
|
130
135
|
this.commonOptions = { ...this.commonOptions, ...options.commonOptions };
|
|
136
|
+
this.isEnableTokenAuth = typeof options.isEnableTokenAuth === 'boolean' ? options.isEnableTokenAuth : true;
|
|
131
137
|
return this;
|
|
132
138
|
};
|
|
133
139
|
|
|
@@ -213,7 +219,7 @@ export class RequestInstance {
|
|
|
213
219
|
if (token) {
|
|
214
220
|
newHeader[globalSettingDataInstance.store.headerTokenName || 'token'] = token;
|
|
215
221
|
} else {
|
|
216
|
-
if (isIgnoreToken !== true) {
|
|
222
|
+
if (isIgnoreToken !== true && this.isEnableTokenAuth) {
|
|
217
223
|
// 跳转登录页
|
|
218
224
|
if (isShowErrorMessage !== false) {
|
|
219
225
|
if (globalSettingDataInstance.store.isUseTaroToast) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
|
-
import { useSnapshot } from 'valtio';
|
|
2
|
+
import { useSnapshot, proxy } from 'valtio';
|
|
3
3
|
import { ProxyInstanceObjectBase } from './instance';
|
|
4
4
|
export * from './instance';
|
|
5
5
|
|
|
@@ -21,3 +21,12 @@ export const useValtioInstaceState = <
|
|
|
21
21
|
const state = useSnapshot(instance.store);
|
|
22
22
|
return [state, instance, (state as any).__defaultValue] as const;
|
|
23
23
|
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 创建valtio proxy 状态管理
|
|
27
|
+
*/
|
|
28
|
+
export const useValtioProxyState = <T extends object>(inital?: T) => {
|
|
29
|
+
const instance = useRef(proxy(inital || ({} as T))).current;
|
|
30
|
+
const state = useSnapshot(instance);
|
|
31
|
+
return [state, instance, (state as any).__defaultValue] as const;
|
|
32
|
+
};
|