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.

137 lines
3.8 KiB

Page({
/**
* 页面的初始数据
*/
data: {
courseList: [],
isAdmin: true
},
enterCourse : function(event) {
const courseId = event.currentTarget.dataset.id;
const description = event.currentTarget.dataset.description;
wx.setStorageSync('courseId', courseId);
wx.setStorageSync('description', description);
console.log('courseId', courseId);
console.log('description', description);
if (this.data.isAdmin) {
wx.navigateTo({url: '/pages/course_detail/course_detail'});
} else {
wx.navigateTo({url: '/pages/course_detail(2)/course_detail(2)'});
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
this.getCourse();
},
getCourse: function() {
const that = this;
that.setData ({
isAdmin: wx.getStorageSync("isAdmin")
});
if (that.data.isAdmin) {
wx.request({
url: 'http://10.133.15.50:8888/admin/ownCourseList',
method: 'GET',
header: {
admin_token: wx.getStorageSync('token') // 携带token
},
success(res) {
if (res.statusCode === 200) {
console.log(res.data.data);
that.setData({
courseList: res.data.data
});
}
},
fail(error) {
console.error(err);
}
});
} else {
wx.request({
url: 'http://10.133.15.50:8888/student/ownCourseList',
method: 'GET',
header: {
student_token: wx.getStorageSync('token') // 携带token
},
success(res) {
if (res.statusCode === 200) {
console.log(res.data.data);
that.setData({
courseList: res.data.data
});
}
},
fail(error) {
console.error(err);
}
});
}
},
update: function(event) {
const that = this;
if (wx.getStorageSync('isAdmin') == true) {
wx.showModal({
title:'创建新课程',
editable:true,//显示输入框
placeholderText:'输入课程名',//显示输入框提示信息
success: res => {
if (res.confirm) { //点击了确认
console.log(res.content)//用户输入的值
wx.request({
url: 'http://10.133.15.50:8888/admin/createCourse?courseDescription=' + res.content,
method: 'POST',
header: {
'admin_token': wx.getStorageSync('token') // 携带token
},
success(res) {
if (res.statusCode === 200) {
console.log("yes");
}
that.getCourse();
},
fail(error) {
console.error(error);
}
})
} else {
console.log("取消");
}
}
})
} else {
wx.showModal({
title:'加入课程',
editable:true,//显示输入框
placeholderText:'输入课程名',//显示输入框提示信息
success: res => {
if (res.confirm) { //点击了确认
console.log(res.content)//用户输入的值
wx.request({
url: 'http://10.133.15.50:8888/student/joinCourse?courseDescription=' + res.content,
method: 'POST',
header: {
'student_token': wx.getStorageSync('token') // 携带token
},
success(res) {
if (res.statusCode === 200) {
console.log("yes");
}
that.getCourse();
},
fail(error) {
console.error(error);
}
})
} else {
console.log("取消");
}
}
})
}
}
})