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.
138 lines
3.9 KiB
138 lines
3.9 KiB
const app = getApp();
|
|
Component({
|
|
|
|
properties: {
|
|
hidden:{
|
|
type:Boolean,
|
|
value: true,
|
|
observer:function(hidden){
|
|
if(!hidden){
|
|
wx.getClipboardData({
|
|
success:res=>{
|
|
if(!res.data||res.data==this.clipboardData) return;
|
|
this.clipboardData = res.data;
|
|
var match = res.data.match(/(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Z]{5,6}/);
|
|
if(match)
|
|
this.setData({invite_code: match[0]});
|
|
}
|
|
})
|
|
}
|
|
}
|
|
},
|
|
show_code:{
|
|
type:Number,
|
|
value:1
|
|
},
|
|
invite_code: String,
|
|
auto_navigate:{
|
|
type:Number,
|
|
value:1
|
|
},
|
|
opentype:{
|
|
type:String,
|
|
value:"navigateTo"
|
|
}
|
|
},
|
|
|
|
data: {
|
|
identities:[],
|
|
hidden:true,
|
|
buttons:[
|
|
{text:"取消"},
|
|
{text:"提交"}
|
|
]
|
|
},
|
|
methods: {
|
|
scan(){
|
|
wx.scanCode({
|
|
success:res=>{
|
|
;
|
|
var fail = false;
|
|
if(res.scanType=="QR_CODE")
|
|
this.setData({invite_code: res.result});
|
|
else if(res.scanType=="WX_CODE"&&res.path){
|
|
var match = res.path.match(/course_invite\?(.*)$/)
|
|
;
|
|
if(match){
|
|
var options = {}
|
|
match[1].split("&").map(i=>{
|
|
var index = i.indexOf("=");
|
|
var k = i.slice(0, index);
|
|
var v = i.slice(index + 1);
|
|
options[k]=v})
|
|
;
|
|
if(options.scene){
|
|
var scene = {};
|
|
for (var i of decodeURIComponent(options.scene).split("&")) {
|
|
var index = i.indexOf("=");
|
|
var k = i.slice(0,index);
|
|
var v = i.slice(index+1);
|
|
scene[k] = v;
|
|
}
|
|
;
|
|
if(scene.course_id){
|
|
var {course_id} = scene;
|
|
app.api("weapps.courses.basic_info")({ course_id })
|
|
.then(({ course:{invite_code=""}}) => {
|
|
;
|
|
this.setData({invite_code});
|
|
}).catch(app.showError);
|
|
}else
|
|
fail = true;
|
|
}else
|
|
fail = true;
|
|
}else
|
|
fail= true;
|
|
}else
|
|
fail = true;
|
|
if(fail)
|
|
wx.showToast({
|
|
title:"识别失败",icon:"none"
|
|
})
|
|
}
|
|
})
|
|
},
|
|
onCancel() {
|
|
this.setData({ hidden: true,invite_code:'', professor:"", student:"", assistant_professor:"" });
|
|
},
|
|
onTapButton({detail:{index}}){
|
|
if(index==0)
|
|
this.onCancel();
|
|
else if(index==1)
|
|
this.join_course();
|
|
},
|
|
update_invite_code: function ({ detail: { value } }) {
|
|
this.setData({ invite_code: value });
|
|
},
|
|
update_identities: function ({ detail: { value } }) {
|
|
var data = {assistant_professor:"", professor:"",student:""}
|
|
for(var identity of value)
|
|
data[identity] = 1
|
|
this.setData(data)
|
|
},
|
|
join_course () {
|
|
if(this.disabled) return;
|
|
let { invite_code="", assistant_professor="", professor,student=""} = this.data;
|
|
this.disabled = true;
|
|
app.api("courses.apply_to_join_course")({ invite_code, assistant_professor, professor, student,complete: res=>{this.disabled=false}})
|
|
.then(res => {
|
|
app.showMsg(res,800);
|
|
wx.reportAnalytics('join_course', {});
|
|
if (res.course_id&&this.data.auto_navigate&&res.message.indexOf("助教申请")==-1){
|
|
setTimeout(()=>{
|
|
app[this.data.opentype]({
|
|
url: `{course}?course_id=${res.course_id}`
|
|
});
|
|
},640);
|
|
}
|
|
this.triggerEvent("success");
|
|
this.onCancel();
|
|
})
|
|
.catch(e=>{
|
|
e.message =e.message||'未知错误';
|
|
app.showError(e);
|
|
})
|
|
}
|
|
}
|
|
})
|