@fairys/taro-tools-react 0.0.2 → 0.0.3

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.
@@ -15,7 +15,7 @@ const FairysTaroMessageItem = (props)=>{
15
15
  itemClassName,
16
16
  bordered
17
17
  ]);
18
- const classIconName = useMemo(()=>clsx('fairys_taro-ui-message-icon fairystaro__box-border ', iconClassName, {
18
+ const classIconName = useMemo(()=>clsx('fairys_taro-ui-message-icon fairystaro__box-border fairystaro__text-_zkh1_0_dl_6rem_zhk2_', iconClassName, {
19
19
  'ant-design--close-circle-outlined': 'error' === type && !isIcon,
20
20
  'ant-design--exclamation-circle-outlined': 'warning' === type && !isIcon,
21
21
  'ant-design--check-circle-outlined': 'success' === type && !isIcon,
@@ -34,7 +34,7 @@ const FairysTaroMessageItem = (props)=>{
34
34
  isIconString,
35
35
  icon
36
36
  ]);
37
- const titleClassNames = useMemo(()=>clsx('fairys_taro-ui-message-item-title fairystaro__font-bold', titleClassName), [
37
+ const titleClassNames = useMemo(()=>clsx('fairys_taro-ui-message-item-title fairystaro__font-bold fairystaro__text-_zkh1_0_dl_6rem_zhk2_', titleClassName), [
38
38
  titleClassName
39
39
  ]);
40
40
  const _iconStyle = {
@@ -78,7 +78,7 @@ const FairysTaroMessageItem = (props)=>{
78
78
  children: title
79
79
  }) : /*#__PURE__*/ jsx(Fragment, {}),
80
80
  children ? /*#__PURE__*/ jsx(View, {
81
- className: clsx('fairys_taro-ui-message-item-body', bodyClassName),
81
+ className: clsx('fairys_taro-ui-message-item-body fairystaro__text-_zkh1_0_dl_6rem_zhk2_', bodyClassName),
82
82
  style: bodyStyle,
83
83
  children: children
84
84
  }) : /*#__PURE__*/ jsx(Fragment, {})
@@ -101,7 +101,7 @@ const FairysTaroPortalMessage = (props)=>{
101
101
  const { className: messageClassName, ...rest } = props;
102
102
  const [state] = useGlobalData();
103
103
  const messageData = state.messageData;
104
- const classNames = useMemo(()=>clsx('fairys_taro-ui-portal-message fairystaro__pointer-events-none fairystaro__position-fixed fairystaro__top-0 fairystaro__right-0 fairystaro__bottom-0 fairystaro__left-0', messageClassName), [
104
+ const classNames = useMemo(()=>clsx('fairys_taro-ui-portal-message fairystaro__pointer-events-none fairystaro__position-fixed fairystaro__top-0 fairystaro__right-0 fairystaro__bottom-0 fairystaro__left-0', messageClassName), [
105
105
  messageClassName
106
106
  ]);
107
107
  return /*#__PURE__*/ jsx(FairysTaroPortal, {
@@ -0,0 +1,55 @@
1
+ /**用户信息,权限判断等*/
2
+ export interface AuthDataInstanceState<T = any> {
3
+ /**用户信息*/
4
+ userInfo?: T;
5
+ /**登录凭证(token)*/
6
+ token?: string;
7
+ /**权限列表*/
8
+ permissions?: string[];
9
+ /**数据默认值不使用*/
10
+ __defaultValue?: string;
11
+ }
12
+ export declare class AuthDataInstance<T = any> {
13
+ store: AuthDataInstanceState<T>;
14
+ /**
15
+ * 设置用户信息
16
+ * @param userInfo 用户信息
17
+ */
18
+ set userInfo(userInfo: T);
19
+ /**
20
+ * 获取用户信息
21
+ * @returns 用户信息
22
+ */
23
+ get userInfo(): T;
24
+ /**
25
+ * 设置登录凭证(token)
26
+ * @param token 登录凭证(token)
27
+ */
28
+ set token(token: string);
29
+ /**
30
+ * 获取登录凭证(token)
31
+ * @returns 登录凭证(token)
32
+ */
33
+ get token(): string;
34
+ /**
35
+ * 设置权限列表
36
+ * @param permissions 权限列表
37
+ */
38
+ set permissions(permissions: string[]);
39
+ /**
40
+ * 获取权限列表
41
+ * @returns 权限列表
42
+ */
43
+ get permissions(): string[];
44
+ /**
45
+ * 判断是否有指定权限
46
+ * @param permission 权限
47
+ * @returns 是否有指定权限
48
+ */
49
+ hasPermission(permission: string): boolean;
50
+ }
51
+ export declare const authDataInstance: AuthDataInstance<any>;
52
+ /**
53
+ * 全局数据状态管理
54
+ */
55
+ export declare function useAuthData<T = any>(): [AuthDataInstanceState<T>, AuthDataInstance<T>, string | undefined];
@@ -0,0 +1,67 @@
1
+ import taro from "@tarojs/taro";
2
+ import { proxy, useSnapshot } from "valtio";
3
+ import { globalSettingDataInstance } from "./global.setting.data.instance.js";
4
+ class AuthDataInstance {
5
+ store = proxy({
6
+ userInfo: void 0,
7
+ token: void 0,
8
+ permissions: void 0
9
+ });
10
+ set userInfo(userInfo) {
11
+ this.store.userInfo = userInfo;
12
+ if (userInfo) taro.setStorageSync('userInfo', JSON.stringify(userInfo));
13
+ else taro.removeStorageSync('userInfo');
14
+ }
15
+ get userInfo() {
16
+ if (!this.store.userInfo) {
17
+ const userInfo = taro.getStorageSync('userInfo');
18
+ if (userInfo) try {
19
+ this.store.userInfo = JSON.parse(userInfo);
20
+ } catch (error) {
21
+ console.error("\u89E3\u6790\u7528\u6237\u4FE1\u606F\u5931\u8D25", error);
22
+ }
23
+ }
24
+ return this.store.userInfo || {};
25
+ }
26
+ set token(token) {
27
+ this.store.token = token;
28
+ if (token) taro.setStorageSync(globalSettingDataInstance.store.tokenFieldName || 'token', token);
29
+ else taro.removeStorageSync(globalSettingDataInstance.store.tokenFieldName || 'token');
30
+ }
31
+ get token() {
32
+ if (!this.store.token) {
33
+ const token = taro.getStorageSync(globalSettingDataInstance.store.tokenFieldName || 'token');
34
+ if (token) this.store.token = token;
35
+ }
36
+ return this.store.token || '';
37
+ }
38
+ set permissions(permissions) {
39
+ this.store.permissions = permissions;
40
+ if (permissions) taro.setStorageSync('permissions', JSON.stringify(permissions));
41
+ else taro.removeStorageSync('permissions');
42
+ }
43
+ get permissions() {
44
+ if (!this.store.permissions) {
45
+ const permissions = taro.getStorageSync('permissions');
46
+ if (permissions) try {
47
+ this.store.permissions = JSON.parse(permissions);
48
+ } catch (error) {
49
+ console.error("\u89E3\u6790\u6743\u9650\u5217\u8868\u5931\u8D25", error);
50
+ }
51
+ }
52
+ return this.store.permissions || [];
53
+ }
54
+ hasPermission(permission) {
55
+ return this.permissions.includes(permission);
56
+ }
57
+ }
58
+ const authDataInstance = new AuthDataInstance();
59
+ function useAuthData() {
60
+ const store = useSnapshot(authDataInstance.store);
61
+ return [
62
+ store,
63
+ authDataInstance,
64
+ store.__defaultValue
65
+ ];
66
+ }
67
+ export { AuthDataInstance, authDataInstance, useAuthData };