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.
167 lines
4.0 KiB
167 lines
4.0 KiB
5 years ago
|
const app = getApp()
|
||
|
|
||
|
Page({
|
||
|
allnavData: [
|
||
|
{
|
||
|
text: "全部",
|
||
|
exercise_status: "all",
|
||
|
course_identities: [2, 5, 6]
|
||
|
},
|
||
|
{
|
||
|
text: "未发布",
|
||
|
exercise_status: 1,
|
||
|
course_identities: [2]
|
||
|
},
|
||
|
{
|
||
|
text: '提交中',
|
||
|
exercise_status: 2,
|
||
|
course_identities: [2, 5, 6]
|
||
|
},
|
||
|
{
|
||
|
text: '已截止',
|
||
|
exercise_status: 3,
|
||
|
course_identities: [2, 5, 6]
|
||
|
},
|
||
|
],
|
||
|
data: {
|
||
|
loading: true,
|
||
5 years ago
|
require_login: false,
|
||
|
page_status: 0, // 0=>loading 1=>success 2=>fail
|
||
5 years ago
|
exercises: [],
|
||
|
navData: [
|
||
|
{
|
||
|
text: "全部",
|
||
|
exercise_status: "all",
|
||
|
course_identities: [2, 5, 6]
|
||
|
},
|
||
|
{
|
||
|
text: '提交中',
|
||
|
exercise_status: 2,
|
||
|
course_identities: [2, 5, 6]
|
||
|
},
|
||
|
{
|
||
|
text: '已截止',
|
||
|
exercise_status: 3,
|
||
|
course_identities: [2, 5, 6]
|
||
|
},
|
||
5 years ago
|
{
|
||
|
text: "未发布",
|
||
|
exercise_status: 1,
|
||
|
course_identities: [2]
|
||
|
},
|
||
5 years ago
|
],
|
||
|
currentTab: 0,
|
||
|
navScrollLeft: 0
|
||
|
},
|
||
5 years ago
|
exercise_result: function ({ currentTarget: { dataset } }){
|
||
|
wx.navigateTo({
|
||
|
url: `../exercise_result/exercise_result?exercise_id=${dataset.exercise_id}`,
|
||
|
})
|
||
|
},
|
||
5 years ago
|
see_grade: function({currentTarget:{dataset}}){
|
||
|
wx.navigateTo({
|
||
|
url: `../exercise_grade/exercise_grade?exercise_id=${dataset.exercise_id}`,
|
||
|
})
|
||
|
},
|
||
|
edit_exercise: function({currentTarget:{dataset}}){
|
||
|
wx.navigateTo({
|
||
|
url: `../exercise_setting/exercise_setting?course_id=${this.course_id}&exercise_id=${dataset.exercise_id}`,
|
||
|
})
|
||
|
},
|
||
|
create_exercise: function(){
|
||
|
wx.navigateTo({
|
||
|
url: `../exercise_setting/exercise_setting?course_id=${this.course_id}`,
|
||
|
})
|
||
|
},
|
||
5 years ago
|
pull_courses_info: function(){
|
||
|
app.client.get_user_info()
|
||
|
.then();
|
||
|
/**@todo */
|
||
|
},
|
||
5 years ago
|
pull_exercise: function(){
|
||
5 years ago
|
app.client.search_exercises({ course_id: this.course_id })
|
||
5 years ago
|
.then(res => {
|
||
|
console.log("pull_exercise");
|
||
|
console.log(res);
|
||
|
if(res.data.exercises){
|
||
|
this.setData({exercises: res.data.exercises, loading: false});
|
||
|
}else if(res.data.status==401){
|
||
5 years ago
|
this.setData({require_login: true});
|
||
5 years ago
|
wx.showToast({
|
||
|
title: '请登陆后重试',
|
||
|
icon: "none"
|
||
|
});
|
||
|
}
|
||
|
console.log(this.data)
|
||
|
})
|
||
|
.catch(error=>{
|
||
|
console.error(error);
|
||
|
wx.showToast({
|
||
|
title: error.toString(),
|
||
|
icon: "none",
|
||
|
duration: 5000
|
||
|
})
|
||
|
});
|
||
5 years ago
|
},
|
||
|
see_exercise: function ({ currentTarget: { dataset } }){
|
||
|
wx.navigateTo({
|
||
|
url: '../exercise/exercise?exercise_id=' + dataset.exercise_id,
|
||
|
});
|
||
|
},
|
||
|
enter_exercise: function({currentTarget:{dataset}}){
|
||
|
wx.showModal({
|
||
|
title: '确认',
|
||
|
content: '开始作答吗?',
|
||
|
success: res=>{
|
||
|
if(res.confirm){
|
||
|
wx.navigateTo({
|
||
|
url: '../exercise/exercise?exercise_id='+dataset.exercise_id,
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
});
|
||
|
},
|
||
|
//事件处理函数
|
||
|
onLoad: function (options) {
|
||
|
this.course_id = options.id;
|
||
5 years ago
|
app.client.get_course_info({course_id: this.course_id})
|
||
|
.then(res=>{
|
||
|
this.setData({course:res.data})
|
||
|
console.log(res)
|
||
|
})
|
||
5 years ago
|
},
|
||
|
onShow: function(){
|
||
5 years ago
|
this.setData({require_login: false});
|
||
5 years ago
|
this.pull_exercise();
|
||
5 years ago
|
},
|
||
|
switchNav(event) {
|
||
|
var cur = event.currentTarget.dataset.current;
|
||
|
//每个tab选项宽度占1/5
|
||
|
var singleNavWidth = this.data.windowWidth / 3;
|
||
|
//tab选项居中
|
||
|
this.setData({
|
||
|
navScrollLeft: (cur - 1) * singleNavWidth
|
||
|
})
|
||
|
if (this.data.currentTab == cur) {
|
||
|
return false;
|
||
|
} else {
|
||
|
this.setData({
|
||
|
currentTab: cur
|
||
|
})
|
||
|
}
|
||
|
},
|
||
|
switchTab(event) {
|
||
|
var cur = event.detail.current;
|
||
|
var singleNavWidth = this.data.windowWidth / 5;
|
||
|
this.setData({
|
||
|
currentTab: cur,
|
||
|
navScrollLeft: (cur - 1) * singleNavWidth
|
||
|
});
|
||
|
},
|
||
|
onPullDownRefresh: function(){
|
||
5 years ago
|
this.pull_exercise();
|
||
|
},
|
||
|
onShareAppMessage:function(){
|
||
|
|
||
5 years ago
|
}
|
||
|
})
|