jmash-core-mp 0.1.13 → 0.1.14

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