|
|
@ -3,16 +3,11 @@ const app = getApp();
|
|
|
|
statuses:[]
|
|
|
|
statuses:[]
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
const getDataForRender = class_ => ({
|
|
|
|
|
|
|
|
name: class_.get('name'),
|
|
|
|
|
|
|
|
objectId: class_.get('objectId')
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
const categories = [{ text: "我学习的", value: "study" }, { text: "我管理的", value: "manage" }];
|
|
|
|
|
|
|
|
Component({
|
|
|
|
Component({
|
|
|
|
data: {
|
|
|
|
data: {
|
|
|
|
imgDir: global.config.imgDir,
|
|
|
|
imgDir: global.config.imgDir,
|
|
|
|
attachDir: global.config.attachDir,
|
|
|
|
attachDir: global.config.attachDir,
|
|
|
|
categories,
|
|
|
|
categories: [{ text: "我学习的", value: "study" }, { text: "我管理的", value: "manage" }],
|
|
|
|
statuses: [{ text: "正在进行", value: "processing" }, { text: "已结束", value: "end" }],
|
|
|
|
statuses: [{ text: "正在进行", value: "processing" }, { text: "已结束", value: "end" }],
|
|
|
|
courses: [],
|
|
|
|
courses: [],
|
|
|
|
status: 0,
|
|
|
|
status: 0,
|
|
|
@ -21,26 +16,38 @@ Component({
|
|
|
|
current_cate: -1
|
|
|
|
current_cate: -1
|
|
|
|
},
|
|
|
|
},
|
|
|
|
attached() {
|
|
|
|
attached() {
|
|
|
|
|
|
|
|
let user = app.user();
|
|
|
|
|
|
|
|
let key = `cache-weapps.home-${user.user_id}-${user.is_teacher}`
|
|
|
|
|
|
|
|
let cache_courses = wx.getStorageSync(key);
|
|
|
|
|
|
|
|
if(cache_courses)
|
|
|
|
|
|
|
|
this.setData({courses:cache_courses}); // set local cache;
|
|
|
|
this.options = { page: 1, limit: 15 };
|
|
|
|
this.options = { page: 1, limit: 15 };
|
|
|
|
if (app.user().is_teacher)
|
|
|
|
if (user.is_teacher)
|
|
|
|
var current_cate = 1;
|
|
|
|
var current_cate = 1;
|
|
|
|
else
|
|
|
|
else
|
|
|
|
var current_cate = 0;
|
|
|
|
var current_cate = 0;
|
|
|
|
this.setData({ current_cate });
|
|
|
|
this.options["category"] = this.data.categories[current_cate].value;
|
|
|
|
|
|
|
|
this.pullCourses({refresh:1})
|
|
|
|
|
|
|
|
.then(res=>{
|
|
|
|
|
|
|
|
if(res.courses){
|
|
|
|
|
|
|
|
var user = app.user();
|
|
|
|
|
|
|
|
wx.setStorageSync(key, res.courses);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
this.setData({current_cate});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
pageLifetimes: {
|
|
|
|
pageLifetimes: {
|
|
|
|
show: function () {
|
|
|
|
show: function () {
|
|
|
|
if (this.data.current_cate >= 0) {
|
|
|
|
if (this.data.current_cate >= 0) {
|
|
|
|
this.pullCourses({ refresh: 2 });
|
|
|
|
this.pullCourses({ refresh: 2, showError:0 });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
onCategoryChange: function ({ detail: { current, value } }) {
|
|
|
|
onCategoryChange: function ({ detail: { current, value, source } }) {
|
|
|
|
;
|
|
|
|
if(source!='touch') return;
|
|
|
|
this.options["category"] = value.value;
|
|
|
|
this.options["category"] = value.value;
|
|
|
|
this.pullCourses({ refresh: 1 });
|
|
|
|
this.pullCourses({ refresh: 1 });
|
|
|
|
this.setData({ category: value.value });
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onStatusChange: function ({ detail: { value } }) {
|
|
|
|
onStatusChange: function ({ detail: { value } }) {
|
|
|
|
this.options["status"] = value.value;
|
|
|
|
this.options["status"] = value.value;
|
|
|
@ -66,14 +73,12 @@ Component({
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
},
|
|
|
|
},
|
|
|
|
enter_course: function (event) {
|
|
|
|
enter_course: function (event) {
|
|
|
|
;
|
|
|
|
|
|
|
|
let { id, course_name } = event.currentTarget.dataset;
|
|
|
|
let { id, course_name } = event.currentTarget.dataset;
|
|
|
|
wx.navigateTo({
|
|
|
|
wx.navigateTo({
|
|
|
|
url: "/course/pages/course/course?course_id=" + id + "&course_name=" + course_name,
|
|
|
|
url: "/course/pages/course/course?course_id=" + id + "&course_name=" + course_name,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
pullCourses: function ({ refresh = 0, showError=1} = {}) {
|
|
|
|
pullCourses: function ({ refresh = 0 } = {}) {
|
|
|
|
|
|
|
|
if (refresh) {
|
|
|
|
if (refresh) {
|
|
|
|
if (refresh == 1) {
|
|
|
|
if (refresh == 1) {
|
|
|
|
this.options.page = 1;
|
|
|
|
this.options.page = 1;
|
|
|
@ -88,7 +93,7 @@ Component({
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return app.callApi({
|
|
|
|
return app.callApi({
|
|
|
|
name: "weapps.home", data
|
|
|
|
name: "weapps.home", data
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(res => {
|
|
|
|
.then(res => {
|
|
|
|
let { courses } = res;
|
|
|
|
let { courses } = res;
|
|
|
|
if (data.status)
|
|
|
|
if (data.status)
|
|
|
@ -98,15 +103,18 @@ Component({
|
|
|
|
if (!refresh)
|
|
|
|
if (!refresh)
|
|
|
|
courses = this.data.courses.concat(courses);
|
|
|
|
courses = this.data.courses.concat(courses);
|
|
|
|
this.setData({ courses, loading: false });
|
|
|
|
this.setData({ courses, loading: false });
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}).catch(e => {
|
|
|
|
}).catch(e => {
|
|
|
|
this.setData({ courses: [], loading: false });
|
|
|
|
if(showError)
|
|
|
|
|
|
|
|
app.showError(e);
|
|
|
|
|
|
|
|
this.setData({loading: false });
|
|
|
|
|
|
|
|
return e;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onReachBottom() {
|
|
|
|
onReachBottom() {
|
|
|
|
this.pullCourses();
|
|
|
|
this.pullCourses();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
;
|
|
|
|
|
|
|
|
this.pullCourses({ refresh: 2 });
|
|
|
|
this.pullCourses({ refresh: 2 });
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|