|
|
@ -2,6 +2,7 @@
|
|
|
|
const AV = require("../../lib/av-live-query-weapp-min")
|
|
|
|
const AV = require("../../lib/av-live-query-weapp-min")
|
|
|
|
const { jsonify } = require('../../utils/leancloudutils');
|
|
|
|
const { jsonify } = require('../../utils/leancloudutils');
|
|
|
|
const bind = require("../../lib/live-query-binding")
|
|
|
|
const bind = require("../../lib/live-query-binding")
|
|
|
|
|
|
|
|
const Message = require("../../model/message")
|
|
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
Page({
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -14,10 +15,12 @@ Page({
|
|
|
|
student.present 是否出席
|
|
|
|
student.present 是否出席
|
|
|
|
student.isasking :0:没有提问,1:提问,2:请回答
|
|
|
|
student.isasking :0:没有提问,1:提问,2:请回答
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
class:null,
|
|
|
|
students: [],
|
|
|
|
students: [],
|
|
|
|
presences: [],
|
|
|
|
presences: [],
|
|
|
|
my_presence: null,
|
|
|
|
my_presence: null,
|
|
|
|
is_askiny: null,
|
|
|
|
asking_presence: null,
|
|
|
|
|
|
|
|
idStudentMap: {},
|
|
|
|
data: {
|
|
|
|
data: {
|
|
|
|
//以下数据的同步由该代码文件实现,数据的呈现由classroom.wxml实现
|
|
|
|
//以下数据的同步由该代码文件实现,数据的呈现由classroom.wxml实现
|
|
|
|
students: [], // 该课程所有的学生, 元素类型见上文中的student
|
|
|
|
students: [], // 该课程所有的学生, 元素类型见上文中的student
|
|
|
@ -29,6 +32,59 @@ Page({
|
|
|
|
//属性如下:objectId, username, name
|
|
|
|
//属性如下:objectId, username, name
|
|
|
|
class_name: "", //课程名称
|
|
|
|
class_name: "", //课程名称
|
|
|
|
class_id: "", //该课程的主键(编号)
|
|
|
|
class_id: "", //该课程的主键(编号)
|
|
|
|
|
|
|
|
message_text: "",
|
|
|
|
|
|
|
|
messages: [],
|
|
|
|
|
|
|
|
show_conversation: true
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
pull_messages: function(){
|
|
|
|
|
|
|
|
query = new AV.Query("Message");
|
|
|
|
|
|
|
|
query.equalTo("class", this.class);
|
|
|
|
|
|
|
|
query.include("sender");
|
|
|
|
|
|
|
|
set_messages = this.set_messages.bind(this);
|
|
|
|
|
|
|
|
return AV.Promise.all([query.find().then(set_messages), query.subscribe()]).then(([messages, subscription]) => {
|
|
|
|
|
|
|
|
this.messageSubscription = subscription;
|
|
|
|
|
|
|
|
if (this.messageUnbind) this.messageUnbind();
|
|
|
|
|
|
|
|
this.messageUnbind = bind(subscription, messages, set_messages);
|
|
|
|
|
|
|
|
}).catch(error => console.error(error.message));
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
set_messages: function(messages){
|
|
|
|
|
|
|
|
console.log("set_messages");
|
|
|
|
|
|
|
|
messages = messages.map(message=>{
|
|
|
|
|
|
|
|
sender = message.get("sender");
|
|
|
|
|
|
|
|
console.log(this.idStudentMap);
|
|
|
|
|
|
|
|
console.log(sender.id);
|
|
|
|
|
|
|
|
console.log(!sender.get("name") && sender.id in this.idStudentMap)
|
|
|
|
|
|
|
|
if(!sender.get("name")&&sender.id in this.idStudentMap){
|
|
|
|
|
|
|
|
sender = this.idStudentMap[sender.id];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
message.set("sender_name", sender.get("name"));
|
|
|
|
|
|
|
|
message.set("sender_username", sender.get("username"));
|
|
|
|
|
|
|
|
return message;
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log(jsonify({ messages }));
|
|
|
|
|
|
|
|
this.setData(jsonify({messages}));
|
|
|
|
|
|
|
|
return messages;
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
send_message:function(event){
|
|
|
|
|
|
|
|
let {message_text} = this.data;
|
|
|
|
|
|
|
|
if(message.trim()==""){return;}
|
|
|
|
|
|
|
|
message = new Message({
|
|
|
|
|
|
|
|
text: message_text,
|
|
|
|
|
|
|
|
class: this.class,
|
|
|
|
|
|
|
|
sender: AV.User.current()
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
message.save().then(()=>{
|
|
|
|
|
|
|
|
this.setData({message_text: ""});
|
|
|
|
|
|
|
|
console.log("send_message")
|
|
|
|
|
|
|
|
}).catch(console.error);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
close_conversation: function(event){
|
|
|
|
|
|
|
|
this.setData({show_conversation: false});
|
|
|
|
|
|
|
|
this.messageSubscription.unsubscribe();
|
|
|
|
|
|
|
|
this.messageUnbind();
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
update_message:function({detail:{value}}){
|
|
|
|
|
|
|
|
this.setData({message_text: value});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
enter_setting: function(event){
|
|
|
|
enter_setting: function(event){
|
|
|
|
wx.navigateTo({
|
|
|
|
wx.navigateTo({
|
|
|
@ -43,9 +99,9 @@ Page({
|
|
|
|
},
|
|
|
|
},
|
|
|
|
select_stu: function(event){
|
|
|
|
select_stu: function(event){
|
|
|
|
id = event.currentTarget.dataset.id;
|
|
|
|
id = event.currentTarget.dataset.id;
|
|
|
|
if(id!='none'){
|
|
|
|
if(id=='none'){
|
|
|
|
console.log(id);
|
|
|
|
id="";
|
|
|
|
}else{console.log("none");id=""}
|
|
|
|
}
|
|
|
|
this.setData({select_stu_id: id});
|
|
|
|
this.setData({select_stu_id: id});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -53,14 +109,13 @@ Page({
|
|
|
|
userid = event.currentTarget.dataset.id;
|
|
|
|
userid = event.currentTarget.dataset.id;
|
|
|
|
status = event.currentTarget.dataset.status;
|
|
|
|
status = event.currentTarget.dataset.status;
|
|
|
|
console.log("set_isasking");
|
|
|
|
console.log("set_isasking");
|
|
|
|
console.log(status);
|
|
|
|
this.asking_presence = this.presences.filter(presence=>presence.get("user").id==userid)[0];
|
|
|
|
console.log(typeof status);
|
|
|
|
console.log(this.asking_presence);
|
|
|
|
this.asking_present = this.presences.filter(presence=>presence.get("user").id==userid)[0];
|
|
|
|
this.asking_presence.isasking = status;
|
|
|
|
this.asking_present.isasking = status;
|
|
|
|
|
|
|
|
wx.showLoading({
|
|
|
|
wx.showLoading({
|
|
|
|
title: '请稍候',
|
|
|
|
title: '请稍候',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
this.asking_present.save().then(()=>{
|
|
|
|
this.asking_presence.save().then(()=>{
|
|
|
|
wx.hideLoading();
|
|
|
|
wx.hideLoading();
|
|
|
|
}, ()=>{
|
|
|
|
}, ()=>{
|
|
|
|
wx.hideLoading();
|
|
|
|
wx.hideLoading();
|
|
|
@ -71,11 +126,10 @@ Page({
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
add_mark: function(event){
|
|
|
|
add_mark: function(event){
|
|
|
|
|
|
|
|
console.log("add_mark");
|
|
|
|
id = event.currentTarget.dataset.id;
|
|
|
|
id = event.currentTarget.dataset.id;
|
|
|
|
mark = event.currentTarget.dataset.mark;
|
|
|
|
mark = event.currentTarget.dataset.mark;
|
|
|
|
console.log("add_mark");
|
|
|
|
console.log(this.presences);
|
|
|
|
console.log(mark);
|
|
|
|
|
|
|
|
console.log(typeof mark);
|
|
|
|
|
|
|
|
presence = this.presences.filter(presence => presence.get("user").id == id)[0];
|
|
|
|
presence = this.presences.filter(presence => presence.get("user").id == id)[0];
|
|
|
|
if(presence==null){
|
|
|
|
if(presence==null){
|
|
|
|
console.warn("没有选择学生");
|
|
|
|
console.warn("没有选择学生");
|
|
|
@ -90,21 +144,22 @@ Page({
|
|
|
|
|
|
|
|
|
|
|
|
pull_presence: function(){
|
|
|
|
pull_presence: function(){
|
|
|
|
var query = new AV.Query("Presence");
|
|
|
|
var query = new AV.Query("Presence");
|
|
|
|
//console.log(this.class);
|
|
|
|
|
|
|
|
query.equalTo("class", this.class);
|
|
|
|
query.equalTo("class", this.class);
|
|
|
|
query.include("user");
|
|
|
|
query.include("user");
|
|
|
|
set_presence = this.set_presence.bind(this);
|
|
|
|
set_presence = this.set_presence.bind(this);
|
|
|
|
return AV.Promise.all([query.find().then(set_presence), query.subscribe()]).then(([presents, subscription])=>{
|
|
|
|
return AV.Promise.all([query.find().then(set_presence), query.subscribe()]).then(([presences, subscription])=>{
|
|
|
|
this.PresentSubscription = subscription;
|
|
|
|
this.presenceSubscription = subscription;
|
|
|
|
if(this.presentUnbind) this.presentUnbind();
|
|
|
|
if(this.presenceUnbind) this.presenceUnbind();
|
|
|
|
this.presentUnbind = bind(subscription, presents, set_presence);
|
|
|
|
console.log("shwo set_presence");
|
|
|
|
|
|
|
|
console.log(presences);
|
|
|
|
|
|
|
|
console.log(set_presence);
|
|
|
|
|
|
|
|
this.presenceUnbind = bind(subscription, presences, set_presence);
|
|
|
|
}).catch(error=> console.error(error.message));
|
|
|
|
}).catch(error=> console.error(error.message));
|
|
|
|
},
|
|
|
|
},
|
|
|
|
set_presence: function(presences){
|
|
|
|
set_presence: function(presences){
|
|
|
|
console.log("set_presence");
|
|
|
|
console.log("set_presence");
|
|
|
|
//console.log(presences);
|
|
|
|
console.log(presences);
|
|
|
|
this.presences = presences;
|
|
|
|
this.presences = presences;
|
|
|
|
console.log(this.presences);
|
|
|
|
|
|
|
|
students = this.presences.map((presence)=>{
|
|
|
|
students = this.presences.map((presence)=>{
|
|
|
|
student = presence.get("user");
|
|
|
|
student = presence.get("user");
|
|
|
|
if(student.get("username")==null){
|
|
|
|
if(student.get("username")==null){
|
|
|
@ -115,6 +170,7 @@ Page({
|
|
|
|
student.fetch();
|
|
|
|
student.fetch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.idStudentMap[student.id]=student;
|
|
|
|
student.set("present", presence.get("present"));
|
|
|
|
student.set("present", presence.get("present"));
|
|
|
|
student.set("isasking",presence.get("isasking"));
|
|
|
|
student.set("isasking",presence.get("isasking"));
|
|
|
|
student.set("mark", presence.get("mark"));
|
|
|
|
student.set("mark", presence.get("mark"));
|
|
|
@ -125,7 +181,6 @@ Page({
|
|
|
|
return student;
|
|
|
|
return student;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
this.students = students;
|
|
|
|
this.students = students;
|
|
|
|
console.log(students);
|
|
|
|
|
|
|
|
this.setData(jsonify({students}));
|
|
|
|
this.setData(jsonify({students}));
|
|
|
|
return presences;
|
|
|
|
return presences;
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -135,23 +190,14 @@ Page({
|
|
|
|
query.equalTo("objectId", class_id);
|
|
|
|
query.equalTo("objectId", class_id);
|
|
|
|
query.include("teacher");
|
|
|
|
query.include("teacher");
|
|
|
|
return query.find().then((classes) => {
|
|
|
|
return query.find().then((classes) => {
|
|
|
|
//console.log(this.class);
|
|
|
|
|
|
|
|
this.class = classes[0];
|
|
|
|
this.class = classes[0];
|
|
|
|
teacher = this.class.get("teacher");
|
|
|
|
teacher = this.class.get("teacher");
|
|
|
|
console.log("pull_class");
|
|
|
|
|
|
|
|
console.log(teacher);
|
|
|
|
|
|
|
|
teacher = teacher.toJSON();
|
|
|
|
teacher = teacher.toJSON();
|
|
|
|
// if(typeof teacher.toJson == "function"){
|
|
|
|
|
|
|
|
// teacher = teacher.toJson();
|
|
|
|
|
|
|
|
// console.log("toJson");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
this.setData({
|
|
|
|
this.setData({
|
|
|
|
class_name: this.class.get("name"),
|
|
|
|
class_name: this.class.get("name"),
|
|
|
|
class_id: this.class.get("objectId"),
|
|
|
|
class_id: this.class.get("objectId"),
|
|
|
|
teacher: teacher
|
|
|
|
teacher: teacher
|
|
|
|
});
|
|
|
|
});
|
|
|
|
console.log(teacher);
|
|
|
|
|
|
|
|
//this.setData(teacher);
|
|
|
|
|
|
|
|
}).catch(error=>console.error(error.message))
|
|
|
|
}).catch(error=>console.error(error.message))
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -164,16 +210,18 @@ Page({
|
|
|
|
})
|
|
|
|
})
|
|
|
|
this.setData({current_user: AV.User.current().toJSON()});
|
|
|
|
this.setData({current_user: AV.User.current().toJSON()});
|
|
|
|
this.class_id = options.class_id;
|
|
|
|
this.class_id = options.class_id;
|
|
|
|
|
|
|
|
this.class = AV.Object.createWithoutData("Class_", this.class_id);
|
|
|
|
|
|
|
|
this.pull_presence.bind(this)().then((presences) => {
|
|
|
|
|
|
|
|
this.my_presence.enter();
|
|
|
|
|
|
|
|
});
|
|
|
|
this.pull_class.bind(this)(this.class_id)
|
|
|
|
this.pull_class.bind(this)(this.class_id)
|
|
|
|
.then(() => {
|
|
|
|
.then(() => {
|
|
|
|
wx.setNavigationBarTitle({
|
|
|
|
wx.setNavigationBarTitle({
|
|
|
|
title: this.data.class_name,
|
|
|
|
title: this.data.class_name,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
console.log("pull_presence");
|
|
|
|
wx.hideLoading();//better place??
|
|
|
|
this.pull_presence.bind(this)().then((presences) => { this.my_presence.enter(); this.presences = presences;});
|
|
|
|
|
|
|
|
wx.hideLoading();
|
|
|
|
|
|
|
|
console.log("hideLoading");
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
this.pull_messages.bind(this)();
|
|
|
|
console.log("onLoad");
|
|
|
|
console.log("onLoad");
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
@ -189,9 +237,8 @@ Page({
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
onShow: function () {
|
|
|
|
onShow: function () {
|
|
|
|
console.log("onShow");
|
|
|
|
console.log("onShow");
|
|
|
|
console.log("enter class when onShow");
|
|
|
|
|
|
|
|
console.log(AV.User.current());
|
|
|
|
|
|
|
|
if(this.my_presence){
|
|
|
|
if(this.my_presence){
|
|
|
|
|
|
|
|
console.log("enter class when onShow");
|
|
|
|
this.my_presence.enter();
|
|
|
|
this.my_presence.enter();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -210,14 +257,17 @@ Page({
|
|
|
|
onUnload: function () {
|
|
|
|
onUnload: function () {
|
|
|
|
this.my_presence.leave();
|
|
|
|
this.my_presence.leave();
|
|
|
|
console.log("onUnload");
|
|
|
|
console.log("onUnload");
|
|
|
|
this.PresentSubscription.unsubscribe();
|
|
|
|
this.presenceSubscription.unsubscribe();
|
|
|
|
this.presentUnbind();
|
|
|
|
this.presenceUnbind();
|
|
|
|
|
|
|
|
this.messageSubscription.unsubscribe();
|
|
|
|
|
|
|
|
this.messageUnbind();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
|
|
console.log(this.idStudentMap);
|
|
|
|
this.pull_presence.bind(this)();
|
|
|
|
this.pull_presence.bind(this)();
|
|
|
|
this.pull_class.bind(this)(this.class_id)
|
|
|
|
this.pull_class.bind(this)(this.class_id)
|
|
|
|
.then(() => {
|
|
|
|
.then(() => {
|
|
|
|