diff --git a/model/class.js b/model/class.js index 2da7d9f..b8d0e97 100644 --- a/model/class.js +++ b/model/class.js @@ -1,5 +1,5 @@ const AV = require('../lib/av-live-query-weapp-min'); -const Presence = require("./presence") +const Presence = require("./presence") class Class extends AV.Object{ get name(){ @@ -22,6 +22,8 @@ class Class extends AV.Object{ } enter() { this.leave(); + console.log("class.enter"); + console.log(AV.User.current()); this._presence = new Presence({ user: AV.User.current(), class: this diff --git a/model/presence.js b/model/presence.js index 129e0d4..a7add19 100644 --- a/model/presence.js +++ b/model/presence.js @@ -13,6 +13,12 @@ class Presence extends AV.Object{ get class(){ return this.get("class"); } + set isasking(value){ + this.set("isasking", value); + } + get isasking(){ + return this.get("isasking"); + } } AV.Object.register(Presence, "Presence"); diff --git a/model/studentclassmap.js b/model/studentclassmap.js new file mode 100644 index 0000000..ccecdda --- /dev/null +++ b/model/studentclassmap.js @@ -0,0 +1,17 @@ +const AV = require("../..//lib/av-live-query-weapp-min") + + +class StudentClassMap extends AV.Object{ + get class(){ + return this.get("class"); + } + set class(value){ + this.set("class", value); + } + get user(){ + return this.get("user"); + } + set user(value){ + this.set("user", value); + } +} \ No newline at end of file diff --git a/pages/classes/classes.js b/pages/classes/classes.js index aa29363..cfca575 100644 --- a/pages/classes/classes.js +++ b/pages/classes/classes.js @@ -37,7 +37,10 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad: function (options) { - login(); + login().then((user)=>{ + console.log(user); + console.log(AV.User.current()); + }); }, /** diff --git a/pages/classroom/classroom.js b/pages/classroom/classroom.js index 015e05d..f0ba9ec 100644 --- a/pages/classroom/classroom.js +++ b/pages/classroom/classroom.js @@ -11,6 +11,8 @@ Page({ student.objectId 该学生的主键,唯一 student.username 学生的用户名,是唯一,就像微信号一样 student.name 学生的姓名 + student.present 是否出席 + student.isasking :0:没有提问,1:提问,2:请回答 */ presence: null, students: [], @@ -18,15 +20,14 @@ Page({ class_id: null, data: { //以下数据的同步由该代码文件实现,数据的呈现由classroom.wxml实现 - //命名可能有点混乱...... - present_students: [], - // 出席的学生的用户名即上文提及的student.username,考虑弃用,建议替换为presen_stu_ids - present_stu_ids: [], //出席的学生的主键objectId students: [], // 该课程所有的学生, 元素类型见上文中的student - present_stus: [], //出席的学生,元素类型与students中的一样 - unpresent_students: [], //没有出席的学生的用户名,不建议使用该数据,弃用 - class_name: "",//课程名称 - class_id: "",//该课程的主键(编号) + current_user: null, //目前登陆的用户,类型为对象,属性有objectId,username, name + teacher: null, + //该课程教员,类型为对象 + //请在进入界面时判断用户是否为教员以给与权限或更改界面 + //属性如下:objectId, username, name + class_name: "", //课程名称 + class_id: "", //该课程的主键(编号) }, pull_present: function(){ @@ -36,31 +37,32 @@ Page({ query.include("user"); set_present = this.set_present.bind(this); return AV.Promise.all([query.find().then(set_present), query.subscribe()]).then(([presents, subscription])=>{ - this.subscription = subscription; - if(this.presenceUnbind) this.unbind(); - this.presenceUnbind = bind(subscription, presents, set_present); + this.PresentSubscription = subscription; + if(this.presentUnbind) this.presentUnbind(); + this.presentUnbind = bind(subscription, presents, set_present); }).catch(error=> console.error(error.message)); }, set_present: function(presents){ //console.log("set_present"); //console.log(presents); - var student_ids = presents.map((present)=>{ + var is_asking={}; + var present_stu_ids = presents.map((present)=>{ user = present.get("user"); - //console.log(user); - //console.log(typeof user); + is_asking[user.id]=present.get("isasking"); return user.id; - //return user.get("username"); }); - //console.log("student_ids:"+student_ids.toString()); - //console.log("students:"+this.students); - present_stus = this.students.filter(student=> student_ids.indexOf(student.id)>-1) - //console.log(present_stus); - present_stu_usernames = present_stus.map(stu => stu.get("username")); - present_stu_ids = present_stus.map(stu=>stu.id) - this.setData({ - present_stu_ids: present_stu_ids, - present_students: present_stu_usernames}); - this.setData(jsonify({present_stus})); + students = this.students.map((student)=>{ + if(present_stu_ids.indexOf(student.id)>-1){ + student.set("ispresent",true); + student.set("isasking", is_asking[student.id]); + }else{ + student.set("ispresent",false); + student.set("isasking", 0); + } + + return student; + }) + this.setData(jsonify({students})); return presents; }, @@ -119,6 +121,7 @@ Page({ onShow: function () { console.log("onShow"); console.log("enter class when onShow"); + console.log(AV.User.current()); this.class.enter(); }, @@ -136,7 +139,8 @@ Page({ onUnload: function () { this.class.leave(); console.log("onUnload"); - + this.PresentSubscription.unsubscribe(); + this.presentUnbind(); }, /** diff --git a/pages/classroom/classroom.wxml b/pages/classroom/classroom.wxml index 0213ae7..c2fd462 100644 --- a/pages/classroom/classroom.wxml +++ b/pages/classroom/classroom.wxml @@ -1,9 +1,9 @@ -pages/classroom/classroom.wxml +pages/classroom/classroom.wxml{{class_name}}{{class_id}} - {{student.username}} + {{student.username}} {{student.ispresent}} {{student.isasking}}