HomeApe.js
10.1 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
//*
// 首页模块
// */
import Loger from "../Loger";
import Ape from "./Ape";
import $ from "jquery";
import ClassDataProxy from "proxy/ClassDataProxy";
import MessageTypes from "../MessageTypes";
const classifyList = `<div class="classifyList {_classifyListR}" data="{_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>`;
const teacherList = `<div class="classifyList {_classifyListR}" data="{_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-HomeApe');
class HomeApe extends Ape {
constructor() {
super();
this.classDateList = {};//课堂的所有数据
//判断列表在右侧时取消边距
this._judgeListPlace();
this.isLocalStorage();
this.addEvent();
this.init();
}
init() {
$('#header_list li').on('click',this.switchHeaderHandler.bind(this));
$('#liveBtnMove').on('click',this.liveBtnMoveHandler.bind(this));//最新直播课程
$('#lanclassBtnMove').on('click',this.lanclassBtnMoveHandler.bind(this));//最新互动课程
$('#teacherBtnMove').on('click',this.teacherBtnMoveHandler.bind(this));//最新老师推荐
$('#homeCenterBtn').on('click',this._homeCenterBtnHandler.bind(this));//个人中心
}
addEvent() {
}
isLocalStorage(){
this.homeAllDate();
}
switchHeaderHandler(evt){
$(evt.currentTarget).addClass('header_listMsgCheck').siblings().removeClass('header_listMsgCheck');
let ind = $(evt.target).index();
this._emit(MessageTypes.SWITCH_HEADER,ind);
}
liveBtnMoveHandler(){
this.switchClass(1);
this._emit(MessageTypes.SWITCH_HEADER,1);
}
lanclassBtnMoveHandler(){
this.switchClass(2);
this._emit(MessageTypes.SWITCH_HEADER,2);
}
teacherBtnMoveHandler(){
this.switchClass(3);
this._emit(MessageTypes.SWITCH_HEADER,3);
}
switchClass(ind){
$('#header_list li').eq(ind).addClass('header_listMsgCheck').siblings().removeClass('header_listMsgCheck');
}
_judgeListPlace(){
let i;
let curriculumList = document.getElementsByClassName('curriculumList');
for(i=0;i<curriculumList.length;i++){
if((i%4) == 3){
$(curriculumList[i]).addClass('classifyListR');
}
}
}
homeAllDate(){
//直播信息
this.liveModule();
//互动信息
this.interactModule();
//老师信息
this.teacherModule();
}
//直播信息
liveModule(){
let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/meeting/getMeeting';
let data = {siteId:ClassDataProxy.siteId,meetingType:2};
let that = this;
this.detailPage(_url,data,8,1,function(_data){
if(_data){
// loger.log('首页直播信息',_data)
that._liveClassData(_data.returnData.data.meetingInfo);
}
})
}
//互动信息
interactModule(){
let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/meeting/getMeeting';
let data = {siteId:ClassDataProxy.siteId,meetingType:1};
let that = this;
this.detailPage(_url,data,8,1,function(_data){
if(_data){
// loger.log('首页互动信息',_data)
that._gainClassData(_data.returnData.data.meetingInfo);
}
})
}
//老师信息
teacherModule(){
let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/users/getUserByUserType';
let data = {siteId:ClassDataProxy.siteId,userType :1}
let that = this;
this.detailPage(_url,data,8,1,function(_data){
if(_data){
// loger.log('首页老师信息',_data)
that._teacherDate(_data.returnData.data.users);
}
})
}
detailPage(url,data,num,ind,callback){
let that = this;
$.ajax({
type: "POST",
url: url,
timeout:5000,
data : data,
headers: {siteId:ClassDataProxy.siteId,pageno:num, page:ind,
'token':ClassDataProxy.token},
success:function(_data){
//获取我的课程数据
if(_data && _data.code == 200){
if(callback){
callback(_data);
}
}else{
if(callback){
callback(null);
}
}
},
error:function(error){
//alert('直播数据获取失败')
if(callback){
callback(null);
}
loger.log(error,'直播数据获取失败')
}
})
}
_liveClassData(_data){
let liveList = $('#liveList');
liveList.empty();
if(_data){
for(let i = 0;i<_data.length;i++){
if(i<8){
let j = (i%4)==3;
let _getTime = ClassDataProxy.getTimeDifference(_data[i].beginTime,_data[i].endTime)
let _img = '../images/u373.png';
let _classImg = _data[i].meetingPhoto;
let _classifyList = this._format(classifyList,{
_classifyListR : j?'classifyListR':'',
_id : _data[i].id,
_msgImg :_classImg?_classImg:_img,
_classroomTitle : _data[i].meetingName,
_schoolTime : _getTime,
_subscribeNum : _data[i].reservationNumber+'人预约'
})
liveList.append(_classifyList);
}
}
}
}
_gainClassData(_data){
let lanclassList = $('#lanclassList');
lanclassList.empty();
if(_data){
for(let i = 0;i<_data.length;i++){
if(i<8){
let j = (i%4)==3;
let _getTime = ClassDataProxy.getTimeDifference(_data[i].beginTime,_data[i].endTime)
let _img = '../images/u373.png';
let _classImg = _data[i].meetingPhoto;
let _classifyList = this._format(classifyList,{
_classifyListR : j?'classifyListR':'',
_id : _data[i].id,
_msgImg :_classImg?_classImg:_img,
_classroomTitle : _data[i].meetingName,
_schoolTime : _getTime,
_subscribeNum : _data[i].reservationNumber+'人预约'
})
lanclassList.append(_classifyList);
}
}
}
}
_teacherDate(_data){
let teacherIntro = $('#teacherIntro');
teacherIntro.empty();
if(_data){
for(let i = 0;i<_data.length;i++){
let j = (i%4)==3;
let _getTime = ClassDataProxy.getTimeDifference(_data[i].create_time,_data[i].end_time);
let _img = '../images/u373.png';
let _classImg = _data[i].meetingPhoto;
let _classifyList = this._format(teacherList,{
_classifyListR : j?'classifyListR':'',
_id : _data[i].id,
_msgImg :_classImg?_classImg:_img,
_classroomTitle : _data[i].user_name,
_schoolTime : _getTime.split('-')[0],
_subscribeNum : _data[i].reservationNumber+'人预约'
})
teacherIntro.append(_classifyList);
}
}
}
_gainClassDataErr(){
let liveList = $('#liveList');
let lanclassList = $('#lanclassList');
let teacherIntro = $('#teacherIntro');
liveList.empty();
lanclassList.empty();
teacherIntro.empty();
let _classifyList = '<div class="dataHomeErrorTitle">数据获取失败~</div>'
liveList.append(_classifyList)
lanclassList.append(_classifyList)
teacherIntro.append(_classifyList)
}
//首页点击 进入个人中心
_homeCenterBtnHandler(){
$('#homeUserLoginBtn').attr('data','');
if(ClassDataProxy.userType == ClassDataProxy.USER_TYPE_0){
this.toLogin();
}else if(ClassDataProxy.userType == ClassDataProxy.USER_TYPE_8){
$('#slideshow').hide();
$('#defaultBox').hide();
$('#classifyListBox').hide();
$('#lanclassBox').hide();
$('#liveContentAllBox').hide();
$('#lanclassAllBox').hide();
$('#teacherIntroAllBox').hide();
$('#teacherDetailBox').hide();
$('#myCenterBox').show();
}
}
studentClick(){
$('#slideshow').show();
$('#defaultBox').show();
$('.curriculumBox').show();
$('#classifyListBox').hide();
$('#teacherDetailBox').hide();
$('#lanclassBox').hide();
$('#myCenterBox').hide();
$('#lanclassAllBox').hide();
}
toLogin(){
ClassDataProxy.getMarginTopHandler($('#userLogin'));
$('#userLoginBox').show();
}
//工具类
_format(str, obj) {
return str.replace(/\{(\w+)\}/g, function (match, group, index) {
return obj[group];
});
};
}
export default HomeApe;