jmash-core-mp 0.1.76 → 0.1.78

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