增加了课堂文件功能

smart_class
educoder_weapp 5 years ago
parent 01771b1c50
commit 0187942f49

@ -20,5 +20,8 @@ App({
console.log(user); console.log(user);
console.log(AV.User.current()); console.log(AV.User.current());
}); });
wx.cloud.init({
env: 'test-tkkvk'
})
} }
}); });

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

@ -0,0 +1,37 @@
const AV = require("../lib/av-live-query-weapp-min")
class File extends AV.Object{
get url(){
return this.get("url");
}
set url(value){
this.set("url", value);
}
get fileid(){
return this.get("fileid");
}
set fileid(value){
this.set("fileid", value);
}
get class(){
return this.get("class");
}
set class(value){
this.set("class", value);
}
get filename(){
return this.get("filename");
}
set filename(value){
this.set("filename", value);
}
get uploader(){
return this.get("uploader");
}
set uploader(value){
this.set("uploader", value);
}
}
AV.Object.register(File, "File_");
module.exports = File;

@ -0,0 +1,203 @@
// pages/classdetail/classdetail.js
const AV = require("../../lib/av-live-query-weapp-min")
const File = require("../../model/file")
const Class = require("../../model/class")
const { jsonify } = require('../../utils/leancloudutils');
Page({
/**
* 页面的初始数据
*/
class: null,
pic_urls: [],
data: {
files:[]
},
preview_pic:function(event){
wx.showLoading({
title: '加载中',
})
fileid = event.currentTarget.dataset.fileid;
wx.previewImage({
urls: [fileid],
current: this.pic_urls,
complete:wx.hideLoading
})
},
del_file: function(event){
},
download: function(event){
console.log(event);
fileid = event.currentTarget.dataset.fileid;
wx.showLoading({
title: '下载中',
})
wx.cloud.downloadFile({
fileID: fileid,
success: res => {
// 返回临时文件路径
console.log(res.tempFilePath);
wx.openDocument({
filePath: res.tempFilePath,
success: function (res) {
console.log('打开文档成功')
},
fail:console.error,
complete:wx.hideLoading
})
// wx.saveFile({
// tempFilePath: res.tempFilePath,
// success(res) {
// const savedFilePath = res.savedFilePath;
// console.log(savedFilePath);
// }
// })
},
fail: console.error
})
},
upload: function(event){
console.log(event)
pull_files = this.pull_files.bind(this);
class_ = this.class;
wx.showToast({
title: '请选择聊天文件',
icon:"none"
})
wx.chooseMessageFile({
count: 1,
success(res){
const tempFile = res.tempFiles[0];
const filename = tempFile.name;
const filepath = tempFile.path;
const cloudpath = tempFile.time+"/" + filename;
console.log(res);
wx.showLoading({
title: '上传中',
})
wx.cloud.uploadFile({
cloudPath: cloudpath,
filePath: filepath,
success: res => {
// 返回文件 ID
fileid = res.fileID;
file = new File({
filename: filename,
class: class_,
uploader: AV.User.current(),
fileid: fileid
}).save().then(()=>{
wx.hideLoading();
pull_files();
wx.showToast({
title: '上传成功',
})
},
()=>{
wx.hideLoading();
wx.showToast({
title: "上传失败",
icon: "none"
})
}).catch(console.error);
console.log(res.fileID);
},
fail: error=>{
console.error(error);
wx.hideLoading();
wx.showToast({
title: '上传失败',
icon:"none"
})
}
})
}
})
},
pull_files:function(){
query = new AV.Query("File_");
query.equalTo("class", this.class);
query.include("uploader");
query.find().then(this.set_files);
},
set_files: function(files){
files = files.map(file=>{
uploader = file.get("uploader");
file.set("uploader_name", uploader.get("name"));
file.set("uploader_username", uploader.get("username"));
filename = file.get("filename");
if(filename.endsWith(".png") || filename.endsWith(".jpg")){
file.set("ispic", true);
this.pic_urls.push(file.get("fileid"));
console.log(this.pic_urls);
}else{
file.set("ispic", false);
}
return file;
})
this.setData(jsonify({files}));
console.log(this.data);
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
class_id = options.class_id;
this.class = AV.Object.createWithoutData("Class_", class_id);
this.pull_files();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
this.pull_files();
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})

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

@ -0,0 +1,18 @@
<!--pages/classdetail/classdetail.wxml-->
<!--pages/changeuser/changeuser.wxml-->
<view class="container">
<text>课堂资源</text>
<view class="file-list form-wrap">
<block wx:for="{{files}}" wx:for-item="file" wx:key="objectId">
<image wx:if="{{file.ispic}}" src="{{file.fileid}}" bindtap="preview_pic" data-fileid="{{file.fileid}}"></image>
<view class="file-item flex-wrap" bindtap="{{file.ispic?'preview_pic':'download'}}" data-fileid="{{file.fileid}}" data-id="{{file.objectId}}">
<!--image wx:if="{{file.ispic}}" src="{{file.fileid}}"></image-->
<text>{{file.filename}}</text>
<text class="hint file-uploader">上传者:{{file.uploader_username}}</text>
</view>
</block>
</view>
<view class="upload-file">
<button type="primary" bindtap="upload">上传文件资源</button>
</view>
</view>

@ -0,0 +1,24 @@
/* pages/classdetail/classdetail.wxss */
.file-list{
display: flex;
flex-direction: column;
margin: 0 -12px
}
.file-item{
background: white;
border-bottom: 1px solid #eee;
padding: 16rpx 16px;
position: relative;
}
.file-item text{
vertical-align: middle;
}
.file-uploader{
font-size: 10px;
}
button{
margin: 10px 36px;
}

@ -34,7 +34,7 @@ Page({
success(res) { success(res) {
if (res.confirm) { if (res.confirm) {
wx.showLoading({ wx.showLoading({
title: '', title: '请稍候',
}) })
presence.destroy().then(() => { presence.destroy().then(() => {
pull_classes(); pull_classes();

@ -9,13 +9,36 @@ classes: 课程列表 type: Array
<view class="class-list"> <view class="class-list">
<text wx:if="{{classes.length==0}}">你还没有加入任何课堂</text> <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 flex-wrap" data-class_id="{{class.objectId}}" data-class_name="{{class.name}}" bindtap="enter_class" bindlongtap="del_class"> <view class="classroom flex-wrap" data-class_id="{{class.objectId}}" data-class_name="{{class.name}}" bindtap="enter_class" catchlongtap="del_class">
<!--icon type="success"></icon--> <!--icon type="success"></icon-->
<myicon class="classroom-icon" type="internet_class" size="26" color="#2351e4"></myicon> <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>
<text class="hint">
# 项目简介
## 学员可以在点击右下角”加入课堂”选择课程加入,教员可以在“加入课堂中”新建课程
## 长按相应课程可以退出学习
## 进入课堂界面会显示在位,头像为彩色,若退出课堂界面则会显示灰色头像
## 教员在课堂界面中可以直观地看到学员在位情况,可以选择学员让其起立回答问题,并且对学员可以进行加分、减分操作
## 学员可以收到教员让其起立提问、回答的提示,还可以点击“我要提问、回答”
## 在课堂界面右下角进入“更多”可以查看本课堂的课程文件资源
## 其他
### 用户可以在设置中更改姓名、用户名
### 为方便测试,在设置中可以选择测试用户登陆
</text>
</view> </view>
<view class="footer flex-wrap"> <view class="footer flex-wrap">
<navigator url="../setting/setting" class="setting tappable">设置</navigator> <navigator url="../setting/setting" class="setting tappable">设置</navigator>

@ -31,6 +31,11 @@ Page({
class_id: "", //该课程的主键(编号) class_id: "", //该课程的主键(编号)
}, },
enter_detail: function(event){
wx.navigateTo({
url: '../classdetail/classdetail?class_id='+this.data.class_id,
})
},
select_stu: function(event){ select_stu: function(event){
id = event.currentTarget.dataset.id; id = event.currentTarget.dataset.id;
if(id!='none'){ if(id!='none'){
@ -48,7 +53,7 @@ Page({
this.asking_present = this.presences.filter(presence=>presence.get("user").id==userid)[0]; this.asking_present = this.presences.filter(presence=>presence.get("user").id==userid)[0];
this.asking_present.isasking = status; this.asking_present.isasking = status;
wx.showLoading({ wx.showLoading({
title: '', title: '请稍候',
}) })
this.asking_present.save().then(()=>{ this.asking_present.save().then(()=>{
wx.hideLoading(); wx.hideLoading();

@ -26,8 +26,9 @@
<button hidden="{{current_user.isasking!=2}}" type="primary" catchtap="set_isasking" data-id="{{current_user.objectId}}" data-status="{{0}}">完成回答</button> <button hidden="{{current_user.isasking!=2}}" type="primary" catchtap="set_isasking" data-id="{{current_user.objectId}}" data-status="{{0}}">完成回答</button>
</view> </view>
</view> </view>
<view class="{{teacher.objectId!=current_user.objectId?'footer':''}}"> <view class="{{teacher.objectId!=current_user.objectId?'footer white':'footer'}}">
<!--text hidden="{{teacher.objectId==current_user.objectId}}">测试</text--> <!--text hidden="{{teacher.objectId==current_user.objectId}}">测试</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>
</view> </view>
</view> </view>

@ -80,12 +80,16 @@
padding: 0 12px; padding: 0 12px;
position: absolute; position: absolute;
} }
.class-detail{
right: 0;
}
button{ button{
margin: 10px 36px; margin: 10px 36px;
} }
.footer { .footer {
background: white;
position: fixed; position: fixed;
bottom: 0; bottom: 0;
height: 44px; height: 44px;
@ -96,3 +100,7 @@ button{
font-size: 16px; font-size: 16px;
text-align: center; text-align: center;
} }
.white{
background: white;
}

Loading…
Cancel
Save