jmash-core-mp 0.1.1 → 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 +1 -1
- package/src/api/auth/index.ts +4 -1
- package/src/api/files/index.ts +29 -39
- package/src/app.mpx +4 -3
- package/src/components/auth-user/jmash-update-user.mpx +344 -0
- package/src/components/auth-user/jmash-user.mpx +126 -36
- package/src/packages/index.mpx +1 -0
- package/src/packages/pages/auth/update-user.mpx +18 -0
- package/src/pages/tabbar/home.mpx +1 -2
- package/src/pages/tabbar/my.mpx +1 -2
- package/src/utils/auth.ts +6 -4
- package/src/utils/request.ts +10 -5
- package/src/components/auth-user/jmash-update-user/index.mpx +0 -31
- package/src/components/common/auth-avatar/avatar-edit/index.mpx +0 -31
- /package/src/components/common/{auth-search/index.mpx → auth-search.mpx} +0 -0
package/package.json
CHANGED
package/src/api/auth/index.ts
CHANGED
|
@@ -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: {
|
|
24
|
+
header: {
|
|
25
|
+
"content-type": "application/json",
|
|
26
|
+
Authorization: false,
|
|
27
|
+
},
|
|
25
28
|
});
|
|
26
29
|
}
|
|
27
30
|
// 手机号注册登录
|
package/src/api/files/index.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
126
|
+
const p = mpx.downloadFile({
|
|
136
127
|
url: url,
|
|
137
128
|
header: {
|
|
138
129
|
Authorization: db.getBearerToken(),
|
|
139
130
|
},
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
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,14 +1,15 @@
|
|
|
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
|
-
|
|
10
|
-
import apiProxy from '@mpxjs/api-proxy';
|
|
11
|
-
mpx.use(apiProxy, { usePromise: true })
|
|
12
|
+
|
|
12
13
|
createApp({
|
|
13
14
|
globalData: {
|
|
14
15
|
config: config
|
|
@@ -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,33 +2,46 @@
|
|
|
2
2
|
<view class="auth-user-box">
|
|
3
3
|
<block wx:if="{{ token }}">
|
|
4
4
|
<view class="auth-user-l">
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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">
|
|
12
|
-
<
|
|
13
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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 {
|
|
31
|
-
import {
|
|
43
|
+
import { auth } from "../../utils/auth";
|
|
44
|
+
import { UserInfo } from "../../api/auth/types";
|
|
32
45
|
|
|
33
46
|
createComponent({
|
|
34
47
|
properties: {
|
|
@@ -50,12 +63,15 @@ createComponent({
|
|
|
50
63
|
let resourceUrl = ref(config.resourceUrl);
|
|
51
64
|
let baseUrl = ref(config.baseUrl);
|
|
52
65
|
let token = ref('');
|
|
53
|
-
let userInfo = ref({});
|
|
66
|
+
let userInfo = ref({} as UserInfo);
|
|
54
67
|
let refreshFunc = () => {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
68
|
+
// 检查登录是否有效?
|
|
69
|
+
if (auth.checkLogin()) {
|
|
70
|
+
token.value = db.getToken();
|
|
71
|
+
auth.getUserInfo().then((resp) => {
|
|
72
|
+
userInfo.value = resp;
|
|
73
|
+
})
|
|
74
|
+
}
|
|
59
75
|
};
|
|
60
76
|
onShow(refreshFunc);
|
|
61
77
|
console.log(resourceUrl);
|
|
@@ -63,12 +79,14 @@ createComponent({
|
|
|
63
79
|
},
|
|
64
80
|
methods: {
|
|
65
81
|
handleLogin() {
|
|
82
|
+
console.log("handleLogin");
|
|
66
83
|
//检查登录并跳转登录
|
|
67
84
|
auth.loginOnlyAC().then(() => {
|
|
68
85
|
//登录成功,加载业务
|
|
69
86
|
console.log("静默登录成功");
|
|
70
87
|
this.refreshFunc();
|
|
71
88
|
}).catch(() => {
|
|
89
|
+
console.log("登录失败!");
|
|
72
90
|
mpx.navigateTo({
|
|
73
91
|
url: '/jmash/pages/auth/login' + "?backurl=" + encodeURIComponent(this.properties.backurl) + "&tabbar=" + this.properties.tabbar
|
|
74
92
|
})
|
|
@@ -76,7 +94,7 @@ createComponent({
|
|
|
76
94
|
},
|
|
77
95
|
handleUpdateUser() {
|
|
78
96
|
mpx.navigateTo({
|
|
79
|
-
url: '/pages/user
|
|
97
|
+
url: '/jmash/pages/auth/update-user'
|
|
80
98
|
})
|
|
81
99
|
},
|
|
82
100
|
}
|
|
@@ -87,41 +105,113 @@ createComponent({
|
|
|
87
105
|
<style lang="scss">
|
|
88
106
|
@use "../../styles/index.scss" as *;
|
|
89
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
|
+
|
|
90
117
|
.auth-user-box {
|
|
91
118
|
display: flex;
|
|
92
119
|
align-items: center;
|
|
93
|
-
padding:
|
|
120
|
+
padding: 48rpx 32rpx;
|
|
121
|
+
background-color: $bg-card;
|
|
94
122
|
|
|
95
123
|
.auth-user-l {
|
|
96
124
|
display: flex;
|
|
97
125
|
align-items: center;
|
|
98
|
-
|
|
99
|
-
font-weight: bold;
|
|
126
|
+
flex: 1;
|
|
100
127
|
|
|
101
|
-
.avatar-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
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
|
+
}
|
|
106
159
|
}
|
|
107
160
|
}
|
|
108
161
|
|
|
109
162
|
.auth-user-r {
|
|
163
|
+
flex: 1;
|
|
164
|
+
min-width: 0;
|
|
165
|
+
|
|
110
166
|
.user-edit {
|
|
111
167
|
display: flex;
|
|
112
168
|
align-items: center;
|
|
169
|
+
margin-bottom: 8rpx;
|
|
170
|
+
cursor: pointer;
|
|
113
171
|
|
|
114
|
-
.
|
|
115
|
-
|
|
116
|
-
|
|
172
|
+
.user-name {
|
|
173
|
+
font-size: 34rpx;
|
|
174
|
+
font-weight: 600;
|
|
175
|
+
color: $text-1;
|
|
176
|
+
line-height: 1.2;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
.edit-icon {
|
|
180
|
+
font-size: 18rpx;
|
|
181
|
+
color: $text-3;
|
|
117
182
|
margin-left: 10rpx;
|
|
118
183
|
}
|
|
119
184
|
}
|
|
120
185
|
|
|
121
186
|
.user-mobile {
|
|
122
|
-
font-size:
|
|
123
|
-
color: $
|
|
124
|
-
|
|
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
|
+
}
|
|
125
215
|
}
|
|
126
216
|
}
|
|
127
217
|
}
|
|
@@ -132,4 +222,4 @@ createComponent({
|
|
|
132
222
|
"component": true,
|
|
133
223
|
"usingComponents": {}
|
|
134
224
|
}
|
|
135
|
-
</script>
|
|
225
|
+
</script>
|
package/src/packages/index.mpx
CHANGED
|
@@ -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>
|
|
@@ -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
|
-
|
|
18
|
+
this.getTabBar().$refs.tabBar.activeTab("Home");
|
|
20
19
|
}
|
|
21
20
|
},
|
|
22
21
|
methods: {
|
package/src/pages/tabbar/my.mpx
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
166
|
+
mpx.login({
|
|
165
167
|
success: (res) => {
|
|
166
168
|
// 发送 res.code 到后台换取 openId, sessionKey, unionId
|
|
167
169
|
if (res.code) {
|
package/src/utils/request.ts
CHANGED
|
@@ -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 (
|
|
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>
|
|
File without changes
|