@fairys/taro-tools-react 0.0.2 → 0.0.4

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.
package/README.md CHANGED
@@ -1 +1,10 @@
1
1
  # 框架 ui 组件库
2
+
3
+ - [X] 全局弹框
4
+ - [X] 页面布局
5
+ - [X] 请求封装
6
+ - [X] 路由封装
7
+ - [X] 权限管理
8
+ - [X] 用户信息
9
+
10
+ 文档地址:[fairys-taro-react](https://autumn-fairy-tales.github.io/fairys-taro-react/)
@@ -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,73 @@
1
+ /**用户信息,权限判断等*/
2
+ export interface AuthDataInstanceState<T = any> {
3
+ /**用户信息*/
4
+ userInfo?: T;
5
+ /**登录凭证(token)*/
6
+ token?: string;
7
+ /**权限列表*/
8
+ permissions?: string[];
9
+ /**菜单权限列表*/
10
+ menusPermissions?: string[];
11
+ /**数据默认值不使用*/
12
+ __defaultValue?: string;
13
+ }
14
+ export declare class AuthDataInstance<T = any> {
15
+ store: AuthDataInstanceState<T>;
16
+ /**
17
+ * 设置用户信息
18
+ * @param userInfo 用户信息
19
+ */
20
+ set userInfo(userInfo: T);
21
+ /**
22
+ * 获取用户信息
23
+ * @returns 用户信息
24
+ */
25
+ get userInfo(): T;
26
+ /**
27
+ * 设置登录凭证(token)
28
+ * @param token 登录凭证(token)
29
+ */
30
+ set token(token: string);
31
+ /**
32
+ * 获取登录凭证(token)
33
+ * @returns 登录凭证(token)
34
+ */
35
+ get token(): string;
36
+ /**
37
+ * 设置权限列表
38
+ * @param permissions 权限列表
39
+ */
40
+ set permissions(permissions: string[]);
41
+ /**
42
+ * 获取权限列表
43
+ * @returns 权限列表
44
+ */
45
+ get permissions(): string[];
46
+ /**
47
+ * 设置菜单权限列表
48
+ * @param menusPermissions 菜单权限列表
49
+ */
50
+ set menusPermissions(menusPermissions: string[]);
51
+ /**
52
+ * 获取菜单权限列表
53
+ * @returns 菜单权限列表
54
+ */
55
+ get menusPermissions(): string[];
56
+ /**
57
+ * 判断是否有指定菜单权限
58
+ * @param menuPermission 菜单权限
59
+ * @returns 是否有指定菜单权限
60
+ */
61
+ hasMenuPermission(menuPermission: string): boolean;
62
+ /**
63
+ * 判断是否有指定权限
64
+ * @param permission 权限
65
+ * @returns 是否有指定权限
66
+ */
67
+ hasPermission(permission: string): boolean;
68
+ }
69
+ export declare const authDataInstance: AuthDataInstance<any>;
70
+ /**
71
+ * 全局数据状态管理
72
+ */
73
+ export declare function useAuthData<T = any>(): [AuthDataInstanceState<T>, AuthDataInstance<T>, string | undefined];
@@ -0,0 +1,89 @@
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
+ menusPermissions: void 0
10
+ });
11
+ set userInfo(userInfo) {
12
+ this.store.userInfo = userInfo;
13
+ if (userInfo) taro.setStorageSync('userInfo', JSON.stringify(userInfo));
14
+ else taro.removeStorageSync('userInfo');
15
+ }
16
+ get userInfo() {
17
+ if (!this.store.userInfo) {
18
+ const userInfo = taro.getStorageSync('userInfo');
19
+ if (userInfo) try {
20
+ this.store.userInfo = JSON.parse(userInfo);
21
+ } catch (error) {
22
+ console.error("\u89E3\u6790\u7528\u6237\u4FE1\u606F\u5931\u8D25", error);
23
+ }
24
+ }
25
+ return this.store.userInfo || {};
26
+ }
27
+ set token(token) {
28
+ this.store.token = token;
29
+ if (token) taro.setStorageSync(globalSettingDataInstance.store.tokenFieldName || 'token', token);
30
+ else taro.removeStorageSync(globalSettingDataInstance.store.tokenFieldName || 'token');
31
+ }
32
+ get token() {
33
+ if (!this.store.token) {
34
+ const token = taro.getStorageSync(globalSettingDataInstance.store.tokenFieldName || 'token');
35
+ if (token) this.store.token = token;
36
+ }
37
+ return this.store.token || '';
38
+ }
39
+ set permissions(permissions) {
40
+ this.store.permissions = permissions;
41
+ if (permissions) taro.setStorageSync('permissions', JSON.stringify(permissions));
42
+ else taro.removeStorageSync('permissions');
43
+ }
44
+ get permissions() {
45
+ if (!this.store.permissions) {
46
+ const permissions = taro.getStorageSync('permissions');
47
+ if (permissions) try {
48
+ this.store.permissions = JSON.parse(permissions);
49
+ } catch (error) {
50
+ console.error("\u89E3\u6790\u6743\u9650\u5217\u8868\u5931\u8D25", error);
51
+ }
52
+ }
53
+ return this.store.permissions || [];
54
+ }
55
+ set menusPermissions(menusPermissions) {
56
+ this.store.menusPermissions = menusPermissions;
57
+ if (menusPermissions) taro.setStorageSync('menusPermissions', JSON.stringify(menusPermissions));
58
+ else taro.removeStorageSync('menusPermissions');
59
+ }
60
+ get menusPermissions() {
61
+ if (!this.store.menusPermissions) {
62
+ const menusPermissions = taro.getStorageSync('menusPermissions');
63
+ if (menusPermissions) try {
64
+ this.store.menusPermissions = JSON.parse(menusPermissions);
65
+ } catch (error) {
66
+ console.error("\u89E3\u6790\u83DC\u5355\u6743\u9650\u5217\u8868\u5931\u8D25", error);
67
+ }
68
+ }
69
+ return this.store.menusPermissions || [];
70
+ }
71
+ hasMenuPermission(menuPermission) {
72
+ if (!globalSettingDataInstance.store.isEnableAuth) return true;
73
+ return this.menusPermissions.includes(menuPermission);
74
+ }
75
+ hasPermission(permission) {
76
+ if (!globalSettingDataInstance.store.isEnableAuth) return true;
77
+ return this.permissions.includes(permission);
78
+ }
79
+ }
80
+ const authDataInstance = new AuthDataInstance();
81
+ function useAuthData() {
82
+ const store = useSnapshot(authDataInstance.store);
83
+ return [
84
+ store,
85
+ authDataInstance,
86
+ store.__defaultValue
87
+ ];
88
+ }
89
+ export { AuthDataInstance, authDataInstance, useAuthData };