增加了一些内容

smart_class
educoder_weapp 5 years ago
parent 73dd4ed545
commit bafeb81743

1
.gitignore vendored

@ -9,6 +9,7 @@ $RECYCLE.BIN/
.Spotlight-V100
.TemporaryItems
.Trashes
lib_refer
project.config.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",

@ -1,6 +1,11 @@
page, .lab {
height: 100%;
}
.flex-wrap{
display: flex;
flex-direction: row;
}
.lab {
display: flex;
flex-direction: column;

@ -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)
}
}

@ -19,5 +19,31 @@ 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();
}
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;

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

@ -14,3 +14,6 @@ class Presence extends AV.Object{
return this.get("class");
}
}
AV.Object.register(Presence, "Presence");
module.exports = Presence;

@ -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};

@ -1,3 +0,0 @@
<!--pages/class/class.wxml-->
<text>pages/class/class.wxml
界面待完成</text>

@ -1 +0,0 @@
/* pages/class/class.wxss */

@ -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 () {
}
})

@ -0,0 +1,4 @@
{
"usingComponents": {},
"enablePullDownRefresh": true
}

@ -0,0 +1,7 @@
<view class="class-list">
<block wx:for="{{classes}}" wx:for-item="class" wx:key="objectId">
<view class="flex-wrap classroom" data-class_id="{{class.objectId}}" data-class_name="{{class.name}}" bindtap="enter_class">
<text>{{class.name}}</text>
</view>
</block>
</view>

@ -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;
}

@ -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 () {
}
})

@ -0,0 +1,3 @@
{
"usingComponents": {}
}

@ -0,0 +1,42 @@
<!--pages/classroom/classroom.wxml-->
<text>pages/classroom/classroom.wxml</text>
<view class="students">
<view class="grid-view">
<view class="grid-cell">
<icon class="iconfont icon-shouye"></icon>
<view>Home</view>
</view>
<view class="grid-cell">
<icon class="iconfont icon-xinfeng"></icon>
<view>Email</view>
</view>
<view class="grid-cell">
<icon class="iconfont icon-duihuaxinxi"></icon>
<view>Chat</view>
</view>
<view class="grid-cell">
<icon class="iconfont icon-dibiao"></icon>
<view>location</view>
</view>
<view class="grid-cell">
<icon type="search" size='30'></icon>
<view>search</view>
</view>
<view class="grid-cell">
<icon class="iconfont icon-dianhua"></icon>
<view>phone</view>
</view>
<view class="grid-cell">
<icon class="iconfont icon-shezhi"></icon>
<view>setting</view>
</view>
<view class="grid-cell">
<icon type="info" size='30' color='#797979'></icon>
<view>about</view>
</view>
<view class="grid-cell">
<icon class="iconfont icon-gengduotianchong"></icon>
<view>more</view>
</view>
</view>
</view>

@ -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;
}

@ -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() });
},

@ -1,2 +0,0 @@
<!--pages/outside.wxml-->
<text>pages/outside.wxml</text>

@ -1 +0,0 @@
/* pages/outside.wxss */

@ -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);
Loading…
Cancel
Save