可以创建、退出课程

smart_class
educoder_weapp 5 years ago
parent 160b27dc15
commit 01771b1c50

@ -1,5 +1,6 @@
{ {
"pages": [ "pages": [
"pages/classes/classes", "pages/classes/classes",
"pages/changeuser/changeuser", "pages/changeuser/changeuser",
"pages/index/index", "pages/index/index",
@ -12,7 +13,8 @@
"pages/outside/outside", "pages/outside/outside",
"pages/classroom/classroom", "pages/classroom/classroom",
"pages/setting/setting", "pages/setting/setting",
"pages/user/user" "pages/user/user",
"pages/addclass/addclass"
], ],
"window": { "window": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light",

@ -8,19 +8,28 @@ page {
} }
.form-wrap { .form-wrap {
border-top: 1px solid #eee; border-top: 1px solid #eee;
margin: 8px 0; margin: 12px 0;
} }
.tappable:hover { .tappable:hover {
opacity: .6; opacity: .6;
} }
.container {
padding: 4px 12px;
}
.hint, .hint,
.error { .error
.warning {
display: block; display: block;
margin: 8px 0; margin: 8px 0;
color: #888; color: #888;
font-size: 14px; font-size: 14px;
} }
.error{
color:red;
}
.warning{
color: orange;
}
.lab { .lab {
display: flex; display: flex;

@ -0,0 +1,34 @@
// components/icon/myicon.js
Component({
/**
* 组件的属性列表
*/
properties: {
addGlobalClass: true
},
externalClasses: ['custom-class'],
properties: {
info: null,
type: String,
size: String,
color: String
},
/**
* 组件的初始数据
*/
data: {
},
/**
* 组件的方法列表
*/
methods: {
onClick() {
this.triggerEvent('click');
}
}
})

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

@ -0,0 +1,7 @@
<!--components/icon/myicon.wxml-->
<view
class="custom-class iconfont myicon-{{ type }}"
style="{{ color ? 'color: ' + color : '' }}; {{ size ? 'font-size: ' + size + 'px' : '' }}"
bind:tap="onClick">
<view wx:if="{{ info !== null }}" class="myicon__info">{{ info }}</view>
</view>

@ -0,0 +1,51 @@
@font-face {font-family: "iconfont";
src: url('iconfont.eot?t=1571740835844'); /* IE9 */
src: url('iconfont.eot?t=1571740835844#iefix') format('embedded-opentype'), /* I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BYchDTnD4oF913YhZmvoVnzHXQLMYUpL3G45rSzsJt7CVEjo/+BrOSkgny9SUd/oJsgynIgUfyirGwrXY7neu8bCeUcJ1Stvta1IlVypBd6GEJgykt2kPXR1HV+O50U7wVHyXG08agEQg0yZICBtRxOYolaubZpNP8DtEYglD2LWi1/Qalit06aaKgxgPqOJNCie5k4UUu7mkRKCoUzSywixaQEwe9iZBx/Lwek2tGwER25m0ZkqSHQyHH9WPzKm2CKt0uPjBI1WnzXj8xObG8F9w2GRqS5aWwm9h61SLqJq2RgZZD0vjOroeGe9GgEAAA=') format('woff2'),
url('iconfont.woff?t=1571740835844') format('woff'),
url('iconfont.ttf?t=1571740835844') format('truetype'), /* chrome, firefox, opera, Safari, Android, iOS 4.2+ */
url('iconfont.svg?t=1571740835844#iconfont') format('svg'); /* iOS 4.1- */
}
.iconfont {
font-family: "iconfont" !important;
font-size: 16px;
font-style: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.myicon-absent_student:before {
content: "\e635";
}
.myicon-present_student:before {
content: "\e60d";
}
.myicon-answer:before {
content: "\e647";
}
.myicon-question:before {
content: "\e670";
}
.myicon-internet_class:before {
content: "\e67f";
}
.myicon__info {
color: #fff;
left: 100%;
top: -.5em;
font-size: 0.5em;
padding: 0 0.3em;
text-align: center;
min-width: 1.2em;
line-height: 1.2;
position: absolute;
border-radius: 0.6em;
box-sizing: border-box;
background-color: #f44;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
font-family: PingFang SC, Helvetica Neue, Arial, sans-serif;
}

@ -37,10 +37,10 @@ class Presence extends AV.Object{
enter(){ enter(){
console.log("presence.enter"); console.log("presence.enter");
console.log(this); console.log(this);
this.set("present", true).save().catch(error=>console.error(error.message)); this.set("present", true).set("isasking", 0).save().catch(error=>console.error(error.message));
} }
leave(){ leave(){
this.set("present", false).save() this.set("present", false).set("isasking", 0).save();
} }
} }

@ -0,0 +1,169 @@
// pages/addclass/addclass.js
const AV = require("../../lib/av-live-query-weapp-min")
const Presence = require("../../model/presence")
const Class = require("../../model/class")
const { jsonify } = require('../../utils/leancloudutils');
Page({
/**
* 页面的初始数据
*/
classes: [],
data: {
new_classname:'',
new_class_teacher_username: '',
classes: []
},
updateName: function ({detail: {value}}){
this.setData({new_classname:value});
},
create_class: function(event){
const {new_classname} = this.data;
class_ = new Class({
name: new_classname,
teacher: AV.User.current()
})
presence = new Presence({
user: AV.User.current(),
class: class_
});
wx.showLoading({
title: '请稍候',
})
presence.save().then(()=>{
wx.hideLoading();
wx.showToast({
title: '创建成功,可在首页课程列表以教师身份进入课堂',
icon:"none",
duration: 4000
});
this.setData({new_classname: ""});
},
()=>{
wx.hideLoading();
wx.showToast({
title: '操作失败',
icon: "none"
});
});
},
add_class:function(event){
class_id = event.currentTarget.dataset.id;
class_name = event.currentTarget.dataset.name;
pull_presences = this.pull_presences.bind(this);
wx.showModal({
title: '确认',
content: '是否加入学习'+class_name,
success(res) {
if (res.confirm) {
class_ = AV.Object.createWithoutData("Class_", class_id);
presence = new Presence({
user: AV.User.current(),
class: class_
});
wx.showLoading({
title: '请稍候',
})
presence.save().then(()=>{
pull_presences();
wx.hideLoading();
wx.showToast({
title: '加入成功',
icon: "success"
})
},
() => {
wx.hideLoading();
wx.showToast({
title: '加入失败',
icon: "none"
})
}).catch(error=>console.error(error.message));
}
}
})
},
pull_classes: function(){
query = new AV.Query("Class_");
return query.find().then(classes=>{console.log(classes);this.classes=classes});
},
pull_presences: function(){
query = new AV.Query("Presence");
query.equalTo("user", AV.User.current());
query.include("class");
query.find().then(this.set_presences.bind(this));
},
set_presences: function(presences){
console.log("set_presences");
console.log(presences);
present_class_ids = presences.map(presence=>presence.get("class").id);
classes =this.classes.map(class_=>{
if(present_class_ids.indexOf(class_.id)>-1){
class_.set("present", true);
}else{
class_.set("present", false);
}
return class_;
});
console.log(classes);
this.setData(jsonify({classes}));
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.pull_classes().then(this.pull_presences);
this.setData({new_class_teacher_username: AV.User.current().get("username")});
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.pull_classes().then(this.pull_presences);
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})

@ -0,0 +1,7 @@
{
"navigationBarTitleText": "未加入的课程",
"usingComponents": {
"myicon": "/components/icon/myicon"
},
"enablePullDownRefresh": true
}

@ -0,0 +1,23 @@
<!--pages/addclass/addclass.wxml-->
<view class="container">
<view class="class-list form-wrap">
<block wx:for="{{classes}}" wx:for-item="class" wx:key="objectId">
<view hidden="{{class.present}}" bindtap="add_class" class="class-item flex-wrap" data-id="{{class.objectId}}" data-name="{{class.name}}">
<myicon class="class-icon" type="internet_class" size="26"></myicon>
<text>{{class.name}}</text>
</view>
</block>
</view>
<view class="create-class">
<text>创建我的课程</text>
<view class="flex-wrap input-wrap">
<text class="label">课程名称:</text>
<input value="{{new_classname}}" bindinput="updateName" id="name" class="info-input"/>
</view>
<view class="flex-wrap input-wrap">
<text class="label">教师用户名:</text>
<input value="{{new_class_teacher_username}}" id="teacher_name" class="info-input disabled" disabled="true"/>
</view>
<button bindtap="create_class">创建新课程</button>
</view>
</view>

@ -0,0 +1,67 @@
/* pages/addclass/addclass.wxss */
.class-icon{
margin-left: 2px;
margin-right: 12px;
}
.class-list{
display: flex;
flex-direction: column;
margin: 0 -12px
}
.class-item{
align-items: center;
background: white;
padding: 30rpx 12px;
border-bottom: 1rpx solid #EEE;
position: relative;
}
.class-item:after {
content: '加入学习>';
display: block;
position: absolute;
right: 3rpx;
top: 50%;
height: 40rpx;
line-height: 40rpx;
margin-top: -20rpx;
margin-right: 30rpx;
color: #999;
}
.class-item text{
vertical-align: middle;
}
.input-wrap {
background: #fff;
border-bottom: 1px solid #eee;
margin: 0 -12px;
padding: 0 12px;
height: 46px;
line-height: 46px;
}
.info-input {
font-size: 18px;
line-height: 100%;
height: 100%;
}
.disabled{
color: #999;
}
.label {
color: #999;
width: 7em;
}
.create-class{
position: fixed;
bottom: 0;
}
button{
margin: 4px 26px;
font-size: 14px;
}

@ -39,10 +39,7 @@ Page({
}).catch(error=>console.error(error.message)); }).catch(error=>console.error(error.message));
}, },
/** pull_users: function(){
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData(jsonify({ current_user: AV.User.current() })); this.setData(jsonify({ current_user: AV.User.current() }));
query = new AV.Query("User"); query = new AV.Query("User");
return query.find().then((users) => { return query.find().then((users) => {
@ -50,6 +47,12 @@ Page({
this.setData(jsonify({ users })); this.setData(jsonify({ users }));
}); });
}, },
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.pull_users()
},
/** /**
* 生命周期函数--监听页面初次渲染完成 * 生命周期函数--监听页面初次渲染完成
@ -83,7 +86,7 @@ Page({
* 页面相关事件处理函数--监听用户下拉动作 * 页面相关事件处理函数--监听用户下拉动作
*/ */
onPullDownRefresh: function () { onPullDownRefresh: function () {
this.pull_users();
}, },
/** /**

@ -2,6 +2,7 @@
.user-list{ .user-list{
display: flex; display: flex;
flex-direction: column; flex-direction: column;
margin: 0 -12px
} }
.user-item{ .user-item{
background: white; background: white;

@ -18,11 +18,41 @@ Page({
class.name 课程名称 class.name 课程名称
*/ */
data: { data: {
classes: [ //classes: [{objectId: "232323", "name":"测试"}]
] classes: []
}, },
presences: [],
classes: [], classes: [],
del_class: function(event){
class_id = event.currentTarget.dataset.class_id;
class_name = event.currentTarget.dataset.class_name;
presence = this.presences.filter(presence=>presence.get("class").id==class_id)[0];
pull_classes = this.pull_classes.bind(this);
wx.showModal({
title: '退出学习',
content: '退出学习会清零你该门课程的分数',
success(res) {
if (res.confirm) {
wx.showLoading({
title: '',
})
presence.destroy().then(() => {
pull_classes();
wx.hideLoading();
wx.showToast({
title: '退出成功',
icon: "success"
})
},
() => {
wx.hideLoading();
wx.showToast({
title: '操作失败',
icon: "none"
})
}).catch(error => console.error(error.message));
} } });
},
enter_class: function(event){ enter_class: function(event){
console.log(event); console.log(event);
var class_id = event.currentTarget.dataset.class_id; var class_id = event.currentTarget.dataset.class_id;
@ -46,15 +76,24 @@ Page({
}, },
pull_classes: function(){
console.log("classes.pull_classes");
var query = new AV.Query("Presence");
query.equalTo("user", AV.User.current());
query.include("class");
query.find().then((presences) => {
this.presences = presences;
this.classes = presences.map((presence) => {return presence.get("class")});
console.log(this.classes);
this.setData(jsonify({ classes: this.classes }));
})
},
/** /**
* 生命周期函数--监听页面显示 * 生命周期函数--监听页面显示
*/ */
onShow: function () { onShow: function () {
var query = new AV.Query("Class_"); console.log("classes.onShow()");
query.find().then((classes) => { this.pull_classes();
this.classes = classes
this.setData(jsonify({ classes }));
})
}, },
/** /**
@ -75,11 +114,7 @@ Page({
* 页面相关事件处理函数--监听用户下拉动作 * 页面相关事件处理函数--监听用户下拉动作
*/ */
onPullDownRefresh: function () { onPullDownRefresh: function () {
var query = new AV.Query("Class_"); this.pull_classes();
query.find().then((classes) => {
this.classes = classes
this.setData(jsonify({classes}));
})
}, },
/** /**

@ -1,5 +1,7 @@
{ {
"navigationBarTitleText": "课程列表", "navigationBarTitleText": "我的课程",
"usingComponents": {}, "usingComponents": {
"myicon": "/components/icon/myicon"
},
"enablePullDownRefresh": true "enablePullDownRefresh": true
} }

@ -5,15 +5,19 @@ classes: 课程列表 type: Array
class.objectId 唯一键 class.objectId 唯一键
class.name 课程名称 class.name 课程名称
--> -->
<view class="form-wrap"> <view class="container">
<view class="class-list"> <view class="class-list">
<text wx:if="{{classes.length==0}}">你还没有加入任何课堂</text>
<block wx:for="{{classes}}" wx:for-item="class" wx:key="objectId"> <block wx:for="{{classes}}" wx:for-item="class" wx:key="objectId">
<view class="classroom" data-class_id="{{class.objectId}}" data-class_name="{{class.name}}" bindtap="enter_class"> <view class="classroom flex-wrap" data-class_id="{{class.objectId}}" data-class_name="{{class.name}}" bindtap="enter_class" bindlongtap="del_class">
<!--icon type="success"></icon-->
<myicon class="classroom-icon" type="internet_class" size="26" color="#2351e4"></myicon>
<text>{{class.name}}</text> <text>{{class.name}}</text>
</view> </view>
</block> </block>
</view> </view>
<view class="footer">
<navigator url="../setting/setting" class="setting tappable">设置</navigator>
</view> </view>
<view class="footer flex-wrap">
<navigator url="../setting/setting" class="setting tappable">设置</navigator>
<navigator url="../addclass/addclass" class="addclass tappable">加入课堂</navigator>
</view> </view>

@ -2,9 +2,11 @@
.class-list { .class-list {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
margin: 0 -12px
} }
.classroom { .classroom {
align-items: center;
background: white; background: white;
padding: 30rpx 12px; padding: 30rpx 12px;
border-bottom: 1rpx solid #EEE; border-bottom: 1rpx solid #EEE;
@ -28,8 +30,9 @@
vertical-align: middle; vertical-align: middle;
} }
.classroom icon { .classroom-icon{
margin-right: 25rpx; margin-left: 2px;
margin-right: 10px;
} }
.footer { .footer {
@ -44,3 +47,16 @@
font-size: 16px; font-size: 16px;
text-align: center; text-align: center;
} }
.tappable{
color: #1aad19;
padding: 0 12px;
position: absolute;
}
.addclass{
right:0;
}
.setting{
left:0;
}

@ -14,55 +14,68 @@ Page({
student.present 是否出席 student.present 是否出席
student.isasking :0:没有提问,1:提问,2:请回答 student.isasking :0:没有提问,1:提问,2:请回答
*/ */
presence: null,
origin_presences: [],
students: [], students: [],
class: null,
presences: [], presences: [],
class_id: null,
asking_presence: null,
my_presence: null, my_presence: null,
is_askiny: null,
data: { data: {
//以下数据的同步由该代码文件实现数据的呈现由classroom.wxml实现 //以下数据的同步由该代码文件实现数据的呈现由classroom.wxml实现
students: [], // 该课程所有的学生, 元素类型见上文中的student students: [], // 该课程所有的学生, 元素类型见上文中的student
current_user: null, //目前登陆的用户,类型为对象属性有objectIdusername, name current_user: null, //目前登陆的用户,类型为对象属性有objectIdusername, name
teacher: null, teacher: null,
select_stu_id: '',
//该课程教员,类型为对象 //该课程教员,类型为对象
//请在进入界面时判断用户是否为教员以给与权限或更改界面 //请在进入界面时判断用户是否为教员以给与权限或更改界面
//属性如下objectId, username, name //属性如下objectId, username, name
class_name: "", //课程名称 class_name: "", //课程名称
class_id: "", //该课程的主键(编号) class_id: "", //该课程的主键(编号)
}, },
sco1: function () {
//打1分的函数 select_stu: function(event){
}, id = event.currentTarget.dataset.id;
sco2: function () { if(id!='none'){
//打2分的函数 console.log(id);
}, }else{console.log("none");id=""}
sco3: function () { this.setData({select_stu_id: id});
//打3分的函数
},
ask: function (event) {
//学生提问的函数
console.log(event);
//set_asking()
},
rep: function (event) {
console.log(event);
//点这个学生要回答他问题的函数
}, },
set_asking: function(userid, status){
this.asking_present = this.presents.filter(present=>present.get("user").id==userid)[0]; set_isasking: function(event){
userid = event.currentTarget.dataset.id;
status = event.currentTarget.dataset.status;
console.log("set_isasking");
console.log(status);
console.log(typeof status);
this.asking_present = this.presences.filter(presence=>presence.get("user").id==userid)[0];
this.asking_present.isasking = status; this.asking_present.isasking = status;
this.asking_present.save(); wx.showLoading({
title: '',
})
this.asking_present.save().then(()=>{
wx.hideLoading();
}, ()=>{
wx.hideLoading();
wx.showToast({
title: '操作失败',
icon: "none"
})
});
}, },
add_mark: function(mark){ add_mark: function(event){
if(this.asking_present==null){ id = event.currentTarget.dataset.id;
mark = event.currentTarget.dataset.mark;
console.log("add_mark");
console.log(mark);
console.log(typeof mark);
presence = this.presences.filter(presence => presence.get("user").id == id)[0];
if(presence==null){
console.warn("没有选择学生"); console.warn("没有选择学生");
}else{
user = this.asking_present.get("user");
studentClassMap = this.studentClassMaps.filter(studentClassMap=>studentClassMap.get("user"))
} }
presence.increment("mark", mark).save().then(()=>{
wx.showToast({
title: '操作成功',
icon:"none"
})
}).catch(error=>console.error(error.message));
}, },
pull_presence: function(){ pull_presence: function(){
@ -79,8 +92,9 @@ Page({
}, },
set_presence: function(presences){ set_presence: function(presences){
console.log("set_presence"); console.log("set_presence");
console.log(presences); //console.log(presences);
this.presences = presences; this.presences = presences;
console.log(this.presences);
students = this.presences.map((presence)=>{ students = this.presences.map((presence)=>{
student = presence.get("user"); student = presence.get("user");
if(student.get("username")==null){ if(student.get("username")==null){
@ -96,6 +110,7 @@ Page({
student.set("mark", presence.get("mark")); student.set("mark", presence.get("mark"));
if(student.id==AV.User.current().id){ if(student.id==AV.User.current().id){
this.my_presence = presence; this.my_presence = presence;
this.setData({current_user:student.toJSON()});
} }
return student; return student;
}); });
@ -106,10 +121,12 @@ Page({
}, },
fetch_class: function(class_id){ fetch_class: function(class_id){
this.class = AV.Object.createWithoutData("Class_", class_id); query = new AV.Query("Class_");
//this.class.include("teacher"); query.equalTo("objectId", class_id);
return this.class.fetch().then((class_) => { query.include("teacher");
return query.find().then((classes) => {
//console.log(this.class); //console.log(this.class);
this.class = classes[0];
teacher = this.class.get("teacher"); teacher = this.class.get("teacher");
console.log("fetch_class"); console.log("fetch_class");
console.log(teacher); console.log(teacher);
@ -135,15 +152,15 @@ Page({
wx.showLoading({ wx.showLoading({
title: '加载中' title: '加载中'
}) })
this.setData({current_user: AV.User.current()}); this.setData({current_user: AV.User.current().toJSON()});
this.class_id = options.class_id; this.class_id = options.class_id;
this.fetch_class.bind(this)(this.class_id) this.fetch_class.bind(this)(this.class_id)
.then(()=>{ .then(()=>{
this.pull_presence.bind(this)(); console.log("pull_presence");
this.pull_presence.bind(this)().then((presences) => { this.my_presence.enter(); this.presences = presences;});
wx.hideLoading(); wx.hideLoading();
console.log(this.data); console.log("hideLoading");
}) });
.then(this.my_presence.enter);
console.log("onLoad"); console.log("onLoad");
}, },

@ -1,4 +1,6 @@
{ {
"usingComponents": {}, "usingComponents": {
"myicon": "/components/icon/myicon"
},
"enablePullDownRefresh": true "enablePullDownRefresh": true
} }

@ -1,47 +1,33 @@
<!--pages/classroom/classroom.wxml--> <view bindtap="select_stu" data-id="none">
<view class="index"> <text class="hint">课程名称:{{class_name}}\t教员姓名:{{teacher.name}}</text>
<view class="grid-cell"> <view class="student-list">
<view class="grid-view"> <block wx:for="{{students}}" wx:for-item="student" wx:key="objectId">
<view class="grid-cell" wx:for="{{students}}" wx:for-item="student" wx:key="objectId" bindtap="rep"> <view class="{{teacher.objectId==current_user.objectId?'student selectable':'student'}}" hidden="{{teacher.objectId==student.objectId}}" catchtap="select_stu" data-id="{{student.objectId}}">
<view wx:if="{{student.isasking==0}}"> <myicon wx:if="{{!student.present}}" class="student-icon" type="absent_student" size="36"></myicon>
<text>{{student.username}}</text> <myicon wx:elif="{{student.isasking==1}}" class="student-icon" type="question" size="36" color="red"></myicon>
</view> <myicon wx:elif="{{student.isasking==0}}" class="student-icon" type="present_student" color="#00ff00" size="36"></myicon>
<view wx:elif="{{student.isasking==1}}"> <myicon wx:elif="{{student.isasking==2}}" class="student-icon" type="answer" color="#0000ff" size="36"></myicon>
<text class="reed">{{student.username}}</text> <text class="{{student.present?'present':'absent'}}">{{student.name+'\n'}}</text>
</view> <text>{{student.mark}}分</text>
<view wx:elif="{{student.isasking==2}}">
<text class="gre">{{student.username}}</text>
</view>
</view>
</view>
</view>
<!-- -->
<view wx:if="{{current_user.objectId!=teacher.objectId}}">
<view class="sco">
<button bindtap="ask">提问</button>
</view> </view>
</block>
</view> </view>
<view wx:else> <view class="operation-list">
<button data-id='{{students.username}}' bindtap="sco1">打1分</button> <view class="teacher-operation" hidden="{{teacher.objectId!=current_user.objectId || select_stu_id==''}}">
<button data-id='{{students.username}}' bindtap="sco2">打2分</button> <button type="primary" catchtap="add_mark" data-id="{{select_stu_id}}" data-mark="{{-1}}">减一分</button>
<button data-id='{{students.username}}' bindtap="sco3">打3分</button> <button type="primary" catchtap="add_mark" data-id="{{select_stu_id}}" data-mark="{{1}}">加一分</button>
<button type="primary" catchtap="add_mark" data-id="{{select_stu_id}}" data-mark="{{2}}">加两分</button>
<button type="primary" catchtap="set_isasking" data-id="{{select_stu_id}}" data-status="{{2}}">请起立</button>
</view> </view>
<view class="student-operation" hidden="{{teacher.objectId==current_user.objectId}}">
<button hidden="{{current_user.isasking!=0}}" type="primary" catchtap="set_isasking" data-id="{{current_user.objectId}}" data-status="{{1}}">我要提问/回答</button>
<button hidden="{{current_user.isasking!=1}}" type="primary" catchtap="set_isasking" data-id="{{current_user.objectId}}" data-status="{{0}}">取消提问</button>
<text hidden="{{current_user.isasking!=2}}" class="warning">请起立提问/回答</text>
<button hidden="{{current_user.isasking!=2}}" type="primary" catchtap="set_isasking" data-id="{{current_user.objectId}}" data-status="{{0}}">完成回答</button>
</view> </view>
<view class="containner">
<view class="student-list">
<block wx:for="{{students}}" wx:for-item="student" wx:key="objectId">
<view class="student">
<text>姓名:{{student.name}} 用户名:{{student.username}}
是否出席:{{student.present}} 提问状态:{{student.isasking}}
</text>
</view> </view>
</block> <view class="{{teacher.objectId!=current_user.objectId?'footer':''}}">
<!--text hidden="{{teacher.objectId==current_user.objectId}}">测试</text-->
<text hidden="{{teacher.objectId==current_user.objectId}}">我的得分:{{current_user.mark}}分</text>
</view> </view>
</view> </view>

@ -48,3 +48,51 @@
.sco { .sco {
margin: 20rpx 50rpx; margin: 20rpx 50rpx;
} }
.student-list{
display: -webkit-flex;
display: flex;
align-items: center;
justify-content: space-between;
flex-wrap: wrap;
width: 100%;
}
.student{
flex: 0 0 auto;
width: 23%;
text-align: center;
color: #797979;
padding: 40rpx 0;
font-size: 30rpx;
}
.present{
color: green;
}
.selectable:hover{
border-style: inset;
border-color: green;
opacity: .6;
}
.tappable{
color: #1aad19;
padding: 0 12px;
position: absolute;
}
button{
margin: 10px 36px;
}
.footer {
background: white;
position: fixed;
bottom: 0;
height: 44px;
width: 100%;
line-height: 44px;
color: #666;
border-top: 1px solid #eee;
font-size: 16px;
text-align: center;
}

@ -6,7 +6,6 @@ Page({
username: '', username: '',
password: '', password: '',
error: null, error: null,
authData: '',
}, },
onLoad: function() { onLoad: function() {
const user = User.current(); const user = User.current();
@ -14,7 +13,6 @@ Page({
this.setData({ this.setData({
name: user.get("name"), name: user.get("name"),
username: user.get('username'), username: user.get('username'),
authData: JSON.stringify(user.get('authData'), undefined, 2),
}); });
} }
}, },

@ -15,6 +15,4 @@
</view> </view>
<text wx:if="{{error}}" class="error">{{error}}</text> <text wx:if="{{error}}" class="error">{{error}}</text>
<button class="submit" type="primary" disabled="{{!(username || password)}}" bindtap="save">更新</button> <button class="submit" type="primary" disabled="{{!(username || password)}}" bindtap="save">更新</button>
<text class="hint">当前用户 authData: </text>
<textarea class="hint" auto-height='true' disabled maxlength="-1" value="{{authData}}"></textarea>
</view> </view>

Loading…
Cancel
Save