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);