-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabout.html
executable file
·389 lines (381 loc) · 15.4 KB
/
about.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>关于-闲言</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="res/layui/css/layui.css">
<link rel="stylesheet" href="res/static/css/mian.css">
<link href="http://cdn.bootcss.com/twitter-bootstrap/2.0.4/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="res/static/css/register.css">
<link rel="stylesheet" href="res/static/css/about.css">
<link href="https://cdn.bootcss.com/cropper/3.1.3/cropper.min.css" rel="stylesheet">
</head>
<body class="lay-blog">
<div class="header">
<div class="header-wrap">
<h1 class="logo pull-left">
<a href="index.html">
<img src="res/static/images/logo.png" alt="" class="logo-img">
<img src="res/static/images/logo-text.png" alt="" class="logo-text">
</a>
</h1>
<form class="layui-form blog-seach pull-left" action="">
<div class="layui-form-item blog-sewrap">
<div class="layui-input-block blog-sebox">
<i class="layui-icon layui-icon-search"></i>
<input type="text" name="title" lay-verify="title" autocomplete="off" class="layui-input">
</div>
</div>
</form>
<div class="blog-nav pull-right">
<ul class="layui-nav pull-left">
<li class="layui-nav-item"><a href="index.html">首页</a></li>
<li class="layui-nav-item"><a href="message.html">留言</a></li>
<li class="layui-nav-item layui-this"><a href="about.html">关于</a></li>
</ul>
<a href="#" class="personal pull-left layui-nav-item exit" style="font-size: 16px;">
<i class="layui-icon layui-icon-username"></i>
退出
</a>
</div>
<div class="mobile-nav pull-right" id="mobile-nav">
<a href="javascript:;">
<i class="layui-icon layui-icon-more"></i>
</a>
</div>
</div>
<ul class="pop-nav" id="pop-nav">
<li><a href="index.html">首页</a></li>
<li><a href="message.html">留言</a></li>
<li><a href="about.html">关于</a></li>
</ul>
</div>
<div class="bg">
<div class="bg-wrap">
</div>
</div>
<div class="container-wrap">
<div class="container">
<div class="contar-wrap">
<form class="form-horizontal log-form">
<fieldset>
<div id="legend" class="log-head">
<legend class="">修改资料</legend>
</div>
<div class="control-group ">
<label class="control-label"></label>
<div class="controls fileUpload">
<input type="file" id="upload" accept="image/jpg, image/png, image/jpeg, image/gif">
<span class="upload" id="result">点击修改</span>
</div>
</div>
<div class="control-group">
<label class="control-label">邮箱</label>
<div class="controls">
<div class="input-append">
<input class="span2 email" type="email" disabled="disabled">
</div>
<p class="help-block">提示:邮箱作为登录账号不可改</p>
</div>
</div>
<div class="control-group">
<label class="control-label">昵称</label>
<div class="controls">
<input type="text" class="input-xlarge nickname">
<p class="help-block"></p>
</div>
</div>
<div class="control-group">
<label class="control-label">性别</label>
<div class="controls">
<label class="radio inline">
<input type="radio" value="男" name="sex">
男
</label>
<label class="radio inline">
<input type="radio" value="女" name="sex">
女
</label>
</div>
</div>
<div class="control-group">
<label class="control-label">年龄</label>
<div class="controls">
<input type="number" class="input-xlarge age">
<p class="help-block"></p>
</div>
</div>
<div class="control-group">
<label class="control-label">星座</label>
<div class="controls">
<select class="input-xlarge xinzuo">
<option>白羊座</option>
<option>金牛座</option>
<option>双子座</option>
<option>巨蟹座</option>
<option>狮子座</option>
<option>处女座</option>
<option>天秤座</option>
<option>天蝎座</option>
<option>射手座</option>
<option>摩羯座</option>
<option>水瓶座</option>
<option>双鱼座</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">个性签名</label>
<div class="controls">
<div class="textarea">
<textarea type="" class="motto"> </textarea>
</div>
</div>
</div>
<div>
<label class="control-label"></label>
<div class="controls">
<span class="sub-button">提交</span>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
<div class="footer">
<p>
<span>© 2019</span>
<span><a href="http://www.layui.com" target="_blank">浙江大学软件学院</a></span>
<span>S403</span>
</p>
<p><span>人生就是一场修行,祝君猪事顺利</span></p>
</div>
<div class="big-mask" style="display: none">
<div class="box">
<div class="show">
<img src="" id="photo">
<div class="img-preview"></div>
<button class="btn btn-primary ok-btn" onclick="crop()">确认裁剪</button>
</div>
</div>
</div>
<script src="res/layui/layui.js"></script>
<script src="res/jquery/jquery-1.12.4.js"></script>
<script src="https://cdn.bootcss.com/cropper/3.1.3/cropper.min.js"></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script>
layui.config({
base: 'res/static/js/'
}).use('blog');
</script>
<!--修改资料-->
<script>
$(function () {
let user = JSON.parse(localStorage.getItem('UserAccount'));
let preSex;
// 获取个人资料数据
$.ajax({
url:'http://47.100.226.85:8080/find-friends/user/personal',
type:'get',
xhrFields:{
withCredentials:true
},
contentType: "application/json",
success:function (data) {
// 将个人数据注入表单
$('.controls .email').val(data.email);
$('.controls .nickname').val(data.name);
$('.controls .age').val(data.age);
$('.controls .xinzuo').val(data.xinzuo);
$('.controls .motto').val(data.motto);
$('.controls .upload').css({
background: `url("${data.headpic}") center center`,
backgroundSize: '100%'
});
$("input:radio[name='sex'][value='" + data.sex + "']").prop("checked", "checked");
preSex = data.sex;
}
});
// 数据格式的验证及提交
//昵称的验证
let changeFlag = 0;
let $nickname = $('.nickname');
let nickname = $nickname.val();
$nickname.change(function () {
nickname = $.trim($nickname.val());
changeFlag += 1;
});
$nickname.on('blur', function () {
if (!nickname || nickname.length > 8) {
$nickname.val('');
$nickname.parents('.control-group').attr('class', 'error control-group');
}
else {
$nickname.parents('.control-group').attr('class', 'control-group');
}
});
//年龄的验证
let $age = $('.age');
let age = $age.val();
$age.change(function () {
age = $age.val();
changeFlag += 1;
});
$age.on('blur', function () {
let reg = /^(?:[1-9][0-9]?|1[01][0-9]|120)$/;
if (!reg.test(age)) {
$age.parents('.control-group').attr('class', 'error control-group');
$age.val('');
}
else {
$age.parents('.control-group').attr('class', 'control-group');
}
});
//星座的选取
let $xinzuo = $('.xinzuo');
let xinzuo = $xinzuo.val();
$xinzuo.change(function () {
xinzuo = $xinzuo.val();
changeFlag += 1;
});
//个性签名设置
let $motto = $('.motto');
let motto = $motto.val();
$motto.change(function () {
motto = $motto.val;
changeFlag += 1;
});
//性别的选取
let $sex;
let sex = $("input:radio[name='sex'][checked='checked']").attr('value');
$("input:radio[name='sex']").on('click', function () {
$(this).attr('checked', 'checked');
$(this).parent().siblings().children('input').removeAttr('checked');
$sex = $("input:radio[name='sex'][checked='checked']");
sex = $sex.attr('value');
if(!sex){
$sex.parents('.control-group').attr('class','error control-group');
}
console.log(sex);
changeFlag += 1;
});
// 提交修改
$('.sub-button').on('click', function () {
if ($('.error').length>0){
alert('抱歉,还有内容没有通过填写!');
}
else if(!changeFlag) {
confirm('内容没有变化,是否提交?')
}
else {
alert('提交成功!');
let userInfo= {
nickname:$nickname.val(),
motto:$motto.val(),
sex: $("input:radio[name='sex'][checked='checked']").attr('value')|| preSex,
age:$age.val(),
xinzuo:$xinzuo.val()
};
$.ajax({
url:'http://47.100.226.85:8080/find-friends/user/personal',
type:'post',
xhrFields:{
withCredentials:true
},
data:JSON.stringify(userInfo),
success: function(data){
},
contentType: "application/json",
});
}
changeFlag = 0;
});
});
</script>
<!-- 更换头像-->
<script>
// cropper.js调用配置
var initCropper = function (img, input) {
var $image = img;
var options = {
aspectRatio: 1, // 纵横比
viewMode: 2,
preview: '.img-preview' // 预览图的class名
};
$image.cropper(options);
var $inputImage = input;
var uploadedImageURL;
if (URL) {
// 给input添加监听
$inputImage.change(function () {
// 出现蒙版
$('.big-mask').css('display', 'block');
var files = this.files;
var file;
if (!$image.data('cropper')) {
return;
}
if (files && files.length) {
file = files[0];
// 判断是否是图像文件
if (/^image\/\w+$/.test(file.type)) {
// 如果URL已存在就先释放
if (uploadedImageURL) {
URL.revokeObjectURL(uploadedImageURL);
}
uploadedImageURL = URL.createObjectURL(file);
// 销毁cropper后更改src属性再重新创建cropper
$image.cropper('destroy').attr('src', uploadedImageURL).cropper(options);
$inputImage.val('');
} else {
window.alert('请选择一个图像文件!');
}
}
});
} else {
$inputImage.prop('disabled', true).addClass('disabled');
}
};
// 图片裁剪函数
var crop = function () {
var $image = $('#photo'); // 被选中供裁剪的图片
var $target = $('#result'); // 裁剪完成的图像存放的目标位置
$image.cropper('getCroppedCanvas', {
width: 100, // 裁剪后的长宽
height: 100
}).toBlob(function (blob) {
// 裁剪后将图片放到指定标签
$target.css('background', 'url("' + URL.createObjectURL(blob) + '") center center');
blobToDataURL(blob,function (dataURL) {
// 裁剪的图片先转成base64编码
$.ajax({
url:'http://47.100.226.85:8080/find-friends/user/headpic',
xhrFields:{
withCredentials:true
},
type:'post',
data:JSON.stringify({'pic':dataURL}),
success:function () {
console.log(1);
},
contentType: "application/json",
});
});
});
$('.big-mask').css('display', 'none'); // 隐藏蒙版
};
// 将blob转成base64
var blobToDataURL =function(blob, callback) {
var a = new FileReader();
a.onload = function (e) { callback(e.target.result); };
a.readAsDataURL(blob);
};
// 函数调用的入口
$(function () {
initCropper($('#photo'), $('#upload'));
});
</script>
</body>
</html>