修补了一些bug

smart_class
educoder_weapp 5 years ago
parent 58b6b3ef3a
commit bf2aaac3b1

@ -1,7 +1,7 @@
//app.js //app.js
//导入leancloud库与后台交互 //导入leancloud库与后台交互
const AV = require('./lib/av-live-query-weapp-min'); const AV = require('./lib/av-live-query-weapp-min');
const login = require("./model/user");
//初始化 //初始化
AV.init({ AV.init({
appId: 'eVHYNBdT5D2lDxNj5jtJXsWT-MdYXbMMI', appId: 'eVHYNBdT5D2lDxNj5jtJXsWT-MdYXbMMI',
@ -17,5 +17,9 @@ App({
}, },
onLaunch () { onLaunch () {
console.log('App.onLaunch()'); console.log('App.onLaunch()');
login().then((user) => {
console.log(user);
console.log(AV.User.current());
});
} }
}); });

@ -1,5 +1,6 @@
{ {
"pages": [ "pages": [
"pages/classes/classes",
"pages/index/index", "pages/index/index",
"pages/config/config", "pages/config/config",
"pages/https/https", "pages/https/https",
@ -8,7 +9,6 @@
"pages/game/game", "pages/game/game",
"pages/shouquan/shouquan", "pages/shouquan/shouquan",
"pages/outside/outside", "pages/outside/outside",
"pages/classes/classes",
"pages/classroom/classroom" "pages/classroom/classroom"
], ],
"window": { "window": {

@ -20,20 +20,8 @@ class Class extends AV.Object{
this.remove(user.id); this.remove(user.id);
} }
} }
enter() { set_asking(status){
this.leave(); return this._presence.set("isasking", status).save()
console.log("class.enter");
console.log(AV.User.current());
this._presence = new Presence({
user: AV.User.current(),
class: this
});
this._presence.save();
}
leave() {
if (this._presence != null) {
this._presence.destroy();
}
} }
present_students() { present_students() {
var query = new AV.Query("Presence"); var query = new AV.Query("Presence");

@ -14,11 +14,9 @@ class Grade extends AV.Object {
set student(value){ set student(value){
this.set("student". value); this.set("student". value);
} }
get class() { get class() {
return this.get('class'); return this.get('class');
} }
set class(value){ set class(value){
this.set("class", value); this.set("class", value);
} }

@ -19,6 +19,29 @@ class Presence extends AV.Object{
get isasking(){ get isasking(){
return this.get("isasking"); return this.get("isasking");
} }
get present(){
return this.get("present");
}
set present(value){
this.set("present", value);
}
get mark() {
return this.get('done');
}
set mark(value) {
this.set('mark', value);
}
add_mark(value) {
this.increment(value);
}
enter(){
console.log("presence.enter");
console.log(this);
this.set("present", true).save().catch(error=>console.error(error.message));
}
leave(){
this.set("present", false).save()
}
} }
AV.Object.register(Presence, "Presence"); AV.Object.register(Presence, "Presence");

@ -14,4 +14,16 @@ class StudentClassMap extends AV.Object{
set user(value){ set user(value){
this.set("user", value); this.set("user", value);
} }
get mark() {
return this.get('done');
} }
set mark(value) {
this.set('mark', value);
}
add_mark(value) {
this.increment(value);
}
}
AV.Object.register(StudentClassMap, "StudentClassMap");
module.exports=StudentClassMap;

@ -10,7 +10,6 @@ const getDataForRender = class_ => ({
}); });
Page({ Page({
/** /**
页面的初始数据data用于与.wxlm文件绑定 页面的初始数据data用于与.wxlm文件绑定
classes: 课程列表 type: Array classes: 课程列表 type: Array
@ -37,10 +36,7 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad: function (options) {
login().then((user)=>{
console.log(user);
console.log(AV.User.current());
});
}, },
/** /**

@ -15,9 +15,13 @@ Page({
student.isasking :0:没有提问,1:提问,2:请回答 student.isasking :0:没有提问,1:提问,2:请回答
*/ */
presence: null, presence: null,
origin_presences: [],
students: [], students: [],
class: null, class: null,
presences : [],
class_id: null, class_id: null,
asking_presence: null,
my_presence: null,
data: { data: {
//以下数据的同步由该代码文件实现数据的呈现由classroom.wxml实现 //以下数据的同步由该代码文件实现数据的呈现由classroom.wxml实现
students: [], // 该课程所有的学生, 元素类型见上文中的student students: [], // 该课程所有的学生, 元素类型见上文中的student
@ -38,88 +42,95 @@ Page({
sco3: function () { sco3: function () {
//打3分的函数 //打3分的函数
}, },
ask: function () { ask: function (event) {
//学生提问的函数 //学生提问的函数
console.log(event);
set_asking()
}, },
rep: function () { rep: function (event) {
console.log(event);
//点这个学生要回答他问题的函数 //点这个学生要回答他问题的函数
}, },
set_asking: function(userid, status){
this.asking_present = this.presents.filter(present=>present.get("user").id==userid)[0];
this.asking_present.isasking = status;
this.asking_present.save();
},
add_mark: function(mark){
if(this.asking_present==null){
console.warn("没有选择学生");
}else{
user = this.asking_present.get("user");
studentClassMap = this.studentClassMaps.filter(studentClassMap=>studentClassMap.get("user"))
}
},
pull_present: function(){ pull_presence: function(){
var query = new AV.Query("Presence"); var query = new AV.Query("Presence");
//console.log(this.class); //console.log(this.class);
query.equalTo("class", this.class); query.equalTo("class", this.class);
query.include("user"); query.include("user");
set_present = this.set_present.bind(this); set_presence = this.set_presence.bind(this);
return AV.Promise.all([query.find().then(set_present), query.subscribe()]).then(([presents, subscription])=>{ return AV.Promise.all([query.find().then(set_presence), query.subscribe()]).then(([presents, subscription])=>{
this.PresentSubscription = subscription; this.PresentSubscription = subscription;
if(this.presentUnbind) this.presentUnbind(); if(this.presentUnbind) this.presentUnbind();
this.presentUnbind = bind(subscription, presents, set_present); this.presentUnbind = bind(subscription, presents, set_presence);
}).catch(error=> console.error(error.message)); }).catch(error=> console.error(error.message));
}, },
set_present: function(presents){ set_presence: function(presences){
//console.log("set_present"); console.log("set_presence");
//console.log(presents); console.log(presences);
var is_asking={}; this.presences = presences;
var present_stu_ids = presents.map((present)=>{ students = this.presences.map((presence)=>{
user = present.get("user"); student = presence.get("user");
is_asking[user.id]=present.get("isasking"); if(student.get("username")==null){
return user.id; students = this.students.filter(stu=>stu.id==student.id)
}); if(students.length==1){
students = this.students.map((student)=>{ student = students[0];
if(present_stu_ids.indexOf(student.id)>-1){
student.set("ispresent",true);
student.set("isasking", is_asking[student.id]);
}else{ }else{
student.set("ispresent",false); student.fetch();
student.set("isasking", 0); }
}
student.set("ispresent", presence.get("present"));
student.set("isasking",presence.get("isasking"));
student.set("mark", presence.get("mark"))
if(student.id==AV.User.current().id){
this.my_presence = presence;
} }
return student; return student;
}) });
this.students = students;
console.log(students);
this.setData(jsonify({students})); this.setData(jsonify({students}));
return presents; return presences;
}, },
fetch_class: function(class_id){ fetch_class: function(class_id){
this.class = AV.Object.createWithoutData("Class_", class_id); this.class = AV.Object.createWithoutData("Class_", class_id);
//this.class.include("teacher");
return this.class.fetch().then((class_) => { return this.class.fetch().then((class_) => {
//console.log(this.class); //console.log(this.class);
teacher = this.class.get("teacher");
console.log("fetch_class");
//console.log(teacher);
if(typeof teacher.toJson == "function"){
teacher = teacher.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
}); });
}).catch(error=>console.error(error.message)) }).catch(error=>console.error(error.message))
}, },
fetch_students: function(){
//console.log("fetch_students");
var query = new AV.Query("StudentClassMap");
query.equalTo("class", this.class);
query.include("user");
//console.log("fetch_students2")
return query.find();
},
set_students: function(studentClassMaps){
//console.log("set_students");
var students = []
studentClassMaps.forEach((scm, idx, a)=>{
console.log(a);
students.push(scm.get("user"));
});
this.students = students;
console.log("this.students");
console.log(students);
this.setData(jsonify((students)));
return students;
},
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad: function (options) { onLoad: function (options) {
this.setData({current_user: AV.User.current()});
this.class_id = options.class_id; this.class_id = options.class_id;
//this.class = AV.Object.createWithoutData("Class_", this.class_id); this.fetch_class.bind(this)(this.class_id).then(this.pull_presence.bind(this)).then((presences)=>{this.origin_presences=presences, this.my_presence.enter()});
this.fetch_class.bind(this)(this.class_id).then(this.fetch_students).then(this.set_students.bind(this)).then(this.pull_present.bind(this));
console.log("onLoad"); console.log("onLoad");
}, },
@ -137,14 +148,16 @@ Page({
console.log("onShow"); console.log("onShow");
console.log("enter class when onShow"); console.log("enter class when onShow");
console.log(AV.User.current()); console.log(AV.User.current());
this.class.enter(); if(this.my_presence){
this.my_presence.enter();
}
}, },
/** /**
* 生命周期函数--监听页面隐藏 * 生命周期函数--监听页面隐藏
*/ */
onHide: function () { onHide: function () {
this.class.leave(); this.my_presence.leave();
console.log("onHide"); console.log("onHide");
}, },
@ -152,7 +165,7 @@ Page({
* 生命周期函数--监听页面卸载 * 生命周期函数--监听页面卸载
*/ */
onUnload: function () { onUnload: function () {
this.class.leave(); this.my_presence.leave();
console.log("onUnload"); console.log("onUnload");
this.PresentSubscription.unsubscribe(); this.PresentSubscription.unsubscribe();
this.presentUnbind(); this.presentUnbind();
@ -162,7 +175,7 @@ Page({
* 页面相关事件处理函数--监听用户下拉动作 * 页面相关事件处理函数--监听用户下拉动作
*/ */
onPullDownRefresh: function () { onPullDownRefresh: function () {
this.pull_present.bind(this)(); this.pull_presence.bind(this)();
}, },
/** /**

@ -4,6 +4,7 @@
<view class="grid-view"> <view class="grid-view">
<view class="grid-cell" wx:for="{{students}}" wx:for-item="student" wx:key="objectId" bindtap="rep"> <view class="grid-cell" wx:for="{{students}}" wx:for-item="student" wx:key="objectId" bindtap="rep">
<view wx:if="{{student.isasking==0}}"> <view wx:if="{{student.isasking==0}}">
<text>{{student.username}}</text>
</view> </view>
<view wx:elif="{{student.isasking==1}}"> <view wx:elif="{{student.isasking==1}}">
<text class="reed">{{student.username}}</text> <text class="reed">{{student.username}}</text>
@ -11,7 +12,7 @@
<view wx:elif="{{student.isasking==2}}"> <view wx:elif="{{student.isasking==2}}">
<text class="gre">{{student.username}}</text> <text class="gre">{{student.username}}</text>
</view> </view>
<text>{{student.username}}</text>
</view> </view>
</view> </view>
</view> </view>

Loading…
Cancel
Save