MyChangeInfoApe.js
7.6 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
//*
// 首页模块
// */
import Loger from "../Loger";
import Ape from "./Ape";
import $ from "jquery";
import ClassDataProxy from "proxy/ClassDataProxy";
import ErrorApe from "./ErrorApe";
let loger = Loger.getLoger('PC-MyChangeInfoApe');
class MyChangeInfoApe extends Ape {
constructor() {
super();
this.addEvent();
this.init();
}
init() {
$('#updateInputYes').on('click',this._updateInputYesHandler.bind(this));//确定时把输入的信息存入数据中
$('#accountInfoSaveBtn').on('click',this._accountInfoSaveBtnHandler.bind(this));//更新用户信息按钮
$('#updateInputBoxA').on('click',this._hideInputBox.bind(this));//关闭弹框
$('#updateInputNo').on('click',this._hideInputBox.bind(this));//关闭弹框
//修改账户信息
$('#accountPassWordBtn').on('click',this._accountPassWordBtnHandler.bind(this));//密码
$('#accountEmailBtn').on('click',this._accountEmailBtnHandler.bind(this));//邮箱
$('#accountMobilelBtn').on('click',this._accountMobilelBtnHandler.bind(this));//手机号
}
addEvent() {
}
//修改密码
_accountPassWordBtnHandler(){
this.data = 0;
this._showInputBox(this.data);
}
//修改邮箱
_accountEmailBtnHandler(){
this.data = 1;
this._showInputBox(this.data);
}
//修改手机号
_accountMobilelBtnHandler(){
this.data = 2;
this._showInputBox(this.data);
}
_updateInputYesHandler(evt){
let updateInput = $('#updateInput').val();
switch (parseInt(this.data)){
case 0:
//密码
let reg = /^[0-9a-zA-Z]{8,12}$/;
if(!updateInput || !(reg.test(updateInput))){
ClassDataProxy.getMarginTopHandler($('#warnHintBox'));
ErrorApe.showWarnError('密码格式不正确,请重新输入');
return;
}
$('#setPassWord').attr('data',updateInput);
this._hideInputBox();
break;
case 1:
//邮箱
let filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if(!updateInput || !(filter.test(updateInput))){
ClassDataProxy.getMarginTopHandler($('#warnHintBox'));
ErrorApe.showWarnError('邮箱格式不正确,请重新输入');
return;
}
$('#setMail').attr('data',updateInput);
$('#setMail').html(this.updateEmail(updateInput))
this._hideInputBox();
break;
case 2:
//手机号
let reg1 = /^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$/;
let regPhone = "^1[3|4|5|8][0-9]\\d{8}$";
let re = new RegExp(regPhone);
if(!updateInput || !(re.test(updateInput))){
ClassDataProxy.getMarginTopHandler($('#warnHintBox'));
ErrorApe.showWarnError('手机格式不正确,请重新输入');
return;
}
$('#setPhone').attr('data',updateInput);
$('#setPhone').html(this.updateMobile(updateInput))
this._hideInputBox();
break;
default:
return;
}
}
_hideInputBox(){
$('#updateInput').val('');
$('#updateInputShade').hide();
}
_showInputBox(ind){
let arr = ['请输入新密码 :','请输入新邮箱 :','请输入新手机号 :']
ClassDataProxy.getMarginTopHandler($('.updateInputBox'));
$('#updateInputShade').show();
$('#updateInputText').text(arr[ind])
}
updateEmail(userEmail){
return userEmail.replace(/(\d{2})\d{2}(\d{1})/, '$1****$2')
}
updateMobile(userMobile){
return userMobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
}
//提交用户信息修改
_accountInfoSaveBtnHandler(){
let id = ClassDataProxy.id;//id
let loginName = ClassDataProxy.loginName;//登录名
let userMobile = ClassDataProxy.userMobile;//手机号
let userEmail = ClassDataProxy.userEmail;//邮箱
let monicker = ClassDataProxy.monicker;//用户名
let passWord = ClassDataProxy.password;//密码
let oneselfInfoLoginName = $('#oneselfInfoLoginName').val();//登录名
let oneselfInfoUserName = $('#oneselfInfoUserName').val();//用户名
let oneselfInfoMan = $('#oneselfInfoMan');//性别
let setPassWord = $('#setPassWord').attr('data');//密码
let setMail = $('#setMail').attr('data');//邮箱
let setPhone = $('#setPhone').attr('data');//手机号
let signInfo = {};
if(oneselfInfoLoginName != loginName){
signInfo.loginName = oneselfInfoLoginName;
}
if(oneselfInfoUserName != monicker){
signInfo.userName = oneselfInfoUserName;
}
if(!setPassWord){
// signInfo.loginName = oneselfInfoLoginName;
}
if(setMail != userEmail){
signInfo.userEmail = setMail;
}
if(setPhone != userMobile){
signInfo.userMobile = setPhone;
}
let that = this;
let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/users/updateUserByUserId/' + id;
$.ajax({
type: "PUT",
url: _url,
timeout:5000,
headers: {siteId:ClassDataProxy.siteId,
'token':ClassDataProxy.token},
data:signInfo,
success:function(_data){
//获取个人信息数据
if(_data && _data.code == 200){
loger.log('修改信息成功',_data)
ClassDataProxy.getMarginTopHandler($('#warnHintBox'));
ErrorApe.showWarnError('修改信息成功');
ClassDataProxy.loginName =_data.returnData.data.loginName;
ClassDataProxy.monicker = _data.returnData.data.userName;
ClassDataProxy.userEmail = _data.returnData.data.userEmail;
ClassDataProxy.userMobile = _data.returnData.data.userMobile;
window.localStorage.setItem('loginName', ClassDataProxy.loginName);
window.localStorage.setItem('monicker', ClassDataProxy.monicker);
window.localStorage.setItem('userEmail', ClassDataProxy.userEmail);
window.localStorage.setItem('userMobile', ClassDataProxy.userMobile);
$('#teacherMyCenterName').html(ClassDataProxy.loginName);
}else if(_data.code == 400){
ClassDataProxy.getMarginTopHandler($('#warnHintBox'));
ErrorApe.showWarnError('账号未修改');
}else{
ClassDataProxy.getMarginTopHandler($('#warnHintBox'));
ErrorApe.showWarnError(_data.returnData.data.msg);
}
},
error:function(error){
loger.log(error,'修改信息失败')
}
})
}
clearLocalStorage(){
window.localStorage.clear();
ClassDataProxy.userType = ClassDataProxy.USER_TYPE_0;
ClassDataProxy.loginName ="";
ClassDataProxy.password =""
ClassDataProxy.token ="";
ClassDataProxy.status = false;
}
//个人信息
_updatMessage(){
$('#oneselfInfoLoginName').val( ClassDataProxy.loginName);//登录名
$('#oneselfInfoUserName').val(ClassDataProxy.monicker);//用户名
}
}
export default MyChangeInfoApe;