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.
128 lines
3.7 KiB
128 lines
3.7 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(/[A-Z0-9]{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
|
|
},
|
|
methods: {
|
|
scan(){
|
|
wx.scanCode({
|
|
success:res=>{
|
|
console.log(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\?(.*)$/)
|
|
console.log("match",match);
|
|
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})
|
|
console.log("options",options);
|
|
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;
|
|
}
|
|
console.log(scene);
|
|
if(scene.course_id){
|
|
var {course_id} = scene;
|
|
app.api("weapps.courses.basic_info")({ course_id })
|
|
.then(({ course:{invite_code=""}}) => {
|
|
console.log(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"
|
|
})
|
|
}
|
|
})
|
|
},
|
|
cancel: function (event) {
|
|
this.setData({ hidden: true });
|
|
},
|
|
update_invite_code: function ({ detail: { value } }) {
|
|
console.log(value);
|
|
this.setData({ invite_code: value });
|
|
},
|
|
update_identities: function ({ detail: { value } }) {
|
|
var data = {assistant_professor:"", professor:"",student:""}
|
|
console.log(value);
|
|
for(var identity of value)
|
|
data[identity] = 1
|
|
console.log(data);
|
|
this.setData(data)
|
|
},
|
|
join_course: function (event) {
|
|
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);
|
|
if (res.course_id&&this.data.auto_navigate&&res.message.indexOf("助教申请")==-1){
|
|
setTimeout(()=>{
|
|
app[this.data.opentype]({
|
|
url: `{course}?course_id=${res.course_id}`
|
|
});
|
|
},800);
|
|
}
|
|
this.triggerEvent("success");
|
|
this.cancel();
|
|
})
|
|
.catch(app.showError)
|
|
|
|
}
|
|
}
|
|
})
|