@fairys/taro-tools-react 1.0.33 → 1.0.34

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 (34) hide show
  1. package/esm/components/custom-tab-bar/index.css +39 -0
  2. package/esm/components/custom-tab-bar/index.d.ts +57 -0
  3. package/esm/components/custom-tab-bar/index.js +114 -0
  4. package/esm/components/index.d.ts +1 -0
  5. package/esm/components/index.js +1 -0
  6. package/esm/context/global.data.instance.d.ts +27 -0
  7. package/esm/context/global.data.instance.js +40 -0
  8. package/esm/context/global.message.data.instance.d.ts +0 -7
  9. package/esm/context/global.message.data.instance.js +0 -25
  10. package/esm/context/index.d.ts +1 -0
  11. package/esm/context/index.js +1 -0
  12. package/esm/styles/index.css +18 -0
  13. package/esm/utils/request.js +3 -2
  14. package/lib/components/custom-tab-bar/index.css +39 -0
  15. package/lib/components/custom-tab-bar/index.d.ts +57 -0
  16. package/lib/components/custom-tab-bar/index.js +165 -0
  17. package/lib/components/index.d.ts +1 -0
  18. package/lib/components/index.js +9 -0
  19. package/lib/context/global.data.instance.d.ts +27 -0
  20. package/lib/context/global.data.instance.js +91 -0
  21. package/lib/context/global.message.data.instance.d.ts +0 -7
  22. package/lib/context/global.message.data.instance.js +0 -36
  23. package/lib/context/index.d.ts +1 -0
  24. package/lib/context/index.js +9 -0
  25. package/lib/styles/index.css +18 -0
  26. package/lib/utils/request.js +3 -2
  27. package/package.json +1 -1
  28. package/src/components/custom-tab-bar/index.css +38 -0
  29. package/src/components/custom-tab-bar/index.tsx +169 -0
  30. package/src/components/index.ts +1 -0
  31. package/src/context/global.data.instance.ts +69 -0
  32. package/src/context/global.message.data.instance.ts +0 -37
  33. package/src/context/index.ts +1 -0
  34. package/src/utils/request.ts +3 -2
@@ -4,3 +4,4 @@ export * from './Mesage';
4
4
  export * from './Toast';
5
5
  export * from './connectToastMessage';
6
6
  export * from './MainPage';
7
+ export * from './custom-tab-bar';
@@ -17,6 +17,9 @@ var __webpack_modules__ = {
17
17
  },
18
18
  "./connectToastMessage": function(module) {
19
19
  module.exports = require("./connectToastMessage/index.js");
20
+ },
21
+ "./custom-tab-bar": function(module) {
22
+ module.exports = require("./custom-tab-bar/index.js");
20
23
  }
21
24
  };
22
25
  var __webpack_module_cache__ = {};
@@ -98,6 +101,12 @@ var __webpack_exports__ = {};
98
101
  return _MainPage__WEBPACK_IMPORTED_MODULE_5__[key];
99
102
  }).bind(0, __WEBPACK_IMPORT_KEY__);
100
103
  __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
104
+ var _custom_tab_bar__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__("./custom-tab-bar");
105
+ var __WEBPACK_REEXPORT_OBJECT__ = {};
106
+ for(var __WEBPACK_IMPORT_KEY__ in _custom_tab_bar__WEBPACK_IMPORTED_MODULE_6__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
107
+ return _custom_tab_bar__WEBPACK_IMPORTED_MODULE_6__[key];
108
+ }).bind(0, __WEBPACK_IMPORT_KEY__);
109
+ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
101
110
  })();
102
111
  for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
103
112
  Object.defineProperty(exports, '__esModule', {
@@ -0,0 +1,27 @@
1
+ import { ProxyInstanceObjectBase } from '../utils/valtio/instance';
2
+ export interface GlobalDataInstanceState {
3
+ /**数据默认值不使用*/
4
+ __defaultValue?: string;
5
+ }
6
+ /**
7
+ * 全局数据实例
8
+ */
9
+ export declare class GlobalDataInstance extends ProxyInstanceObjectBase<GlobalDataInstanceState> {
10
+ store: GlobalDataInstanceState;
11
+ /**
12
+ * 跳转登录页面前执行
13
+ */
14
+ onBeforetToLoginPage?: () => boolean | void;
15
+ /**跳转 redirect 路由*/
16
+ toRedirect: () => void;
17
+ /**跳转登录页面*/
18
+ toLoginPage: () => void;
19
+ }
20
+ /**
21
+ * 全局数据实例
22
+ */
23
+ export declare const globalDataInstance: GlobalDataInstance;
24
+ /**
25
+ * 全局数据状态管理
26
+ */
27
+ export declare const useGlobalData: () => [GlobalDataInstanceState, GlobalDataInstance, string | undefined];
@@ -0,0 +1,91 @@
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
+ useGlobalData: ()=>useGlobalData,
37
+ GlobalDataInstance: ()=>GlobalDataInstance,
38
+ globalDataInstance: ()=>globalDataInstance
39
+ });
40
+ const external_valtio_namespaceObject = require("valtio");
41
+ const navigate_js_namespaceObject = require("../utils/navigate.js");
42
+ var navigate_js_default = /*#__PURE__*/ __webpack_require__.n(navigate_js_namespaceObject);
43
+ const instance_js_namespaceObject = require("../utils/valtio/instance.js");
44
+ const external_global_setting_data_instance_js_namespaceObject = require("./global.setting.data.instance.js");
45
+ const taro_namespaceObject = require("@tarojs/taro");
46
+ var taro_default = /*#__PURE__*/ __webpack_require__.n(taro_namespaceObject);
47
+ const external_auth_data_instance_js_namespaceObject = require("./auth.data.instance.js");
48
+ class GlobalDataInstance extends instance_js_namespaceObject.ProxyInstanceObjectBase {
49
+ store = (0, external_valtio_namespaceObject.proxy)({});
50
+ onBeforetToLoginPage;
51
+ toRedirect = ()=>{
52
+ const currentPath = taro_default().getCurrentInstance().router?.params?.redirect || '';
53
+ if (currentPath) navigate_js_default().navigateTo({
54
+ url: currentPath
55
+ });
56
+ };
57
+ toLoginPage = ()=>{
58
+ external_auth_data_instance_js_namespaceObject.authDataInstance.clear();
59
+ if (this.onBeforetToLoginPage) {
60
+ const f = this.onBeforetToLoginPage();
61
+ if (false === f) return;
62
+ }
63
+ const loginPageRoute = external_global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.loginPageRoute || '';
64
+ const isLoginPage = navigate_js_default().isCurrentPage(loginPageRoute || '');
65
+ const _loginPageRoute = `${loginPageRoute || ''}`.replace(/^\//, '');
66
+ if (isLoginPage) return;
67
+ taro_default().navigateTo({
68
+ url: `/${_loginPageRoute}`
69
+ });
70
+ };
71
+ }
72
+ const globalDataInstance = new GlobalDataInstance();
73
+ const useGlobalData = ()=>{
74
+ const store = (0, external_valtio_namespaceObject.useSnapshot)(globalDataInstance.store);
75
+ return [
76
+ store,
77
+ globalDataInstance,
78
+ store.__defaultValue
79
+ ];
80
+ };
81
+ exports.GlobalDataInstance = __webpack_exports__.GlobalDataInstance;
82
+ exports.globalDataInstance = __webpack_exports__.globalDataInstance;
83
+ exports.useGlobalData = __webpack_exports__.useGlobalData;
84
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
85
+ "GlobalDataInstance",
86
+ "globalDataInstance",
87
+ "useGlobalData"
88
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
89
+ Object.defineProperty(exports, '__esModule', {
90
+ value: true
91
+ });
@@ -40,13 +40,6 @@ export declare class GlobalMessageDataInstance extends ProxyInstanceObjectBase<G
40
40
  showToast: (config?: Partial<ToastDataType>) => void;
41
41
  /**隐藏Toast */
42
42
  hideToast: () => void;
43
- /**
44
- * 跳转登录页面前执行
45
- */
46
- onBeforetToLoginPage?: () => boolean | void;
47
- toRedirect: () => void;
48
- /**跳转登录页面*/
49
- toLoginPage: () => void;
50
43
  }
51
44
  /**
52
45
  * 全局消息数据实例
@@ -1,14 +1,5 @@
1
1
  "use strict";
2
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
3
  (()=>{
13
4
  __webpack_require__.d = (exports1, definition)=>{
14
5
  for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
@@ -38,14 +29,8 @@ __webpack_require__.d(__webpack_exports__, {
38
29
  useGlobalMessageData: ()=>useGlobalMessageData
39
30
  });
40
31
  const external_valtio_namespaceObject = require("valtio");
41
- const navigate_js_namespaceObject = require("../utils/navigate.js");
42
- var navigate_js_default = /*#__PURE__*/ __webpack_require__.n(navigate_js_namespaceObject);
43
32
  const useId_js_namespaceObject = require("../utils/useId.js");
44
33
  const instance_js_namespaceObject = require("../utils/valtio/instance.js");
45
- const external_global_setting_data_instance_js_namespaceObject = require("./global.setting.data.instance.js");
46
- const taro_namespaceObject = require("@tarojs/taro");
47
- var taro_default = /*#__PURE__*/ __webpack_require__.n(taro_namespaceObject);
48
- const external_auth_data_instance_js_namespaceObject = require("./auth.data.instance.js");
49
34
  class GlobalMessageDataInstance extends instance_js_namespaceObject.ProxyInstanceObjectBase {
50
35
  store = (0, external_valtio_namespaceObject.proxy)({
51
36
  messageData: (0, external_valtio_namespaceObject.ref)([]),
@@ -88,27 +73,6 @@ class GlobalMessageDataInstance extends instance_js_namespaceObject.ProxyInstanc
88
73
  visible: false
89
74
  });
90
75
  };
91
- onBeforetToLoginPage;
92
- toRedirect = ()=>{
93
- const currentPath = taro_default().getCurrentInstance().router?.params?.redirect || '';
94
- if (currentPath) navigate_js_default().navigateTo({
95
- url: currentPath
96
- });
97
- };
98
- toLoginPage = ()=>{
99
- external_auth_data_instance_js_namespaceObject.authDataInstance.clear();
100
- if (this.onBeforetToLoginPage) {
101
- const f = this.onBeforetToLoginPage();
102
- if (false === f) return;
103
- }
104
- const loginPageRoute = external_global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.loginPageRoute || '';
105
- const isLoginPage = navigate_js_default().isCurrentPage(loginPageRoute || '');
106
- const _loginPageRoute = `${loginPageRoute || ''}`.replace(/^\//, '');
107
- if (isLoginPage) return;
108
- taro_default().navigateTo({
109
- url: `/${_loginPageRoute}`
110
- });
111
- };
112
76
  }
113
77
  const globalMessageDataInstance = new GlobalMessageDataInstance();
114
78
  const useGlobalMessageData = ()=>{
@@ -3,3 +3,4 @@ export * from './page.data.instance';
3
3
  export * from './page.info.data.instance';
4
4
  export * from './auth.data.instance';
5
5
  export * from './global.setting.data.instance';
6
+ export * from './global.data.instance';
@@ -3,6 +3,9 @@ var __webpack_modules__ = {
3
3
  "./auth.data.instance": function(module) {
4
4
  module.exports = require("./auth.data.instance.js");
5
5
  },
6
+ "./global.data.instance": function(module) {
7
+ module.exports = require("./global.data.instance.js");
8
+ },
6
9
  "./global.message.data.instance": function(module) {
7
10
  module.exports = require("./global.message.data.instance.js");
8
11
  },
@@ -89,6 +92,12 @@ var __webpack_exports__ = {};
89
92
  return _global_setting_data_instance__WEBPACK_IMPORTED_MODULE_4__[key];
90
93
  }).bind(0, __WEBPACK_IMPORT_KEY__);
91
94
  __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
95
+ var _global_data_instance__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__("./global.data.instance");
96
+ var __WEBPACK_REEXPORT_OBJECT__ = {};
97
+ for(var __WEBPACK_IMPORT_KEY__ in _global_data_instance__WEBPACK_IMPORTED_MODULE_5__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
98
+ return _global_data_instance__WEBPACK_IMPORTED_MODULE_5__[key];
99
+ }).bind(0, __WEBPACK_IMPORT_KEY__);
100
+ __webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
92
101
  })();
93
102
  for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
94
103
  Object.defineProperty(exports, '__esModule', {
@@ -181,6 +181,11 @@
181
181
  font-size: 12.8px;
182
182
  }
183
183
 
184
+ .fairystaro__text-black {
185
+ --un-text-opacity: 1;
186
+ color: rgb(0 0 0 / var(--un-text-opacity));
187
+ }
188
+
184
189
  .fairystaro__text-color-_zkh1_blue_zhk2_ {
185
190
  color: #00f;
186
191
  }
@@ -197,10 +202,23 @@
197
202
  color: red;
198
203
  }
199
204
 
205
+ .fairystaro__text-gray-400 {
206
+ --un-text-opacity: 1;
207
+ color: rgb(156 163 175 / var(--un-text-opacity));
208
+ }
209
+
200
210
  .fairystaro__font-bold {
201
211
  font-weight: 700;
202
212
  }
203
213
 
214
+ .fairystaro__opacity-100 {
215
+ opacity: 1;
216
+ }
217
+
218
+ .fairystaro__opacity-60 {
219
+ opacity: .6;
220
+ }
221
+
204
222
  @keyframes fairys_taro_loading_transform {
205
223
  0% {
206
224
  --fairys-enter-loading-transform-color: #00a98e;
@@ -41,6 +41,7 @@ const taro_namespaceObject = require("@tarojs/taro");
41
41
  var taro_default = /*#__PURE__*/ __webpack_require__.n(taro_namespaceObject);
42
42
  const global_setting_data_instance_js_namespaceObject = require("../context/global.setting.data.instance.js");
43
43
  const global_message_data_instance_js_namespaceObject = require("../context/global.message.data.instance.js");
44
+ const global_data_instance_js_namespaceObject = require("../context/global.data.instance.js");
44
45
  const codeMessage = {
45
46
  400: "\u53D1\u51FA\u7684\u8BF7\u6C42\u9519\u8BEF",
46
47
  401: "\u7528\u6237\u6CA1\u6709\u6743\u9650",
@@ -62,7 +63,7 @@ const requestResponseHandle = (result, options)=>{
62
63
  const code = result?.data?.code;
63
64
  if (401 === statusCode || 401 === code || code === global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.tokenExpiredCode) {
64
65
  msg = "\u8BF7\u91CD\u65B0\u767B\u5F55";
65
- global_message_data_instance_js_namespaceObject.globalMessageDataInstance.toLoginPage();
66
+ global_data_instance_js_namespaceObject.globalDataInstance.toLoginPage();
66
67
  } else msg = [
67
68
  global_setting_data_instance_js_namespaceObject.globalSettingDataInstance.store.requestSuccessCode,
68
69
  requestSuccessCode,
@@ -174,7 +175,7 @@ class RequestInstance {
174
175
  options?.fail?.({
175
176
  errMsg: "\u672A\u767B\u5F55"
176
177
  });
177
- global_message_data_instance_js_namespaceObject.globalMessageDataInstance.toLoginPage();
178
+ global_data_instance_js_namespaceObject.globalDataInstance.toLoginPage();
178
179
  return;
179
180
  }
180
181
  return {
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.33",
6
+ "version": "1.0.34",
7
7
  "main": "esm/index.js",
8
8
  "types": "esm/index.d.ts",
9
9
  "module": "esm/index.js",
@@ -0,0 +1,38 @@
1
+ .fairys_taro_custom_tab_bar {
2
+ position: fixed;
3
+ bottom: 0;
4
+ left: 0;
5
+ right: 0;
6
+ height: 60px;
7
+ background: white;
8
+ display: flex;
9
+ padding-bottom: env(safe-area-inset-bottom);
10
+ }
11
+
12
+ .fairys_taro_custom_tab_bar-border {
13
+ background-color: rgba(0, 0, 0, 0.33);
14
+ position: absolute;
15
+ left: 0;
16
+ top: 0;
17
+ width: 100%;
18
+ height: 1px;
19
+ transform: scaleY(0.5);
20
+ }
21
+
22
+ .fairys_taro_custom_tab_bar_item {
23
+ flex: 1;
24
+ text-align: center;
25
+ display: flex;
26
+ justify-content: center;
27
+ align-items: center;
28
+ flex-direction: column;
29
+ }
30
+
31
+ .fairys_taro_custom_tab_bar_item cover-image {
32
+ width: 54px;
33
+ height: 54px;
34
+ }
35
+
36
+ .fairys_taro_custom_tab_bar_item cover-view {
37
+ font-size: 14px;
38
+ }
@@ -0,0 +1,169 @@
1
+ import { proxy, useSnapshot, ref } from 'valtio';
2
+ import { CoverImage, CoverView } from '@tarojs/components';
3
+ import Taro from '@tarojs/taro';
4
+ import { Fragment, memo, useMemo } from 'react';
5
+ import clsx from 'clsx';
6
+
7
+ let fairysTaroCustomTabBarRender: React.ReactNode | undefined;
8
+
9
+ /**自定义底部导航栏状态管理*/
10
+ export const fairysTaroCustomTabBarState = proxy({
11
+ /**当前选中的项*/
12
+ selected: '',
13
+ items: ref([]) as FairysTaroCustomTabBarItemItem[],
14
+ isUpdatedItems: false,
15
+ /**未选中颜色*/
16
+ color: 'rgb(156 163 175)',
17
+ /**选中颜色*/
18
+ selectedColor: '#000',
19
+ /**切换标签*/
20
+ onSwitchTab: (url: string) => {
21
+ fairysTaroCustomTabBarState.selected = url;
22
+ Taro.switchTab({ url });
23
+ },
24
+ /**更新自定义底部导航栏项*/
25
+ onUpdatedItems: (items: FairysTaroCustomTabBarItemItem[]) => {
26
+ fairysTaroCustomTabBarState.items = ref(items);
27
+ fairysTaroCustomTabBarState.isUpdatedItems = true;
28
+ },
29
+ /**设置自定义底部导航栏渲染*/
30
+ onSetTabBarRender: (_tabBarRender: React.ReactNode) => {
31
+ fairysTaroCustomTabBarRender = _tabBarRender;
32
+ fairysTaroCustomTabBarState.isUpdatedItems = false;
33
+ },
34
+ });
35
+
36
+ export interface FairysTaroCustomTabBarItemItem {
37
+ /**自定义底部导航栏项文本*/
38
+ text: string;
39
+ /**自定义底部导航栏项 URL*/
40
+ url: string;
41
+ /**自定义底部导航栏项图标*/
42
+ icon?: string;
43
+ /**自定义底部导航栏项样式*/
44
+ style?: React.CSSProperties;
45
+ /**自定义底部导航栏项类名*/
46
+ className?: string;
47
+ /**自定义底部导航栏项选中图标*/
48
+ selectedIcon?: string;
49
+ /**自定义底部导航栏项选中图标样式*/
50
+ selectedIconStyle?: React.CSSProperties;
51
+ /**自定义底部导航栏项图标样式*/
52
+ iconStyle?: React.CSSProperties;
53
+ /**自定义底部导航栏项选中图标类名*/
54
+ selectedIconClassName?: string;
55
+ /**自定义底部导航栏项选中文本样式*/
56
+ selectedTextStyle?: React.CSSProperties;
57
+ /**自定义底部导航栏项文本样式*/
58
+ textStyle?: React.CSSProperties;
59
+ /**自定义底部导航栏项选中文本类名*/
60
+ selectedTextClassName?: string;
61
+ }
62
+
63
+ export interface FairysTaroCustomTabBarProps {}
64
+
65
+ export interface FairysTaroCustomTabBarItemProps {
66
+ /**自定义底部导航栏项*/
67
+ item: FairysTaroCustomTabBarItemItem;
68
+ }
69
+
70
+ const FairysTaroCustomTabBarItemBase = (props: FairysTaroCustomTabBarItemProps) => {
71
+ const { item } = props;
72
+ const { selected, color, selectedColor } = useSnapshot(fairysTaroCustomTabBarState);
73
+ const isSelected = selected === item.url;
74
+ const className = useMemo(() => clsx('fairys_taro_custom_tab_bar_item', item.className), [item.className]);
75
+ const imgClassName = useMemo(
76
+ () =>
77
+ clsx('fairys_taro_custom_tab_bar_item_img', item.selectedIconClassName, {
78
+ fairys_taro_custom_tab_bar_item_img_selected: isSelected,
79
+ // 'fairystaro__opacity-100': isSelected,
80
+ // 'fairystaro__opacity-60': !isSelected,
81
+ }),
82
+ [item.selectedIconClassName, isSelected],
83
+ );
84
+ const imgStyle = useMemo(() => {
85
+ return {
86
+ opacity: isSelected ? 1 : 0.6,
87
+ };
88
+ }, [isSelected]);
89
+
90
+ const textClassName = useMemo(
91
+ () =>
92
+ clsx('fairys_taro_custom_tab_bar_item_text', item.selectedTextClassName, {
93
+ fairys_taro_custom_tab_bar_item_text_selected: isSelected,
94
+ // 'fairystaro__text-black': isSelected,
95
+ // 'fairystaro__text-gray-400': !isSelected,
96
+ }),
97
+ [item.selectedTextClassName, isSelected],
98
+ );
99
+
100
+ const textStyle = useMemo(() => {
101
+ return { color: isSelected ? selectedColor : color };
102
+ }, [isSelected, color, selectedColor]);
103
+
104
+ return (
105
+ <CoverView
106
+ onClick={() => fairysTaroCustomTabBarState.onSwitchTab(item.url)}
107
+ key={item.url}
108
+ style={item.style}
109
+ className={className}
110
+ >
111
+ {item.icon ? (
112
+ <CoverImage
113
+ src={isSelected ? item.selectedIcon || item.icon : item.icon}
114
+ className={imgClassName}
115
+ style={{ ...imgStyle, ...((isSelected ? item.selectedIconStyle : item.iconStyle) || {}) }}
116
+ />
117
+ ) : (
118
+ <Fragment />
119
+ )}
120
+ <CoverView
121
+ className={textClassName}
122
+ style={{
123
+ ...((isSelected ? item.selectedTextStyle : item.textStyle) || {}),
124
+ ...textStyle,
125
+ }}
126
+ >
127
+ {item.text}
128
+ </CoverView>
129
+ </CoverView>
130
+ );
131
+ };
132
+
133
+ const FairysTaroCustomTabBarBase = () => {
134
+ const { items } = useSnapshot(fairysTaroCustomTabBarState);
135
+ const _itemsRender = useMemo(() => {
136
+ if (fairysTaroCustomTabBarState.isUpdatedItems === false && fairysTaroCustomTabBarRender) {
137
+ return fairysTaroCustomTabBarRender;
138
+ }
139
+ const render = items.map((item) => {
140
+ return <FairysTaroCustomTabBarItemBase key={item.url} item={item} />;
141
+ });
142
+ fairysTaroCustomTabBarState.onSetTabBarRender(render);
143
+ return render;
144
+ }, [items]);
145
+
146
+ return (
147
+ <CoverView className="fairys_taro_custom_tab_bar">
148
+ <CoverView className="fairys_taro_custom_tab_bar-border"></CoverView>
149
+ {_itemsRender}
150
+ </CoverView>
151
+ );
152
+ };
153
+
154
+ export const FairysTaroCustomTabBar = memo(() => {
155
+ return useMemo(() => <FairysTaroCustomTabBarBase />, []);
156
+ });
157
+
158
+ /**
159
+ * 页面高度问题
160
+ */
161
+ export const useFairysTaroCustomTabBarPageStyle = () => {
162
+ return useMemo(() => {
163
+ const height = Taro.getSystemInfoSync().windowHeight;
164
+ return {
165
+ height: height - 60,
166
+ overflowY: 'auto',
167
+ };
168
+ }, []);
169
+ };
@@ -4,3 +4,4 @@ export * from './Mesage';
4
4
  export * from './Toast';
5
5
  export * from './connectToastMessage';
6
6
  export * from './MainPage';
7
+ export * from './custom-tab-bar';
@@ -0,0 +1,69 @@
1
+ import { proxy, useSnapshot } from 'valtio';
2
+ import navigate from 'utils/navigate';
3
+ import { ProxyInstanceObjectBase } from 'utils/valtio/instance';
4
+ import { globalSettingDataInstance } from './global.setting.data.instance';
5
+ import Taro from '@tarojs/taro';
6
+ import { authDataInstance } from './auth.data.instance';
7
+
8
+ export interface GlobalDataInstanceState {
9
+ /**数据默认值不使用*/
10
+ __defaultValue?: string;
11
+ }
12
+
13
+ /**
14
+ * 全局数据实例
15
+ */
16
+ export class GlobalDataInstance extends ProxyInstanceObjectBase<GlobalDataInstanceState> {
17
+ store = proxy<GlobalDataInstanceState>({});
18
+ /**
19
+ * 跳转登录页面前执行
20
+ */
21
+ onBeforetToLoginPage?: () => boolean | void;
22
+ /**跳转 redirect 路由*/
23
+ toRedirect = () => {
24
+ // 获取当前路由参数
25
+ const currentPath = Taro.getCurrentInstance().router?.params?.redirect || '';
26
+ if (currentPath) {
27
+ // 跳转 redirect 路由
28
+ navigate.navigateTo({ url: currentPath });
29
+ }
30
+ };
31
+
32
+ /**跳转登录页面*/
33
+ toLoginPage = () => {
34
+ // 清除登录凭证(token)、权限列表、菜单权限列表、用户信息
35
+ authDataInstance.clear();
36
+ if (this.onBeforetToLoginPage) {
37
+ const f = this.onBeforetToLoginPage();
38
+ if (f === false) {
39
+ // 如果返回false则不跳转登录页面
40
+ return;
41
+ }
42
+ }
43
+ const loginPageRoute = globalSettingDataInstance.store.loginPageRoute || '';
44
+ const isLoginPage = navigate.isCurrentPage(loginPageRoute || '');
45
+ const _loginPageRoute = `${loginPageRoute || ''}`.replace(/^\//, '');
46
+ if (isLoginPage) {
47
+ // 如果是登录页面不进行跳转
48
+ return;
49
+ }
50
+ // 跳转登录页面
51
+ Taro.navigateTo({ url: `/${_loginPageRoute}` });
52
+ };
53
+ }
54
+ /**
55
+ * 全局数据实例
56
+ */
57
+ export const globalDataInstance = new GlobalDataInstance();
58
+
59
+ /**
60
+ * 全局数据状态管理
61
+ */
62
+ export const useGlobalData = () => {
63
+ const store = useSnapshot(globalDataInstance.store);
64
+ return [store, globalDataInstance, store.__defaultValue] as [
65
+ GlobalDataInstanceState,
66
+ GlobalDataInstance,
67
+ string | undefined,
68
+ ];
69
+ };
@@ -78,43 +78,6 @@ export class GlobalMessageDataInstance extends ProxyInstanceObjectBase<GlobalMes
78
78
  hideToast = () => {
79
79
  this.store.toastData = ref({ ...this.store.toastData, visible: false });
80
80
  };
81
-
82
- /**
83
- * 跳转登录页面前执行
84
- */
85
- onBeforetToLoginPage?: () => boolean | void;
86
- // 跳转 redirect 路由
87
- toRedirect = () => {
88
- // 获取当前路由参数
89
- const currentPath = Taro.getCurrentInstance().router?.params?.redirect || '';
90
- if (currentPath) {
91
- // 跳转 redirect 路由
92
- navigate.navigateTo({ url: currentPath });
93
- }
94
- };
95
-
96
- /**跳转登录页面*/
97
- toLoginPage = () => {
98
- // 清除登录凭证(token)、权限列表、菜单权限列表、用户信息
99
- authDataInstance.clear();
100
-
101
- if (this.onBeforetToLoginPage) {
102
- const f = this.onBeforetToLoginPage();
103
- if (f === false) {
104
- // 如果返回false则不跳转登录页面
105
- return;
106
- }
107
- }
108
- const loginPageRoute = globalSettingDataInstance.store.loginPageRoute || '';
109
- const isLoginPage = navigate.isCurrentPage(loginPageRoute || '');
110
- const _loginPageRoute = `${loginPageRoute || ''}`.replace(/^\//, '');
111
- if (isLoginPage) {
112
- // 如果是登录页面不进行跳转
113
- return;
114
- }
115
- // 跳转登录页面
116
- Taro.navigateTo({ url: `/${_loginPageRoute}` });
117
- };
118
81
  }
119
82
  /**
120
83
  * 全局消息数据实例
@@ -3,3 +3,4 @@ export * from './page.data.instance';
3
3
  export * from './page.info.data.instance';
4
4
  export * from './auth.data.instance';
5
5
  export * from './global.setting.data.instance';
6
+ export * from './global.data.instance';