From 600a02673df95063a6befb7bc0adfa207ef1afa0 Mon Sep 17 00:00:00 2001 From: educoder_weapp Date: Fri, 18 Oct 2019 18:37:41 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E6=95=B0=E6=8D=AEmodel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/grade.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 model/grade.js diff --git a/model/grade.js b/model/grade.js new file mode 100644 index 0000000..2f853a7 --- /dev/null +++ b/model/grade.js @@ -0,0 +1,40 @@ +const AV = require('../lib/av-live-query-weapp-min'); + +//数据储存模板--分数 +class Grade extends AV.Object { + get mark() { + return this.get('done'); + } + set mark(value) { + this.set('mark', value); + } + get student(){ + return this.get("student"); + } + set student(value){ + this.set("student". value); + } + + get class() { + return this.get('class'); + } + + set class(value){ + this.set("class", value); + } + get content(){ + return this.get("content"); + } + set content(value) { + this.set('content', value); + } + get date(){ + return this.get("date"); + } + set date(value){ + this.set("date", value) + } +} + +AV.Object.register(Grade, 'Grade'); +module.exports = Grade; \ No newline at end of file From 73dd4ed545ee85fedd08e68926116753c22dc64a Mon Sep 17 00:00:00 2001 From: educoder_weapp Date: Fri, 18 Oct 2019 18:41:28 +0800 Subject: [PATCH 02/10] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9Bmodels?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 + app.js | 2 +- app.json | 3 +- readme.txt.txt => constants/api.js | 0 constants/appconstants.js | 1 + model/class.js | 23 +++++++++++ model/presence.js | 16 ++++++++ model/user.js | 0 pages/class.wxml | 0 pages/class.wxss | 0 pages/class/class.js | 66 ++++++++++++++++++++++++++++++ pages/class/class.json | 3 ++ pages/class/class.wxml | 3 ++ pages/class/class.wxss | 1 + pages/index/index.js | 3 +- utils.js | 0 utils/userutils.js | 0 读我.txt | 8 +++- 18 files changed, 126 insertions(+), 5 deletions(-) rename readme.txt.txt => constants/api.js (100%) create mode 100644 constants/appconstants.js create mode 100644 model/class.js create mode 100644 model/presence.js create mode 100644 model/user.js create mode 100644 pages/class.wxml create mode 100644 pages/class.wxss create mode 100644 pages/class/class.js create mode 100644 pages/class/class.json create mode 100644 pages/class/class.wxml create mode 100644 pages/class/class.wxss create mode 100644 utils.js create mode 100644 utils/userutils.js diff --git a/.gitignore b/.gitignore index 14ea590..9d10d27 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ $RECYCLE.BIN/ .Spotlight-V100 .TemporaryItems .Trashes +lib_refer +project.config.json # Node.js node_modules/ diff --git a/app.js b/app.js index 4edc902..e7e59cf 100644 --- a/app.js +++ b/app.js @@ -1,6 +1,6 @@ //app.js //导入leancloud库,与后台交互 -const AV = require('./utils/av-live-query-weapp-min'); +const AV = require('./lib/av-live-query-weapp-min'); //初始化 AV.init({ diff --git a/app.json b/app.json index 8fac543..6294d88 100644 --- a/app.json +++ b/app.json @@ -8,7 +8,8 @@ "pages/game/game", "pages/shouquan/shouquan", "pages/outside", - "pages/outside/outside" + "pages/outside/outside", + "pages/class/class" ], "window": { "backgroundTextStyle": "light", diff --git a/readme.txt.txt b/constants/api.js similarity index 100% rename from readme.txt.txt rename to constants/api.js diff --git a/constants/appconstants.js b/constants/appconstants.js new file mode 100644 index 0000000..d9b8108 --- /dev/null +++ b/constants/appconstants.js @@ -0,0 +1 @@ +export const marster_key = ""; //to be completed \ No newline at end of file diff --git a/model/class.js b/model/class.js new file mode 100644 index 0000000..0d17ce1 --- /dev/null +++ b/model/class.js @@ -0,0 +1,23 @@ +const AV = require('../lib/av-live-query-weapp-min'); + +class Class extends AV.Object{ + get name(){ + return this.get("name"); + } + set name(value){ + this.set("name", value); + } + get students(){ + return this.get("students"); + } + add_student(user){ + this.addUnique("students", user.id); + } + del_student(user){ + let students = this.get("students"); + if(user.id in students){ + this.remove(user.id); + } + } + +} \ No newline at end of file diff --git a/model/presence.js b/model/presence.js new file mode 100644 index 0000000..ac1b644 --- /dev/null +++ b/model/presence.js @@ -0,0 +1,16 @@ +const AV = require('../lib/av-live-query-weapp-min'); + +class Presence extends AV.Object{ + set user(value){ + this.set("user", value); + } + get user(){ + return this.get("user"); + } + set class(value){ + this.set("class", value); + } + get class(){ + return this.get("class"); + } +} \ No newline at end of file diff --git a/model/user.js b/model/user.js new file mode 100644 index 0000000..e69de29 diff --git a/pages/class.wxml b/pages/class.wxml new file mode 100644 index 0000000..e69de29 diff --git a/pages/class.wxss b/pages/class.wxss new file mode 100644 index 0000000..e69de29 diff --git a/pages/class/class.js b/pages/class/class.js new file mode 100644 index 0000000..694d348 --- /dev/null +++ b/pages/class/class.js @@ -0,0 +1,66 @@ +// pages/class/class.js +Page({ + + /** + * 页面的初始数据 + */ + data: { + + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/pages/class/class.json b/pages/class/class.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/class/class.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/class/class.wxml b/pages/class/class.wxml new file mode 100644 index 0000000..2f7bc55 --- /dev/null +++ b/pages/class/class.wxml @@ -0,0 +1,3 @@ + +pages/class/class.wxml +界面待完成 diff --git a/pages/class/class.wxss b/pages/class/class.wxss new file mode 100644 index 0000000..3d5fb7d --- /dev/null +++ b/pages/class/class.wxss @@ -0,0 +1 @@ +/* pages/class/class.wxss */ \ No newline at end of file diff --git a/pages/index/index.js b/pages/index/index.js index f1def29..3da9585 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -7,7 +7,8 @@ Page({ { id: 'https', title: '实验一:HTTPS' }, { id: 'session', title: '实验二:会话' }, { id: 'websocket', title: '实验三:WebSocket' }, - { id: 'game', title: '实验四:剪刀石头布小游戏' } + { id: 'game', title: '实验四:剪刀石头布小游戏' }, + { id: "class", title: "进入教室"} ], done: lab.getFinishLabs() }, diff --git a/utils.js b/utils.js new file mode 100644 index 0000000..e69de29 diff --git a/utils/userutils.js b/utils/userutils.js new file mode 100644 index 0000000..e69de29 diff --git a/读我.txt b/读我.txt index 9ebb734..904c984 100644 --- a/读我.txt +++ b/读我.txt @@ -1,11 +1,15 @@ -登录微信公众平台,前往 设置 > 开发设置 > 服务器配置 > 「修改」 链接,增加下述域名为白名单中的域名 +# 后台数据交互部分日志 + +## 登录微信公众平台,前往 设置 > 开发设置 > 服务器配置 > 「修改」 链接,增加下述域名为白名单中的域名 +request合法域名 fqcxn98z.api.lncldglobal.com fqcxn98z.engine.lncldglobal.com fqcxn98z.rtm.lncldglobal.com fqcxn98z.push.lncldglobal.com app-router.leancloud.cn +socket合法域名 us-w1-backend2.leancloud.cn us-w1-backend3.leancloud.cn us-w1-backend4.leancloud.cn us-w1-backend5.leancloud.cn -us-w1-backend6.leancloud.cn \ No newline at end of file +us-w1-backend6.leancloud.cn From bafeb81743a963bb59d45f9b55f49cf891e529e7 Mon Sep 17 00:00:00 2001 From: educoder_weapp Date: Sat, 19 Oct 2019 18:47:04 +0800 Subject: [PATCH 03/10] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + app.json | 4 +- app.wxss | 5 ++ lib/live-query-binding.js | 25 +++++++++ model/class.js | 30 ++++++++++- model/grade.js | 3 ++ model/presence.js | 5 +- model/user.js | 9 ++++ pages/class.wxml | 0 pages/class.wxss | 0 pages/class/class.wxml | 3 -- pages/class/class.wxss | 1 - pages/classes/classes.js | 94 ++++++++++++++++++++++++++++++++++ pages/classes/classes.json | 4 ++ pages/classes/classes.wxml | 7 +++ pages/classes/classes.wxss | 28 ++++++++++ pages/classroom/classroom.js | 73 ++++++++++++++++++++++++++ pages/classroom/classroom.json | 3 ++ pages/classroom/classroom.wxml | 42 +++++++++++++++ pages/classroom/classroom.wxss | 17 ++++++ pages/index/index.js | 3 +- pages/outside.wxml | 2 - pages/outside.wxss | 1 - utils/leancloudutils.js | 20 ++++++++ 24 files changed, 367 insertions(+), 13 deletions(-) create mode 100644 lib/live-query-binding.js delete mode 100644 pages/class.wxml delete mode 100644 pages/class.wxss delete mode 100644 pages/class/class.wxml delete mode 100644 pages/class/class.wxss create mode 100644 pages/classes/classes.js create mode 100644 pages/classes/classes.json create mode 100644 pages/classes/classes.wxml create mode 100644 pages/classes/classes.wxss create mode 100644 pages/classroom/classroom.js create mode 100644 pages/classroom/classroom.json create mode 100644 pages/classroom/classroom.wxml create mode 100644 pages/classroom/classroom.wxss delete mode 100644 pages/outside.wxml delete mode 100644 pages/outside.wxss create mode 100644 utils/leancloudutils.js diff --git a/.gitignore b/.gitignore index 9d10d27..154f96c 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ $RECYCLE.BIN/ .Spotlight-V100 .TemporaryItems .Trashes + lib_refer project.config.json diff --git a/app.json b/app.json index 6294d88..aad6154 100644 --- a/app.json +++ b/app.json @@ -7,9 +7,9 @@ "pages/websocket/websocket", "pages/game/game", "pages/shouquan/shouquan", - "pages/outside", "pages/outside/outside", - "pages/class/class" + "pages/classes/classes", + "pages/classroom/classroom" ], "window": { "backgroundTextStyle": "light", diff --git a/app.wxss b/app.wxss index d5b078b..145c85b 100644 --- a/app.wxss +++ b/app.wxss @@ -1,6 +1,11 @@ page, .lab { height: 100%; } +.flex-wrap{ + display: flex; + flex-direction: row; +} + .lab { display: flex; flex-direction: column; diff --git a/lib/live-query-binding.js b/lib/live-query-binding.js new file mode 100644 index 0000000..8d08007 --- /dev/null +++ b/lib/live-query-binding.js @@ -0,0 +1,25 @@ +module.exports = (subscription, initialStats, onChange) => { + let stats = [...initialStats] + const remove = value => { + stats = stats.filter(target => target.id !== value.id) + return onChange(stats) + } + const upsert = value => { + let existed = false; + stats = stats.map(target => (target.id === value.id ? ((existed = true), value) : target)) + if (!existed) stats = [value, ...stats] + return onChange(stats) + } + subscription.on('create', upsert) + subscription.on('update', upsert) + subscription.on('enter', upsert) + subscription.on('leave', remove) + subscription.on('delete', remove) + return () => { + subscription.off('create', upsert) + subscription.off('update', upsert) + subscription.off('enter', upsert) + subscription.off('leave', remove) + subscription.off('delete', remove) + } +} diff --git a/model/class.js b/model/class.js index 0d17ce1..6809e91 100644 --- a/model/class.js +++ b/model/class.js @@ -19,5 +19,31 @@ class Class extends AV.Object{ this.remove(user.id); } } - -} \ No newline at end of file + static all() { + var query = new AV.Query("Class_"); + return query.find(); + } + enter() { + this.leave(); + this._presence = new Presence({ + user: AV.User.current(), + class: this + }); + this._presence.save(); + } + leave() { + if (this._presence != null) { + this._presence.destroy(); + } + } + present_students() { + var query = new AV.Query("Presence"); + //query.equalTo("class", this._class.id); + let students = query.find(); + console.log(students); + return students; + } +} + +AV.Object.register(Class, "Class_"); +module.exports = Class; \ No newline at end of file diff --git a/model/grade.js b/model/grade.js index 2f853a7..53d936b 100644 --- a/model/grade.js +++ b/model/grade.js @@ -34,6 +34,9 @@ class Grade extends AV.Object { set date(value){ this.set("date", value) } + add_mark(value){ + this.increment(value); + } } AV.Object.register(Grade, 'Grade'); diff --git a/model/presence.js b/model/presence.js index ac1b644..129e0d4 100644 --- a/model/presence.js +++ b/model/presence.js @@ -13,4 +13,7 @@ class Presence extends AV.Object{ get class(){ return this.get("class"); } -} \ No newline at end of file +} + +AV.Object.register(Presence, "Presence"); +module.exports = Presence; \ No newline at end of file diff --git a/model/user.js b/model/user.js index e69de29..55279c6 100644 --- a/model/user.js +++ b/model/user.js @@ -0,0 +1,9 @@ +function login() { + return AV.Promise.resolve(AV.User.current()).then(user => + user ? (user.isAuthenticated().then(authed => authed ? user : null)) : null + ).then(user => user ? user : AV.User.loginWithWeapp({ + preferUnionId: true, + })).catch(error => console.error(error.message)); +} + +export{login}; \ No newline at end of file diff --git a/pages/class.wxml b/pages/class.wxml deleted file mode 100644 index e69de29..0000000 diff --git a/pages/class.wxss b/pages/class.wxss deleted file mode 100644 index e69de29..0000000 diff --git a/pages/class/class.wxml b/pages/class/class.wxml deleted file mode 100644 index 2f7bc55..0000000 --- a/pages/class/class.wxml +++ /dev/null @@ -1,3 +0,0 @@ - -pages/class/class.wxml -界面待完成 diff --git a/pages/class/class.wxss b/pages/class/class.wxss deleted file mode 100644 index 3d5fb7d..0000000 --- a/pages/class/class.wxss +++ /dev/null @@ -1 +0,0 @@ -/* pages/class/class.wxss */ \ No newline at end of file diff --git a/pages/classes/classes.js b/pages/classes/classes.js new file mode 100644 index 0000000..4d25c8a --- /dev/null +++ b/pages/classes/classes.js @@ -0,0 +1,94 @@ +const { Class } = require("../../model/class"); +const { login } = require("../../model/user"); +const AV = require("../../lib/av-live-query-weapp-min.js"); +const { jsonify } = require('../../utils/leancloudutils'); +// pages/class/class.js + +const getDataForRender = class_ => ({ + name: class_.get('name'), + objectId: class_.get('objectId') +}); + +Page({ + + /** + * 页面的初始数据 + */ + classes : [], + data: { + classes: [ + ] + }, + enter_class: function(event){ + console.log(event); + var class_id = event.currentTarget.dataset.class_id; + var class_name = event.currentTarget.dataset.class_name; + wx.navigateTo({ + url: "../classroom/classroom?class_id="+class_id+"&"+"class_name="+class_name, + }) + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + var query = new AV.Query("Class_"); + query.find().then((classes) => { + this.classes = classes + this.setData(jsonify({ classes })); + }) + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + var query = new AV.Query("Class_"); + query.find().then((classes) => { + this.classes = classes + this.setData(jsonify({classes})); + }) + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/pages/classes/classes.json b/pages/classes/classes.json new file mode 100644 index 0000000..7360326 --- /dev/null +++ b/pages/classes/classes.json @@ -0,0 +1,4 @@ +{ + "usingComponents": {}, + "enablePullDownRefresh": true +} \ No newline at end of file diff --git a/pages/classes/classes.wxml b/pages/classes/classes.wxml new file mode 100644 index 0000000..abe87c6 --- /dev/null +++ b/pages/classes/classes.wxml @@ -0,0 +1,7 @@ + + + + {{class.name}} + + + \ No newline at end of file diff --git a/pages/classes/classes.wxss b/pages/classes/classes.wxss new file mode 100644 index 0000000..015bcde --- /dev/null +++ b/pages/classes/classes.wxss @@ -0,0 +1,28 @@ +.header { + height: 54px; + align-items: center; + background-color: #FFF; +} + +.class-list { + padding: 4px 6px 48px; +} + +.classroom { + font-size: 18px; + height: 30px; + padding: 10px 12px; + overflow: hidden; + align-items: center; + background-color: #fff; + margin: 1px 0; + border-radius: 3px; +} + +.classroom text { + white-space: nowrap; + display: block; + width: 100%; + height: 50px; + line-height: 17px; +} diff --git a/pages/classroom/classroom.js b/pages/classroom/classroom.js new file mode 100644 index 0000000..b627596 --- /dev/null +++ b/pages/classroom/classroom.js @@ -0,0 +1,73 @@ +// pages/classroom/classroom.js +const AV = require("../../lib/av-live-query-weapp-min.js") + +Page({ + + /** + * 页面的初始数据 + */ + class: null, + data: { + class_name: "", + class_id: "", + }, + + /** + * 生命周期函数--监听页面加载 + */ + onLoad: function (options) { + this.class = AV.Object.createWithoutData("Class_", options.class_id); + this.class.fetch().then((class_)=>{ + this.setData(this.class.get("name")); + }) + }, + + /** + * 生命周期函数--监听页面初次渲染完成 + */ + onReady: function () { + + }, + + /** + * 生命周期函数--监听页面显示 + */ + onShow: function () { + + }, + + /** + * 生命周期函数--监听页面隐藏 + */ + onHide: function () { + + }, + + /** + * 生命周期函数--监听页面卸载 + */ + onUnload: function () { + + }, + + /** + * 页面相关事件处理函数--监听用户下拉动作 + */ + onPullDownRefresh: function () { + + }, + + /** + * 页面上拉触底事件的处理函数 + */ + onReachBottom: function () { + + }, + + /** + * 用户点击右上角分享 + */ + onShareAppMessage: function () { + + } +}) \ No newline at end of file diff --git a/pages/classroom/classroom.json b/pages/classroom/classroom.json new file mode 100644 index 0000000..8835af0 --- /dev/null +++ b/pages/classroom/classroom.json @@ -0,0 +1,3 @@ +{ + "usingComponents": {} +} \ No newline at end of file diff --git a/pages/classroom/classroom.wxml b/pages/classroom/classroom.wxml new file mode 100644 index 0000000..867ba34 --- /dev/null +++ b/pages/classroom/classroom.wxml @@ -0,0 +1,42 @@ + +pages/classroom/classroom.wxml + + + + + Home + + + + Email + + + + Chat + + + + location + + + + search + + + + phone + + + + setting + + + + about + + + + more + + + diff --git a/pages/classroom/classroom.wxss b/pages/classroom/classroom.wxss new file mode 100644 index 0000000..cd19d69 --- /dev/null +++ b/pages/classroom/classroom.wxss @@ -0,0 +1,17 @@ +/* pages/classroom/classroom.wxss */ +.grid-view{ + display: -webkit-flex; + display: flex; + align-items: center; + justify-content: space-between; + flex-wrap: wrap; + width: 100%; +} +.grid-cell{ + flex: 0 0 auto; + width: 25%; + text-align: center; + color: #797979; + padding: 40rpx 0; + font-size: 30rpx; +} diff --git a/pages/index/index.js b/pages/index/index.js index 3da9585..7d68f54 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -8,12 +8,13 @@ Page({ { id: 'session', title: '实验二:会话' }, { id: 'websocket', title: '实验三:WebSocket' }, { id: 'game', title: '实验四:剪刀石头布小游戏' }, - { id: "class", title: "进入教室"} + { id: "classes", title: "进入教室"} ], done: lab.getFinishLabs() }, onShow() { + console.log({ done: lab.getFinishLabs() }); this.setData({ done: lab.getFinishLabs() }); }, diff --git a/pages/outside.wxml b/pages/outside.wxml deleted file mode 100644 index a60b311..0000000 --- a/pages/outside.wxml +++ /dev/null @@ -1,2 +0,0 @@ - -pages/outside.wxml diff --git a/pages/outside.wxss b/pages/outside.wxss deleted file mode 100644 index ab8be02..0000000 --- a/pages/outside.wxss +++ /dev/null @@ -1 +0,0 @@ -/* pages/outside.wxss */ \ No newline at end of file diff --git a/utils/leancloudutils.js b/utils/leancloudutils.js new file mode 100644 index 0000000..d0c7702 --- /dev/null +++ b/utils/leancloudutils.js @@ -0,0 +1,20 @@ +const isPlainObject = target => + target && + target.toString() == '[object Object]' && + Object.getPrototypeOf(target) == Object.prototype; +const _jsonify = target => { + if (target && typeof target.toJSON === 'function') return target.toJSON(); + if (Array.isArray(target)) return target.map(_jsonify); + return target; +}; + +exports.jsonify = target => + isPlainObject(target) + ? Object.keys(target).reduce( + (result, key) => ({ + ...result, + [key]: _jsonify(target[key]) + }), + {} + ) + : _jsonify(target); From 6b69e12239782bd0feda3c0504956cb191e489fb Mon Sep 17 00:00:00 2001 From: educoder_weapp Date: Sat, 19 Oct 2019 19:41:36 +0800 Subject: [PATCH 04/10] add function --- constants/appconstants.js | 1 - model/class.js | 1 + model/user.js | 2 +- pages/class/class.js | 66 ---------------------------------- pages/class/class.json | 3 -- pages/classroom/classroom.js | 35 ++++++++++++++---- pages/classroom/classroom.wxml | 37 ++----------------- pages/outside.js | 66 ---------------------------------- pages/outside.json | 3 -- project.config.json | 8 ++--- 10 files changed, 36 insertions(+), 186 deletions(-) delete mode 100644 pages/class/class.js delete mode 100644 pages/class/class.json delete mode 100644 pages/outside.js delete mode 100644 pages/outside.json diff --git a/constants/appconstants.js b/constants/appconstants.js index d9b8108..e69de29 100644 --- a/constants/appconstants.js +++ b/constants/appconstants.js @@ -1 +0,0 @@ -export const marster_key = ""; //to be completed \ No newline at end of file diff --git a/model/class.js b/model/class.js index 6809e91..5bed300 100644 --- a/model/class.js +++ b/model/class.js @@ -1,4 +1,5 @@ const AV = require('../lib/av-live-query-weapp-min'); +const Presence = require("./presence") class Class extends AV.Object{ get name(){ diff --git a/model/user.js b/model/user.js index 55279c6..5421420 100644 --- a/model/user.js +++ b/model/user.js @@ -6,4 +6,4 @@ function login() { })).catch(error => console.error(error.message)); } -export{login}; \ No newline at end of file +module.exports=login; \ No newline at end of file diff --git a/pages/class/class.js b/pages/class/class.js deleted file mode 100644 index 694d348..0000000 --- a/pages/class/class.js +++ /dev/null @@ -1,66 +0,0 @@ -// pages/class/class.js -Page({ - - /** - * 页面的初始数据 - */ - data: { - - }, - - /** - * 生命周期函数--监听页面加载 - */ - onLoad: function (options) { - - }, - - /** - * 生命周期函数--监听页面初次渲染完成 - */ - onReady: function () { - - }, - - /** - * 生命周期函数--监听页面显示 - */ - onShow: function () { - - }, - - /** - * 生命周期函数--监听页面隐藏 - */ - onHide: function () { - - }, - - /** - * 生命周期函数--监听页面卸载 - */ - onUnload: function () { - - }, - - /** - * 页面相关事件处理函数--监听用户下拉动作 - */ - onPullDownRefresh: function () { - - }, - - /** - * 页面上拉触底事件的处理函数 - */ - onReachBottom: function () { - - }, - - /** - * 用户点击右上角分享 - */ - onShareAppMessage: function () { - - } -}) \ No newline at end of file diff --git a/pages/class/class.json b/pages/class/class.json deleted file mode 100644 index 8835af0..0000000 --- a/pages/class/class.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "usingComponents": {} -} \ No newline at end of file diff --git a/pages/classroom/classroom.js b/pages/classroom/classroom.js index b627596..7ed1f95 100644 --- a/pages/classroom/classroom.js +++ b/pages/classroom/classroom.js @@ -1,16 +1,27 @@ // pages/classroom/classroom.js -const AV = require("../../lib/av-live-query-weapp-min.js") +const AV = require("../../lib/av-live-query-weapp-min") +const { jsonify } = require('../../utils/leancloudutils'); Page({ - /** * 页面的初始数据 */ + presence: null, + students: [], + present_students: [], class: null, data: { + present_students: [], + students: [], + unpresent_students: [], class_name: "", class_id: "", }, + fetch_present: function(){ + var query = new AV.Query("Presence"); + query.include("user"); + return query.find(); + }, /** * 生命周期函数--监听页面加载 @@ -18,36 +29,46 @@ Page({ 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"); }, /** @@ -68,6 +89,6 @@ Page({ * 用户点击右上角分享 */ onShareAppMessage: function () { - + console.log("onShareAppMessage"); } }) \ No newline at end of file diff --git a/pages/classroom/classroom.wxml b/pages/classroom/classroom.wxml index 867ba34..0213ae7 100644 --- a/pages/classroom/classroom.wxml +++ b/pages/classroom/classroom.wxml @@ -2,41 +2,8 @@ pages/classroom/classroom.wxml - - - Home - - - - Email - - - - Chat - - - - location - - - - search - - - - phone - - - - setting - - - - about - - - - more + + {{student.username}} diff --git a/pages/outside.js b/pages/outside.js deleted file mode 100644 index 409184f..0000000 --- a/pages/outside.js +++ /dev/null @@ -1,66 +0,0 @@ -// pages/outside.js -Page({ - - /** - * 页面的初始数据 - */ - data: { - - }, - - /** - * 生命周期函数--监听页面加载 - */ - onLoad: function (options) { - - }, - - /** - * 生命周期函数--监听页面初次渲染完成 - */ - onReady: function () { - - }, - - /** - * 生命周期函数--监听页面显示 - */ - onShow: function () { - - }, - - /** - * 生命周期函数--监听页面隐藏 - */ - onHide: function () { - - }, - - /** - * 生命周期函数--监听页面卸载 - */ - onUnload: function () { - - }, - - /** - * 页面相关事件处理函数--监听用户下拉动作 - */ - onPullDownRefresh: function () { - - }, - - /** - * 页面上拉触底事件的处理函数 - */ - onReachBottom: function () { - - }, - - /** - * 用户点击右上角分享 - */ - onShareAppMessage: function () { - - } -}) \ No newline at end of file diff --git a/pages/outside.json b/pages/outside.json deleted file mode 100644 index 8835af0..0000000 --- a/pages/outside.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "usingComponents": {} -} \ No newline at end of file diff --git a/project.config.json b/project.config.json index a7461b2..dc053c0 100644 --- a/project.config.json +++ b/project.config.json @@ -4,8 +4,8 @@ "ignore": [] }, "setting": { - "urlCheck": false, - "es6": true, + "urlCheck": true, + "es6": false, "postcss": true, "minified": true, "newFeature": true, @@ -22,8 +22,8 @@ }, "compileType": "miniprogram", "libVersion": "2.8.3", - "appid": "wx2a901996834ef5fb", - "projectname": "miniprogram-3", + "appid": "wxfacd79888fb03788", + "projectname": "smart-class", "debugOptions": { "hidedInDevtools": [] }, From cad2f921440471edb594560af7890a5c5a33c65d Mon Sep 17 00:00:00 2001 From: educoder_weapp Date: Sat, 19 Oct 2019 20:10:23 +0800 Subject: [PATCH 05/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 4 ++-- project.config.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index e7e59cf..3ae0495 100644 --- a/app.js +++ b/app.js @@ -4,8 +4,8 @@ const AV = require('./lib/av-live-query-weapp-min'); //初始化 AV.init({ - appId: 'fQCxN98zS5thYY3AceKdI8Pj-MdYXbMMI', - appKey: 'Tdi1DcLlVYrTabFiBaA00pjj', + appId: 'eVHYNBdT5D2lDxNj5jtJXsWT-MdYXbMMI', + appKey: 'waM3bwf1ftpsMLjRBqqVyJIQ', }); App({ diff --git a/project.config.json b/project.config.json index dc053c0..8dad655 100644 --- a/project.config.json +++ b/project.config.json @@ -22,7 +22,7 @@ }, "compileType": "miniprogram", "libVersion": "2.8.3", - "appid": "wxfacd79888fb03788", + "appid": "wx2a901996834ef5fb", "projectname": "smart-class", "debugOptions": { "hidedInDevtools": [] From c5e3548a22f87b0d69373f9823c84b55c6c35133 Mon Sep 17 00:00:00 2001 From: educoder_weapp Date: Sat, 19 Oct 2019 20:10:31 +0800 Subject: [PATCH 06/10] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app.js b/app.js index 3ae0495..ccedb93 100644 --- a/app.js +++ b/app.js @@ -7,6 +7,9 @@ AV.init({ appId: 'eVHYNBdT5D2lDxNj5jtJXsWT-MdYXbMMI', appKey: 'waM3bwf1ftpsMLjRBqqVyJIQ', }); +// test Appid +// appId: 'fQCxN98zS5thYY3AceKdI8Pj-MdYXbMMI', +// appKey: 'Tdi1DcLlVYrTabFiBaA00pjj', App({ config: { From ca083688ca6e48b0b3f98db5973fc899c72ea95e Mon Sep 17 00:00:00 2001 From: educoder_weapp Date: Sat, 19 Oct 2019 20:46:54 +0800 Subject: [PATCH 07/10] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/classes/classes.js | 9 +++++++-- pages/classes/classes.wxml | 7 +++++++ pages/classroom/classroom.js | 18 ++++++++++++------ pages/classroom/classroom.wxss | 1 + 读我.txt | 2 +- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/pages/classes/classes.js b/pages/classes/classes.js index 4d25c8a..85c06ee 100644 --- a/pages/classes/classes.js +++ b/pages/classes/classes.js @@ -12,13 +12,18 @@ const getDataForRender = class_ => ({ Page({ /** - * 页面的初始数据 + 页面的初始数据data,用于与.wxlm文件绑定 + classes: 课程列表 type: Array + 元素class: 课程信息 class.objectId 唯一 + class.objectId 课程唯一主键 + class.name 课程名称 */ - classes : [], data: { classes: [ ] }, + + classes: [], enter_class: function(event){ console.log(event); var class_id = event.currentTarget.dataset.class_id; diff --git a/pages/classes/classes.wxml b/pages/classes/classes.wxml index abe87c6..1afd37e 100644 --- a/pages/classes/classes.wxml +++ b/pages/classes/classes.wxml @@ -1,3 +1,10 @@ + diff --git a/pages/classroom/classroom.js b/pages/classroom/classroom.js index 7ed1f95..e8ec9e4 100644 --- a/pages/classroom/classroom.js +++ b/pages/classroom/classroom.js @@ -4,18 +4,24 @@ const { jsonify } = require('../../utils/leancloudutils'); Page({ /** - * 页面的初始数据 + 页面的初始数据 + students: 该课程所有的学生 + 元素student + student.username 学生的用户名,是唯一,就像微信号一样 + student.name 学生的姓名 + */ presence: null, students: [], present_students: [], class: null, data: { - present_students: [], - students: [], - unpresent_students: [], - class_name: "", - class_id: "", + //以下数据的同步由该代码文件实现,数据的呈现由classroom.wxml实现 + present_students: [], // 出席的学生的用户名即上文提及的student.username + students: [], // 该课程所有的学生 + unpresent_students: [], //没有出席的学生的用户名,不建议使用该数据,考虑弃用 + class_name: "",//课程名称 + class_id: "",//该课程的主键(编号) }, fetch_present: function(){ var query = new AV.Query("Presence"); diff --git a/pages/classroom/classroom.wxss b/pages/classroom/classroom.wxss index cd19d69..d9f9251 100644 --- a/pages/classroom/classroom.wxss +++ b/pages/classroom/classroom.wxss @@ -7,6 +7,7 @@ flex-wrap: wrap; width: 100%; } +/* 下面这个实现表格式的布局,有多行多列,width=25% 表示将会显示4列 */ .grid-cell{ flex: 0 0 auto; width: 25%; diff --git a/读我.txt b/读我.txt index 904c984..47dd6d7 100644 --- a/读我.txt +++ b/读我.txt @@ -1,6 +1,6 @@ # 后台数据交互部分日志 -## 登录微信公众平台,前往 设置 > 开发设置 > 服务器配置 > 「修改」 链接,增加下述域名为白名单中的域名 +## 已完成-登录微信公众平台,前往 设置 > 开发设置 > 服务器配置 > 「修改」 链接,增加下述域名为白名单中的域名 request合法域名 fqcxn98z.api.lncldglobal.com fqcxn98z.engine.lncldglobal.com From ac723f3c059690898e3283dc5ca6c4a1277ef03b Mon Sep 17 00:00:00 2001 From: educoder_weapp Date: Sat, 19 Oct 2019 20:58:24 +0800 Subject: [PATCH 08/10] =?UTF-8?q?=E6=94=B9=E4=BA=86=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E5=B0=8F=E6=BC=8F=E6=B4=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/user.js | 4 +++- pages/classes/classes.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/model/user.js b/model/user.js index 5421420..47db961 100644 --- a/model/user.js +++ b/model/user.js @@ -1,3 +1,5 @@ +const AV = require("../lib/av-live-query-weapp-min") + function login() { return AV.Promise.resolve(AV.User.current()).then(user => user ? (user.isAuthenticated().then(authed => authed ? user : null)) : null @@ -6,4 +8,4 @@ function login() { })).catch(error => console.error(error.message)); } -module.exports=login; \ No newline at end of file +module.exports = login; \ No newline at end of file diff --git a/pages/classes/classes.js b/pages/classes/classes.js index 85c06ee..aa29363 100644 --- a/pages/classes/classes.js +++ b/pages/classes/classes.js @@ -1,5 +1,5 @@ const { Class } = require("../../model/class"); -const { login } = require("../../model/user"); +const login = require("../../model/user"); const AV = require("../../lib/av-live-query-weapp-min.js"); const { jsonify } = require('../../utils/leancloudutils'); // pages/class/class.js @@ -37,7 +37,7 @@ Page({ * 生命周期函数--监听页面加载 */ onLoad: function (options) { - + login(); }, /** From 35cb9a5ad4e6addfe156f9ee8160979eae1d4bcf Mon Sep 17 00:00:00 2001 From: educoder_weapp Date: Sun, 20 Oct 2019 08:30:10 +0800 Subject: [PATCH 09/10] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BA=86=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=90=8C=E6=AD=A5=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/class.js | 12 ++--- pages/classroom/classroom.js | 96 ++++++++++++++++++++++++++++------ pages/classroom/classroom.json | 3 +- 3 files changed, 85 insertions(+), 26 deletions(-) diff --git a/model/class.js b/model/class.js index 5bed300..2da7d9f 100644 --- a/model/class.js +++ b/model/class.js @@ -9,10 +9,10 @@ class Class extends AV.Object{ this.set("name", value); } get students(){ - return this.get("students"); + } add_student(user){ - this.addUnique("students", user.id); + } del_student(user){ let students = this.get("students"); @@ -20,23 +20,19 @@ class Class extends AV.Object{ this.remove(user.id); } } - static all() { - var query = new AV.Query("Class_"); - return query.find(); - } enter() { this.leave(); this._presence = new Presence({ user: AV.User.current(), class: this }); - this._presence.save(); + this._presence.save(); } leave() { if (this._presence != null) { this._presence.destroy(); } - } + } present_students() { var query = new AV.Query("Presence"); //query.equalTo("class", this._class.id); diff --git a/pages/classroom/classroom.js b/pages/classroom/classroom.js index e8ec9e4..015e05d 100644 --- a/pages/classroom/classroom.js +++ b/pages/classroom/classroom.js @@ -1,55 +1,115 @@ // pages/classroom/classroom.js const AV = require("../../lib/av-live-query-weapp-min") const { jsonify } = require('../../utils/leancloudutils'); +const bind = require("../../lib/live-query-binding") Page({ /** 页面的初始数据 students: 该课程所有的学生 元素student + student.objectId 该学生的主键,唯一 student.username 学生的用户名,是唯一,就像微信号一样 student.name 学生的姓名 - */ presence: null, students: [], - present_students: [], class: null, + class_id: null, data: { //以下数据的同步由该代码文件实现,数据的呈现由classroom.wxml实现 - present_students: [], // 出席的学生的用户名即上文提及的student.username - students: [], // 该课程所有的学生 - unpresent_students: [], //没有出席的学生的用户名,不建议使用该数据,考虑弃用 + //命名可能有点混乱...... + present_students: [], + // 出席的学生的用户名即上文提及的student.username,考虑弃用,建议替换为presen_stu_ids + present_stu_ids: [], //出席的学生的主键objectId + students: [], // 该课程所有的学生, 元素类型见上文中的student + present_stus: [], //出席的学生,元素类型与students中的一样 + unpresent_students: [], //没有出席的学生的用户名,不建议使用该数据,弃用 class_name: "",//课程名称 class_id: "",//该课程的主键(编号) }, - fetch_present: function(){ + + pull_present: function(){ var query = new AV.Query("Presence"); + //console.log(this.class); + query.equalTo("class", this.class); + 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); + }).catch(error=> console.error(error.message)); + }, + set_present: function(presents){ + //console.log("set_present"); + //console.log(presents); + var student_ids = presents.map((present)=>{ + user = present.get("user"); + //console.log(user); + //console.log(typeof user); + 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})); + return presents; + }, + + fetch_class: function(class_id){ + this.class = AV.Object.createWithoutData("Class_", class_id); + return this.class.fetch().then((class_) => { + //console.log(this.class); + this.setData({ + class_name: this.class.get("name"), + class_id: this.class.get("objectId") + }); + }).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) { - this.class = AV.Object.createWithoutData("Class_", options.class_id); - this.class.fetch().then((class_)=>{ - console.log(this.class); - this.setData(this.class.get("name")); - }) + 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.fetch_students).then(this.set_students.bind(this)).then(this.pull_present.bind(this)); 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"); }, @@ -58,6 +118,7 @@ Page({ */ onShow: function () { console.log("onShow"); + console.log("enter class when onShow"); this.class.enter(); }, @@ -75,13 +136,14 @@ Page({ onUnload: function () { this.class.leave(); console.log("onUnload"); + }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { - + this.pull_present.bind(this)(); }, /** diff --git a/pages/classroom/classroom.json b/pages/classroom/classroom.json index 8835af0..7360326 100644 --- a/pages/classroom/classroom.json +++ b/pages/classroom/classroom.json @@ -1,3 +1,4 @@ { - "usingComponents": {} + "usingComponents": {}, + "enablePullDownRefresh": true } \ No newline at end of file From 3c239f559526490cc330494ee0dd10032b428bfa Mon Sep 17 00:00:00 2001 From: educoder_weapp Date: Sun, 20 Oct 2019 12:02:21 +0800 Subject: [PATCH 10/10] =?UTF-8?q?=E6=94=B9=E5=8F=98=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- model/class.js | 4 ++- model/presence.js | 6 ++++ model/studentclassmap.js | 17 +++++++++++ pages/classes/classes.js | 5 ++- pages/classroom/classroom.js | 56 ++++++++++++++++++---------------- pages/classroom/classroom.wxml | 4 +-- 6 files changed, 62 insertions(+), 30 deletions(-) create mode 100644 model/studentclassmap.js 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}}