教师可以删除课程或学员

smart_class
educoder_weapp 5 years ago
parent 0187942f49
commit c8664c2f01

@ -14,7 +14,8 @@
"pages/setting/setting", "pages/setting/setting",
"pages/user/user", "pages/user/user",
"pages/addclass/addclass", "pages/addclass/addclass",
"pages/classdetail/classdetail" "pages/classdetail/classdetail",
"pages/classsetting/classsetting"
], ],
"window": { "window": {
"backgroundTextStyle": "light", "backgroundTextStyle": "light",

@ -19,7 +19,15 @@ Page({
this.setData({new_classname:value}); this.setData({new_classname:value});
}, },
create_class: function(event){ create_class: function(event){
const {new_classname} = this.data; let {new_classname} = this.data;
new_classname = new_classname.trim();
if(new_classname==""){
wx.showToast({
title:"课程名称不能为空",
icon: "none"
})
return;
}
class_ = new Class({ class_ = new Class({
name: new_classname, name: new_classname,
teacher: AV.User.current() teacher: AV.User.current()

@ -1,13 +1,5 @@
<!--pages/addclass/addclass.wxml--> <!--pages/addclass/addclass.wxml-->
<view class="container"> <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"> <view class="create-class">
<text>创建我的课程</text> <text>创建我的课程</text>
<view class="flex-wrap input-wrap"> <view class="flex-wrap input-wrap">
@ -19,5 +11,15 @@
<input value="{{new_class_teacher_username}}" id="teacher_name" class="info-input disabled" disabled="true"/> <input value="{{new_class_teacher_username}}" id="teacher_name" class="info-input disabled" disabled="true"/>
</view> </view>
<button bindtap="create_class">创建新课程</button> <button bindtap="create_class">创建新课程</button>
<view class="class-list form-wrap">
<text>可加入学习:</text>
<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> </view>
</view> </view>

@ -3,7 +3,6 @@
margin-left: 2px; margin-left: 2px;
margin-right: 12px; margin-right: 12px;
} }
.class-list{ .class-list{
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@ -53,11 +52,9 @@
.label { .label {
color: #999; color: #999;
width: 7em;
} }
.create-class{ .create-class{
position: fixed;
bottom: 0; bottom: 0;
} }

@ -20,8 +20,8 @@ Page({
}) })
fileid = event.currentTarget.dataset.fileid; fileid = event.currentTarget.dataset.fileid;
wx.previewImage({ wx.previewImage({
urls: [fileid], urls: this.pic_urls,
current: this.pic_urls, current: fileid,
complete:wx.hideLoading complete:wx.hideLoading
}) })
}, },

@ -1,4 +1,5 @@
{ {
"usingComponents": {}, "usingComponents": {},
"navigationBarTitleText": "更多",
"enablePullDownRefresh": true "enablePullDownRefresh": true
} }

@ -12,7 +12,7 @@
</view> </view>
</block> </block>
</view> </view>
<view class="upload-file">
<button type="primary" bindtap="upload">上传文件资源</button>
</view> </view>
<view class="upload-file foot">
<button type="primary" bindtap="upload">上传文件资源</button>
</view> </view>

@ -2,7 +2,8 @@
.file-list{ .file-list{
display: flex; display: flex;
flex-direction: column; flex-direction: column;
margin: 0 -12px margin: 0 -12px;
margin-bottom: 40px;
} }
.file-item{ .file-item{
background: white; background: white;
@ -18,7 +19,17 @@
.file-uploader{ .file-uploader{
font-size: 10px; font-size: 10px;
} }
.foot{
width: 100%;
position: fixed;
bottom: 0;
}
button{ button{
margin: 10px 36px; margin: 0px 36px;
vertical-align: center;
font-size: 14px;
}
.upload-file{
background: white;
} }

@ -30,6 +30,11 @@ Page({
class_name: "", //课程名称 class_name: "", //课程名称
class_id: "", //该课程的主键(编号) class_id: "", //该课程的主键(编号)
}, },
enter_setting: function(event){
wx.navigateTo({
url: '../classsetting/classsetting?class_id='+this.data.class_id+"&teacher_id="+this.data.teacher.objectId,
})
},
enter_detail: function(event){ enter_detail: function(event){
wx.navigateTo({ wx.navigateTo({
@ -161,6 +166,9 @@ Page({
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(()=>{
wx.setNavigationBarTitle({
title: this.data.class_name,
})
console.log("pull_presence"); console.log("pull_presence");
this.pull_presence.bind(this)().then((presences) => { this.my_presence.enter(); this.presences = presences;}); this.pull_presence.bind(this)().then((presences) => { this.my_presence.enter(); this.presences = presences;});
wx.hideLoading(); wx.hideLoading();

@ -1,5 +1,5 @@
<view bindtap="select_stu" data-id="none"> <view bindtap="select_stu" data-id="none">
<text class="hint">课程名称:{{class_name}}\t教员姓名:{{teacher.name}}</text> <text class="hint">课程名称:{{class_name}} 教员姓名:{{teacher.name}}</text>
<view class="student-list"> <view class="student-list">
<block wx:for="{{students}}" wx:for-item="student" wx:key="objectId"> <block wx:for="{{students}}" wx:for-item="student" wx:key="objectId">
<view class="{{teacher.objectId==current_user.objectId?'student selectable':'student'}}" hidden="{{teacher.objectId==student.objectId}}" catchtap="select_stu" data-id="{{student.objectId}}"> <view class="{{teacher.objectId==current_user.objectId?'student selectable':'student'}}" hidden="{{teacher.objectId==student.objectId}}" catchtap="select_stu" data-id="{{student.objectId}}">
@ -27,7 +27,7 @@
</view> </view>
</view> </view>
<view class="{{teacher.objectId!=current_user.objectId?'footer white':'footer'}}"> <view class="{{teacher.objectId!=current_user.objectId?'footer white':'footer'}}">
<!--text hidden="{{teacher.objectId==current_user.objectId}}">测试</text--> <text class="tappable class-setting" hidden="{{teacher.objectId!=current_user.objectId}}" bindtap="enter_setting" data-id="{{class_id}}">设置</text>
<text hidden="{{teacher.objectId==current_user.objectId}}">我的得分:{{current_user.mark}}分</text> <text hidden="{{teacher.objectId==current_user.objectId}}">我的得分:{{current_user.mark}}分</text>
<text class="tappable class-detail" bindtap="enter_detail">更多</text> <text class="tappable class-detail" bindtap="enter_detail">更多</text>
</view> </view>

@ -84,6 +84,9 @@
.class-detail{ .class-detail{
right: 0; right: 0;
} }
.class-setting{
left:0;
}
button{ button{
margin: 10px 36px; margin: 10px 36px;

@ -0,0 +1,154 @@
const AV = require("../../lib/av-live-query-weapp-min")
const Presence = require("../../model/presence")
const Class = require("../../model/class")
const { jsonify } = require('../../utils/leancloudutils');
// pages/classsetting/classsetting.js
Page({
/**
* 页面的初始数据
*/
class: null,
data: {
presences:[],
teacher_id: ""
},
del_class:function(event){
class_ = this.class;
wx.showModal({
title: '确认',
content: '删除课程会删除该课程相关的一切数据',
success: res=>{
if(res.confirm){
wx.showLoading({
title: '请稍候',
})
query_presence = new AV.Query("Presence");
query_presence.equalTo("class", class_);
query_presence.find().then(AV.Object.destroyAll);
query_file = new AV.Query("File_");
query_file.equalTo("class", class_);
query_file.find().then(files=>{
filelist = files.map(file=>file.get("fileid"));
wx.cloud.deleteFile({
fileList: filelist,
success: res => {
// handle success
console.log(res.fileList)
},
fail: console.error
})
AV.Object.destroyAll(files)});
class_.destroy().then(()=>{
wx.hideLoading();
wx.showToast({
title: '删除成功',
});
wx.navigateBack({
delta: 2
})
});
}
}
})
},
del_student:function(event){
presence_id = event.currentTarget.dataset.id;
pull_presences = this.pull_presences.bind(this);
wx.showModal({
title: '确认',
content: '是否将该学员从课程中移除?',
success: res => {
if (res.confirm) {
AV.Object.createWithoutData("Presence", presence_id).destroy().then(()=>{
pull_presences();
wx.showToast({
title: '移除成功',
})}, ()=>{
wx.showToast({
title: '移除失败',
icon:"none"
})
});
}
}
})
},
pull_presences:function(){
query = new AV.Query("Presence");
query.equalTo("class", this.class);
query.include("user");
query.find().then(this.set_presences);
},
set_presences:function(presences){
presences = presences.map(presence=>{
user = presence.get("user");
presence.set("student_username", user.get("username"));
presence.set("student_name", user.get("name"));
presence.set("student_id", user.get("objectId"))
return presence;
})
this.setData(jsonify({presences}));
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
class_id = options.class_id;
teacher_id = options.teacher_id;
console.log(teacher_id);
this.class = AV.Object.createWithoutData("Class_", class_id);
this.setData({teacher_id: teacher_id});
this.pull_presences();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.pull_presences();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})

@ -0,0 +1,5 @@
{
"navigationBarTitleText": "课程设置",
"usingComponents": {},
"enablePullDownRefresh": true
}

@ -0,0 +1,15 @@
<!--pages/classsetting/classsetting.wxml-->
<view class="container">
<view class="student-list">
<text>学员列表</text>
<block wx:for="{{presences}}" wx:for-item="presence" wx:key="objectId">
<view hidden="{{presence.student_id==teacher_id}}" class="student flex-wrap" data-id="{{presence.objectId}}" bindlongtap="del_student">
<text>{{presence.student_name}}</text>
<text class="hint">{{presence.student_username}}</text>
</view>
</block>
</view>
</view>
<view class="footer">
<button type="primary" bindtap="del_class">删除该课程</button>
</view>

@ -0,0 +1,28 @@
/* pages/classsetting/classsetting.wxss */
button{
margin: 2px 36px;
font-size: 14px;
}
.hint{
padding-left: 16px;
}
.student-list{
margin-bottom: 40px;
}
.student{
align-items: center;
background: white;
padding: 20rpx 16px;
border-bottom: 1rpx solid #EEE;
position: relative;
margin: 0 -12px;
}
.container{
margin-bottom: 40px;
}
.footer{
position: fixed;
bottom: 0;
background: white;
width: 100%;
}
Loading…
Cancel
Save