jmash-core-mp 0.1.0 → 0.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "jmash-core-mp",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "private": false,
5
5
  "dependencies": {
6
6
  "@mpxjs/api-proxy": "^2.10.19",
@@ -21,7 +21,10 @@ class AuthApi {
21
21
  url: "/v1/front/rbac/miniapp_login/" + config.tenant,
22
22
  method: "POST",
23
23
  data,
24
- header: { "content-type": "application/json" },
24
+ header: {
25
+ "content-type": "application/json",
26
+ Authorization: false,
27
+ },
25
28
  });
26
29
  }
27
30
  // 手机号注册登录
@@ -90,7 +90,7 @@ class FileApi {
90
90
  uploadFile(file: string): Promise<FileInfo> {
91
91
  const that = this;
92
92
  return new Promise((resolve, reject) => {
93
- wx.uploadFile({
93
+ const p = mpx.uploadFile({
94
94
  url: that.uploadUrl(),
95
95
  filePath: file,
96
96
  name: "file",
@@ -98,33 +98,24 @@ class FileApi {
98
98
  "Content-Type": "multipart/form-data",
99
99
  Authorization: db.getBearerToken(),
100
100
  },
101
- success(response) {
102
- if (response.statusCode === 200) {
103
- resolve({
104
- code: response.statusCode,
105
- message: response.errMsg,
106
- data: JSON.parse(response.data),
107
- } as any);
108
- } else if (response.statusCode === 401) {
109
- //TODO console.log("token过期....")
110
- // 清理登录信息
111
- wx.clearStorage();
112
- } else {
113
- mpx.showToast({
114
- title: response.errMsg,
115
- icon: "none",
116
- duration: 2000,
117
- });
118
- resolve({
119
- code: response.statusCode,
120
- message: response.errMsg,
121
- data: JSON.parse(response.data),
122
- } as any);
123
- }
124
- },
125
- fail(error) {
126
- reject(error);
127
- },
101
+ } as WechatMiniprogram.UploadFileOption) as any;
102
+ p.then((res: any) => {
103
+ console.log("uploadFile", res);
104
+ if (res.statusCode === 200) {
105
+ resolve(JSON.parse(res.data) as FileInfo);
106
+ } else if (res.statusCode === 401) {
107
+ // 清理登录信息
108
+ mpx.clearStorage();
109
+ } else {
110
+ mpx.showToast({
111
+ title: res.errMsg,
112
+ icon: "none",
113
+ duration: 2000,
114
+ });
115
+ resolve(JSON.parse(res.data) as FileInfo);
116
+ }
117
+ }).catch((err: any) => {
118
+ reject(err);
128
119
  });
129
120
  });
130
121
  }
@@ -132,21 +123,20 @@ class FileApi {
132
123
  // 上传文件
133
124
  downloadFile(url: string): Promise<FileDownInfo> {
134
125
  return new Promise((resolve, reject) => {
135
- wx.downloadFile({
126
+ const p = mpx.downloadFile({
136
127
  url: url,
137
128
  header: {
138
129
  Authorization: db.getBearerToken(),
139
130
  },
140
- success(response) {
141
- resolve({
142
- statusCode: response.statusCode,
143
- tempFilePath: response.tempFilePath,
144
- filePath: response.tempFilePath,
145
- } as FileDownInfo);
146
- },
147
- fail(error) {
148
- reject(error);
149
- },
131
+ }) as any;
132
+ p.then((res: any) => {
133
+ resolve({
134
+ statusCode: res.statusCode,
135
+ tempFilePath: res.tempFilePath,
136
+ filePath: res.tempFilePath,
137
+ } as FileDownInfo);
138
+ }).catch((err: any) => {
139
+ reject(err);
150
140
  });
151
141
  });
152
142
  }
package/src/app.mpx CHANGED
@@ -1,19 +1,24 @@
1
1
  <script lang="ts">
2
2
  import mpx, { createApp } from '@mpxjs/core';
3
+ //api代理
4
+ import apiProxy from '@mpxjs/api-proxy';
5
+ mpx.use(apiProxy, { usePromise: true })
3
6
  //状态管理
4
7
  import { createPinia } from '@mpxjs/pinia';
5
8
  createPinia();
6
9
  //网络请求和App配置
7
10
  import { mpxFetch, config } from "./index";
8
11
  mpx.use(mpxFetch);
9
- //api代理
10
- import apiProxy from '@mpxjs/api-proxy';
11
- mpx.use(apiProxy, { usePromise: true })
12
+
12
13
  createApp({
13
14
  globalData: {
14
15
  config: config
15
16
  }
16
17
  })
18
+ // 只有运行时才能调用
19
+ const accountInfo = mpx.getAccountInfoSync();
20
+ // 微信
21
+ config.appId = accountInfo.miniProgram.appId;
17
22
  </script>
18
23
 
19
24
  <style></style>
@@ -0,0 +1,344 @@
1
+ <template>
2
+ <!-- 我的页面 中个人信息编辑页面 -->
3
+ <view class="my-information">
4
+ <view class="main">
5
+ <!-- 头像区域 -->
6
+ <view class="main-profile" wx:if="{{ isUserAvatar }}">
7
+ <view class="profile-left">头像</view>
8
+ <view class="profile-right">
9
+ <button class="avatar-wrapper" open-type="chooseAvatar" bind:chooseavatar="onChooseAvatar">
10
+ <image class="avatar-img" src="{{ resourceUrl + '/components/gray_head2x.png' }}" mode="aspectFill"
11
+ wx:if="{{ !userInfo.avatar }}" />
12
+ <image class="avatar-img" src="{{ imageUrl + userInfo.avatar }}" mode="aspectFill" wx:else />
13
+ <view class="avatar-badge">
14
+ <text class="badge-icon">✎</text>
15
+ </view>
16
+ </button>
17
+ </view>
18
+ </view>
19
+
20
+ <!-- 昵称 -->
21
+ <view class="main-nickname" wx:if="{{ isUserNickName }}">
22
+ <view class="nickname-left">昵称</view>
23
+ <view class="nickname-right">
24
+ <input wx:model="{{ userInfo.nickName }}" wx:model-prop="value" type="nickname" class="nickname-input"
25
+ placeholder="请输入昵称" />
26
+ </view>
27
+ </view>
28
+
29
+ <!-- 姓名 -->
30
+ <view class="main-nickname" wx:if="{{ isUserRealName }}">
31
+ <view class="nickname-left">姓名</view>
32
+ <view class="nickname-right">
33
+ <input wx:model="{{ userInfo.realName }}" wx:model-prop="value" type="text" class="nickname-input"
34
+ placeholder="请输入姓名" />
35
+ </view>
36
+ </view>
37
+
38
+ <!-- 手机号 -->
39
+ <view class="main-phone" wx:if="{{ isUserMobilePhone }}">
40
+ <view class="phone-left">手机号</view>
41
+ <view class="phone-right">
42
+ <view class="phone-number">{{ userInfo.mobilePhone }}</view>
43
+ <button open-type="getPhoneNumber" class="phone-right-btn" bindgetphonenumber="getPhoneNumber"
44
+ wx:if="{{ isChangePhone }}">更换手机号</button>
45
+ </view>
46
+ </view>
47
+ </view>
48
+
49
+ <!-- 保存按钮 -->
50
+ <view class="main-btn">
51
+ <button class="main-btn-item" bindtap="handleUpdateUser">保存</button>
52
+ </view>
53
+ </view>
54
+ </template>
55
+
56
+ <script lang="ts">
57
+ import mpx, { createComponent } from '@mpxjs/core'
58
+ import { config } from '../../utils/config'
59
+ import { UpdateUserReq, UserInfo } from '../../api/auth/types'
60
+ import { authApi } from '../../api/auth/index'
61
+ import { fileApi } from '../../api/files/index';
62
+ import { db } from '../../utils/db';
63
+ import { FileInfo } from '../../api/files/types';
64
+ import { auth } from '../../utils/auth';
65
+
66
+ createComponent({
67
+ properties: {
68
+ // 是否显示用户头像
69
+ isUserAvatar: {
70
+ type: Boolean,
71
+ value: true
72
+ },
73
+ // 是否显示昵称
74
+ isUserNickName: {
75
+ type: Boolean,
76
+ value: true
77
+ },
78
+ // 是否显示姓名
79
+ isUserRealName: {
80
+ type: Boolean,
81
+ value: true
82
+ },
83
+ // 是否显示手机号
84
+ isUserMobilePhone: {
85
+ type: Boolean,
86
+ value: true
87
+ },
88
+ // 是否显示更换手机号
89
+ isChangePhone: {
90
+ type: Boolean,
91
+ value: true
92
+ }
93
+ },
94
+ data: {
95
+ resourceUrl: config.resourceUrl + "/images",
96
+ imageUrl: config.baseUrl + "/v1/file/path/",
97
+ userInfo: {} as UserInfo
98
+ },
99
+ ready() {
100
+ this.getUserInfo();
101
+ },
102
+ /**
103
+ * 组件的方法列表
104
+ */
105
+ methods: {
106
+ // 获取用户信息
107
+ getUserInfo() {
108
+ console.log("getUserInfo");
109
+ auth.getUserInfo().then((resp: UserInfo) => {
110
+ console.log("getUserInfo", resp);
111
+ this.userInfo = resp;
112
+ })
113
+ },
114
+
115
+ // 获取微信头像
116
+ onChooseAvatar(e: any) {
117
+ console.log("onChooseAvatar", e);
118
+ const { avatarUrl } = e.detail;
119
+
120
+ fileApi.uploadFile(avatarUrl).then((res: FileInfo) => {
121
+ console.log("uploadFile1", res);
122
+ this.userInfo.avatar = res.fileSrc;
123
+ });
124
+ },
125
+
126
+ // 更换手机号
127
+ getPhoneNumber(e: any) {
128
+ if (e.detail.errMsg === "getPhoneNumber:ok") {
129
+ // 授权成功后,调用rbac模块接口 已登陆状态小程序更换绑定手机号
130
+ authApi.replaceBindphone({
131
+ appId: config.appId,
132
+ phoneCode: e.detail.code,
133
+ componentAppid: config.componentAppid
134
+ }).then((res) => {
135
+ if (res.data) {
136
+ auth.getUserInfo(false).then((res) => {
137
+ this.userInfo = res as UserInfo;
138
+ });
139
+ }
140
+ })
141
+ }
142
+ },
143
+ // 更新用户信息
144
+ handleUpdateUser() {
145
+ let updateReq: UpdateUserReq = { ...this.userInfo } as UpdateUserReq;
146
+ updateReq.requestId = Math.random() * 10 + "";
147
+ updateReq.updateMask = "nickName,avatar,realName";
148
+ authApi.updateUserInfo(updateReq).then((res) => {
149
+ // 保存成功后重新设置本地缓存信息,并跳转到我的页面
150
+ if (res.statusCode === 200) {
151
+ db.setUserInfo(res.data)
152
+ mpx.navigateBack({
153
+ delta: 1
154
+ })
155
+ }
156
+ })
157
+ }
158
+ }
159
+ }
160
+
161
+ )
162
+ </script>
163
+
164
+ <style lang="scss">
165
+ @use "../../styles/index.scss" as *;
166
+
167
+ // 颜色变量
168
+ $primary: #07c160;
169
+ $primary-dark: #06ad56;
170
+ $text-1: #111111;
171
+ $text-2: #555555;
172
+ $text-3: #888888;
173
+ $border: #e8e8e8;
174
+ $bg-page: #f2f2f2;
175
+ $bg-card: #ffffff;
176
+
177
+ .my-information {
178
+ background-color: $bg-page;
179
+ width: 100%;
180
+ min-height: 100vh;
181
+ position: relative;
182
+ padding: 30rpx 0;
183
+
184
+ .main {
185
+ background-color: $bg-card;
186
+ margin: 0 30rpx;
187
+ border-radius: 24rpx;
188
+ overflow: hidden;
189
+ box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.05);
190
+
191
+ .main-profile,
192
+ .main-nickname,
193
+ .main-phone {
194
+ display: flex;
195
+ justify-content: space-between;
196
+ align-items: center;
197
+ height: 120rpx;
198
+ padding: 0 32rpx;
199
+ border-bottom: 1rpx solid $border;
200
+ transition: background-color 0.2s;
201
+
202
+ &:last-child {
203
+ border-bottom: none;
204
+ }
205
+
206
+ &:active {
207
+ background-color: rgba(0, 0, 0, 0.02);
208
+ }
209
+
210
+ .profile-left,
211
+ .nickname-left,
212
+ .phone-left {
213
+ font-size: 30rpx;
214
+ color: $text-1;
215
+ font-weight: 500;
216
+ }
217
+
218
+ .profile-right {
219
+ .avatar-wrapper {
220
+ position: relative;
221
+ margin: 0;
222
+ padding: 0;
223
+ background: transparent;
224
+ border: none;
225
+ line-height: 1;
226
+
227
+ .avatar-img {
228
+ width: 88rpx;
229
+ height: 88rpx;
230
+ border-radius: 50%;
231
+ border: 2rpx solid $border;
232
+ display: block;
233
+ }
234
+
235
+ .avatar-badge {
236
+ position: absolute;
237
+ right: -4rpx;
238
+ bottom: -4rpx;
239
+ width: 36rpx;
240
+ height: 36rpx;
241
+ background: $primary;
242
+ border-radius: 50%;
243
+ border: 2rpx solid $bg-card;
244
+ display: flex;
245
+ align-items: center;
246
+ justify-content: center;
247
+
248
+ .badge-icon {
249
+ font-size: 16rpx;
250
+ color: #fff;
251
+ }
252
+ }
253
+ }
254
+ }
255
+
256
+ .nickname-right,
257
+ .phone-right {
258
+ display: flex;
259
+ justify-content: flex-end;
260
+ align-items: center;
261
+ flex: 1;
262
+ margin-left: 30rpx;
263
+ }
264
+
265
+ .nickname-input {
266
+ flex: 1;
267
+ text-align: right;
268
+ font-size: 30rpx;
269
+ color: $text-1;
270
+ background: transparent;
271
+ border: none;
272
+ outline: none;
273
+ height: 80rpx;
274
+ line-height: 80rpx;
275
+ padding: 0;
276
+
277
+ &::placeholder {
278
+ color: $text-3;
279
+ }
280
+ }
281
+
282
+ .phone-right {
283
+ .phone-number {
284
+ font-size: 30rpx;
285
+ color: $text-1;
286
+ font-weight: 500;
287
+ }
288
+
289
+ .phone-right-btn {
290
+ background-color: #e6f7ff;
291
+ border-radius: 24rpx;
292
+ margin-left: 20rpx;
293
+ border: none;
294
+ font-size: 24rpx;
295
+ color: $primary;
296
+ padding: 12rpx 24rpx;
297
+ height: auto;
298
+ line-height: 1.4;
299
+ }
300
+ }
301
+ }
302
+
303
+ .main-phone {
304
+ border-bottom: none;
305
+ }
306
+ }
307
+
308
+ // 保存按钮样式
309
+ .main-btn {
310
+ display: flex;
311
+ justify-content: center;
312
+ align-items: center;
313
+ padding: 60rpx 30rpx;
314
+ }
315
+
316
+ .main-btn-item {
317
+ width: 100%;
318
+ height: 88rpx;
319
+ border-radius: 44rpx;
320
+ font-size: 32rpx;
321
+ font-weight: 600;
322
+ letter-spacing: 2rpx;
323
+ background-color: $primary;
324
+ color: #fff;
325
+ border: none;
326
+ display: flex;
327
+ align-items: center;
328
+ justify-content: center;
329
+ transition: background-color 0.2s;
330
+ box-shadow: 0 4rpx 12rpx rgba(7, 193, 96, 0.3);
331
+
332
+ &:active {
333
+ background-color: $primary-dark;
334
+ }
335
+ }
336
+ }
337
+ </style>
338
+
339
+ <script type="application/json">
340
+ {
341
+ "component": true,
342
+ "usingComponents": {}
343
+ }
344
+ </script>
@@ -2,32 +2,46 @@
2
2
  <view class="auth-user-box">
3
3
  <block wx:if="{{ token }}">
4
4
  <view class="auth-user-l">
5
- <image src="{{ baseUrl+'/v1/file/image/clip/200/200/' + userInfo.avatar }}" class="avatar-img"
6
- wx:if="{{ userInfo.avatar }}"></image>
7
- <image src="{{ resourceUrl + '/images/mall/' + defaultAvatar }}" class="avatar-img" style="border-radius:50%"
8
- wx:elif="{{ defaultAvatar }}"></image>
9
- <image src="{{ resourceUrl }}/images/mall/tswk.png" class="avatar-img" wx:else></image>
5
+ <!-- 头像 -->
6
+ <view class="avatar-wrapper" bind:tap="handleUpdateUser">
7
+ <image src="{{ baseUrl+'/v1/file/image/clip/200/200/' + userInfo.avatar }}" class="avatar-img"
8
+ wx:if="{{ userInfo.avatar }}" mode="aspectFill"></image>
9
+ <image src="{{ resourceUrl + '/images/mall/' + defaultAvatar }}" class="avatar-img"
10
+ wx:elif="{{ defaultAvatar }}" mode="aspectFill"></image>
11
+ <image src="{{ resourceUrl }}/images/mall/tswk.png" class="avatar-img" wx:else mode="aspectFill"></image>
12
+ <view class="avatar-badge">
13
+ <text class="badge-icon">✎</text>
14
+ </view>
15
+ </view>
16
+
17
+ <!-- 用户信息 -->
10
18
  <view class="auth-user-r">
11
- <view class="user-edit">{{ userInfo.realName }}
12
- <image src="{{ resourceUrl }}/images/mall/book/icon/user_edit_icon.png" class="edit_icon"
13
- bind:tap="handleUpdateUser">
14
- </image>
19
+ <view class="user-edit" bind:tap="handleUpdateUser">
20
+ <text class="user-name">{{ userInfo.realName }}</text>
21
+ <text class="edit-icon">✎</text>
15
22
  </view>
16
23
  <text class="user-mobile">{{ userInfo.mobilePhoneIns }}</text>
17
24
  </view>
18
25
  </view>
19
26
  </block>
20
- <view class="auth-user-l" wx:else>
21
- <image src="{{ resourceUrl }}/images/mall/tswk.png" class="avatar-img"></image>
22
- <text bind:tap="handleLogin">登录</text>
27
+
28
+ <!-- 未登录状态 -->
29
+ <view class="auth-user-l not-logged-in" wx:else>
30
+ <image src="{{ resourceUrl }}/images/mall/tswk.png" class="avatar-img" mode="aspectFill"></image>
31
+ <view class="auth-user-r">
32
+ <view class="login-btn" bind:tap="handleLogin">
33
+ <text class="login-text">登录</text>
34
+ </view>
35
+ </view>
23
36
  </view>
24
37
  </view>
25
38
  </template>
26
39
 
27
- <script>
40
+ <script lang="ts">
28
41
  import mpx, { createComponent, ref, onShow } from '@mpxjs/core'
29
42
  import { db } from '../../utils/db';
30
- import { authApi } from '../../api/auth/index';
43
+ import { auth } from "../../utils/auth";
44
+ import { UserInfo } from "../../api/auth/types";
31
45
 
32
46
  createComponent({
33
47
  properties: {
@@ -35,32 +49,52 @@ createComponent({
35
49
  type: String,
36
50
  value: ''
37
51
  },
52
+ backurl: {
53
+ type: String,
54
+ value: '/pages/home'
55
+ },
56
+ tabbar: {
57
+ type: String,
58
+ value: 'false'
59
+ }
38
60
  },
39
61
  setup(props, context) {
40
62
  let config = getApp().globalData.config;
41
63
  let resourceUrl = ref(config.resourceUrl);
42
64
  let baseUrl = ref(config.baseUrl);
43
65
  let token = ref('');
44
- let userInfo = ref({});
45
-
46
- onShow(() => {
47
- token.value = db.getToken();
48
- authApi.userInfo().then((resp) => {
49
- userInfo.value = resp.data;
50
- })
51
- })
66
+ let userInfo = ref({} as UserInfo);
67
+ let refreshFunc = () => {
68
+ // 检查登录是否有效?
69
+ if (auth.checkLogin()) {
70
+ token.value = db.getToken();
71
+ auth.getUserInfo().then((resp) => {
72
+ userInfo.value = resp;
73
+ })
74
+ }
75
+ };
76
+ onShow(refreshFunc);
52
77
  console.log(resourceUrl);
53
- return { resourceUrl, baseUrl, token, userInfo };
78
+ return { resourceUrl, baseUrl, token, userInfo, refreshFunc };
54
79
  },
55
80
  methods: {
56
81
  handleLogin() {
57
- mpx.navigateTo({
58
- url: '/jmash/pages/auth/login'
59
- })
82
+ console.log("handleLogin");
83
+ //检查登录并跳转登录
84
+ auth.loginOnlyAC().then(() => {
85
+ //登录成功,加载业务
86
+ console.log("静默登录成功");
87
+ this.refreshFunc();
88
+ }).catch(() => {
89
+ console.log("登录失败!");
90
+ mpx.navigateTo({
91
+ url: '/jmash/pages/auth/login' + "?backurl=" + encodeURIComponent(this.properties.backurl) + "&tabbar=" + this.properties.tabbar
92
+ })
93
+ });
60
94
  },
61
95
  handleUpdateUser() {
62
96
  mpx.navigateTo({
63
- url: '/pages/user/index'
97
+ url: '/jmash/pages/auth/update-user'
64
98
  })
65
99
  },
66
100
  }
@@ -71,41 +105,113 @@ createComponent({
71
105
  <style lang="scss">
72
106
  @use "../../styles/index.scss" as *;
73
107
 
108
+ // 颜色变量
109
+ $primary: #07c160;
110
+ $text-1: #111111;
111
+ $text-2: #666666;
112
+ $text-3: #999999;
113
+ $border: #e8e8e8;
114
+ $bg-page: #f5f5f5;
115
+ $bg-card: #ffffff;
116
+
74
117
  .auth-user-box {
75
118
  display: flex;
76
119
  align-items: center;
77
- padding: 30rpx 0 30rpx 30rpx;
120
+ padding: 48rpx 32rpx;
121
+ background-color: $bg-card;
78
122
 
79
123
  .auth-user-l {
80
124
  display: flex;
81
125
  align-items: center;
82
- font-size: 30rpx;
83
- font-weight: bold;
126
+ flex: 1;
84
127
 
85
- .avatar-img {
86
- width: 120rpx;
87
- height: 120rpx;
88
- border-radius: $border-max-radius;
89
- margin-right: 20rpx;
128
+ .avatar-wrapper {
129
+ position: relative;
130
+ margin-right: 24rpx;
131
+ flex-shrink: 0;
132
+
133
+ .avatar-img {
134
+ width: 104rpx;
135
+ height: 104rpx;
136
+ border-radius: 50%;
137
+ background-color: $bg-page;
138
+ display: block;
139
+ }
140
+
141
+ .avatar-badge {
142
+ position: absolute;
143
+ right: -2rpx;
144
+ bottom: -2rpx;
145
+ width: 32rpx;
146
+ height: 32rpx;
147
+ background: $primary;
148
+ border-radius: 50%;
149
+ border: 2rpx solid $bg-card;
150
+ display: flex;
151
+ align-items: center;
152
+ justify-content: center;
153
+
154
+ .badge-icon {
155
+ font-size: 14rpx;
156
+ color: #fff;
157
+ }
158
+ }
90
159
  }
91
160
  }
92
161
 
93
162
  .auth-user-r {
163
+ flex: 1;
164
+ min-width: 0;
165
+
94
166
  .user-edit {
95
167
  display: flex;
96
168
  align-items: center;
169
+ margin-bottom: 8rpx;
170
+ cursor: pointer;
171
+
172
+ .user-name {
173
+ font-size: 34rpx;
174
+ font-weight: 600;
175
+ color: $text-1;
176
+ line-height: 1.2;
177
+ }
97
178
 
98
- .edit_icon {
99
- width: 34rpx;
100
- height: 34rpx;
179
+ .edit-icon {
180
+ font-size: 18rpx;
181
+ color: $text-3;
101
182
  margin-left: 10rpx;
102
183
  }
103
184
  }
104
185
 
105
186
  .user-mobile {
106
- font-size: $font-size;
107
- color: $font-color-grey;
108
- font-weight: 500;
187
+ font-size: 26rpx;
188
+ color: $text-2;
189
+ line-height: 1.4;
190
+ }
191
+ }
192
+
193
+ // 未登录状态
194
+ .not-logged-in {
195
+ .avatar-img {
196
+ opacity: 0.5;
197
+ margin-right: 24rpx;
198
+ }
199
+
200
+ .auth-user-r {
201
+ .login-btn {
202
+ display: flex;
203
+ align-items: center;
204
+ padding: 16rpx 32rpx;
205
+ background-color: $primary;
206
+ border-radius: 40rpx;
207
+ cursor: pointer;
208
+
209
+ .login-text {
210
+ font-size: 28rpx;
211
+ font-weight: 500;
212
+ color: #fff;
213
+ }
214
+ }
109
215
  }
110
216
  }
111
217
  }
@@ -116,4 +222,4 @@ createComponent({
116
222
  "component": true,
117
223
  "usingComponents": {}
118
224
  }
119
- </script>
225
+ </script>
@@ -2,6 +2,7 @@
2
2
  {
3
3
  "pages": [
4
4
  "./pages/auth/login",
5
+ "./pages/auth/update-user",
5
6
  "./pages/auth/cms-protocol"
6
7
  ]
7
8
  }
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <jmash-login tabbar="{{ tabbar }}" backurl="{{ backurl }}">
2
+ <jmash-login linkType="{{ linkType }}" backurl="{{ backurl }}">
3
3
  <image mode="widthFix" src="{{ resourceUrl }}/images/login_bg.png" class="index_bj" slot="before">
4
4
  <image mode="widthFix" src="{{ resourceUrl }}/images/logo.png" class="login_logo"></image>
5
5
  </image>
@@ -11,13 +11,23 @@
11
11
  import { createPage, ref } from '@mpxjs/core'
12
12
 
13
13
  createPage({
14
+ properties: {
15
+ tabbar: {
16
+ type: String,
17
+ value: 'false'
18
+ },
19
+ backurl: {
20
+ type: String,
21
+ value: '/pages/home'
22
+ }
23
+ },
14
24
  setup(props) {
15
25
  let resourceUrl = ref(getApp().globalData.config.resourceUrl);
16
26
  let appName = ref(getApp().globalData.config.name);
17
- let tabbar = ref(props.tabbar === 'true');
18
- let backurl = ref(props.backurl || '');
19
- console.log(appName);
20
- return { resourceUrl, appName, tabbar, backurl };
27
+ let linkType = ref(props.tabbar === 'true' ? "switchTab" : "redirectTo");
28
+ let backurl = ref(props.backurl);
29
+ console.log(appName, linkType, backurl);
30
+ return { resourceUrl, appName, linkType, backurl };
21
31
  }
22
32
  })
23
33
  </script>
@@ -0,0 +1,18 @@
1
+ <template>
2
+ <jmash-update-user></jmash-update-user>
3
+ </template>
4
+
5
+ <script>
6
+ import { createPage } from '@mpxjs/core'
7
+ createPage({})
8
+ </script>
9
+
10
+ <style lang="scss"></style>
11
+
12
+ <script type="application/json">
13
+ {
14
+ "usingComponents": {
15
+ "jmash-update-user": "../../../components/auth-user/jmash-update-user.mpx"
16
+ }
17
+ }
18
+ </script>
@@ -6,17 +6,20 @@
6
6
 
7
7
  <script>
8
8
  import { createPage } from '@mpxjs/core'
9
- import { db } from '../utils/db'
10
9
  import mpx from '@mpxjs/core'
10
+ import { auth } from "../utils/auth.ts";
11
11
 
12
12
  createPage({
13
13
  setup() {
14
- // 无法退回,检查登录状态
15
- if (!db.getToken()) {
14
+ //检查登录并跳转登录
15
+ auth.loginOnlyAC().then(() => {
16
+ //登录成功,加载业务
17
+ console.log("静默登录成功");
18
+ }).catch(() => {
16
19
  mpx.navigateTo({
17
20
  url: '/jmash/pages/auth/login'
18
21
  })
19
- }
22
+ });
20
23
  return {}
21
24
  }
22
25
  })
@@ -13,10 +13,9 @@ import { auth } from '../../utils/auth'
13
13
 
14
14
  createPage({
15
15
  onShow() {
16
- console.log(this.getTabBar);
17
16
  if (typeof this.getTabBar === 'function' &&
18
17
  this.getTabBar()) {
19
- console.log(this.getTabBar().$refs.tabBar.activeTab("Home"));
18
+ this.getTabBar().$refs.tabBar.activeTab("Home");
20
19
  }
21
20
  },
22
21
  methods: {
@@ -1,6 +1,6 @@
1
1
  <template>
2
2
  <view class="basic-component-page">
3
- <jmash-user></jmash-user>
3
+ <jmash-user tabbar="true" backurl="/pages/tabbar/my"></jmash-user>
4
4
  <text>{{ title }}</text>
5
5
  </view>
6
6
  </template>
@@ -13,10 +13,9 @@ createPage({
13
13
  title: 'MY',
14
14
  },
15
15
  onShow() {
16
- console.log(this.getTabBar);
17
16
  if (typeof this.getTabBar === 'function' &&
18
17
  this.getTabBar()) {
19
- console.log(this.getTabBar().$refs.tabBar.activeTab("My"));
18
+ this.getTabBar().$refs.tabBar.activeTab("My");
20
19
  }
21
20
  }
22
21
  })
package/src/utils/auth.ts CHANGED
@@ -1,5 +1,4 @@
1
- import { config } from "./config";
2
- import { db } from "./db";
1
+ import mpx from "@mpxjs/core";
3
2
  import { authApi } from "../api/auth/index";
4
3
  import {
5
4
  LoginReq,
@@ -9,7 +8,8 @@ import {
9
8
  UserInfo,
10
9
  } from "../api/auth/types";
11
10
  import { ResponseData } from "../types/core";
12
- import mpx from "@mpxjs/core";
11
+ import { config } from "./config";
12
+ import { db } from "./db";
13
13
 
14
14
  // 认证
15
15
  class Auth {
@@ -76,6 +76,7 @@ class Auth {
76
76
  if (db.getToken() && !db.isTokenExpires()) {
77
77
  return true;
78
78
  }
79
+
79
80
  return false;
80
81
  }
81
82
 
@@ -133,6 +134,7 @@ class Auth {
133
134
  response.statusCode === 200 &&
134
135
  response.data.status === true
135
136
  ) {
137
+ console.log("silentLogin-res", response);
136
138
  db.setToken(response.data.token);
137
139
  console.log("login success");
138
140
  this.getUserInfo(false);
@@ -161,7 +163,7 @@ class Auth {
161
163
  // 手机号code 注册登录
162
164
  phoneCodeLogin(phoneCode: string, nickName: string = ""): Promise<LoginRes> {
163
165
  return new Promise<LoginRes>((resolve, reject) => {
164
- wx.login({
166
+ mpx.login({
165
167
  success: (res) => {
166
168
  // 发送 res.code 到后台换取 openId, sessionKey, unionId
167
169
  if (res.code) {
@@ -3,7 +3,7 @@ import { AppConfig } from "../types/core";
3
3
  const config: AppConfig = {
4
4
  name: "Jmash Core MPX",
5
5
  dev: true,
6
- testNewUser: true,
6
+ testNewUser: false,
7
7
  tenant: "xyvcard",
8
8
  baseUrl: "https://mm.sooyie.cn",
9
9
  resourceUrl: "https://mm.sooyie.cn/v1/file/path/wxapp",
@@ -17,7 +17,7 @@ const config: AppConfig = {
17
17
 
18
18
  if (__mpx_mode__ === "wx") {
19
19
  // 微信
20
- config.appId = "wx2a8b3d689b8959eb";
20
+ config.appId = "wx2a8b3d689b8959eb1";
21
21
  } else if (__mpx_mode__ === "ali") {
22
22
  // 支付宝
23
23
  config.appId = "2016102700684542";
@@ -19,8 +19,7 @@ mpx.xfetch.interceptors.request.use(function (config) {
19
19
  if (!config.url.startsWith("http")) {
20
20
  config.url = appconfig.baseUrl + config.url;
21
21
  }
22
- console.log(config);
23
-
22
+ console.log("request:", config);
24
23
  // Grpc Gateway 清理默认值,Enum,时间等不能空;
25
24
  grpc.clearEmpty(config.params);
26
25
  grpc.clearEmpty(config.data);
@@ -28,7 +27,10 @@ mpx.xfetch.interceptors.request.use(function (config) {
28
27
  config.header = {};
29
28
  }
30
29
  //配置其他认证请求头信息
31
- if (config.header.Authorization && config.header.Authorization === false) {
30
+ if (
31
+ config.header.Authorization !== undefined &&
32
+ config.header.Authorization === false
33
+ ) {
32
34
  delete config.header.Authorization;
33
35
  return config;
34
36
  }
@@ -40,7 +42,6 @@ mpx.xfetch.interceptors.request.use(function (config) {
40
42
  }
41
43
  // 请求设置token和租户
42
44
  const expire = db.isTokenExpires();
43
- console.log("expire", expire);
44
45
  if (!expire) {
45
46
  config.header["Authorization"] = "Bearer " + db.getToken();
46
47
  const organTenant = db.getOrganTenant(config.tenant);
@@ -49,7 +50,9 @@ mpx.xfetch.interceptors.request.use(function (config) {
49
50
  } else {
50
51
  delete config.header["Grpc-Metadata-Tenant"];
51
52
  }
52
- console.log(config);
53
+ //console.log("header:", config.header);
54
+ } else {
55
+ console.log("token expire", expire);
53
56
  }
54
57
 
55
58
  const isRefreshToken = config.url.endsWith("/v1/rbac/auth/refresh_token");
@@ -61,6 +64,7 @@ mpx.xfetch.interceptors.request.use(function (config) {
61
64
  refreshToken(db.getRefreshToken())
62
65
  .then((res) => {
63
66
  // token 刷新后将数组的方法重新执行
67
+ console.log("refreshToken-res", res);
64
68
  db.setToken(res.data);
65
69
  requests.forEach((cb) => cb(res.data.accessToken));
66
70
  requests = []; // 刷新完清空
@@ -117,6 +121,7 @@ function refreshToken(refreshToken: string) {
117
121
  tenant: appconfig.tenant,
118
122
  clientId: appconfig.appId,
119
123
  },
124
+ header: { Authorization: false },
120
125
  });
121
126
  }
122
127
 
@@ -1,31 +0,0 @@
1
- <template>
2
- <view class="update-user-component">
3
- <text>用户信息更新组件</text>
4
- </view>
5
- </template>
6
-
7
- <script>
8
- import { createComponent } from '@mpxjs/core'
9
-
10
- createComponent({
11
- data: {
12
- title: '用户信息更新'
13
- }
14
- })
15
- </script>
16
-
17
- <style lang="scss">
18
- .update-user-component {
19
- padding: 40rpx;
20
- text-align: center;
21
- font-size: 32rpx;
22
- color: #333;
23
- }
24
- </style>
25
-
26
- <script type="application/json">
27
- {
28
- "component": true,
29
- "usingComponents": {}
30
- }
31
- </script>
@@ -1,31 +0,0 @@
1
- <template>
2
- <view class="avatar-edit-component">
3
- <text>头像编辑组件</text>
4
- </view>
5
- </template>
6
-
7
- <script>
8
- import { createComponent } from '@mpxjs/core'
9
-
10
- createComponent({
11
- data: {
12
- title: '头像编辑'
13
- }
14
- })
15
- </script>
16
-
17
- <style lang="scss">
18
- .avatar-edit-component {
19
- padding: 40rpx;
20
- text-align: center;
21
- font-size: 32rpx;
22
- color: #333;
23
- }
24
- </style>
25
-
26
- <script type="application/json">
27
- {
28
- "component": true,
29
- "usingComponents": {}
30
- }
31
- </script>