MyCenterApe.js
11.3 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
//*
// 首页模块
// */
import Loger from "../Loger";
import Ape from "./Ape";
import $ from "jquery";
import ClassDataProxy from "proxy/ClassDataProxy";
import ErrorApe from "./ErrorApe";
const classifyList = `<div class="classifyList {_classifyListR}" id="{_id}">
<img class="curriculumListImg" src="{_msgImg}" alt="">
<p class="curriculumListTit">{_classroomTitle}</p>
<p class="curriculumListInfo">
<span class="curriculumListTime">{_schoolTime}</span>
<span class="curriculumListNum">{_subscribeNum}</span>
</p>
</div>`;
let loger = Loger.getLoger('PC-MyCenterApe');
class MyCenterApe extends Ape {
constructor() {
super();
this.isLocalStorage();
this.data = 0;
this.addEvent();
this.init();
}
init() {
$('#personageInfo').on('click',this._myCenterBoxHandler.bind(this));//个人中心
$('#teacherUI li').on('click',this._recordLiHandler.bind(this));//课堂分类
$('#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() {
}
_curriculumInfo(){
let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/meeting/getMeeting';
let that = this;
$.ajax({
type: "POST",
url: _url,
timeout:5000,
data:{siteId:ClassDataProxy.siteId,userType:1},
headers: {siteId:ClassDataProxy.siteId,
'token':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IlhXQnJlRU00T0swYTVqUUIyUTFicGtObHlxOUFWbXZkIiwibmFtZSI6ImFkbWluIiwiY29kZSI6MSwiaWF0IjoxNTAzNDUxODU0LCJleHAiOjIyODEwNTE4NTR9.3kTVzKd_jbP7l69nxOpNaFeSjVnnjZkagYMzRB8fjNo'},
success:function(_data){
loger.log(_data,'个人中心用户列表数据')
//获取课堂数据
//that._gainClassData(_data);
},
error:function(error){
//alert('直播数据获取失败')
loger.log(error,'直播数据获取失败')
}
})
}
isLocalStorage(){
if(ClassDataProxy.userType == ClassDataProxy.USER_TYPE_1){
this._curriculumInfo();
}
$('#teacherMyCenterName').text(ClassDataProxy.loginName);
$('.myCenterContentBox').eq(0).show().siblings().hide();
let newDate = new Date();
let newHours = newDate.getHours();
let text = newHours>12?'下午好,':'上午好,'
$('#teacherMyCenterTime').text(text);
$('.recordLi2').eq(0).addClass('recordLiCheck').siblings().removeClass('recordLiCheck');
$('#oneselfInfoLoginName').val( ClassDataProxy.loginName);//登录名
$('#oneselfInfoUserName').val(ClassDataProxy.monicker);//用户名
let setMail = $('#setMail');//邮箱
let setPhone = $('#setPhone');//手机号
let userEmail = this.updateEmail(ClassDataProxy.userEmail);
let userMobile = this.updateMobile(ClassDataProxy.userMobile);
setMail.attr('data',ClassDataProxy.userEmail);
setPhone.attr('data',ClassDataProxy.userMobile);
setMail.html(userEmail)
setPhone.html(userMobile)
}
_recordLiHandler(evt){
let ind = $(evt.currentTarget).attr('data');
$(evt.currentTarget).addClass('recordLiCheck').siblings().removeClass('recordLiCheck');
$('.myCenterContentBox').eq(ind).show().siblings().hide();
switch (parseInt(ind)){
case 0:
//首页
break;
case 1:
//我的课程
break;
case 2:
//我的预约
break;
case 3:
//个人信息
this._updatMessage();
break;
default:
return;
}
}
//提交用户信息修改
_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':'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IlhXQnJlRU00T0swYTVqUUIyUTFicGtObHlxOUFWbXZkIiwibmFtZSI6ImFkbWluIiwiY29kZSI6MSwiaWF0IjoxNTAzNDUxODU0LCJleHAiOjIyODEwNTE4NTR9.3kTVzKd_jbP7l69nxOpNaFeSjVnnjZkagYMzRB8fjNo'},
data:signInfo,
success:function(_data){
loger.log('修改信息',_data)
//获取个人信息数据
if(_data && _data.code == 200){
loger.log('修改信息成功',_data)
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);
}else if(_data.code == 400){
ErrorApe.showWarnError('账号未修改');
}else{
ErrorApe.showWarnError(_data.returnData.data.msg);
}
},
error:function(error){
// alert('老师界面获取数据失败')
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);//用户名
}
//修改密码
_accountPassWordBtnHandler(){
this.data = 0;
this._showInputBox(this.data);
}
//修改邮箱
_accountEmailBtnHandler(){
this.data = 1;
this._showInputBox(this.data);
}
//修改手机号
_accountMobilelBtnHandler(){
this.data = 2;
this._showInputBox(this.data);
}
_myCenterBoxHandler(){
if(ClassDataProxy.userType == ClassDataProxy.USER_TYPE_2){
return;
}
if(ClassDataProxy.userType == ClassDataProxy.USER_TYPE_8){
$('#slideshow').hide();
$('#defaultBox').hide();
$('#classifyListBox').hide();
$('#lanclassBox').hide();
}
$('#myCenterBox').show();
}
_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))){
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))){
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))){
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 = ['请输入新密码 :','请输入新邮箱 :','请输入新手机号 :']
$('#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')
}
//工具类
_format(str, obj) {
return str.replace(/\{(\w+)\}/g, function (match, group, index) {
return obj[group];
});
};
}
export default MyCenterApe;