From c8664c2f017360c9e16129d26da871f3843c87a9 Mon Sep 17 00:00:00 2001 From: educoder_weapp Date: Thu, 24 Oct 2019 10:18:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=99=E5=B8=88=E5=8F=AF=E4=BB=A5=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E8=AF=BE=E7=A8=8B=E6=88=96=E5=AD=A6=E5=91=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.json | 3 +- pages/addclass/addclass.js | 10 +- pages/addclass/addclass.wxml | 18 ++-- pages/addclass/addclass.wxss | 3 - pages/classdetail/classdetail.js | 4 +- pages/classdetail/classdetail.json | 1 + pages/classdetail/classdetail.wxml | 4 +- pages/classdetail/classdetail.wxss | 17 ++- pages/classroom/classroom.js | 8 ++ pages/classroom/classroom.wxml | 4 +- pages/classroom/classroom.wxss | 3 + pages/classsetting/classsetting.js | 154 +++++++++++++++++++++++++++ pages/classsetting/classsetting.json | 5 + pages/classsetting/classsetting.wxml | 15 +++ pages/classsetting/classsetting.wxss | 28 +++++ 15 files changed, 255 insertions(+), 22 deletions(-) create mode 100644 pages/classsetting/classsetting.js create mode 100644 pages/classsetting/classsetting.json create mode 100644 pages/classsetting/classsetting.wxml create mode 100644 pages/classsetting/classsetting.wxss diff --git a/app.json b/app.json index f5a417a..7cb299d 100644 --- a/app.json +++ b/app.json @@ -14,7 +14,8 @@ "pages/setting/setting", "pages/user/user", "pages/addclass/addclass", - "pages/classdetail/classdetail" + "pages/classdetail/classdetail", + "pages/classsetting/classsetting" ], "window": { "backgroundTextStyle": "light", diff --git a/pages/addclass/addclass.js b/pages/addclass/addclass.js index 3b3f0f5..2d5c12f 100644 --- a/pages/addclass/addclass.js +++ b/pages/addclass/addclass.js @@ -19,7 +19,15 @@ Page({ this.setData({new_classname:value}); }, 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({ name: new_classname, teacher: AV.User.current() diff --git a/pages/addclass/addclass.wxml b/pages/addclass/addclass.wxml index 6e34cba..f9dc285 100644 --- a/pages/addclass/addclass.wxml +++ b/pages/addclass/addclass.wxml @@ -1,13 +1,5 @@ - - - - - 创建我的课程 @@ -19,5 +11,15 @@ + + 可加入学习: + + + + + \ No newline at end of file diff --git a/pages/addclass/addclass.wxss b/pages/addclass/addclass.wxss index 53820a4..e50d560 100644 --- a/pages/addclass/addclass.wxss +++ b/pages/addclass/addclass.wxss @@ -3,7 +3,6 @@ margin-left: 2px; margin-right: 12px; } - .class-list{ display: flex; flex-direction: column; @@ -53,11 +52,9 @@ .label { color: #999; - width: 7em; } .create-class{ - position: fixed; bottom: 0; } diff --git a/pages/classdetail/classdetail.js b/pages/classdetail/classdetail.js index ea05dc9..9972e17 100644 --- a/pages/classdetail/classdetail.js +++ b/pages/classdetail/classdetail.js @@ -20,8 +20,8 @@ Page({ }) fileid = event.currentTarget.dataset.fileid; wx.previewImage({ - urls: [fileid], - current: this.pic_urls, + urls: this.pic_urls, + current: fileid, complete:wx.hideLoading }) }, diff --git a/pages/classdetail/classdetail.json b/pages/classdetail/classdetail.json index 7360326..0251ffe 100644 --- a/pages/classdetail/classdetail.json +++ b/pages/classdetail/classdetail.json @@ -1,4 +1,5 @@ { "usingComponents": {}, + "navigationBarTitleText": "更多", "enablePullDownRefresh": true } \ No newline at end of file diff --git a/pages/classdetail/classdetail.wxml b/pages/classdetail/classdetail.wxml index a5f1014..6768c45 100644 --- a/pages/classdetail/classdetail.wxml +++ b/pages/classdetail/classdetail.wxml @@ -12,7 +12,7 @@ - + + - diff --git a/pages/classdetail/classdetail.wxss b/pages/classdetail/classdetail.wxss index a0f0361..f57e050 100644 --- a/pages/classdetail/classdetail.wxss +++ b/pages/classdetail/classdetail.wxss @@ -2,7 +2,8 @@ .file-list{ display: flex; flex-direction: column; - margin: 0 -12px + margin: 0 -12px; + margin-bottom: 40px; } .file-item{ background: white; @@ -18,7 +19,17 @@ .file-uploader{ font-size: 10px; } - +.foot{ + width: 100%; + position: fixed; + bottom: 0; +} button{ - margin: 10px 36px; + margin: 0px 36px; + vertical-align: center; + font-size: 14px; +} +.upload-file{ + background: white; + } \ No newline at end of file diff --git a/pages/classroom/classroom.js b/pages/classroom/classroom.js index 4058592..15e3117 100644 --- a/pages/classroom/classroom.js +++ b/pages/classroom/classroom.js @@ -30,6 +30,11 @@ Page({ class_name: "", //课程名称 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){ wx.navigateTo({ @@ -161,6 +166,9 @@ Page({ this.class_id = options.class_id; this.fetch_class.bind(this)(this.class_id) .then(()=>{ + wx.setNavigationBarTitle({ + title: this.data.class_name, + }) console.log("pull_presence"); this.pull_presence.bind(this)().then((presences) => { this.my_presence.enter(); this.presences = presences;}); wx.hideLoading(); diff --git a/pages/classroom/classroom.wxml b/pages/classroom/classroom.wxml index 8b27370..461a332 100644 --- a/pages/classroom/classroom.wxml +++ b/pages/classroom/classroom.wxml @@ -1,5 +1,5 @@ - 课程名称:{{class_name}}\t教员姓名:{{teacher.name}} + 课程名称:{{class_name}} 教员姓名:{{teacher.name}} - + 更多 diff --git a/pages/classroom/classroom.wxss b/pages/classroom/classroom.wxss index a4a9a3c..3f6d221 100644 --- a/pages/classroom/classroom.wxss +++ b/pages/classroom/classroom.wxss @@ -84,6 +84,9 @@ .class-detail{ right: 0; } +.class-setting{ + left:0; +} button{ margin: 10px 36px; diff --git a/pages/classsetting/classsetting.js b/pages/classsetting/classsetting.js new file mode 100644 index 0000000..8be3c27 --- /dev/null +++ b/pages/classsetting/classsetting.js @@ -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 () { + + } +}) \ No newline at end of file diff --git a/pages/classsetting/classsetting.json b/pages/classsetting/classsetting.json new file mode 100644 index 0000000..ebd09dc --- /dev/null +++ b/pages/classsetting/classsetting.json @@ -0,0 +1,5 @@ +{ + "navigationBarTitleText": "课程设置", + "usingComponents": {}, + "enablePullDownRefresh": true +} \ No newline at end of file diff --git a/pages/classsetting/classsetting.wxml b/pages/classsetting/classsetting.wxml new file mode 100644 index 0000000..fd6ec72 --- /dev/null +++ b/pages/classsetting/classsetting.wxml @@ -0,0 +1,15 @@ + + + + 学员列表 + + + + + + + + \ No newline at end of file diff --git a/pages/classsetting/classsetting.wxss b/pages/classsetting/classsetting.wxss new file mode 100644 index 0000000..55e0417 --- /dev/null +++ b/pages/classsetting/classsetting.wxss @@ -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%; +} \ No newline at end of file