jmash-core-mp 0.1.21 → 0.1.22

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 (150) hide show
  1. package/.editorconfig +9 -9
  2. package/README.md +60 -60
  3. package/babel.config.json +34 -34
  4. package/eslint.config.mjs +7 -7
  5. package/lib/api/auth/index.d.ts +21 -21
  6. package/lib/api/auth/index.js +199 -199
  7. package/lib/api/auth/types.d.ts +86 -86
  8. package/lib/api/auth/types.js +9 -9
  9. package/lib/api/cms/index.d.ts +20 -20
  10. package/lib/api/cms/index.js +161 -161
  11. package/lib/api/cms/types.d.ts +200 -200
  12. package/lib/api/cms/types.js +1 -1
  13. package/lib/api/constant.d.ts +5 -5
  14. package/lib/api/constant.js +6 -6
  15. package/lib/api/dict/index.d.ts +18 -18
  16. package/lib/api/dict/index.js +34 -34
  17. package/lib/api/dict/types.d.ts +28 -28
  18. package/lib/api/dict/types.js +1 -1
  19. package/lib/api/dicts.d.ts +18 -18
  20. package/lib/api/dicts.js +67 -67
  21. package/lib/api/files/index.d.ts +25 -25
  22. package/lib/api/files/index.js +135 -135
  23. package/lib/api/files/types.d.ts +38 -38
  24. package/lib/api/files/types.js +1 -1
  25. package/lib/api/index.d.ts +4 -4
  26. package/lib/api/index.js +6 -6
  27. package/lib/api/myorgan/types.d.ts +22 -22
  28. package/lib/api/myorgan/types.js +1 -1
  29. package/lib/api/region/index.d.ts +7 -7
  30. package/lib/api/region/index.js +19 -19
  31. package/lib/api/region/types.d.ts +19 -19
  32. package/lib/api/region/types.js +1 -1
  33. package/lib/api/storage/index.d.ts +10 -10
  34. package/lib/api/storage/index.js +43 -43
  35. package/lib/api/storage/types.d.ts +28 -28
  36. package/lib/api/storage/types.js +1 -1
  37. package/lib/api/types.d.ts +42 -42
  38. package/lib/api/types.js +1 -1
  39. package/lib/app.mpx.d.ts +1 -1
  40. package/lib/components/auth-user/jmash-update-user.mpx.d.ts +1 -1
  41. package/lib/components/auth-user/jmash-user.mpx.d.ts +1 -1
  42. package/lib/components/cms/jmash-cms-acticle-list.mpx.d.ts +1 -1
  43. package/lib/components/cms/jmash-cms-article-item.mpx.d.ts +1 -1
  44. package/lib/components/cms/jmash-cms-article-view.mpx.d.ts +1 -0
  45. package/lib/components/cms/jmash-cms-article.mpx.d.ts +1 -1
  46. package/lib/components/cms/jmash-cms-like.mpx.d.ts +1 -1
  47. package/lib/components/common/jmash-upload-picture.mpx.d.ts +1 -0
  48. package/lib/components/core/jmash-login.mpx.d.ts +1 -0
  49. package/lib/index.d.ts +21 -21
  50. package/lib/index.js +14 -14
  51. package/lib/packages/pages/cms/cms-article-list.mpx.d.ts +1 -1
  52. package/lib/pages/index.mpx.d.ts +1 -0
  53. package/lib/store/user.d.ts +31 -31
  54. package/lib/store/user.js +227 -227
  55. package/lib/utils/common.d.ts +35 -35
  56. package/lib/utils/common.js +166 -166
  57. package/lib/utils/config.d.ts +5 -5
  58. package/lib/utils/config.js +29 -29
  59. package/lib/utils/db.d.ts +21 -21
  60. package/lib/utils/db.js +84 -84
  61. package/lib/utils/grpc.d.ts +5 -5
  62. package/lib/utils/grpc.js +20 -20
  63. package/lib/utils/net.d.ts +7 -7
  64. package/lib/utils/net.js +15 -15
  65. package/lib/utils/request.d.ts +2 -2
  66. package/lib/utils/request.js +123 -123
  67. package/mpx.config.js +27 -27
  68. package/package.json +1 -1
  69. package/postcss.config.js +11 -11
  70. package/project.config.json +24 -24
  71. package/project.private.config.json +13 -13
  72. package/public/index.html +15 -15
  73. package/src/api/auth/index.ts +227 -227
  74. package/src/api/auth/types.ts +166 -166
  75. package/src/api/cms/index.ts +218 -218
  76. package/src/api/cms/types.ts +379 -379
  77. package/src/api/constant.ts +6 -6
  78. package/src/api/dict/index.ts +44 -44
  79. package/src/api/dict/types.ts +49 -49
  80. package/src/api/dicts.ts +72 -72
  81. package/src/api/files/index.ts +163 -163
  82. package/src/api/files/types.ts +67 -67
  83. package/src/api/index.ts +11 -11
  84. package/src/api/myorgan/types.ts +42 -42
  85. package/src/api/region/index.ts +23 -23
  86. package/src/api/region/types.ts +36 -36
  87. package/src/api/storage/index.ts +62 -62
  88. package/src/api/storage/types.ts +54 -54
  89. package/src/api/types.ts +72 -72
  90. package/src/app.mpx +71 -71
  91. package/src/components/auth-user/jmash-logout.mpx +91 -91
  92. package/src/components/auth-user/jmash-update-user.mpx +386 -386
  93. package/src/components/auth-user/jmash-update-user.web.mpx +366 -366
  94. package/src/components/auth-user/jmash-user.mpx +359 -359
  95. package/src/components/cms/jmash-cms-acticle-list.mpx +182 -182
  96. package/src/components/cms/jmash-cms-article-item.mpx +241 -241
  97. package/src/components/cms/jmash-cms-article-view.mpx +131 -131
  98. package/src/components/cms/jmash-cms-article.mpx +68 -68
  99. package/src/components/cms/jmash-cms-like.mpx +151 -151
  100. package/src/components/common/jmash-avatar-edit.mpx +153 -153
  101. package/src/components/common/jmash-cascader-region.mpx +112 -112
  102. package/src/components/common/jmash-menu.mpx +129 -129
  103. package/src/components/common/jmash-none-data.mpx +82 -82
  104. package/src/components/common/jmash-pic-swiper.mpx +71 -71
  105. package/src/components/common/jmash-popup.mpx +137 -137
  106. package/src/components/common/jmash-search.mpx +126 -126
  107. package/src/components/common/jmash-single-btn.mpx +53 -53
  108. package/src/components/common/jmash-stepper.mpx +214 -214
  109. package/src/components/common/jmash-tab-bar.mpx +50 -50
  110. package/src/components/common/jmash-textarea.mpx +88 -88
  111. package/src/components/common/jmash-top-navigation.mpx +203 -203
  112. package/src/components/common/jmash-upload-picture.mpx +129 -126
  113. package/src/components/core/jmash-cms-protocol.mpx +66 -66
  114. package/src/components/core/jmash-login.ali.mpx +284 -284
  115. package/src/components/core/jmash-login.mpx +348 -348
  116. package/src/components/core/jmash-login.web.mpx +421 -421
  117. package/src/components/core/jmash-popup-login.ali.mpx +311 -311
  118. package/src/components/core/jmash-popup-login.mpx +415 -415
  119. package/src/components/core/jmash-popup-login.web.mpx +389 -389
  120. package/src/custom-tab-bar/index.mpx +10 -10
  121. package/src/global.d.ts +11 -11
  122. package/src/index.ts +71 -71
  123. package/src/packages/index.mpx +10 -10
  124. package/src/packages/pages/auth/cms-protocol.mpx +31 -31
  125. package/src/packages/pages/auth/login.mpx +59 -59
  126. package/src/packages/pages/auth/update-user.mpx +17 -17
  127. package/src/packages/pages/cms/cms-article-list.mpx +164 -164
  128. package/src/packages/pages/cms/cms-article.mpx +32 -32
  129. package/src/pages/basic-component.mpx +30 -30
  130. package/src/pages/half-home.mpx +58 -58
  131. package/src/pages/home.mpx +52 -52
  132. package/src/pages/home2.mpx +47 -47
  133. package/src/pages/index.mpx +13 -3
  134. package/src/pages/tabbar/home.mpx +77 -77
  135. package/src/pages/tabbar/my.mpx +80 -80
  136. package/src/store/user.ts +270 -270
  137. package/src/styles/index.scss +20 -20
  138. package/src/styles/vars.scss +27 -27
  139. package/src/utils/common.ts +179 -179
  140. package/src/utils/config.ts +35 -35
  141. package/src/utils/db.ts +100 -100
  142. package/src/utils/grpc.ts +21 -21
  143. package/src/utils/net.ts +18 -18
  144. package/src/utils/request.ts +134 -134
  145. package/static/ali/mini.project.json +4 -4
  146. package/static/dd/project.config.json +15 -15
  147. package/static/swan/project.swan.json +14 -14
  148. package/static/tt/project.config.json +11 -11
  149. package/static/wx/project.config.json +40 -40
  150. package/uno.config.js +9 -9
package/src/store/user.ts CHANGED
@@ -1,270 +1,270 @@
1
- import { defineStore } from "@mpxjs/pinia";
2
- import {
3
- LoginReq,
4
- PhoneRegisterReq,
5
- WebLoginReq,
6
- LoginRes,
7
- RolesPerms,
8
- TokenModel,
9
- UserInfo,
10
- } from "../api/auth/types";
11
- import { authApi } from "../api/auth/index";
12
- import { ResponseData } from "../api/types";
13
- import { db } from "../utils/db";
14
- import { net } from "../utils/net";
15
- import mpx from "@mpxjs/core";
16
-
17
- interface UserState {
18
- //用户信息
19
- userInfo: UserInfo;
20
- // 角色编码
21
- roleCodes: string[];
22
- // 权限编码
23
- permCodes: string[];
24
- //访问Token
25
- accessToken: string;
26
- //Token过期时间
27
- expiresDate: number;
28
- }
29
-
30
- export const useUserStore = defineStore("user", {
31
- state: (): UserState => ({
32
- userInfo: (db.getUserInfo() as UserInfo) || {},
33
- roleCodes: (db.getRoleCodes() as string[]) || [],
34
- permCodes: (db.getPermCodes() as string[]) || [],
35
- accessToken: (db.getToken() as string) || "",
36
- expiresDate: (db.getTokenExpiresDate() as number) || 0,
37
- }),
38
- actions: {
39
- /** 登录检查 */
40
- loginOnlyAC(): Promise<boolean> {
41
- // 1. 已登录 → 直接返回成功
42
- if (this.checkLogin()) {
43
- return Promise.resolve(true);
44
- }
45
- const config = getApp().globalData.config;
46
- // 2. 测试环境特殊配置 → 直接返回失败
47
- if (config.dev && config.testNewUser) {
48
- return Promise.reject("测试环境,要求用户登录!");
49
- }
50
-
51
- // 3. 执行静默登录
52
- return this.silentLogin().then((res) => {
53
- return res.status;
54
- });
55
- },
56
- /** 登录检查并跳转登录 */
57
- loginAC(
58
- backurl: string,
59
- tabbar: boolean,
60
- loginurl: string = "/jmash/pages/auth/login"
61
- ): Promise<boolean> {
62
- // 1. 已登录 → 直接 resolve
63
- if (this.checkLogin()) {
64
- return Promise.resolve(true);
65
- }
66
-
67
- // 2. 拼接登录跳转地址(抽离公共逻辑)
68
- const toUrl = `${loginurl}?tabbar=${tabbar}&backurl=${encodeURIComponent(
69
- backurl
70
- )}`;
71
- const config = getApp().globalData.config;
72
-
73
- // 3. 测试环境特殊处理
74
- if (config.dev && config.testNewUser) {
75
- mpx.navigateTo({ url: toUrl });
76
- return Promise.resolve(false);
77
- }
78
-
79
- // 4. 生产环境:执行静默登录
80
- return this.silentLogin()
81
- .then((res) => {
82
- // 静默登录成功
83
- return Promise.resolve(res.status);
84
- })
85
- .catch(() => {
86
- mpx.navigateTo({ url: toUrl });
87
- return Promise.resolve(false);
88
- });
89
- },
90
-
91
- /** 静默登录 */
92
- silentLogin(): Promise<LoginRes> {
93
- const obj = __mpx_mode__ === "ali" ? { scopes: "auth_base" } : {};
94
- const config = getApp().globalData.config;
95
- return mpx
96
- .login(obj as WechatMiniprogram.LoginOption)
97
- .then((res: any) => {
98
- console.log("silentLogin-res", res);
99
- if (res.code) {
100
- return authApi
101
- .mpLogin({
102
- loginCode: res.code,
103
- appId: config.appId,
104
- componentAppid: config.componentAppid,
105
- } as LoginReq)
106
- .then(this.loginProcess);
107
- }
108
- throw new Error("接口登录失败!");
109
- })
110
- .catch((error: any) => {
111
- console.log("小程序登录失败!", error);
112
- return Promise.reject(error);
113
- });
114
- },
115
- // 手机号code 注册登录
116
- mpRegister(
117
- phoneCode: string,
118
- nickName: string = "",
119
- avatar: string = ""
120
- ): Promise<LoginRes> {
121
- const obj = __mpx_mode__ === "ali" ? { scopes: "auth_user" } : {};
122
- const config = getApp().globalData.config;
123
- return mpx
124
- .login(obj as WechatMiniprogram.LoginOption)
125
- .then((res: any) => {
126
- if (res.code) {
127
- return authApi
128
- .mpPhoneRegister({
129
- phoneCode: phoneCode,
130
- loginCode: res.code,
131
- appId: config.appId,
132
- nickName: nickName,
133
- avatar: avatar,
134
- componentAppid: config.componentAppid,
135
- } as PhoneRegisterReq)
136
- .then(this.loginProcess);
137
- }
138
- throw new Error("小程序登录失败!");
139
- });
140
- },
141
- //web登录.
142
- webLogin(userName: string, pwd: string): Promise<LoginRes> {
143
- // 编码密码
144
- const encodePwd = net.encrypt(pwd);
145
- return authApi
146
- .webLogin({ userName, encodePwd: encodePwd } as WebLoginReq)
147
- .then((res) => {
148
- return {
149
- status: true,
150
- token: this.loginSuccess(res.data),
151
- message: "登录成功!",
152
- } as LoginRes;
153
- });
154
- },
155
- // 登录处理
156
- loginProcess(resp: ResponseData<LoginRes>): LoginRes {
157
- //console.log("miniappLogin", resp);
158
- if (resp.statusCode === 200 && resp.data.status === true) {
159
- console.log("login success");
160
- this.loginSuccess(resp.data.token);
161
- } else if (resp.statusCode !== 200) {
162
- throw new Error(resp.errMsg);
163
- } else if (resp.data.status === false) {
164
- throw new Error("用户未注册!");
165
- }
166
- return resp.data;
167
- },
168
- loginSuccess(token: TokenModel): TokenModel {
169
- this.accessToken = token.accessToken;
170
- this.expiresDate = token.expiresIn * 1000 + new Date().getTime();
171
- db.setToken(token);
172
- this.getUserInfo(false);
173
- this.getRolePerm(false);
174
- return token;
175
- },
176
- // 退出登录,清空状态
177
- logout() {
178
- db.clearStorage();
179
- this.userInfo = {} as UserInfo;
180
- this.roleCodes = [];
181
- this.permCodes = [];
182
- this.accessToken = "";
183
- this.expiresDate = 0;
184
- },
185
- /** 检查登录是否有效? */
186
- checkLogin(): boolean {
187
- if (this.accessToken && !this.isTokenExpires()) {
188
- return true;
189
- }
190
- return false;
191
- },
192
- //是否Token过期.
193
- isTokenExpires(): boolean {
194
- const expiresDate = this.expiresDate;
195
- //无token/无过期时间直接视为过期
196
- if (!this.accessToken || !expiresDate) return true;
197
- const now = new Date().getTime();
198
- return now + 30000 > expiresDate;
199
- },
200
- // 检查角色
201
- checkRole(role: string): boolean {
202
- // 获取roleCodes
203
- const roleCodes: Array<string> = this.roleCodes;
204
- return roleCodes.length > 0 && roleCodes.indexOf(role) !== -1;
205
- },
206
-
207
- // 获取用户信息
208
- getUserInfo(cache: boolean = true): Promise<UserInfo> {
209
- const userInfo = this.userInfo;
210
- // 有缓存直接返回
211
- if (cache && Object.keys(userInfo).length > 0) {
212
- return Promise.resolve(userInfo);
213
- }
214
- // 无缓存请求接口
215
- return authApi
216
- .userInfo()
217
- .then((resp: ResponseData<UserInfo>) => {
218
- this.userInfo = resp.data;
219
- db.setUserInfo(resp.data);
220
- return resp.data;
221
- })
222
- .catch(() => Promise.reject("获取用户信息错误!"));
223
- },
224
- setUserInfo(userInfo: UserInfo) {
225
- this.userInfo = userInfo;
226
- db.setUserInfo(userInfo);
227
- },
228
-
229
- // 获取角色权限
230
- getRolePerm(cache: boolean = true): Promise<RolesPerms> {
231
- const rolesPerms = {
232
- roleCodes: this.roleCodes,
233
- permCodes: this.permCodes,
234
- };
235
-
236
- // 有缓存直接返回
237
- if (
238
- cache &&
239
- (rolesPerms.roleCodes.length > 0 || rolesPerms.permCodes.length > 0)
240
- ) {
241
- return Promise.resolve(rolesPerms);
242
- }
243
-
244
- // 无缓存请求接口
245
- return authApi
246
- .userRolesPerms()
247
- .then((response: ResponseData<RolesPerms>) => {
248
- this.roleCodes = response.data.roleCodes;
249
- this.permCodes = response.data.permCodes;
250
- db.setRoleCodes(response.data.roleCodes);
251
- db.setPermCodes(response.data.permCodes);
252
- return response.data;
253
- })
254
- .catch(() => Promise.reject("获取角色权限错误!"));
255
- },
256
-
257
- // 刷新Token.
258
- refreshToken(): Promise<boolean> {
259
- return authApi
260
- .refreshToken()
261
- .then((response: ResponseData<TokenModel>) => {
262
- this.accessToken = response.data.accessToken;
263
- this.expiresDate =
264
- response.data.expiresIn * 1000 + new Date().getTime();
265
- db.setToken(response.data);
266
- return true;
267
- });
268
- },
269
- },
270
- });
1
+ import { defineStore } from "@mpxjs/pinia";
2
+ import {
3
+ LoginReq,
4
+ PhoneRegisterReq,
5
+ WebLoginReq,
6
+ LoginRes,
7
+ RolesPerms,
8
+ TokenModel,
9
+ UserInfo,
10
+ } from "../api/auth/types";
11
+ import { authApi } from "../api/auth/index";
12
+ import { ResponseData } from "../api/types";
13
+ import { db } from "../utils/db";
14
+ import { net } from "../utils/net";
15
+ import mpx from "@mpxjs/core";
16
+
17
+ interface UserState {
18
+ //用户信息
19
+ userInfo: UserInfo;
20
+ // 角色编码
21
+ roleCodes: string[];
22
+ // 权限编码
23
+ permCodes: string[];
24
+ //访问Token
25
+ accessToken: string;
26
+ //Token过期时间
27
+ expiresDate: number;
28
+ }
29
+
30
+ export const useUserStore = defineStore("user", {
31
+ state: (): UserState => ({
32
+ userInfo: (db.getUserInfo() as UserInfo) || {},
33
+ roleCodes: (db.getRoleCodes() as string[]) || [],
34
+ permCodes: (db.getPermCodes() as string[]) || [],
35
+ accessToken: (db.getToken() as string) || "",
36
+ expiresDate: (db.getTokenExpiresDate() as number) || 0,
37
+ }),
38
+ actions: {
39
+ /** 登录检查 */
40
+ loginOnlyAC(): Promise<boolean> {
41
+ // 1. 已登录 → 直接返回成功
42
+ if (this.checkLogin()) {
43
+ return Promise.resolve(true);
44
+ }
45
+ const config = getApp().globalData.config;
46
+ // 2. 测试环境特殊配置 → 直接返回失败
47
+ if (config.dev && config.testNewUser) {
48
+ return Promise.reject("测试环境,要求用户登录!");
49
+ }
50
+
51
+ // 3. 执行静默登录
52
+ return this.silentLogin().then((res) => {
53
+ return res.status;
54
+ });
55
+ },
56
+ /** 登录检查并跳转登录 */
57
+ loginAC(
58
+ backurl: string,
59
+ tabbar: boolean,
60
+ loginurl: string = "/jmash/pages/auth/login"
61
+ ): Promise<boolean> {
62
+ // 1. 已登录 → 直接 resolve
63
+ if (this.checkLogin()) {
64
+ return Promise.resolve(true);
65
+ }
66
+
67
+ // 2. 拼接登录跳转地址(抽离公共逻辑)
68
+ const toUrl = `${loginurl}?tabbar=${tabbar}&backurl=${encodeURIComponent(
69
+ backurl
70
+ )}`;
71
+ const config = getApp().globalData.config;
72
+
73
+ // 3. 测试环境特殊处理
74
+ if (config.dev && config.testNewUser) {
75
+ mpx.navigateTo({ url: toUrl });
76
+ return Promise.resolve(false);
77
+ }
78
+
79
+ // 4. 生产环境:执行静默登录
80
+ return this.silentLogin()
81
+ .then((res) => {
82
+ // 静默登录成功
83
+ return Promise.resolve(res.status);
84
+ })
85
+ .catch(() => {
86
+ mpx.navigateTo({ url: toUrl });
87
+ return Promise.resolve(false);
88
+ });
89
+ },
90
+
91
+ /** 静默登录 */
92
+ silentLogin(): Promise<LoginRes> {
93
+ const obj = __mpx_mode__ === "ali" ? { scopes: "auth_base" } : {};
94
+ const config = getApp().globalData.config;
95
+ return mpx
96
+ .login(obj as WechatMiniprogram.LoginOption)
97
+ .then((res: any) => {
98
+ console.log("silentLogin-res", res);
99
+ if (res.code) {
100
+ return authApi
101
+ .mpLogin({
102
+ loginCode: res.code,
103
+ appId: config.appId,
104
+ componentAppid: config.componentAppid,
105
+ } as LoginReq)
106
+ .then(this.loginProcess);
107
+ }
108
+ throw new Error("接口登录失败!");
109
+ })
110
+ .catch((error: any) => {
111
+ console.log("小程序登录失败!", error);
112
+ return Promise.reject(error);
113
+ });
114
+ },
115
+ // 手机号code 注册登录
116
+ mpRegister(
117
+ phoneCode: string,
118
+ nickName: string = "",
119
+ avatar: string = ""
120
+ ): Promise<LoginRes> {
121
+ const obj = __mpx_mode__ === "ali" ? { scopes: "auth_user" } : {};
122
+ const config = getApp().globalData.config;
123
+ return mpx
124
+ .login(obj as WechatMiniprogram.LoginOption)
125
+ .then((res: any) => {
126
+ if (res.code) {
127
+ return authApi
128
+ .mpPhoneRegister({
129
+ phoneCode: phoneCode,
130
+ loginCode: res.code,
131
+ appId: config.appId,
132
+ nickName: nickName,
133
+ avatar: avatar,
134
+ componentAppid: config.componentAppid,
135
+ } as PhoneRegisterReq)
136
+ .then(this.loginProcess);
137
+ }
138
+ throw new Error("小程序登录失败!");
139
+ });
140
+ },
141
+ //web登录.
142
+ webLogin(userName: string, pwd: string): Promise<LoginRes> {
143
+ // 编码密码
144
+ const encodePwd = net.encrypt(pwd);
145
+ return authApi
146
+ .webLogin({ userName, encodePwd: encodePwd } as WebLoginReq)
147
+ .then((res) => {
148
+ return {
149
+ status: true,
150
+ token: this.loginSuccess(res.data),
151
+ message: "登录成功!",
152
+ } as LoginRes;
153
+ });
154
+ },
155
+ // 登录处理
156
+ loginProcess(resp: ResponseData<LoginRes>): LoginRes {
157
+ //console.log("miniappLogin", resp);
158
+ if (resp.statusCode === 200 && resp.data.status === true) {
159
+ console.log("login success");
160
+ this.loginSuccess(resp.data.token);
161
+ } else if (resp.statusCode !== 200) {
162
+ throw new Error(resp.errMsg);
163
+ } else if (resp.data.status === false) {
164
+ throw new Error("用户未注册!");
165
+ }
166
+ return resp.data;
167
+ },
168
+ loginSuccess(token: TokenModel): TokenModel {
169
+ this.accessToken = token.accessToken;
170
+ this.expiresDate = token.expiresIn * 1000 + new Date().getTime();
171
+ db.setToken(token);
172
+ this.getUserInfo(false);
173
+ this.getRolePerm(false);
174
+ return token;
175
+ },
176
+ // 退出登录,清空状态
177
+ logout() {
178
+ db.clearStorage();
179
+ this.userInfo = {} as UserInfo;
180
+ this.roleCodes = [];
181
+ this.permCodes = [];
182
+ this.accessToken = "";
183
+ this.expiresDate = 0;
184
+ },
185
+ /** 检查登录是否有效? */
186
+ checkLogin(): boolean {
187
+ if (this.accessToken && !this.isTokenExpires()) {
188
+ return true;
189
+ }
190
+ return false;
191
+ },
192
+ //是否Token过期.
193
+ isTokenExpires(): boolean {
194
+ const expiresDate = this.expiresDate;
195
+ //无token/无过期时间直接视为过期
196
+ if (!this.accessToken || !expiresDate) return true;
197
+ const now = new Date().getTime();
198
+ return now + 30000 > expiresDate;
199
+ },
200
+ // 检查角色
201
+ checkRole(role: string): boolean {
202
+ // 获取roleCodes
203
+ const roleCodes: Array<string> = this.roleCodes;
204
+ return roleCodes.length > 0 && roleCodes.indexOf(role) !== -1;
205
+ },
206
+
207
+ // 获取用户信息
208
+ getUserInfo(cache: boolean = true): Promise<UserInfo> {
209
+ const userInfo = this.userInfo;
210
+ // 有缓存直接返回
211
+ if (cache && Object.keys(userInfo).length > 0) {
212
+ return Promise.resolve(userInfo);
213
+ }
214
+ // 无缓存请求接口
215
+ return authApi
216
+ .userInfo()
217
+ .then((resp: ResponseData<UserInfo>) => {
218
+ this.userInfo = resp.data;
219
+ db.setUserInfo(resp.data);
220
+ return resp.data;
221
+ })
222
+ .catch(() => Promise.reject("获取用户信息错误!"));
223
+ },
224
+ setUserInfo(userInfo: UserInfo) {
225
+ this.userInfo = userInfo;
226
+ db.setUserInfo(userInfo);
227
+ },
228
+
229
+ // 获取角色权限
230
+ getRolePerm(cache: boolean = true): Promise<RolesPerms> {
231
+ const rolesPerms = {
232
+ roleCodes: this.roleCodes,
233
+ permCodes: this.permCodes,
234
+ };
235
+
236
+ // 有缓存直接返回
237
+ if (
238
+ cache &&
239
+ (rolesPerms.roleCodes.length > 0 || rolesPerms.permCodes.length > 0)
240
+ ) {
241
+ return Promise.resolve(rolesPerms);
242
+ }
243
+
244
+ // 无缓存请求接口
245
+ return authApi
246
+ .userRolesPerms()
247
+ .then((response: ResponseData<RolesPerms>) => {
248
+ this.roleCodes = response.data.roleCodes;
249
+ this.permCodes = response.data.permCodes;
250
+ db.setRoleCodes(response.data.roleCodes);
251
+ db.setPermCodes(response.data.permCodes);
252
+ return response.data;
253
+ })
254
+ .catch(() => Promise.reject("获取角色权限错误!"));
255
+ },
256
+
257
+ // 刷新Token.
258
+ refreshToken(): Promise<boolean> {
259
+ return authApi
260
+ .refreshToken()
261
+ .then((response: ResponseData<TokenModel>) => {
262
+ this.accessToken = response.data.accessToken;
263
+ this.expiresDate =
264
+ response.data.expiresIn * 1000 + new Date().getTime();
265
+ db.setToken(response.data);
266
+ return true;
267
+ });
268
+ },
269
+ },
270
+ });
@@ -1,20 +1,20 @@
1
- @forward "@/styles/vars.scss";
2
-
3
- //tabbar web 放在底部
4
- /* @mpx-if (__mpx_mode__ === 'web') */
5
- .cube-tab-bar {
6
- position: fixed !important;
7
- left: 0 !important;
8
- bottom: 0 !important;
9
- width: 100% !important;
10
- z-index: 9999 !important;
11
- /* 保证在最上层 */
12
- background: #fff !important;
13
- border-top: 1px solid #eee !important;
14
- }
15
-
16
- /* 给页面主体加内边距,防止内容被 tabbar 挡住 */
17
- .page-body {
18
- padding-bottom: 50px !important;
19
- }
20
- /* @mpx-endif */
1
+ @forward "@/styles/vars.scss";
2
+
3
+ //tabbar web 放在底部
4
+ /* @mpx-if (__mpx_mode__ === 'web') */
5
+ .cube-tab-bar {
6
+ position: fixed !important;
7
+ left: 0 !important;
8
+ bottom: 0 !important;
9
+ width: 100% !important;
10
+ z-index: 9999 !important;
11
+ /* 保证在最上层 */
12
+ background: #fff !important;
13
+ border-top: 1px solid #eee !important;
14
+ }
15
+
16
+ /* 给页面主体加内边距,防止内容被 tabbar 挡住 */
17
+ .page-body {
18
+ padding-bottom: 50px !important;
19
+ }
20
+ /* @mpx-endif */
@@ -1,27 +1,27 @@
1
- // 圆角
2
- $border-radius: 20rpx;
3
- $border-mini-radius: 10rpx;
4
- $border-max-radius: 50rpx;
5
- // 字体大小
6
- $font-size: 28rpx;
7
- $font-size-mini: 24rpx;
8
- // 颜色
9
- $white-color: #fff;
10
- $red-color: #ef4444;
11
- $green-color: #16a34a;
12
- $blue-color: #2563eb;
13
- $black-color: #000;
14
- // 字体颜色
15
- $font-color: #333;
16
- $font-color-grey: #666;
17
- $font-color-grey-opacity: #999;
18
- // 宽
19
- $width: 100%;
20
- // 层级
21
- $z-index: 99999;
22
- // 下拉线颜色
23
- $border-line: #ebebeb;
24
- // 背景色
25
- $background-color: #f6f6f6;
26
- // 白色背景
27
- $background-white-color: #fff;
1
+ // 圆角
2
+ $border-radius: 20rpx;
3
+ $border-mini-radius: 10rpx;
4
+ $border-max-radius: 50rpx;
5
+ // 字体大小
6
+ $font-size: 28rpx;
7
+ $font-size-mini: 24rpx;
8
+ // 颜色
9
+ $white-color: #fff;
10
+ $red-color: #ef4444;
11
+ $green-color: #16a34a;
12
+ $blue-color: #2563eb;
13
+ $black-color: #000;
14
+ // 字体颜色
15
+ $font-color: #333;
16
+ $font-color-grey: #666;
17
+ $font-color-grey-opacity: #999;
18
+ // 宽
19
+ $width: 100%;
20
+ // 层级
21
+ $z-index: 99999;
22
+ // 下拉线颜色
23
+ $border-line: #ebebeb;
24
+ // 背景色
25
+ $background-color: #f6f6f6;
26
+ // 白色背景
27
+ $background-white-color: #fff;