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.
|
|
|
|
// pages/classroom/classroom.js
|
|
|
|
|
const AV = require("../../lib/av-live-query-weapp-min")
|
|
|
|
|
const { jsonify } = require('../../utils/leancloudutils');
|
|
|
|
|
|
|
|
|
|
Page({
|
|
|
|
|
/**
|
|
|
|
|
页面的初始数据
|
|
|
|
|
students: 该课程所有的学生
|
|
|
|
|
元素student
|
|
|
|
|
student.username 学生的用户名,是唯一,就像微信号一样
|
|
|
|
|
student.name 学生的姓名
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
presence: null,
|
|
|
|
|
students: [],
|
|
|
|
|
present_students: [],
|
|
|
|
|
class: null,
|
|
|
|
|
data: {
|
|
|
|
|
//以下数据的同步由该代码文件实现,数据的呈现由classroom.wxml实现
|
|
|
|
|
present_students: [], // 出席的学生的用户名即上文提及的student.username
|
|
|
|
|
students: [], // 该课程所有的学生
|
|
|
|
|
unpresent_students: [], //没有出席的学生的用户名,不建议使用该数据,考虑弃用
|
|
|
|
|
class_name: "",//课程名称
|
|
|
|
|
class_id: "",//该课程的主键(编号)
|
|
|
|
|
},
|
|
|
|
|
fetch_present: function(){
|
|
|
|
|
var query = new AV.Query("Presence");
|
|
|
|
|
query.include("user");
|
|
|
|
|
return query.find();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面加载
|
|
|
|
|
*/
|
|
|
|
|
onLoad: function (options) {
|
|
|
|
|
this.class = AV.Object.createWithoutData("Class_", options.class_id);
|
|
|
|
|
this.class.fetch().then((class_)=>{
|
|
|
|
|
console.log(this.class);
|
|
|
|
|
this.setData(this.class.get("name"));
|
|
|
|
|
})
|
|
|
|
|
console.log("onLoad");
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
|
*/
|
|
|
|
|
onReady: function () {
|
|
|
|
|
this.fetch_present().then((presents)=>{
|
|
|
|
|
console.log({students: presents.map((present)=>{return present.get("user")})});
|
|
|
|
|
this.setData(jsonify({students: presents.map((present)=>{return present.get("user")})}));
|
|
|
|
|
})
|
|
|
|
|
console.log("onReady");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面显示
|
|
|
|
|
*/
|
|
|
|
|
onShow: function () {
|
|
|
|
|
console.log("onShow");
|
|
|
|
|
this.class.enter();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面隐藏
|
|
|
|
|
*/
|
|
|
|
|
onHide: function () {
|
|
|
|
|
this.class.leave();
|
|
|
|
|
console.log("onHide");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生命周期函数--监听页面卸载
|
|
|
|
|
*/
|
|
|
|
|
onUnload: function () {
|
|
|
|
|
this.class.leave();
|
|
|
|
|
console.log("onUnload");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面相关事件处理函数--监听用户下拉动作
|
|
|
|
|
*/
|
|
|
|
|
onPullDownRefresh: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 页面上拉触底事件的处理函数
|
|
|
|
|
*/
|
|
|
|
|
onReachBottom: function () {
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 用户点击右上角分享
|
|
|
|
|
*/
|
|
|
|
|
onShareAppMessage: function () {
|
|
|
|
|
console.log("onShareAppMessage");
|
|
|
|
|
}
|
|
|
|
|
})
|