@fairys/taro-tools-react 1.0.4 → 1.0.6

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.
Files changed (50) hide show
  1. package/esm/context/auth.data.instance.d.ts +3 -3
  2. package/esm/context/auth.data.instance.js +6 -6
  3. package/esm/context/global.data.instance.d.ts +4 -0
  4. package/esm/context/global.data.instance.js +5 -0
  5. package/esm/context/page.info.data.instance.d.ts +1 -1
  6. package/lib/components/EnterLoading/index.d.ts +14 -0
  7. package/lib/components/EnterLoading/index.js +112 -0
  8. package/lib/components/MainPage/index.d.ts +10 -0
  9. package/lib/components/MainPage/index.js +102 -0
  10. package/lib/components/Mesage/index.d.ts +48 -0
  11. package/lib/components/Mesage/index.js +172 -0
  12. package/lib/components/Portal/index.d.ts +8 -0
  13. package/lib/components/Portal/index.js +45 -0
  14. package/lib/components/Toast/index.d.ts +1 -0
  15. package/lib/components/Toast/index.js +54 -0
  16. package/lib/components/connectToastMessage/index.d.ts +10 -0
  17. package/lib/components/connectToastMessage/index.js +62 -0
  18. package/lib/components/index.d.ts +6 -0
  19. package/lib/components/index.js +105 -0
  20. package/lib/context/auth.data.instance.d.ts +81 -0
  21. package/lib/context/auth.data.instance.js +155 -0
  22. package/lib/context/global.data.instance.d.ts +54 -0
  23. package/lib/context/global.data.instance.js +122 -0
  24. package/lib/context/global.setting.data.instance.d.ts +56 -0
  25. package/lib/context/global.setting.data.instance.js +79 -0
  26. package/lib/context/index.d.ts +5 -0
  27. package/lib/context/index.js +96 -0
  28. package/lib/context/page.data.instance.d.ts +151 -0
  29. package/lib/context/page.data.instance.js +382 -0
  30. package/lib/context/page.info.data.instance.d.ts +93 -0
  31. package/lib/context/page.info.data.instance.js +226 -0
  32. package/lib/index.d.ts +3 -0
  33. package/lib/styles/index.css +715 -0
  34. package/lib/utils/index.d.ts +4 -0
  35. package/lib/utils/index.js +87 -0
  36. package/lib/utils/navigate.d.ts +109 -0
  37. package/lib/utils/navigate.js +99 -0
  38. package/lib/utils/request.d.ts +179 -0
  39. package/lib/utils/request.js +358 -0
  40. package/lib/utils/useId.d.ts +2 -0
  41. package/lib/utils/useId.js +50 -0
  42. package/lib/utils/valtio/index.d.ts +9 -0
  43. package/lib/utils/valtio/index.js +99 -0
  44. package/lib/utils/valtio/instance.d.ts +17 -0
  45. package/lib/utils/valtio/instance.js +80 -0
  46. package/package.json +4 -3
  47. package/src/context/auth.data.instance.ts +6 -6
  48. package/src/context/global.data.instance.ts +11 -0
  49. package/src/context/page.info.data.instance.tsx +1 -1
  50. package/src/utils/navigate.ts +1 -0
@@ -0,0 +1,358 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ request: ()=>request_request,
37
+ default: ()=>utils_request,
38
+ RequestInstance: ()=>RequestInstance
39
+ });
40
+ const taro_namespaceObject = require("@tarojs/taro");
41
+ var taro_default = /*#__PURE__*/ __webpack_require__.n(taro_namespaceObject);
42
+ const global_setting_data_instance_js_namespaceObject = require("../context/global.setting.data.instance.js");
43
+ const global_data_instance_js_namespaceObject = require("../context/global.data.instance.js");
44
+ const codeMessage = {
45
+ 400: "\u53D1\u51FA\u7684\u8BF7\u6C42\u9519\u8BEF",
46
+ 401: "\u7528\u6237\u6CA1\u6709\u6743\u9650",
47
+ 403: "\u7528\u6237\u8BBF\u95EE\u88AB\u7981\u6B62",
48
+ 404: "\u8BF7\u6C42\u4E0D\u5B58\u5728\uFF0C\u670D\u52A1\u5668\u6CA1\u6709\u8FDB\u884C\u64CD\u4F5C",
49
+ 406: "\u8BF7\u6C42\u7684\u683C\u5F0F\u9519\u8BEF",
50
+ 410: "\u8D44\u6E90\u88AB\u6C38\u4E45\u5220\u9664",
51
+ 422: "\u9A8C\u8BC1\u9519\u8BEF",
52
+ 500: "\u670D\u52A1\u5668\u53D1\u751F\u9519\u8BEF\uFF0C\u8BF7\u68C0\u67E5\u670D\u52A1\u5668",
53
+ 502: "nginx\u5F02\u5E38",
54
+ 503: "\u670D\u52A1\u4E0D\u53EF\u7528\uFF0C\u670D\u52A1\u5668\u6682\u65F6\u8FC7\u8F7D\u6216\u7EF4\u62A4",
55
+ 504: "nginx\u8D85\u65F6"
56
+ };
57
+ const requestResponseHandle = (result, options)=>{
58
+ let msg = '';
59
+ try {
60
+ const statusCode = result.statusCode;
61
+ const code = result?.data?.code;
62
+ if (401 === statusCode || 401 === code || code === global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.tokenExpiredCode) {
63
+ msg = "\u8BF7\u91CD\u65B0\u767B\u5F55";
64
+ global_data_instance_js_namespaceObject.globalDataInstance.toLoginPage();
65
+ } else msg = [
66
+ global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.requestSuccessCode,
67
+ 200
68
+ ].includes(code) ? codeMessage[result?.statusCode] : result?.data?.message || codeMessage[code || result?.statusCode] || "\u63A5\u53E3\u5F02\u5E38";
69
+ } catch (error) {
70
+ msg = codeMessage[result?.statusCode];
71
+ console.log(error);
72
+ }
73
+ if (msg && options?.isShowErrorMessage !== false) global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
74
+ content: msg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
75
+ type: 'error'
76
+ });
77
+ };
78
+ class RequestInstance {
79
+ IP;
80
+ proxy;
81
+ commonOptions = {};
82
+ constructor(options = {}){
83
+ this.extends(options);
84
+ }
85
+ static create(options = {}) {
86
+ const request = new RequestInstance(options);
87
+ return request;
88
+ }
89
+ extends = (options = {})=>{
90
+ this.IP = options.IP || this.IP;
91
+ this.proxy = options.proxy || this.proxy;
92
+ this.commonOptions = {
93
+ ...this.commonOptions,
94
+ ...options.commonOptions
95
+ };
96
+ return this;
97
+ };
98
+ getHttpPath = (url, module)=>{
99
+ if ('function' == typeof this.IP) return this.IP(url, module, process.env.NODE_ENV) || '';
100
+ return this.IP || '';
101
+ };
102
+ getProxyHost = (url, module)=>{
103
+ let host = '';
104
+ let _url = url;
105
+ if ('h5' === process.env.TARO_ENV) return {
106
+ host: '',
107
+ url: _url
108
+ };
109
+ if (this.proxy) {
110
+ const proxy = this.proxy['production' === process.env.NODE_ENV ? 'pro' : 'dev'];
111
+ if (proxy) for(const key in proxy){
112
+ const rgx = new RegExp(key);
113
+ const item = proxy[key];
114
+ if (rgx.test(url) && item) {
115
+ if ('string' == typeof item) host = item;
116
+ else if (item?.target) {
117
+ host = item.target;
118
+ if (item.pathRewrite) for(const key in item.pathRewrite){
119
+ const rgx = new RegExp(key);
120
+ _url = url.replace(rgx, item.pathRewrite[key]);
121
+ }
122
+ }
123
+ break;
124
+ }
125
+ }
126
+ }
127
+ if (!host) host = this.proxy?.default?.['production' === process.env.NODE_ENV ? 'pro' : 'dev'] || '';
128
+ if (!host) host = this.getHttpPath(url, module);
129
+ return {
130
+ host,
131
+ url: _url
132
+ };
133
+ };
134
+ formatUrl = (url, module)=>{
135
+ if (!url) throw new Error("\u8BF7\u6C42\u7684url\u5FC5\u586B");
136
+ if (url && (url.startsWith('http://') || url.startsWith('https://'))) return url;
137
+ let { host, url: _url } = this.getProxyHost(url, module);
138
+ if (host) host = host.replace(/\/$/, '');
139
+ const newUrl = `${_url}`.replace(/^\//, '').replace(/\/$/, '');
140
+ if (module && 'production' === process.env.NODE_ENV) {
141
+ const m = `${module}`.replace(/^\//, '').replace(/\/$/, '');
142
+ return `${host}/${m}/${newUrl}`;
143
+ }
144
+ return `${host}/${newUrl}`;
145
+ };
146
+ formatRequestOptions = (options)=>{
147
+ const { header = {}, module, isIgnoreToken, isShowErrorMessage, ...restOptions } = options;
148
+ const token = taro_default().getStorageSync(global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.tokenFieldName || 'token');
149
+ const newHeader = {
150
+ ...header
151
+ };
152
+ if (token) newHeader[global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.headerTokenName || 'token'] = token;
153
+ else if (true !== isIgnoreToken) {
154
+ if (false !== isShowErrorMessage) global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
155
+ content: "\u672A\u767B\u5F55",
156
+ type: 'error'
157
+ });
158
+ options?.fail?.({
159
+ errMsg: "\u672A\u767B\u5F55"
160
+ });
161
+ global_data_instance_js_namespaceObject.globalDataInstance.toLoginPage();
162
+ return;
163
+ }
164
+ return {
165
+ header: newHeader,
166
+ ...restOptions,
167
+ url: this.formatUrl(options.url, module)
168
+ };
169
+ };
170
+ requestBase = (options)=>{
171
+ const { isShowErrorMessage } = options;
172
+ const formattedOptions = this.formatRequestOptions(options);
173
+ if (!formattedOptions) return;
174
+ const { header: newHeader, ...restOptions } = formattedOptions;
175
+ return taro_default().request({
176
+ ...this.commonOptions,
177
+ ...restOptions,
178
+ header: {
179
+ ...newHeader,
180
+ ...options?.header || {}
181
+ },
182
+ success: (result)=>{
183
+ requestResponseHandle(result, options);
184
+ options?.success?.(result);
185
+ },
186
+ fail: (result)=>{
187
+ if (false !== isShowErrorMessage) global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
188
+ content: result.errMsg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
189
+ type: 'error'
190
+ });
191
+ options?.fail?.(result);
192
+ }
193
+ });
194
+ };
195
+ request = (options)=>new Promise((resolve, reject)=>{
196
+ this.requestBase({
197
+ ...options,
198
+ success: (result)=>{
199
+ options?.success?.(result);
200
+ resolve(result?.data);
201
+ },
202
+ fail: (result)=>{
203
+ options?.fail?.(result);
204
+ reject(result);
205
+ }
206
+ });
207
+ });
208
+ GET = (options)=>{
209
+ try {
210
+ return this.request({
211
+ ...options,
212
+ method: 'GET'
213
+ });
214
+ } catch (error) {
215
+ throw error;
216
+ }
217
+ };
218
+ POST = (options)=>{
219
+ try {
220
+ return this.request({
221
+ ...options,
222
+ method: 'POST'
223
+ });
224
+ } catch (error) {
225
+ throw error;
226
+ }
227
+ };
228
+ formData = (options)=>{
229
+ try {
230
+ return this.request({
231
+ ...options,
232
+ method: 'POST',
233
+ header: {
234
+ 'Content-Type': 'multipart/form-data',
235
+ ...options.header || {}
236
+ }
237
+ });
238
+ } catch (error) {
239
+ throw error;
240
+ }
241
+ };
242
+ xFormUrlEncoded = (options)=>{
243
+ try {
244
+ return this.request({
245
+ ...options,
246
+ method: 'POST',
247
+ header: {
248
+ 'Content-Type': 'application/x-www-form-urlencoded',
249
+ ...options.header || {}
250
+ }
251
+ });
252
+ } catch (error) {
253
+ throw error;
254
+ }
255
+ };
256
+ downloadFileTask = (options)=>{
257
+ const { isShowErrorMessage } = options;
258
+ const formattedOptions = this.formatRequestOptions(options);
259
+ if (!formattedOptions) return;
260
+ const { header: newHeader, onProgress, ...restOptions } = formattedOptions;
261
+ const downloadTask = taro_default().downloadFile({
262
+ ...this.commonOptions,
263
+ ...restOptions,
264
+ header: {
265
+ ...newHeader,
266
+ ...options?.header || {}
267
+ },
268
+ success: (result)=>{
269
+ if (200 === result.statusCode) options?.success?.(result);
270
+ else {
271
+ requestResponseHandle(result, options);
272
+ options?.fail?.(result);
273
+ }
274
+ },
275
+ fail: (result)=>{
276
+ if (false !== isShowErrorMessage) global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
277
+ content: result.errMsg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
278
+ type: 'error'
279
+ });
280
+ options?.fail?.(result);
281
+ }
282
+ });
283
+ if ('function' == typeof onProgress && downloadTask) downloadTask.onProgressUpdate(onProgress);
284
+ return downloadTask;
285
+ };
286
+ downloadFile = (options)=>{
287
+ try {
288
+ return new Promise((resolve, reject)=>{
289
+ this.downloadFileTask({
290
+ ...options,
291
+ success: (result)=>{
292
+ options?.success?.(result);
293
+ resolve(result);
294
+ },
295
+ fail: (result)=>{
296
+ options?.fail?.(result);
297
+ reject(result);
298
+ }
299
+ });
300
+ });
301
+ } catch (error) {
302
+ throw error;
303
+ }
304
+ };
305
+ uploadFileTask = (options)=>{
306
+ const { isShowErrorMessage } = options;
307
+ const formattedOptions = this.formatRequestOptions(options);
308
+ if (!formattedOptions) return;
309
+ const { header: newHeader, onProgress, ...restOptions } = formattedOptions;
310
+ const uploadTask = taro_default().uploadFile({
311
+ ...this.commonOptions,
312
+ ...restOptions,
313
+ header: {
314
+ ...newHeader,
315
+ ...options?.header || {}
316
+ },
317
+ success: (result)=>{
318
+ requestResponseHandle(result, options);
319
+ options?.success?.(result);
320
+ },
321
+ fail: (result)=>{
322
+ if (false !== isShowErrorMessage) global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
323
+ content: result.errMsg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
324
+ type: 'error'
325
+ });
326
+ options?.fail?.(result);
327
+ }
328
+ });
329
+ if ('function' == typeof onProgress && uploadTask) uploadTask.onProgressUpdate(onProgress);
330
+ return uploadTask;
331
+ };
332
+ uploadFile = (options)=>new Promise((resolve, reject)=>{
333
+ this.uploadFileTask({
334
+ ...options,
335
+ success: (result)=>{
336
+ options?.success?.(result);
337
+ resolve(result);
338
+ },
339
+ fail: (result)=>{
340
+ options?.fail?.(result);
341
+ reject(result);
342
+ }
343
+ });
344
+ });
345
+ }
346
+ const request_request = new RequestInstance();
347
+ const utils_request = request_request;
348
+ exports.RequestInstance = __webpack_exports__.RequestInstance;
349
+ exports["default"] = __webpack_exports__["default"];
350
+ exports.request = __webpack_exports__.request;
351
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
352
+ "RequestInstance",
353
+ "default",
354
+ "request"
355
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
356
+ Object.defineProperty(exports, '__esModule', {
357
+ value: true
358
+ });
@@ -0,0 +1,2 @@
1
+ export declare const createUseId: (suffix?: string) => string;
2
+ export declare const useId: (suffix?: string) => string;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ createUseId: ()=>createUseId,
28
+ useId: ()=>useId
29
+ });
30
+ const external_react_namespaceObject = require("react");
31
+ let localId = 0;
32
+ const createUseId = (suffix = 'D')=>{
33
+ const count = localId++;
34
+ return `FAIRYS_TARO_UI_${count.toString(32)}_${suffix}`;
35
+ };
36
+ const useId = (suffix = 'D')=>{
37
+ const count = (0, external_react_namespaceObject.useRef)(localId++);
38
+ return (0, external_react_namespaceObject.useMemo)(()=>`FAIRYS_TARO_UI_${count.current.toString(32)}_${suffix}`, [
39
+ count.current
40
+ ]);
41
+ };
42
+ exports.createUseId = __webpack_exports__.createUseId;
43
+ exports.useId = __webpack_exports__.useId;
44
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
45
+ "createUseId",
46
+ "useId"
47
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
48
+ Object.defineProperty(exports, '__esModule', {
49
+ value: true
50
+ });
@@ -0,0 +1,9 @@
1
+ import { ProxyInstanceObjectBase } from './instance';
2
+ export * from './instance';
3
+ /**创建简单的状态管理*/
4
+ export declare const useValtioState: <T extends object>(inital?: T) => readonly [import("valtio").Snapshot<T>, ProxyInstanceObjectBase<T>, any];
5
+ export declare const useValtioInstaceState: <T extends object = any, K extends ProxyInstanceObjectBase<T> = ProxyInstanceObjectBase<T>, M extends {
6
+ new (...args: any[]): K;
7
+ } = {
8
+ new (...args: any[]): K;
9
+ }>(Instance: M) => readonly [import("valtio").Snapshot<T>, K, any];
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ var __webpack_modules__ = {
3
+ "./instance": function(module) {
4
+ module.exports = require("./instance.js");
5
+ },
6
+ react: function(module) {
7
+ module.exports = require("react");
8
+ },
9
+ valtio: function(module) {
10
+ module.exports = require("valtio");
11
+ }
12
+ };
13
+ var __webpack_module_cache__ = {};
14
+ function __webpack_require__(moduleId) {
15
+ var cachedModule = __webpack_module_cache__[moduleId];
16
+ if (void 0 !== cachedModule) return cachedModule.exports;
17
+ var module = __webpack_module_cache__[moduleId] = {
18
+ exports: {}
19
+ };
20
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
21
+ return module.exports;
22
+ }
23
+ (()=>{
24
+ __webpack_require__.n = (module)=>{
25
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
26
+ __webpack_require__.d(getter, {
27
+ a: getter
28
+ });
29
+ return getter;
30
+ };
31
+ })();
32
+ (()=>{
33
+ __webpack_require__.d = (exports1, definition)=>{
34
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
35
+ enumerable: true,
36
+ get: definition[key]
37
+ });
38
+ };
39
+ })();
40
+ (()=>{
41
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
42
+ })();
43
+ (()=>{
44
+ __webpack_require__.r = (exports1)=>{
45
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
46
+ value: 'Module'
47
+ });
48
+ Object.defineProperty(exports1, '__esModule', {
49
+ value: true
50
+ });
51
+ };
52
+ })();
53
+ var __webpack_exports__ = {};
54
+ (()=>{
55
+ __webpack_require__.r(__webpack_exports__);
56
+ __webpack_require__.d(__webpack_exports__, {
57
+ useValtioInstaceState: ()=>useValtioInstaceState,
58
+ useValtioState: ()=>useValtioState
59
+ });
60
+ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("react");
61
+ var valtio__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__("valtio");
62
+ var _instance__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__("./instance");
63
+ var __WEBPACK_REEXPORT_OBJECT__ = {};
64
+ for(var __WEBPACK_IMPORT_KEY__ in _instance__WEBPACK_IMPORTED_MODULE_2__)if ([
65
+ "useValtioInstaceState",
66
+ "default",
67
+ "useValtioState"
68
+ ].indexOf(__WEBPACK_IMPORT_KEY__) < 0) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
69
+ return _instance__WEBPACK_IMPORTED_MODULE_2__[key];
70
+ }).bind(0, __WEBPACK_IMPORT_KEY__);
71
+ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
72
+ const useValtioState = (inital)=>{
73
+ const instance = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)(new _instance__WEBPACK_IMPORTED_MODULE_2__.ProxyInstanceObjectBase()._ctor(inital)).current;
74
+ const state = (0, valtio__WEBPACK_IMPORTED_MODULE_1__.useSnapshot)(instance.store);
75
+ return [
76
+ state,
77
+ instance,
78
+ state.__defaultValue
79
+ ];
80
+ };
81
+ const useValtioInstaceState = (Instance)=>{
82
+ const instance = (0, react__WEBPACK_IMPORTED_MODULE_0__.useRef)(new Instance()).current;
83
+ const state = (0, valtio__WEBPACK_IMPORTED_MODULE_1__.useSnapshot)(instance.store);
84
+ return [
85
+ state,
86
+ instance,
87
+ state.__defaultValue
88
+ ];
89
+ };
90
+ })();
91
+ exports.useValtioInstaceState = __webpack_exports__.useValtioInstaceState;
92
+ exports.useValtioState = __webpack_exports__.useValtioState;
93
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
94
+ "useValtioInstaceState",
95
+ "useValtioState"
96
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
97
+ Object.defineProperty(exports, '__esModule', {
98
+ value: true
99
+ });
@@ -0,0 +1,17 @@
1
+ /**
2
+ * 单个proxy对象数据基础实例封装
3
+ */
4
+ export declare class ProxyInstanceObjectBase<T extends Object = any> {
5
+ /**不使用ref存储的字段*/
6
+ notRefFields: string[];
7
+ /**proxy 可状态更新字段 */
8
+ store: T;
9
+ /**初始化存储值*/
10
+ _ctor: (inital?: Partial<T>, fields?: string[]) => this;
11
+ /**更新store数据 循环对象进行存储,当值是对象的时候存储为ref*/
12
+ _setValues: <K = T>(values: Partial<K>, fields?: string[]) => this;
13
+ /**删除字段值*/
14
+ _deleteValue: (names: string | string[]) => this;
15
+ /**创建 ref 对象 (ref对象不做监听更新)*/
16
+ _createRef: <K extends Object = any>(inital?: K) => K;
17
+ }
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ ProxyInstanceObjectBase: ()=>ProxyInstanceObjectBase
37
+ });
38
+ const external_valtio_namespaceObject = require("valtio");
39
+ const external_react_namespaceObject = require("react");
40
+ var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
41
+ class ProxyInstanceObjectBase {
42
+ notRefFields = [];
43
+ store = (0, external_valtio_namespaceObject.proxy)({});
44
+ _ctor = (inital, fields)=>{
45
+ this._setValues(inital || {}, fields);
46
+ return this;
47
+ };
48
+ _setValues = (values, fields)=>{
49
+ if (!this.store) this.store = (0, external_valtio_namespaceObject.proxy)({});
50
+ Object.keys(values).forEach((key)=>{
51
+ const value = values[key];
52
+ if (Array.isArray(fields) && fields.includes(key)) this.store[key] = values[key];
53
+ else if (Array.isArray(this.notRefFields) && this.notRefFields.includes(key)) this.store[key] = value;
54
+ else if (external_react_default().isValidElement(value) || 'function' == typeof value) this.store[key] = (0, external_valtio_namespaceObject.ref)(values[key]);
55
+ else if ('object' == typeof value && null !== value) this.store[key] = (0, external_valtio_namespaceObject.ref)(values[key]);
56
+ else this.store[key] = values[key];
57
+ });
58
+ return this;
59
+ };
60
+ _deleteValue = (names)=>{
61
+ if (Array.isArray(names)) {
62
+ let cacheValue = this.store;
63
+ const newNames = [
64
+ ...names
65
+ ];
66
+ const lastField = newNames.pop();
67
+ for(let index = 0; index < newNames.length; index++)cacheValue = cacheValue[newNames[index]];
68
+ if (cacheValue && lastField) delete cacheValue[lastField];
69
+ } else delete this.store[names];
70
+ return this;
71
+ };
72
+ _createRef = (inital)=>(0, external_valtio_namespaceObject.ref)(inital || {});
73
+ }
74
+ exports.ProxyInstanceObjectBase = __webpack_exports__.ProxyInstanceObjectBase;
75
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
76
+ "ProxyInstanceObjectBase"
77
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
78
+ Object.defineProperty(exports, '__esModule', {
79
+ value: true
80
+ });
package/package.json CHANGED
@@ -3,8 +3,8 @@
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.4",
7
- "main": "lib/index.js",
6
+ "version": "1.0.6",
7
+ "main": "esm/index.js",
8
8
  "types": "esm/index.d.ts",
9
9
  "module": "esm/index.js",
10
10
  "license": "ISC",
@@ -22,7 +22,8 @@
22
22
  },
23
23
  "files": [
24
24
  "src",
25
- "esm"
25
+ "esm",
26
+ "lib"
26
27
  ],
27
28
  "dependencies": {
28
29
  "clsx": "2.1.1",
@@ -144,34 +144,34 @@ export class AuthDataInstance<T = any> {
144
144
  * @param menuPermission 菜单权限
145
145
  * @returns 是否有指定菜单权限
146
146
  */
147
- hasMenuPermission(menuPermission: string): boolean {
147
+ hasMenuPermission = (menuPermission: string): boolean => {
148
148
  if (!globalSettingDataInstance.store.isEnableAuth) {
149
149
  return true;
150
150
  }
151
151
  return this.menusPermissions.includes(menuPermission);
152
- }
152
+ };
153
153
 
154
154
  /**
155
155
  * 判断是否有指定权限
156
156
  * @param permission 权限
157
157
  * @returns 是否有指定权限
158
158
  */
159
- hasPermission(permission: string): boolean {
159
+ hasPermission = (permission: string): boolean => {
160
160
  if (!globalSettingDataInstance.store.isEnableAuth) {
161
161
  return true;
162
162
  }
163
163
  return this.permissions.includes(permission);
164
- }
164
+ };
165
165
 
166
166
  /**
167
167
  * 清除登录凭证(token)、权限列表、菜单权限列表、用户信息
168
168
  */
169
- clear() {
169
+ clear = () => {
170
170
  this.token = '';
171
171
  this.permissions = [];
172
172
  this.menusPermissions = [];
173
173
  this.userInfo = undefined;
174
- }
174
+ };
175
175
 
176
176
  /**
177
177
  * 初始化认证数据实例