@fairys/taro-tools-react 0.0.1

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 (62) hide show
  1. package/README.md +1 -0
  2. package/esm/components/EnterLoading/index.d.ts +14 -0
  3. package/esm/components/EnterLoading/index.js +65 -0
  4. package/esm/components/MainPage/index.d.ts +10 -0
  5. package/esm/components/MainPage/index.js +49 -0
  6. package/esm/components/Mesage/index.d.ts +48 -0
  7. package/esm/components/Mesage/index.js +122 -0
  8. package/esm/components/Portal/index.d.ts +8 -0
  9. package/esm/components/Portal/index.js +11 -0
  10. package/esm/components/Toast/index.d.ts +1 -0
  11. package/esm/components/Toast/index.js +20 -0
  12. package/esm/components/connectToastMessage/index.d.ts +10 -0
  13. package/esm/components/connectToastMessage/index.js +28 -0
  14. package/esm/components/index.d.ts +6 -0
  15. package/esm/components/index.js +6 -0
  16. package/esm/context/global.data.instance.d.ts +5411 -0
  17. package/esm/context/global.data.instance.js +66 -0
  18. package/esm/context/global.setting.data.instance.d.ts +28 -0
  19. package/esm/context/global.setting.data.instance.js +20 -0
  20. package/esm/context/index.d.ts +4 -0
  21. package/esm/context/index.js +4 -0
  22. package/esm/context/page.data.instance.d.ts +71 -0
  23. package/esm/context/page.data.instance.js +139 -0
  24. package/esm/context/page.info.data.instance.d.ts +72 -0
  25. package/esm/context/page.info.data.instance.js +107 -0
  26. package/esm/index.d.ts +3 -0
  27. package/esm/index.js +3 -0
  28. package/esm/styles/index.css +711 -0
  29. package/esm/utils/index.d.ts +4 -0
  30. package/esm/utils/index.js +4 -0
  31. package/esm/utils/navigate.d.ts +109 -0
  32. package/esm/utils/navigate.js +45 -0
  33. package/esm/utils/request.d.ts +112 -0
  34. package/esm/utils/request.js +212 -0
  35. package/esm/utils/useId.d.ts +2 -0
  36. package/esm/utils/useId.js +13 -0
  37. package/esm/utils/valtio/index.d.ts +9 -0
  38. package/esm/utils/valtio/index.js +23 -0
  39. package/esm/utils/valtio/instance.d.ts +15 -0
  40. package/esm/utils/valtio/instance.js +34 -0
  41. package/lib/index.js +78 -0
  42. package/package.json +40 -0
  43. package/src/components/EnterLoading/index.tsx +57 -0
  44. package/src/components/MainPage/index.tsx +72 -0
  45. package/src/components/Mesage/index.tsx +217 -0
  46. package/src/components/Portal/index.tsx +18 -0
  47. package/src/components/Toast/index.tsx +22 -0
  48. package/src/components/connectToastMessage/index.tsx +41 -0
  49. package/src/components/index.ts +6 -0
  50. package/src/context/global.data.instance.ts +106 -0
  51. package/src/context/global.setting.data.instance.ts +36 -0
  52. package/src/context/index.ts +4 -0
  53. package/src/context/page.data.instance.ts +215 -0
  54. package/src/context/page.info.data.instance.ts +182 -0
  55. package/src/index.ts +3 -0
  56. package/src/styles/index.css +515 -0
  57. package/src/utils/index.ts +4 -0
  58. package/src/utils/navigate.ts +159 -0
  59. package/src/utils/request.ts +319 -0
  60. package/src/utils/useId.ts +14 -0
  61. package/src/utils/valtio/index.ts +23 -0
  62. package/src/utils/valtio/instance.ts +59 -0
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@fairys/taro-tools-react",
3
+ "author": "SunLxy <1011771396@qq.com>",
4
+ "description": "框架组件库",
5
+ "homepage": "https://github.com/autumn-fairy-tales/fairys-taro-react",
6
+ "version": "0.0.1",
7
+ "main": "lib/index.js",
8
+ "types": "esm/index.d.ts",
9
+ "module": "esm/index.js",
10
+ "license": "ISC",
11
+ "scripts": {
12
+ "build": "carefrees-rslib build --config=./rslib.config.ts",
13
+ "watch": "carefrees-rslib build --watch --config=./rslib.config.ts"
14
+ },
15
+ "publishConfig": {
16
+ "access": "public"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/autumn-fairy-tales/fairys-taro-react.git",
21
+ "directory": "packages/ui"
22
+ },
23
+ "files": [
24
+ "src",
25
+ "esm"
26
+ ],
27
+ "dependencies": {
28
+ "clsx": "2.1.1",
29
+ "valtio": "~2.1.5"
30
+ },
31
+ "devDependencies": {
32
+ "@nutui/nutui-react-taro": "^3.0.18",
33
+ "@tarojs/components": "4.1.7",
34
+ "@tarojs/react": "4.1.7",
35
+ "@tarojs/taro": "4.1.7",
36
+ "@types/react": "~18.2.21",
37
+ "react": "^18.0.0",
38
+ "react-dom": "^18.0.0"
39
+ }
40
+ }
@@ -0,0 +1,57 @@
1
+ import clsx from 'clsx';
2
+ import { View, Text } from '@tarojs/components';
3
+ import { ViewProps } from '@tarojs/components';
4
+ import { forwardRef, Fragment, ReactNode, Ref, useMemo } from 'react';
5
+ import { FairysTaroPortal } from '../Portal';
6
+
7
+ export interface FairysTaroLoadingProps extends ViewProps {
8
+ /**加载标题*/
9
+ title?: ReactNode;
10
+ /**加载提示*/
11
+ tips?: ReactNode;
12
+ /**是否显示加载动画*/
13
+ loading?: boolean;
14
+ /**是否显示在 Portal 中*/
15
+ isPortal?: boolean;
16
+ }
17
+
18
+ export const FairysTaroLoadingMain = forwardRef(
19
+ (props: Omit<FairysTaroLoadingProps, 'loading' | 'isPortal'>, ref: Ref<ViewProps>) => {
20
+ const { title = '', tips = '载入中', className, ...rest } = props;
21
+
22
+ const classNames = useMemo(() => clsx('fairys_taro_loading fairystaro__bg-white/90', className), [className]);
23
+
24
+ return (
25
+ <Fragment>
26
+ <View {...rest} ref={ref} className={classNames}>
27
+ <View className="fairys_taro_loading-main">
28
+ <View className="square"></View>
29
+ <View className="square"></View>
30
+ <View className="square"></View>
31
+ <View className="square"></View>
32
+ </View>
33
+ {title ? <View className="name">{title}</View> : <Fragment />}
34
+ <View className="tips">
35
+ <Text>{tips}</Text>
36
+ <Text className="loading-dots" />
37
+ </View>
38
+ </View>
39
+ </Fragment>
40
+ );
41
+ },
42
+ );
43
+
44
+ export const FairysTaroLoading = forwardRef((props: FairysTaroLoadingProps, ref: Ref<ViewProps>) => {
45
+ const { loading = false, isPortal = true, ...rest } = props;
46
+ return loading ? (
47
+ isPortal ? (
48
+ <FairysTaroPortal>
49
+ <FairysTaroLoadingMain {...rest} ref={ref} />
50
+ </FairysTaroPortal>
51
+ ) : (
52
+ <FairysTaroLoadingMain {...rest} ref={ref} />
53
+ )
54
+ ) : (
55
+ <Fragment />
56
+ );
57
+ });
@@ -0,0 +1,72 @@
1
+ import { ViewProps, View } from '@tarojs/components';
2
+ import clsx from 'clsx';
3
+ import { useMemo } from 'react';
4
+
5
+ export interface FairysTaroMainPageProps extends ViewProps {}
6
+
7
+ export const FairysTaroMainPage = (props: FairysTaroMainPageProps) => {
8
+ const { className: itemClassName, children, ...rest } = props;
9
+
10
+ const cls = useMemo(
11
+ () =>
12
+ clsx(
13
+ 'fairys_taro-ui-main-page fairystaro__box-border fairystaro__w-full fairystaro__h-full fairystaro__flex fairystaro__flex-col fairystaro__overflow-auto',
14
+ itemClassName,
15
+ ),
16
+ [itemClassName],
17
+ );
18
+
19
+ return (
20
+ <View className={cls} {...rest}>
21
+ {children}
22
+ </View>
23
+ );
24
+ };
25
+
26
+ /**查询*/
27
+ export const FairysTaroMainPageSearch = (props: FairysTaroMainPageProps) => {
28
+ const { className: itemClassName, children, ...rest } = props;
29
+ const cls = useMemo(
30
+ () => clsx('fairys_taro-ui-main-page-search fairystaro__box-border fairystaro__w-full', itemClassName),
31
+ [itemClassName],
32
+ );
33
+
34
+ return (
35
+ <View className={cls} {...rest}>
36
+ {children}
37
+ </View>
38
+ );
39
+ };
40
+
41
+ /**内容*/
42
+ export const FairysTaroMainPageBody = (props: FairysTaroMainPageProps) => {
43
+ const { className: itemClassName, children, ...rest } = props;
44
+ const cls = useMemo(
45
+ () =>
46
+ clsx(
47
+ 'fairys_taro-ui-main-page-body fairystaro__box-border fairystaro__w-full fairystaro__flex-1 fairystaro__overflow-auto',
48
+ itemClassName,
49
+ ),
50
+ [itemClassName],
51
+ );
52
+ return (
53
+ <View className={cls} {...rest}>
54
+ {children}
55
+ </View>
56
+ );
57
+ };
58
+
59
+ /**底部*/
60
+ export const FairysTaroMainPageFooter = (props: FairysTaroMainPageProps) => {
61
+ const { className: itemClassName, children, ...rest } = props;
62
+ const cls = useMemo(
63
+ () => clsx('fairys_taro-ui-main-page-footer fairystaro__box-border fairystaro__w-full', itemClassName),
64
+ [itemClassName],
65
+ );
66
+
67
+ return (
68
+ <View className={cls} {...rest}>
69
+ {children}
70
+ </View>
71
+ );
72
+ };
@@ -0,0 +1,217 @@
1
+ import { View, ViewProps } from '@tarojs/components';
2
+ import { Fragment, useMemo } from 'react';
3
+ import { useGlobalData } from 'context/global.data.instance';
4
+ import { FairysTaroPortal } from 'components/Portal';
5
+ import clsx from 'clsx';
6
+ import type { MessageDataType } from 'context/global.data.instance';
7
+
8
+ export interface FairysTaroMessageItemProps extends Omit<ViewProps, 'style'> {
9
+ /**
10
+ * 提示内容
11
+ */
12
+ title?: React.ReactNode;
13
+ /**
14
+ * 提示框类型
15
+ * @default none
16
+ */
17
+ type?: 'none' | 'success' | 'error' | 'warning' | 'info';
18
+ /**
19
+ * 自定义图标
20
+ */
21
+ icon?: React.ReactNode;
22
+ /**消息项是否显示边框*/
23
+ bordered?: boolean;
24
+ /**图标 className*/
25
+ iconClassName?: string;
26
+ /**图标 style*/
27
+ iconStyle?: React.CSSProperties;
28
+ /**标题 className*/
29
+ titleClassName?: string;
30
+ /**标题 style*/
31
+ titleStyle?: React.CSSProperties;
32
+ /**内容 className*/
33
+ bodyClassName?: string;
34
+ /**内容 style*/
35
+ bodyStyle?: React.CSSProperties;
36
+ /**样式*/
37
+ style?: React.CSSProperties;
38
+ /**图标颜色*/
39
+ iconColor?: string;
40
+ /**边框颜色*/
41
+ borderColor?: string;
42
+ /**背景颜色*/
43
+ backgroundColor?: string;
44
+ /**文本颜色*/
45
+ color?: string;
46
+ /**是否显示图标*/
47
+ showIcon?: boolean;
48
+ }
49
+
50
+ export const FairysTaroMessageItem = (props: FairysTaroMessageItemProps) => {
51
+ const {
52
+ title,
53
+ children,
54
+ type = 'info',
55
+ className: itemClassName,
56
+ bordered = true,
57
+ iconClassName,
58
+ iconStyle = {},
59
+ titleClassName,
60
+ titleStyle,
61
+ bodyClassName,
62
+ bodyStyle,
63
+ icon,
64
+ iconColor,
65
+ borderColor,
66
+ backgroundColor,
67
+ style = {},
68
+ color,
69
+ showIcon = true,
70
+ ...rest
71
+ } = props;
72
+ const isIcon = !!icon;
73
+ const isIconString = typeof icon === 'string';
74
+
75
+ const className = useMemo(
76
+ () =>
77
+ clsx(
78
+ 'fairys_taro-ui-message-item',
79
+ `fairys_taro-ui-message-icon-${type}`,
80
+ 'fairystaro__box-border fairystaro__flex fairystaro__flex-row fairystaro__gap-[0.4rem] fairystaro__p-y-[0.4rem] fairystaro__p-x-[0.4rem] fairystaro__rounded-md fairystaro__text-[0.8rem]',
81
+ {
82
+ 'fairystaro__border fairystaro__border-solid': bordered,
83
+ },
84
+ itemClassName,
85
+ ),
86
+ [type, itemClassName, bordered],
87
+ );
88
+
89
+ const classIconName = useMemo(
90
+ () =>
91
+ clsx('fairys_taro-ui-message-icon fairystaro__box-border ', iconClassName, {
92
+ 'ant-design--close-circle-outlined': type === 'error' && !isIcon,
93
+ 'ant-design--exclamation-circle-outlined': type === 'warning' && !isIcon,
94
+ 'ant-design--check-circle-outlined': type === 'success' && !isIcon,
95
+ 'ant-design--info-circle-outlined': type === 'info' && !isIcon,
96
+ 'fairystaro__text-color-[red]': type === 'error',
97
+ 'fairystaro__text-color-[orange]': type === 'warning',
98
+ 'fairystaro__text-color-[green]': type === 'success',
99
+ 'fairystaro__text-color-[blue]': type === 'info',
100
+ }),
101
+ [type, iconClassName, isIcon],
102
+ );
103
+
104
+ const lastIconClassName = useMemo(
105
+ () => clsx(classIconName, isIconString ? icon : ''),
106
+ [classIconName, isIconString, icon],
107
+ );
108
+
109
+ const titleClassNames = useMemo(
110
+ () => clsx('fairys_taro-ui-message-item-title fairystaro__font-bold', titleClassName),
111
+ [titleClassName],
112
+ );
113
+
114
+ // 图标颜色
115
+ const _iconStyle = { ...iconStyle };
116
+ if (iconColor) {
117
+ _iconStyle.color = iconColor;
118
+ }
119
+
120
+ const _style = { ...style };
121
+ if (borderColor) {
122
+ _style.borderColor = borderColor;
123
+ }
124
+
125
+ if (backgroundColor) {
126
+ _style.backgroundColor = backgroundColor;
127
+ }
128
+ if (color) {
129
+ _style.color = color;
130
+ }
131
+
132
+ return (
133
+ <View className={className} {...rest} style={_style}>
134
+ {showIcon ? (
135
+ <View className="fairystaro__flex fairystaro__flex-row fairystaro__justify-center fairystaro__p-t-[0.15rem]">
136
+ {/* 图标 */}
137
+ {!isIcon ? <View className={classIconName} style={_iconStyle} /> : <Fragment />}
138
+ {isIcon && !isIconString ? (
139
+ <View className={classIconName} style={_iconStyle}>
140
+ {icon}
141
+ </View>
142
+ ) : (
143
+ <Fragment />
144
+ )}
145
+ {isIcon && isIconString ? <View className={lastIconClassName} style={_iconStyle} /> : <Fragment />}
146
+ </View>
147
+ ) : (
148
+ <Fragment />
149
+ )}
150
+ <View>
151
+ {/* 内容 */}
152
+ {title ? (
153
+ <View className={titleClassNames} style={titleStyle}>
154
+ {title}
155
+ </View>
156
+ ) : (
157
+ <Fragment />
158
+ )}
159
+ {children ? (
160
+ <View className={clsx('fairys_taro-ui-message-item-body', bodyClassName)} style={bodyStyle}>
161
+ {children}
162
+ </View>
163
+ ) : (
164
+ <Fragment />
165
+ )}
166
+ </View>
167
+ </View>
168
+ );
169
+ };
170
+
171
+ export interface FairysTaroMessageProps extends ViewProps {}
172
+
173
+ export const FairysTaroMessage = (props: FairysTaroMessageProps) => {
174
+ const { className: messageClassName, ...rest } = props;
175
+ const classNames = useMemo(
176
+ () =>
177
+ clsx(
178
+ 'fairys_taro-ui-message fairystaro__box-border fairystaro__p-2 fairystaro__flex fairystaro__flex-col fairystaro__items-center fairystaro__gap-2 fairystaro__max-w-full fairystaro__max-h-full',
179
+ messageClassName,
180
+ ),
181
+ [messageClassName],
182
+ );
183
+ return <View {...rest} className={classNames} />;
184
+ };
185
+
186
+ /**消息组件(用于全局消息提示)*/
187
+ export const FairysTaroPortalMessage = (props: FairysTaroMessageProps) => {
188
+ const { className: messageClassName, ...rest } = props;
189
+
190
+ const [state] = useGlobalData();
191
+ const messageData = state.messageData;
192
+ const classNames = useMemo(
193
+ () =>
194
+ clsx(
195
+ 'fairys_taro-ui-portal-message fairystaro__pointer-events-none fairystaro__position-fixed fairystaro__top-0 fairystaro__right-0 fairystaro__bottom-0 fairystaro__left-0',
196
+ messageClassName,
197
+ ),
198
+ [messageClassName],
199
+ );
200
+
201
+ return (
202
+ <FairysTaroPortal>
203
+ <FairysTaroMessage {...rest} className={classNames}>
204
+ {messageData.map((item) => {
205
+ const { content, visible, __id, ...rest } = item as MessageDataType;
206
+ if (visible)
207
+ return (
208
+ <FairysTaroMessageItem {...rest} key={__id}>
209
+ {content}
210
+ </FairysTaroMessageItem>
211
+ );
212
+ return <Fragment key={`${__id}_hidden`} />;
213
+ })}
214
+ </FairysTaroMessage>
215
+ </FairysTaroPortal>
216
+ );
217
+ };
@@ -0,0 +1,18 @@
1
+ import { createPortal } from 'react-dom';
2
+ import { RootPortal } from '@tarojs/components';
3
+
4
+ export interface FairysTaroPortalProps {
5
+ children: React.ReactNode;
6
+ /**
7
+ * 自定义容器(h5环境)
8
+ */
9
+ domContainer?: HTMLElement;
10
+ }
11
+
12
+ export const FairysTaroPortal = (props: FairysTaroPortalProps) => {
13
+ const { children, domContainer } = props;
14
+ if (process.env.TARO_ENV === 'weapp') {
15
+ return <RootPortal>{children}</RootPortal>;
16
+ }
17
+ return createPortal(children, domContainer || document.body);
18
+ };
@@ -0,0 +1,22 @@
1
+ import { Toast } from '@nutui/nutui-react-taro';
2
+ import { FairysTaroPortal } from 'components/Portal';
3
+ import { useGlobalData } from 'context/global.data.instance';
4
+
5
+ export const FairysTaroToast = () => {
6
+ const [state, proxyInstance] = useGlobalData();
7
+ const toastConfig = state.toastData as any;
8
+
9
+ return (
10
+ <FairysTaroPortal>
11
+ <Toast
12
+ type="text"
13
+ {...toastConfig}
14
+ visible={toastConfig?.visible || false}
15
+ onClose={() => {
16
+ toastConfig?.onClose?.();
17
+ proxyInstance.hideToast();
18
+ }}
19
+ />
20
+ </FairysTaroPortal>
21
+ );
22
+ };
@@ -0,0 +1,41 @@
1
+ import { FairysTaroPortalMessage } from 'components/Mesage';
2
+ import { FairysTaroToast } from 'components/Toast';
3
+ import React, { Fragment } from 'react';
4
+
5
+ export interface ConnectToastMessageOptions {
6
+ /**
7
+ * 是否是根页面,
8
+ * 在 h5 中,只有入口文件才需要展示 message 组件 和 toast 组件
9
+ * 在微信中,所有页面都需要展示 message 组件 和 toast 组件, 入口文件不展示
10
+ */
11
+ isRoot?: boolean;
12
+ }
13
+
14
+ export const connectToastMessage = (Component: React.FC, options: ConnectToastMessageOptions = {}) => {
15
+ const { isRoot = false } = options;
16
+ return (props: any) => {
17
+ // 在 h5 中,只有根页面才需要展示 message 组件 和 toast 组件,其他页面只是渲染组件就好
18
+
19
+ // 微信中,根目录不显示 message 组件 和 toast 组件,因为会遮挡页面内容
20
+ if (process.env.TARO_ENV === 'weapp') {
21
+ return (
22
+ <Fragment>
23
+ <Component {...props} />
24
+ {/* toast */}
25
+ {!isRoot ? <FairysTaroToast /> : <Fragment />}
26
+ {/* message */}
27
+ {!isRoot ? <FairysTaroPortalMessage /> : <Fragment />}
28
+ </Fragment>
29
+ );
30
+ }
31
+ return (
32
+ <Fragment>
33
+ <Component {...props} />
34
+ {/* toast */}
35
+ {isRoot ? <FairysTaroToast /> : <Fragment />}
36
+ {/* message */}
37
+ {isRoot ? <FairysTaroPortalMessage /> : <Fragment />}
38
+ </Fragment>
39
+ );
40
+ };
41
+ };
@@ -0,0 +1,6 @@
1
+ export * from './EnterLoading';
2
+ export * from './Portal';
3
+ export * from './Mesage';
4
+ export * from './Toast';
5
+ export * from './connectToastMessage';
6
+ export * from './MainPage';
@@ -0,0 +1,106 @@
1
+ import { proxy, ref, useSnapshot } from 'valtio';
2
+ import { TaroToastProps } from '@nutui/nutui-react-taro';
3
+ import navigate from 'utils/navigate';
4
+ import { createUseId } from 'utils/useId';
5
+ import React from 'react';
6
+ import { FairysTaroMessageItemProps } from 'components/Mesage';
7
+ import { ProxyInstanceObjectBase } from 'utils/valtio/instance';
8
+
9
+ export interface MessageDataType extends FairysTaroMessageItemProps {
10
+ /**用于唯一标识提示框(默认自动生成)*/
11
+ __id: string | number;
12
+ /**
13
+ * 提示内容
14
+ */
15
+ content?: React.ReactNode;
16
+ /**
17
+ * 提示框是否可见
18
+ * @default false
19
+ */
20
+ visible?: boolean;
21
+ }
22
+
23
+ export interface ToastDataType extends Partial<TaroToastProps> {}
24
+
25
+ export interface GlobalDataInstanceState {
26
+ /**弹框提示框*/
27
+ messageData?: MessageDataType[];
28
+ /**提示框数据*/
29
+ toastData?: ToastDataType;
30
+ /**数据默认值不使用*/
31
+ __defaultValue?: string;
32
+ }
33
+
34
+ export class GlobalDataInstance extends ProxyInstanceObjectBase<GlobalDataInstanceState> {
35
+ /**
36
+ * 设置登录页面路由(需要在入口文件中进行设置)
37
+ * @param loginPageRoute 登录页面路由(默认pages/login/index)
38
+ */
39
+ public loginPageRoute = 'pages/login/index';
40
+
41
+ store = proxy<GlobalDataInstanceState>({
42
+ messageData: ref([]),
43
+ toastData: undefined,
44
+ });
45
+
46
+ /**用于提示信息*/
47
+ showMessage = (options: Omit<MessageDataType, '__id'> & { __id?: string }, timeout: number = 3000) => {
48
+ const _that = this;
49
+ let newItem = { ...options } as MessageDataType;
50
+ if (!_that.store.messageData) {
51
+ _that.store.messageData = ref([]);
52
+ }
53
+ newItem.visible = true;
54
+ if (!newItem.__id) {
55
+ newItem.__id = `${new Date().valueOf()}__${_that.store.messageData.length + 1}` + '__' + createUseId('message');
56
+ }
57
+ _that.store.messageData = ref([..._that.store.messageData].concat([newItem]));
58
+ if (timeout) {
59
+ const timer = setTimeout(() => {
60
+ newItem.visible = false;
61
+ _that.store.messageData = ref((_that.store.messageData || []).filter((it) => it.__id !== newItem.__id));
62
+ clearTimeout(timer);
63
+ }, timeout);
64
+ }
65
+ return newItem.__id;
66
+ };
67
+
68
+ /**隐藏指定id的提示框*/
69
+ hideMessage = (id: string | number) => {
70
+ this.store.messageData = ref((this.store.messageData || []).filter((it) => it.__id !== id));
71
+ };
72
+
73
+ /**显示Toast */
74
+ showToast = (config: Partial<ToastDataType> = {}) => {
75
+ this.store.toastData = ref({ visible: true, ...config });
76
+ };
77
+
78
+ /**隐藏Toast */
79
+ hideToast = () => {
80
+ this.store.toastData = ref({ ...this.store.toastData, visible: false });
81
+ };
82
+
83
+ /**跳转登录页面*/
84
+ toLoginPage = () => {
85
+ const isLoginPage = navigate.isCurrentPage(this.loginPageRoute || '');
86
+ const _loginPageRoute = `${this.loginPageRoute || ''}`.replace(/^\//, '');
87
+ if (isLoginPage) {
88
+ // 如果是登录页面不进行跳转
89
+ return;
90
+ }
91
+ // 跳转登录页面
92
+ navigate.navigateTo({ url: `/${_loginPageRoute}` });
93
+ };
94
+ }
95
+ /**
96
+ * 全局数据实例
97
+ */
98
+ export const globalDataInstance = new GlobalDataInstance();
99
+
100
+ /**
101
+ * 全局数据状态管理
102
+ */
103
+ export const useGlobalData = () => {
104
+ const store = useSnapshot(globalDataInstance.store);
105
+ return [store, globalDataInstance, store.__defaultValue] as const;
106
+ };
@@ -0,0 +1,36 @@
1
+ import { proxy, useSnapshot } from 'valtio';
2
+ import { ProxyInstanceObjectBase } from 'utils/valtio/instance';
3
+
4
+ export interface GlobalSettingDataInstanceState {
5
+ /**
6
+ * 请求成功返回code
7
+ * @default 200
8
+ */
9
+ requestSuccessCode?: number;
10
+ /**数据默认值不使用*/
11
+ __defaultValue?: string;
12
+ }
13
+
14
+ export class GlobalSettingDataInstance extends ProxyInstanceObjectBase<GlobalSettingDataInstanceState> {
15
+ store = proxy<GlobalSettingDataInstanceState>({
16
+ requestSuccessCode: 200,
17
+ });
18
+ /**
19
+ * 扩展全局设置数据状态
20
+ */
21
+ extendStore = (state: Partial<GlobalSettingDataInstanceState>) => {
22
+ this._setValues(state);
23
+ };
24
+ }
25
+ /**
26
+ * 全局设置数据实例
27
+ */
28
+ export const globalSettingDataInstance = new GlobalSettingDataInstance();
29
+
30
+ /**
31
+ * 全局设置数据状态管理
32
+ */
33
+ export const useGlobalSettingData = () => {
34
+ const store = useSnapshot(globalSettingDataInstance.store);
35
+ return [store, globalSettingDataInstance, store.__defaultValue] as const;
36
+ };
@@ -0,0 +1,4 @@
1
+ export * from './global.data.instance';
2
+ export * from './page.data.instance';
3
+ export * from './page.info.data.instance';
4
+ export * from './global.setting.data.instance';