const app = getApp(); const actions = { "置顶":{ cb:"sticky", cd:{"sticky":[false]} }, "取消置顶":{ cb:"cancelSticky", cd:{"sticky":[true]} }, "邀请成员":{ cb:"share", cd:{"course_identity":[2,3,4]} }, "停用邀请码":{ cb: "set_invite_code_halt", cd: { "invite_code_halt": [0], "course_identity": [2]} }, "启用邀请码":{ cb:"set_invite_code_halt", cd: { "invite_code_halt": [1], "course_identity": [2]} }, "永久退出课堂":{ cb:"exit_course", cd:{"course_identity":[5]} }, "永久删除课堂":{ cb:"delete_course", cd:{course_identity:[2]} } } Component({ properties: { data:Object, category:String }, data: { eduImgDir:global.config.eduImgDir }, methods: { showAction(){ let itemList = this.getActions(); ; let course = this.data.data; wx.showActionSheet({ itemList, success:res=>{ let action = itemList[res.tapIndex]; let cb = actions[action].cb; this[cb](); } }) }, getActions(){ var _actions = []; for(var name in actions){ var flag = true; var action = actions[name]; for(var cdt in action.cd){ if(action.cd[cdt].indexOf(this.data.data[cdt])==-1){ flag=false; break; } } if(flag) _actions.push(name); } return _actions; }, sticky(){ let course_id = this.data.data.id; let category = this.data.category; app.api("weapps.course_stickies")({course_id, category}) .then(res=>{ this.triggerRefresh(); }) .catch(app.showError) }, share(){ app.navigateTo({url:"{course_invite}?course_id="+this.data.data.id}); }, set_invite_code_halt(){ app.api("courses.set_invite_code_halt")({ course_id: this.data.data.id }) .then(res => { res.message="操作成功"; app.showMsg(res); this.triggerRefresh(); }) }, cancelSticky(){ let course_id = this.data.data.id; let category = this.data.category; app.api("weapps.course_stickies.cancel_sticky")({ course_id, category }) .then(res => { this.triggerRefresh(); }) .catch(app.showError) }, exit_course(){ wx.showModal({ title: '提示', content: '退出后您将不再是本课题的成员,\n作品将全部被删除,\n确定要退出该课堂吗?', success:res=>{ if(res.confirm){ app.api("courses.exit_course")({course_id:this.data.data.id}) .then(res=>{ app.showMsg(res); this.triggerRefresh(); }) .catch(app.showError) } } }) }, require_auth({success, fail, complete}){ wx.checkIsSoterEnrolledInDevice({ checkAuthMode: "fingerPrint", success:res=>{ if(res.isEnrolled){ wx.startSoterAuthentication({ requestAuthModes: ["fingerPrint"], challenge: this.data.data.id.toString()||"123456", authContent:"验证身份后删除该课堂", success:res=>{ ; success && success(); complete && complete(); }, fail:e=>{ ; fail && fail({ message: "身份验证失败" }); complete && complete(); } }) }else{ success && success(); complete&&complete(); } }, fail:e=>{ success && success(); complete&&complete(); } }) }, process_delete(){ wx.showLoading({ title: '删除中' }) let {id:course_id} = this.data.data; app.callApi({name:"courses",data:{course_id}, config:{method:"DELETE"}, success:res=>{ res.message = "删除成功"; app.showMsg(res); this.triggerRefresh(); }, complete: res=>{ wx.hideLoading(); }, fail:e=>{ if(e.code==403) e.message = "您没有权限"; else if(e.code==404) e.message = "该课堂已被删除"; app.showError(e); } }) }, delete_course(){ wx.showModal({ title: '警告', content: '课堂删除后所有数据将被删除并且【无法恢复】,\n是否确定删除?', confirmColor:"#fa5151", success: res=>{ if(!res.confirm) return; this.require_auth({ success:res=>{ this.process_delete() }, fail:(e={})=>{ wx.showToast({ title: e.message||'身份验证失败', icon:"none" }) } }); } }); }, edit() { return; app.navigateTo({ url: "{course_setting}?course_id" + this.data.data.id }); }, triggerRefresh() { this.triggerEvent("refresh", {}, { bubbles: true }) }, } })