-
Notifications
You must be signed in to change notification settings - Fork 0
/
userinfo.html
executable file
·396 lines (351 loc) · 12.7 KB
/
userinfo.html
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
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0,maximum-scale=1.0, user-scalable=0">
<title>天天吃货 - 我的信息</title>
<link rel="shortcut icon" href="img/foodie.ico" />
<link href="AmazeUI-2.4.2/assets/css/admin.css" rel="stylesheet" type="text/css">
<link href="AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css">
<link href="css/personal.css" rel="stylesheet" type="text/css">
<link href="css/infstyle.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<!-- <link href="https://unpkg.com/v-calendar/lib/v-calendar.min.css" rel="stylesheet" type="text/css"> -->
<script src="AmazeUI-2.4.2/assets/js/jquery.min.js" type="text/javascript"></script>
<script src="AmazeUI-2.4.2/assets/js/amazeui.js" type="text/javascript"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.9/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="js/moment-with-locales.min.js"></script>
</head>
<body>
<form enctype="multipart/form-data">
</form>
<div id="userInfo">
<div class="nav-table">
<div class="long-title"><span class="all-goods" style="font-weight: bold;">用户中心</span></div>
</div>
<b class="line"></b>
<div class="center">
<div class="col-main">
<div class="main-wrap">
<div class="user-info">
<!--标题 -->
<div class="am-cf am-padding">
<div class="am-fl am-cf"><strong class="am-text-danger am-text-lg">个人资料</strong> / <small>Personal information</small></div>
</div>
<hr/>
<!--头像 -->
<div class="user-infoPic">
<div class="filePic">
<input type="file" id="userFace" @change="uploadFace" class="inputPic" allowexts="jpeg,jpg,png,gif" accept="image/gif,image/jpeg,image/jpg,image/png">
<img class="am-circle am-img-thumbnail" :src="userInfo.face" alt="" />
</div>
<p class="am-form-help">头像</p>
<div class="info-m">
<div style="margin-top: 20px;"><b>用户名:<i>{{userInfo.username}}</i></b></div>
</div>
</div>
<!--个人信息 -->
<div class="info-main" style="padding-bottom: 50px;">
<form class="am-form am-form-horizontal">
<div class="am-form-group">
<label for="user-name2" class="am-form-label">昵称</label>
<div class="am-form-content">
<input type="text" v-model="userInfoMore.nickname" placeholder="nickname" maxlength="12">
</div>
</div>
<div class="am-form-group">
<label for="user-name" class="am-form-label">真实姓名</label>
<div class="am-form-content">
<input type="text" v-model="userInfoMore.realname" placeholder="name" maxlength="12">
</div>
</div>
<div class="am-form-group">
<label class="am-form-label">性别</label>
<div class="am-form-content sex">
<label class="am-radio-inline">
<span v-if="userInfoMore.sex == 1">
<input type="radio" name="usersex" v-model="userInfoMore.sex" value="1" data-am-ucheck checked/> 男
</span>
<span v-else>
<input type="radio" name="usersex" v-model="userInfoMore.sex" value="1" data-am-ucheck/> 男
</span>
</label>
<label class="am-radio-inline">
<span v-if="userInfoMore.sex == 0">
<input type="radio" name="usersex" v-model="userInfoMore.sex" value="0" data-am-ucheck checked/> 女
</span>
<span v-else>
<input type="radio" name="usersex" v-model="userInfoMore.sex" value="0" data-am-ucheck> 女
</span>
</label>
<label class="am-radio-inline">
<span v-if="userInfoMore.sex == 2">
<input type="radio" name="usersex" v-model="userInfoMore.sex" value="2" data-am-ucheck checked/> 保密
</span>
<span v-else>
<input type="radio" name="usersex" v-model="userInfoMore.sex" value="2" data-am-ucheck> 保密
</span>
</label>
</div>
</div>
<div class="am-form-group">
<label for="user-birth" class="am-form-label">生日</label>
<div class="am-form-content birth">
<input type="text" id="datepicker" size="30">
</div>
</div>
<div class="am-form-group">
<label for="user-phone" class="am-form-label">手机</label>
<div class="am-form-content">
<input id="user-phone" v-model="userInfoMore.mobile" placeholder="mobile" type="tel" maxlength="11">
</div>
</div>
<div class="am-form-group">
<label for="user-email" class="am-form-label">电子邮件</label>
<div class="am-form-content">
<input id="user-email" v-model="userInfoMore.email" placeholder="email" type="email">
</div>
</div>
<div class="info-btn">
<div class="am-btn am-btn-danger" @click="saveUserInfo">保存修改</div>
</div>
</form>
</div>
</div>
</div>
<!--底部-->
<div class="footer ">
<div class="footer-hd ">
<p><a href="https://www.imooc.com/" target="_blank">慕课网</a> <b>|</b> <a
href="https://coding.imooc.com/class/217.html" target="_blank">分布式架构仿抖音短视频</a> <b>|</b>
<a href="https://coding.imooc.com/class/261.html" target="_blank">Netty仿微信聊天</a> <b>|</b> <a
href="https://coding.imooc.com/class/201.html" target="_blank">Zookeeper与dubbo入门</a>
<b>|</b> <a href="https://coding.imooc.com/class/293.html" target="_blank">支付宝小程序</a></p>
</div>
<div class="footer-bd ">
<p><em>© 2019 imooc.com 京ICP备12003892号-11 北京奥鹏文化传媒有限公司 版权所有</em></p>
</div>
</div>
</div>
<aside class="menu">
<ul>
<li class="person">
<span style="font-weight: bold;">
<a href="index.html">个人中心</a>
</span>
</li>
<li class="person">
<a href="#">个人资料</a>
<ul>
<li class="active"> <a href="userinfo.html">我的信息</a></li>
<li> <a href="address.html">收货地址</a></li>
</ul>
</li>
<li class="person">
<a href="#">我的交易</a>
<ul>
<li><a href="order.html">订单管理</a></li>
<li> <a href="comment.html">我的评价</a></li>
</ul>
</li>
</ul>
</aside>
</div>
</div>
<!-- <form enctype="multipart/form-data"></form> -->
<script type="text/javascript" src="js/app.js"></script>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#datepicker" ).datepicker({
dateFormat: "yy-mm-dd",
monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
dayNamesMin: ['日', '一', '二', '三', '四', '五', '六']
});
} );
</script>
<script type="text/javascript">
var index = new Vue({
el: "#userInfo",
data: {
userIsLogin: false,
userInfo: {},
userInfoMore: {},
userFace: null, // 用户头像
},
created() {
// var me = this;
// 通过cookie判断用户是否登录
this.judgeUserLoginStatus();
// 渲染用户信息
this.renderUserInfo();
},
methods: {
uploadFace(e) {
// let $target = e.target || e.srcElement;
// let file = $target.files[0];
let f = document.getElementById('userFace').files[0];
// console.log(f);
let multiForm = new FormData() ; //创建一个form对象
multiForm.append('file', f, f.name); //append 向form表单添加数据
var userInfo = this.userInfo;
// console.log(userInfo);
// 请求后端获得最新数据
var serverUrl = app.serverUrl;
axios.defaults.withCredentials = true;
axios.post(
serverUrl + '/userInfo/uploadFace?userId=' + userInfo.id,
multiForm,
{
headers: {
'Content-Type': 'multipart/form-data',
'headerUserId': userInfo.id,
'headerUserToken': userInfo.userUniqueToken
}
})
.then(res => {
if (res.data.status == 200) {
// var userInfoMore = res.data.data;
// console.log(userInfoMore);
alert("头像上传成功!");
window.location.reload();
} else {
alert(res.data.msg);
console.log(res.data.msg);
}
});
},
saveUserInfo() {
var userInfoMore = this.userInfoMore;
var nickname = userInfoMore.nickname;
if (nickname == null || nickname == "" || nickname == undefined) {
alert("昵称不能为空");
return;
}
if (nickname.length > 12) {
alert("昵称长度不能超过12位");
return;
}
var realname = userInfoMore.realname;
if (realname != null && realname != "" && realname != undefined) {
if (realname.length > 12) {
alert("真实姓名长度不能超过12位");
return;
}
}
var mobile = userInfoMore.mobile;
if (mobile != null && mobile != "" && mobile != undefined) {
if (mobile.length != 11) {
alert("手机号长度为11位");
return;
}
var checkMobile = app.checkMobile(mobile);
if (!checkMobile) {
alert('请输入有效的手机号码!');
return;
}
}
var email = userInfoMore.email;
if (email != null && email != "" && email != undefined) {
var checkEmail = app.checkEmail(email);
if (!checkEmail) {
alert('请输入有效的邮箱地址!');
return;
}
}
// console.log(this.userInfoMore);
var birthday = $("#datepicker").val();
userInfoMore.birthday = birthday;
// console.log(userInfoMore);
var userInfo = this.userInfo;
// console.log(userInfo);
// 请求后端获得最新数据
var serverUrl = app.serverUrl;
axios.defaults.withCredentials = true;
axios.post(
serverUrl + '/userInfo/update?userId=' + userInfo.id,
userInfoMore,
{
headers: {
'headerUserId': userInfo.id,
'headerUserToken': userInfo.userUniqueToken
}
})
.then(res => {
if (res.data.status == 200) {
// var userInfoMore = res.data.data;
// console.log(userInfoMore);
alert("用户信息修改成功!");
window.location.reload();
} else {
alert(res.data.msg);
console.log(res.data.msg);
}
});
},
renderUserInfo() {
var userInfo = this.userInfo;
// console.log(userInfo);
// 请求后端获得最新数据
var serverUrl = app.serverUrl;
axios.defaults.withCredentials = true;
axios.get(
serverUrl + '/center/userInfo?userId=' + userInfo.id,
{
headers: {
'headerUserId': userInfo.id,
'headerUserToken': userInfo.userUniqueToken
}
})
.then(res => {
if (res.data.status == 200) {
var userInfoMore = res.data.data;
// console.log(userInfoMore);
this.userInfoMore = userInfoMore;
var datepicker = moment(userInfoMore.birthday).format('YYYY-MM-DD');
$("#datepicker").attr("value", datepicker);
} else {
alert(res.data.msg);
console.log(res.data.msg);
}
});
},
// 查询是否支付成功
// 通过cookie判断用户是否登录
judgeUserLoginStatus() {
var userCookie = app.getCookie("user");
if (
userCookie != null &&
userCookie != undefined &&
userCookie != ""
) {
var userInfoStr = decodeURIComponent(userCookie);
// console.log(userInfoStr);
if (
userInfoStr != null &&
userInfoStr != undefined &&
userInfoStr != ""
) {
var userInfo = JSON.parse(userInfoStr);
// 判断是否是一个对象
if ( typeof(userInfo) == "object" ) {
this.userIsLogin = true;
// console.log(userInfo);
this.userInfo = userInfo;
} else {
this.userIsLogin = false;
this.userInfo = {};
}
}
} else {
this.userIsLogin = false;
this.userInfo = {};
}
}
}
});
</script>
</body>
</html>