set.vue
9.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<template>
<view class="set-page">
<!-- 公共组件-每个页面必须引入 -->
<public-module></public-module>
<view @click="upAvatar" class="u-flex set-main">
<view class="main-image">
<image class="image" :src="avatar || '../../static/logo.png'"></image>
</view>
<view class="main-right-image">
<image class="image" src="../../static/arrow-right.png"></image>
</view>
</view>
<view class="u-m-t-20 basic-text"><text class="text">基本资料</text></view>
<view class="basic-main">
<u--form labelPosition="left" :model="myInfoModel" ref="myForm">
<u-form-item labelWidth="80px" label="真实姓名" prop="realName" borderBottom ref="item1">
<u--input placeholder="请输入真实姓名" v-model="myInfoModel.realName" border="none"></u--input>
</u-form-item>
<u-form-item labelWidth="80px" label="手机号码" prop="phoneNumber" borderBottom ref="item1">
<u--input placeholder="请输入手机号码" v-model="myInfoModel.phoneNumber" border="none"></u--input>
</u-form-item>
<u-form-item labelWidth="80px" label="用户账号" prop="username" borderBottom ref="item1">
<u--input disabled placeholder="请输入用户账号 " v-model="myInfoModel.username" border="none"></u--input>
</u-form-item>
<u-form-item labelWidth="80px" label="邮箱地址" prop="email" borderBottom ref="item1">
<u--input placeholder="请输入邮箱地址" v-model="myInfoModel.email" border="none"></u--input>
</u-form-item>
<u-form-item @click="
showDate = true;
hideKeyboard();
" labelWidth="80px" label="有效期" prop="accountExpireTime" ref="item1">
<u--input v-model="myInfoModel.accountExpireTime" placeholder="请选择有效期" border="none"></u--input>
<u-datetime-picker :formatter="formatter" :show="showDate" :value="datetime" mode="dateTime"
closeOnClickOverlay @confirm="dateConfirm" @cancel="dateClose" @close="dateClose">
</u-datetime-picker>
</u-form-item>
</u--form>
</view>
<view class="basic-bottom u-flex">
<view class="item" v-if="info.data.isThirdLoginAndNoDind && isJudgeBindBtn">
<button class="submit" size="default" @click="clearAccountFunc" :style="{ background: InfoColor }"><text
class="un-bind-text">解绑</text></button>
</view>
<view class="item" style="margin-right: 60rpx;" :style="[
{ position: info.data.isThirdLoginAndNoDind && isJudgeBindBtn ? '' : 'relative' },
{ right: info.data.isThirdLoginAndNoDind && isJudgeBindBtn ? '' : '-190rpx' }
]">
<button class="submit" size="default" @click="onSubmitFunc" :style="{ background: PrimaryColor }"><text
class="un-bind-text">确认</text></button>
</view>
</view>
<!-- #ifdef MP -->
<view class="u-m-t-40"><text style="visibility: hidden;">#</text></view>
<!-- #endif -->
<!-- 解绑账号 -->
<view>
<u-popup bgColor="transparent" :overlay="true" :show="showBind" mode="bottom">
<view class="u-flex logout-main">
<view class="main"><text style="color: #999999">是否需要解除绑定的账号?</text></view>
<view @click="confrimBind(info)" class="main"><text style="color: #f95e5a">是</text></view>
<view @click="showBind = false" class="main1"><text style="color: #3478f7">否</text></view>
</view>
</u-popup>
</view>
<!-- 解绑账号 -->
</view>
</template>
<script>
import {
mapMutations
} from 'vuex';
import baseUrl from '@/config/baseUrl.js';
import {
mapState
} from 'vuex';
import api from '@/api/index.js'
export default {
data() {
return {
showBind: false,
PrimaryColor: '#377DFF', //主题色
InfoColor: '#00C9A7', //主题色
myInfoModel: {
realName: '',
phoneNumber: '',
username: '',
email: '',
accountExpireTime: ''
},
rules: {
phoneNumber: [{
required: true,
message: '请输入正确的手机号码',
trigger: 'change'
},
{
pattern: /^1[3-9][0-9]{9}$/,
message: '请输入正确的手机号码'
}
],
email: [{
required: true,
message: '请输入正确的邮箱号',
trigger: 'change'
},
{
pattern: /^[0-9a-zA-Z]+@(([0-9a-zA-Z]+)[.])+[a-z]{3}$/,
message: '请输入正确的邮箱号'
}
]
},
showDate: false,
dateTime: Number(new Date()),
avatar: '',
id: '',
info: {},
openIds: '',
isUpdatePersonOrLoginInfo: false,
isJudgeBindBtn: true
};
},
onReady() {
this.$refs.myForm.setRules(this.rules);
},
onLoad(e) {
console.log(e);
if (e.data !== null) {
let params = JSON.parse(e.data);
this.info = params;
this.myInfoModel.realName = params.data.realName;
this.myInfoModel.phoneNumber = params.data.phoneNumber;
this.myInfoModel.username = params.data.username;
this.myInfoModel.email = params.data.email;
this.myInfoModel.accountExpireTime = params.data.accountExpireTime;
this.avatar = params.data.avatar == undefined ? '../../static/logo.png' : params.data.avatar;
this.id = params.data.userId;
}
},
onShow() {
let getOpenId = getApp().globalData.openId;
if (getOpenId) {
this.openIds = getOpenId;
console.log('OPenid', this.openIds);
}
},
computed: {
...mapState(['userInfo'])
},
methods: {
...mapMutations(['setUserInfo', 'emptyUserInfo']),
confrimBind(e) {
if (e) {
//解绑
let httpData = {
appUserId: e.data?.userId,
thirdUserId: e.data?.thirdUserId == null ? this.openIds : e.data?.thirdUserId
};
api.loginApi.deleteBindApi(httpData).then(res => {
if (res) {
uni.showToast({
title: '解绑成功'
});
this.showBind = false;
this.isJudgeBindBtn = false;
uni.reLaunch({
url: '/publicLoginSubPage/public/login'
});
this.emptyUserInfo();
} else {
uni.showToast({
title: '解绑失败'
});
this.showBind = false;
}
});
}
},
clearAccountFunc() {
this.showBind = true;
},
// 修改头像
async upAvatar() {
let token;
token = this.userInfo.isToken || uni.getStorageSync('userInfo').isToken || undefined;
// #ifdef H5
token = window.sessionStorage.getItem('userInfo').isToken;
// #endif
if (!token) return uni.$u.toast('请登录后上传图片');
uni.chooseImage({
count: 1,
sourceType: ['camera', 'album'],
success: res => {
const tempFilePaths = res.tempFilePaths;
//限制上传的图片大小不超过5M
let resSize = res.tempFiles[0].size;
if (resSize > 5242880) {
uni.showToast({
title: '上传的图片大小不能超过5M',
icon: 'none',
duration: 2000,
mask: true
});
return;
}
//获取图片扩展名
const fileTxt = res.tempFilePaths[0].split('.').pop();
const judgeType = fileTxt == 'jpg' || fileTxt == 'jpeg' || fileTxt == 'png';
if (!judgeType) {
uni.showToast({
title: '请上传指定图片类型(jpg、jpeg、png)',
icon: 'none',
duration: 2000,
mask: true
});
return;
}
uni.uploadFile({
url: `${baseUrl.baseUrl}/yt/oss/upload`,
filePath: tempFilePaths[0],
name: 'file',
header: {
'content-type': 'multipart/form-data',
Authorization: 'Bearer ' + token
},
formData: {},
success: res => {
let objImage = JSON.parse(res.data);
this.avatar = objImage.fileStaticUri;
uni.$u.toast('头像上传成功');
}
});
}
});
},
onSubmitFunc() {
let httpData = {
avatar: this.avatar,
email: this.myInfoModel.email,
id: this.id,
phoneNumber: this.myInfoModel.phoneNumber,
realName: this.myInfoModel.realName
};
this.$refs.myForm
.validate()
.then(async res => {
const resp = await api.loginApi.postPersonalInfoApi(httpData)
if (res) {
this.setUserInfo(resp);
uni.showToast({
title: '更新个人资料成功~',
icon: 'none'
});
setTimeout(() => {
uni.navigateBack({
delta: 1
});
}, 500);
}
})
.catch(errors => {
uni.$u.toast('校验失败');
});
},
dateClose() {
this.showDate = false;
},
dateConfirm(e) {
this.showDate = false;
this.myInfoModel.userInfo.accountExpireTime = uni.$u.timeFormat(e.value, 'yyyy-mm-dd hh:MM:ss');
},
//格式化日期
formatter(type, value) {
if (type === 'year') {
return `${value}年`;
}
if (type === 'month') {
return `${value}月`;
}
if (type === 'day') {
return `${value}日`;
}
if (type === 'hour') {
return `${value}时`;
}
if (type === 'minute') {
return `${value}分`;
}
return value;
},
//隐藏输入框
hideKeyboard() {
uni.hideKeyboard();
}
}
};
</script>
<style lang="scss" scoped>
.userName {
background-color: green;
}
@import './static/set.scss';
/deep/ .u-line {
width: 662rpx !important;
}
/deep/ .u-form-item {
height: 100rpx !important;
}
/deep/ .u-form-item:nth-child(3) {
.u-form-item__body {
background: #f5f7fa !important;
width: 663rpx !important;
}
}
</style>