import { toast,modal } from '../../utils/extendApi' import { getStorage, setStorage } from '../../utils/storage' //导入ComponentWithStore方法 import { ComponentWithStore } from 'mobx-miniprogram-bindings' import { userStore } from '../../stores/userstore' ComponentWithStore({ storeBindings: { store: userStore, fields: ['id', 'identify'],//从Store中获取id和identify,存放在页面的data里 actions: [] }, data:{ IsStudent:1, Lesson_list:[], Show:0, status:0 }, methods:{ //IsStudent应该在页面加载时就进行更新 onRefresh:function(){ wswx.showLoading({ title: '刷新中...', }) if(this.data.identify === 1){ this.MyLearn() }else if(this.data.identify === 2){ this.MyTeach() } }, MyTeach(){ if(!this.data.IsStudent){ //获取授课信息 wx.request({ url: `http://172.20.10.2:8600/teacher-api/teacher/getteacherlessonlist/${getStorage('id')}`, // teacher_id在onload函数里面getStore获取,或者User success: (res) => { if (res.data.code === 200) { console.log('获取课程列表信息成功', res.data); this.setData({ Lesson_list: res.data.data , //将课程信息拉取到本地包括:"id","lesson_name","teacher_id": 0,"status": 0 // setStorage('') Show:1 }) //提示信息 toast({ title: '授课信息已刷新', icon: 'success' }) } else { console.error('获取课程列表信息失败,系统出错:', res.data); toast({ title: '系统出错', icon: 'error' }); } }, fail(err) { console.error('请求失败:', err); } }); } else { this.setData({ Show:0 }) toast({ title: '无授课信息', icon: 'error' }) } }, //新建课程 AddNewLesson(){ //先进行权限判断,再跳转到新建课程页面, if(getStorage('identify') === 2 ) { wx.navigateTo({ url: '/pages/addlesson/addlesson', }) } else{ toast({ title:'没有权限!', icon:'error' }) } }, // MyLearn(){ if(this.data.IsStudent){ wx.request({ url: `http://172.20.10.2:8600/student-api/student/lessonlist/${getStorage('id')}`, // id在onload函数里面getStore获取 success: (res) => { if (res.data.code === 200) { console.log('获取课程列表信息成功', res.data); this.setData({ Lesson_list: res.data.data, //将课程信息拉取到本地包括:"id","lesson_name","teacher_id": 0,"status": 0 Show : 1 }) //提示信息 toast({ title: '课程信息已刷新', icon: 'success' }) } else { console.error('获取课程列表信息失败,系统出错:', res.data); toast({ title: '系统出错', icon: 'error' }); } }, fail(err) { console.error('请求失败:', err); } }); } else { this.setData({ Show:0 }) toast({ title: '无听课信息', icon: 'error' }) } }, GetInLesson_Teacher: function(event) { const index = event.currentTarget.dataset.index; const item = this.data.Lesson_list[index]; // 获取课程ID和名称,并保存至Storage,进入教师上课界面,upteach; setStorage('LessonId',item.id) setStorage('LessonName',item.lesson_name) wx.navigateTo({ url: '/pages/upteach/upteach', }) // console.log('获取课程名称成功', getStorage('LessonName')); // 这里可以添加你的逻辑,如进入课程等 }, GetInLesson_Student: function(event) { const index = event.currentTarget.dataset.index; const item = this.data.Lesson_list[index]; setStorage('LessonId',item.id); setStorage('LessonName',item.lesson_name); this.setData({ status:item.status }); if(this.data.status === 1){ wx.navigateTo({ url: '/pages/attend/attend', }) } else { toast({title:'还未上课,无法进入',icon:'error'}) } // console.log('获取课程名称成功', getStorage('LessonName')); // 这里可以添加你的逻辑,如进入课程等 }, onLoad(){ setStorage('id',getStorage('id')) if(getStorage('identify') === 1){ // setStorage('identify',1) this.setData({ IsStudent:1 }) } else if(getStorage('identify') === 2){ // setStorage('identify',2) this.setData({ IsStudent:0 }) } } } })