You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
178 lines
4.4 KiB
178 lines
4.4 KiB
const app = getApp();
|
|
//status:[0,401,409]
|
|
const defaultModules=[{type:"activity", name:"课堂动态"}];
|
|
const supportModules = ["activity", "attachment", "exercise","common_homework","shixun_homework"];
|
|
Component({
|
|
properties:{
|
|
course_id:Number,
|
|
module_type:{
|
|
type:String,
|
|
observer:function(module){
|
|
this.setModule(module,0);
|
|
}
|
|
},
|
|
},
|
|
data: {
|
|
status:0,
|
|
refresh:0,
|
|
nav_type:"navigateback",
|
|
module:{
|
|
type:"activity",
|
|
name:"课堂动态"
|
|
},
|
|
course: {},
|
|
is_teacher: true,
|
|
course_modules: [],
|
|
hidden_modules: [] ,
|
|
statusBarHeight:20,
|
|
windowWidth:375,
|
|
eduImgDir: global.config.eduImgDir,
|
|
scenes:{
|
|
401:{
|
|
buttons:["点击登录","返回"]
|
|
},
|
|
409:{
|
|
message:"你不是该课堂的成员",
|
|
buttons:["加入课堂","返回"]
|
|
},
|
|
404:{
|
|
message:"该课堂已经被删除了",
|
|
buttons:["返回"]
|
|
}
|
|
}
|
|
},
|
|
methods:{
|
|
switchRole({target:{dataset:{role}}}){
|
|
if(!role) return;
|
|
app.api("courses.switch_to_"+role)({course_id: this.data.course_id})
|
|
.then(res=>{
|
|
this.onPullDownRefresh();
|
|
app.showMsg(res);
|
|
}).catch(app.showError)
|
|
},
|
|
setModule({type,showToast=1}){
|
|
for(var module of this.data.course_modules){
|
|
if(module.type==type){
|
|
if(supportModules.indexOf(type)==-1){
|
|
if(showToast)
|
|
wx.showToast({
|
|
title: `暂不支持${module.name}模块`,icon:"none"
|
|
});
|
|
return false;
|
|
}
|
|
this.setData({module});
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
},
|
|
enterShare(){
|
|
let {course_id, course} = this.data;
|
|
let url = `{course_invite}?course_id=${course_id}&invite_code=${course.invite_code}`;
|
|
app.navigateTo({url});
|
|
},
|
|
onTapCode() {
|
|
let { name, invite_code, code_halt} = this.data.course;
|
|
if(!code_halt)
|
|
wx.setClipboardData({data: `输入邀请码${invite_code}加入“${name}”吧`})
|
|
else
|
|
wx.showActionSheet({
|
|
itemList: ["启用邀请码"],
|
|
success:res=>{
|
|
app.api("courses.set_invite_code_halt")({course_id: this.data.course_id})
|
|
.then(res=>{
|
|
app.showMsg(res);
|
|
this.refresh({refresh:0});
|
|
})
|
|
}
|
|
})
|
|
},
|
|
switchModule({currentTarget:{dataset:{type}}}){
|
|
let list = this.data.course_modules.filter(item=>item.type==type);
|
|
if(list[0]&&list[0].type)
|
|
this.setModule({type:list[0].type});
|
|
},
|
|
navigateBack(){
|
|
if(this.data.nav_type=="navigateback")
|
|
wx.navigateBack({
|
|
delta:1
|
|
});
|
|
else
|
|
app.reLaunch({
|
|
url: '{main}',
|
|
});
|
|
},
|
|
async pullCourse(){
|
|
let {course_id} = this.data;
|
|
let course = await app.api("courses.top_banner")({course_id});
|
|
this.setData({course});
|
|
return {course};
|
|
},
|
|
async pullModules(){
|
|
let { course_id } = this.data;
|
|
let data = await app.api("courses.left_banner")({ course_id });
|
|
data.course_modules = defaultModules.concat(data.course_modules);
|
|
this.setData(data);
|
|
return data;
|
|
},
|
|
onTapError({detail:{status, target, current}}){
|
|
console.log(target);
|
|
switch(status){
|
|
case 401:
|
|
if(current==0)
|
|
return app.navigateTo({url:"{account}"});
|
|
else if(current==1)
|
|
return this.navigateBack();
|
|
case 409:
|
|
if(current==0)
|
|
return this.setData({show_join_course: 1});
|
|
else if(current==1)
|
|
return this.navigateBack();
|
|
case 404:
|
|
return this.navigateBack();
|
|
}
|
|
},
|
|
refresh({ refresh = 1 } = {}) {
|
|
this.setData({ refresh });
|
|
app.syncUser().then(res => {
|
|
this.pullCourse().then(res=>{
|
|
this.setData({status:200})
|
|
})
|
|
.catch(e=>{
|
|
this.setData({status:e.code});
|
|
});
|
|
this.pullModules()
|
|
.then(res => {
|
|
console.log(res);
|
|
});
|
|
})
|
|
},
|
|
onLoad: function () {
|
|
wx.getSystemInfo({
|
|
success:res=>{
|
|
let { statusBarHeight, windowWidth} = res;
|
|
this.setData({ statusBarHeight, windowWidth})
|
|
},
|
|
});
|
|
let pages = getCurrentPages();
|
|
if(pages.length<=1)
|
|
this.setData({nav_type:"relaunch"});
|
|
else
|
|
this.setData({nav_type:"navigateback"})
|
|
this.refresh({refresh:0});
|
|
},
|
|
onShow: function () {
|
|
if(this.data.status!=200||this.data.status!=0)
|
|
this.refresh();
|
|
},
|
|
onReady:function(){
|
|
|
|
},
|
|
onPullDownRefresh(){
|
|
this.refresh();
|
|
},
|
|
onShareAppMessage: function () {
|
|
|
|
}
|
|
}
|
|
}) |