|
|
|
import { getWXACodeUrl} from '../../../js/utils';
|
|
|
|
const app = getApp();
|
|
|
|
/**
|
|
|
|
* status:[404,-1]
|
|
|
|
*/
|
|
|
|
Page({
|
|
|
|
data: {
|
|
|
|
course:{
|
|
|
|
name:"**课堂邀请",
|
|
|
|
teacher_name:"点击最下方按钮",
|
|
|
|
teacher_school:"登录后查看更多",
|
|
|
|
invite_code:"登录后查看"
|
|
|
|
},
|
|
|
|
imgDir:global.config.imgDir,
|
|
|
|
user:{},
|
|
|
|
status:0,
|
|
|
|
eduImgDir:global.config.eduImgDir
|
|
|
|
},
|
|
|
|
onImgLoad(e){
|
|
|
|
console.log("imageload", e);
|
|
|
|
this.setData({code_loaded:1});
|
|
|
|
},
|
|
|
|
onImgError(e){
|
|
|
|
let page = this.getPageUrl();
|
|
|
|
let scene = this.getScene();
|
|
|
|
wx.cloud.callFunction({ name: "openapi", data: { name:"wxacode.getUnlimited", data:{page, scene}}})
|
|
|
|
.then(res=>{
|
|
|
|
let t = new Date().getTime();
|
|
|
|
wx.cloud.getTempFileURL({
|
|
|
|
fileList:[res.result.fileID],
|
|
|
|
success:res=>{
|
|
|
|
console.log(res)
|
|
|
|
this.setData({invite_code_url: res.fileList[0].tempFileURL+"?t="+t})
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
},
|
|
|
|
login:function(){
|
|
|
|
app.navigateTo({
|
|
|
|
url: '{account}',
|
|
|
|
});
|
|
|
|
},
|
|
|
|
onTapCode(){
|
|
|
|
if(this.data.course.code_halt)
|
|
|
|
return;
|
|
|
|
let data = this.data.course.invite_code || this.data.scene.invite_code;
|
|
|
|
wx.setClipboardData({
|
|
|
|
data
|
|
|
|
})
|
|
|
|
},
|
|
|
|
preview(){
|
|
|
|
if(this.data.course.code_halt)
|
|
|
|
return;
|
|
|
|
wx.previewImage({
|
|
|
|
urls: [this.data.invite_code_url],
|
|
|
|
})
|
|
|
|
},
|
|
|
|
joinCourse: function(event) {
|
|
|
|
if(this.data.status==404){
|
|
|
|
return wx.showToast({
|
|
|
|
title: '该课堂已被删除了',icon:"none"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (this.data.course.code_halt||!this.data.course.invite_code)
|
|
|
|
return wx.showToast({
|
|
|
|
title: '>︿<\n邀请码已经停用了',
|
|
|
|
icon:"none"
|
|
|
|
});
|
|
|
|
this.setData({show_join_modal:1});
|
|
|
|
},
|
|
|
|
getPageUrl(){
|
|
|
|
return app.getPageUrl(`{course_invite}`,"");
|
|
|
|
},
|
|
|
|
getScene(){
|
|
|
|
let { course_id} = this.data;
|
|
|
|
return `course_id=${course_id}`
|
|
|
|
},
|
|
|
|
pull_course(){
|
|
|
|
app.syncUser().then(res=>{
|
|
|
|
app.api("weapps.courses.basic_info")({ course_id: this.data.course_id })
|
|
|
|
.then(({ course }) => {
|
|
|
|
this.setData({ course, status: 200 });
|
|
|
|
}).catch(e => {
|
|
|
|
if(e.code==404){
|
|
|
|
let course = {
|
|
|
|
name:"该课堂已被删除",
|
|
|
|
teacher_name:" ",
|
|
|
|
teacher_school:" ",
|
|
|
|
invite_code:"",
|
|
|
|
code_halt:1
|
|
|
|
};
|
|
|
|
e.message = "该课堂已被删除";
|
|
|
|
this.setData({course});
|
|
|
|
}
|
|
|
|
app.showError(e);
|
|
|
|
this.setData({ status: e.code })
|
|
|
|
});
|
|
|
|
})
|
|
|
|
},
|
|
|
|
onLoad: function (options) {
|
|
|
|
var course_id;
|
|
|
|
if(options.course_id)
|
|
|
|
course_id= options.course_id;
|
|
|
|
else if(options.scene){
|
|
|
|
var scene = {};
|
|
|
|
for (var item of decodeURIComponent(options.scene).split("&")){
|
|
|
|
var [k,v] = item.split("=")
|
|
|
|
scene[k]=v;
|
|
|
|
}
|
|
|
|
course_id = scene.course_id;
|
|
|
|
}else{
|
|
|
|
this.setData({status: 404});
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.setData({ course_id, status: 1});
|
|
|
|
let invite_code_url = getWXACodeUrl({url: this.getPageUrl(), scene:this.getScene()});
|
|
|
|
this.pull_course();
|
|
|
|
this.setData({ invite_code_url});
|
|
|
|
},
|
|
|
|
onShow:function(options){
|
|
|
|
|
|
|
|
app.syncUser()
|
|
|
|
.then(({user})=>{
|
|
|
|
this.setData({user});
|
|
|
|
})
|
|
|
|
if(this.data.status==-1)
|
|
|
|
this.pull_course()
|
|
|
|
},
|
|
|
|
onReady(){
|
|
|
|
app.reportPageHistory();
|
|
|
|
},
|
|
|
|
onShareAppMessage(){
|
|
|
|
let {course} = this.data;
|
|
|
|
return app.shareApp({
|
|
|
|
title: "「课堂邀请」" + course.name
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|