parent
73dd4ed545
commit
bafeb81743
@ -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)
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
@ -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…
Reference in new issue