@fairys/taro-tools-react 1.0.9 → 1.0.10

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.
@@ -31,6 +31,8 @@ export interface GlobalSettingDataInstanceState {
31
31
  useAuthHasMenuPermission?: boolean;
32
32
  /**是否开启权限校验*/
33
33
  isEnableAuth?: boolean;
34
+ /**是否使用Taro自带的toast提示*/
35
+ isUseTaroToast?: boolean;
34
36
  /**数据默认值不使用*/
35
37
  __defaultValue?: string;
36
38
  }
@@ -9,7 +9,8 @@ class GlobalSettingDataInstance extends ProxyInstanceObjectBase {
9
9
  loginPageRoute: 'pages/login/index',
10
10
  ignoreAuthRoutes: [],
11
11
  useAuthHasMenuPermission: true,
12
- isEnableAuth: true
12
+ isEnableAuth: true,
13
+ isUseTaroToast: true
13
14
  };
14
15
  store = proxy({
15
16
  ...this.defaultStore
@@ -311,13 +311,13 @@ function PageDataInstanceContextProvider(props) {
311
311
  });
312
312
  }
313
313
  const usePageDataInstanceState = ()=>{
314
- const PageMainDataInstance = usePageDataInstanceContext();
315
- const store = useSnapshot(PageMainDataInstance.store, {
314
+ const pageMainDataInstance = usePageDataInstanceContext();
315
+ const store = useSnapshot(pageMainDataInstance.store, {
316
316
  sync: true
317
317
  });
318
318
  return [
319
319
  store,
320
- PageMainDataInstance,
320
+ pageMainDataInstance,
321
321
  store.__defaultValue
322
322
  ];
323
323
  };
@@ -155,13 +155,13 @@ function PageInfoDataInstanceContextProvider(props) {
155
155
  });
156
156
  }
157
157
  const usePageInfoDataInstanceState = ()=>{
158
- const PageInfoDataInstance = usePageInfoDataInstanceContext();
159
- const store = useSnapshot(PageInfoDataInstance.store, {
158
+ const pageInfoDataInstance = usePageInfoDataInstanceContext();
159
+ const store = useSnapshot(pageInfoDataInstance.store, {
160
160
  sync: true
161
161
  });
162
162
  return [
163
163
  store,
164
- PageInfoDataInstance,
164
+ pageInfoDataInstance,
165
165
  store.__defaultValue
166
166
  ];
167
167
  };
@@ -30,7 +30,12 @@ const requestResponseHandle = (result, options)=>{
30
30
  msg = codeMessage[result?.statusCode];
31
31
  console.log(error);
32
32
  }
33
- if (msg && options?.isShowErrorMessage !== false) globalDataInstance.showMessage({
33
+ if (msg && options?.isShowErrorMessage !== false) if (globalSettingDataInstance.store.isUseTaroToast) taro.showToast({
34
+ title: msg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
35
+ duration: 3000,
36
+ icon: 'none'
37
+ });
38
+ else globalDataInstance.showMessage({
34
39
  content: msg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
35
40
  type: 'error'
36
41
  });
@@ -111,7 +116,12 @@ class RequestInstance {
111
116
  };
112
117
  if (token) newHeader[globalSettingDataInstance.store.headerTokenName || 'token'] = token;
113
118
  else if (true !== isIgnoreToken) {
114
- if (false !== isShowErrorMessage) globalDataInstance.showMessage({
119
+ if (false !== isShowErrorMessage) if (globalSettingDataInstance.store.isUseTaroToast) taro.showToast({
120
+ title: "\u672A\u767B\u5F55",
121
+ duration: 3000,
122
+ icon: 'none'
123
+ });
124
+ else globalDataInstance.showMessage({
115
125
  content: "\u672A\u767B\u5F55",
116
126
  type: 'error'
117
127
  });
@@ -144,7 +154,12 @@ class RequestInstance {
144
154
  options?.success?.(result);
145
155
  },
146
156
  fail: (result)=>{
147
- if (false !== isShowErrorMessage) globalDataInstance.showMessage({
157
+ if (false !== isShowErrorMessage) if (globalSettingDataInstance.store.isUseTaroToast) taro.showToast({
158
+ title: result.errMsg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
159
+ duration: 3000,
160
+ icon: 'none'
161
+ });
162
+ else globalDataInstance.showMessage({
148
163
  content: result.errMsg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
149
164
  type: 'error'
150
165
  });
@@ -233,7 +248,12 @@ class RequestInstance {
233
248
  }
234
249
  },
235
250
  fail: (result)=>{
236
- if (false !== isShowErrorMessage) globalDataInstance.showMessage({
251
+ if (false !== isShowErrorMessage) if (globalSettingDataInstance.store.isUseTaroToast) taro.showToast({
252
+ title: result.errMsg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
253
+ duration: 3000,
254
+ icon: 'none'
255
+ });
256
+ else globalDataInstance.showMessage({
237
257
  content: result.errMsg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
238
258
  type: 'error'
239
259
  });
@@ -279,7 +299,12 @@ class RequestInstance {
279
299
  options?.success?.(result);
280
300
  },
281
301
  fail: (result)=>{
282
- if (false !== isShowErrorMessage) globalDataInstance.showMessage({
302
+ if (false !== isShowErrorMessage) if (globalSettingDataInstance.store.isUseTaroToast) taro.showToast({
303
+ title: result.errMsg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
304
+ duration: 3000,
305
+ icon: 'none'
306
+ });
307
+ else globalDataInstance.showMessage({
283
308
  content: result.errMsg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
284
309
  type: 'error'
285
310
  });
@@ -31,6 +31,8 @@ export interface GlobalSettingDataInstanceState {
31
31
  useAuthHasMenuPermission?: boolean;
32
32
  /**是否开启权限校验*/
33
33
  isEnableAuth?: boolean;
34
+ /**是否使用Taro自带的toast提示*/
35
+ isUseTaroToast?: boolean;
34
36
  /**数据默认值不使用*/
35
37
  __defaultValue?: string;
36
38
  }
@@ -39,7 +39,8 @@ class GlobalSettingDataInstance extends instance_js_namespaceObject.ProxyInstanc
39
39
  loginPageRoute: 'pages/login/index',
40
40
  ignoreAuthRoutes: [],
41
41
  useAuthHasMenuPermission: true,
42
- isEnableAuth: true
42
+ isEnableAuth: true,
43
+ isUseTaroToast: true
43
44
  };
44
45
  store = (0, external_valtio_namespaceObject.proxy)({
45
46
  ...this.defaultStore
@@ -354,13 +354,13 @@ function PageDataInstanceContextProvider(props) {
354
354
  });
355
355
  }
356
356
  const usePageDataInstanceState = ()=>{
357
- const PageMainDataInstance = usePageDataInstanceContext();
358
- const store = (0, external_valtio_namespaceObject.useSnapshot)(PageMainDataInstance.store, {
357
+ const pageMainDataInstance = usePageDataInstanceContext();
358
+ const store = (0, external_valtio_namespaceObject.useSnapshot)(pageMainDataInstance.store, {
359
359
  sync: true
360
360
  });
361
361
  return [
362
362
  store,
363
- PageMainDataInstance,
363
+ pageMainDataInstance,
364
364
  store.__defaultValue
365
365
  ];
366
366
  };
@@ -199,13 +199,13 @@ function PageInfoDataInstanceContextProvider(props) {
199
199
  });
200
200
  }
201
201
  const usePageInfoDataInstanceState = ()=>{
202
- const PageInfoDataInstance = usePageInfoDataInstanceContext();
203
- const store = (0, external_valtio_namespaceObject.useSnapshot)(PageInfoDataInstance.store, {
202
+ const pageInfoDataInstance = usePageInfoDataInstanceContext();
203
+ const store = (0, external_valtio_namespaceObject.useSnapshot)(pageInfoDataInstance.store, {
204
204
  sync: true
205
205
  });
206
206
  return [
207
207
  store,
208
- PageInfoDataInstance,
208
+ pageInfoDataInstance,
209
209
  store.__defaultValue
210
210
  ];
211
211
  };
@@ -70,7 +70,12 @@ const requestResponseHandle = (result, options)=>{
70
70
  msg = codeMessage[result?.statusCode];
71
71
  console.log(error);
72
72
  }
73
- if (msg && options?.isShowErrorMessage !== false) global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
73
+ if (msg && options?.isShowErrorMessage !== false) if (global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.isUseTaroToast) taro_default().showToast({
74
+ title: msg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
75
+ duration: 3000,
76
+ icon: 'none'
77
+ });
78
+ else global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
74
79
  content: msg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
75
80
  type: 'error'
76
81
  });
@@ -151,7 +156,12 @@ class RequestInstance {
151
156
  };
152
157
  if (token) newHeader[global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.headerTokenName || 'token'] = token;
153
158
  else if (true !== isIgnoreToken) {
154
- if (false !== isShowErrorMessage) global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
159
+ if (false !== isShowErrorMessage) if (global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.isUseTaroToast) taro_default().showToast({
160
+ title: "\u672A\u767B\u5F55",
161
+ duration: 3000,
162
+ icon: 'none'
163
+ });
164
+ else global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
155
165
  content: "\u672A\u767B\u5F55",
156
166
  type: 'error'
157
167
  });
@@ -184,7 +194,12 @@ class RequestInstance {
184
194
  options?.success?.(result);
185
195
  },
186
196
  fail: (result)=>{
187
- if (false !== isShowErrorMessage) global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
197
+ if (false !== isShowErrorMessage) if (global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.isUseTaroToast) taro_default().showToast({
198
+ title: result.errMsg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
199
+ duration: 3000,
200
+ icon: 'none'
201
+ });
202
+ else global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
188
203
  content: result.errMsg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
189
204
  type: 'error'
190
205
  });
@@ -273,7 +288,12 @@ class RequestInstance {
273
288
  }
274
289
  },
275
290
  fail: (result)=>{
276
- if (false !== isShowErrorMessage) global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
291
+ if (false !== isShowErrorMessage) if (global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.isUseTaroToast) taro_default().showToast({
292
+ title: result.errMsg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
293
+ duration: 3000,
294
+ icon: 'none'
295
+ });
296
+ else global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
277
297
  content: result.errMsg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
278
298
  type: 'error'
279
299
  });
@@ -319,7 +339,12 @@ class RequestInstance {
319
339
  options?.success?.(result);
320
340
  },
321
341
  fail: (result)=>{
322
- if (false !== isShowErrorMessage) global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
342
+ if (false !== isShowErrorMessage) if (global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.isUseTaroToast) taro_default().showToast({
343
+ title: result.errMsg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
344
+ duration: 3000,
345
+ icon: 'none'
346
+ });
347
+ else global_data_instance_js_namespaceObject.globalDataInstance.showMessage({
323
348
  content: result.errMsg || "\u8BF7\u6C42\u53D1\u751F\u9519\u8BEF",
324
349
  type: 'error'
325
350
  });
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.9",
6
+ "version": "1.0.10",
7
7
  "main": "esm/index.js",
8
8
  "types": "esm/index.d.ts",
9
9
  "module": "esm/index.js",
@@ -6,6 +6,7 @@ import React from 'react';
6
6
  import type { FairysTaroMessageItemProps } from 'components/Mesage';
7
7
  import { ProxyInstanceObjectBase } from 'utils/valtio/instance';
8
8
  import { globalSettingDataInstance } from './global.setting.data.instance';
9
+ import Taro from '@tarojs/taro';
9
10
 
10
11
  export interface MessageDataType extends FairysTaroMessageItemProps {
11
12
  /**用于唯一标识提示框(默认自动生成)*/
@@ -33,6 +33,8 @@ export interface GlobalSettingDataInstanceState {
33
33
  useAuthHasMenuPermission?: boolean;
34
34
  /**是否开启权限校验*/
35
35
  isEnableAuth?: boolean;
36
+ /**是否使用Taro自带的toast提示*/
37
+ isUseTaroToast?: boolean;
36
38
  /**数据默认值不使用*/
37
39
  __defaultValue?: string;
38
40
  }
@@ -47,6 +49,7 @@ export class GlobalSettingDataInstance extends ProxyInstanceObjectBase<GlobalSet
47
49
  ignoreAuthRoutes: [],
48
50
  useAuthHasMenuPermission: true,
49
51
  isEnableAuth: true,
52
+ isUseTaroToast: true,
50
53
  };
51
54
  store = proxy<GlobalSettingDataInstanceState>({ ...this.defaultStore });
52
55
  /**
@@ -492,7 +492,7 @@ export const usePageDataInstanceState = <
492
492
  T extends PageDataInstanceState = PageDataInstanceState,
493
493
  M extends PageDataInstance<T> = PageDataInstance<T>,
494
494
  >() => {
495
- const PageMainDataInstance = usePageDataInstanceContext<T, M>();
496
- const store = useSnapshot(PageMainDataInstance.store, { sync: true }) as T;
497
- return [store, PageMainDataInstance, store.__defaultValue] as [T, M, string | undefined];
495
+ const pageMainDataInstance = usePageDataInstanceContext<T, M>();
496
+ const store = useSnapshot(pageMainDataInstance.store, { sync: true }) as T;
497
+ return [store, pageMainDataInstance, store.__defaultValue] as [T, M, string | undefined];
498
498
  };
@@ -283,7 +283,7 @@ export const usePageInfoDataInstanceState = <
283
283
  T extends PageInfoDataInstanceState = PageInfoDataInstanceState,
284
284
  M extends PageInfoDataInstance<T> = PageInfoDataInstance<T>,
285
285
  >() => {
286
- const PageInfoDataInstance = usePageInfoDataInstanceContext<T, M>();
287
- const store = useSnapshot(PageInfoDataInstance.store, { sync: true }) as T;
288
- return [store, PageInfoDataInstance, store.__defaultValue] as [T, M, string | undefined];
286
+ const pageInfoDataInstance = usePageInfoDataInstanceContext<T, M>();
287
+ const store = useSnapshot(pageInfoDataInstance.store, { sync: true }) as T;
288
+ return [store, pageInfoDataInstance, store.__defaultValue] as [T, M, string | undefined];
289
289
  };
@@ -64,10 +64,18 @@ const requestResponseHandle = (
64
64
  console.log(error);
65
65
  }
66
66
  if (msg && options?.isShowErrorMessage !== false) {
67
- globalDataInstance.showMessage({
68
- content: msg || '请求发生错误',
69
- type: 'error',
70
- });
67
+ if (globalSettingDataInstance.store.isUseTaroToast) {
68
+ Taro.showToast({
69
+ title: msg || '请求发生错误',
70
+ duration: 3000,
71
+ icon: 'none',
72
+ });
73
+ } else {
74
+ globalDataInstance.showMessage({
75
+ content: msg || '请求发生错误',
76
+ type: 'error',
77
+ });
78
+ }
71
79
  }
72
80
  };
73
81
 
@@ -208,10 +216,18 @@ export class RequestInstance {
208
216
  if (isIgnoreToken !== true) {
209
217
  // 跳转登录页
210
218
  if (isShowErrorMessage !== false) {
211
- globalDataInstance.showMessage({
212
- content: '未登录',
213
- type: 'error',
214
- });
219
+ if (globalSettingDataInstance.store.isUseTaroToast) {
220
+ Taro.showToast({
221
+ title: '未登录',
222
+ duration: 3000,
223
+ icon: 'none',
224
+ });
225
+ } else {
226
+ globalDataInstance.showMessage({
227
+ content: '未登录',
228
+ type: 'error',
229
+ });
230
+ }
215
231
  }
216
232
  options?.fail?.({ errMsg: '未登录' });
217
233
  globalDataInstance.toLoginPage();
@@ -250,10 +266,18 @@ export class RequestInstance {
250
266
  },
251
267
  fail: (result) => {
252
268
  if (isShowErrorMessage !== false) {
253
- globalDataInstance.showMessage({
254
- content: result.errMsg || '请求发生错误',
255
- type: 'error',
256
- });
269
+ if (globalSettingDataInstance.store.isUseTaroToast) {
270
+ Taro.showToast({
271
+ title: result.errMsg || '请求发生错误',
272
+ duration: 3000,
273
+ icon: 'none',
274
+ });
275
+ } else {
276
+ globalDataInstance.showMessage({
277
+ content: result.errMsg || '请求发生错误',
278
+ type: 'error',
279
+ });
280
+ }
257
281
  }
258
282
  options?.fail?.(result);
259
283
  },
@@ -358,10 +382,18 @@ export class RequestInstance {
358
382
  },
359
383
  fail: (result) => {
360
384
  if (isShowErrorMessage !== false) {
361
- globalDataInstance.showMessage({
362
- content: result.errMsg || '请求发生错误',
363
- type: 'error',
364
- });
385
+ if (globalSettingDataInstance.store.isUseTaroToast) {
386
+ Taro.showToast({
387
+ title: result.errMsg || '请求发生错误',
388
+ duration: 3000,
389
+ icon: 'none',
390
+ });
391
+ } else {
392
+ globalDataInstance.showMessage({
393
+ content: result.errMsg || '请求发生错误',
394
+ type: 'error',
395
+ });
396
+ }
365
397
  }
366
398
  options?.fail?.(result);
367
399
  },
@@ -415,10 +447,18 @@ export class RequestInstance {
415
447
  },
416
448
  fail: (result) => {
417
449
  if (isShowErrorMessage !== false) {
418
- globalDataInstance.showMessage({
419
- content: result.errMsg || '请求发生错误',
420
- type: 'error',
421
- });
450
+ if (globalSettingDataInstance.store.isUseTaroToast) {
451
+ Taro.showToast({
452
+ title: result.errMsg || '请求发生错误',
453
+ duration: 3000,
454
+ icon: 'none',
455
+ });
456
+ } else {
457
+ globalDataInstance.showMessage({
458
+ content: result.errMsg || '请求发生错误',
459
+ type: 'error',
460
+ });
461
+ }
422
462
  }
423
463
  options?.fail?.(result);
424
464
  },