|
@@ -15,13 +15,16 @@ Page({
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
+ homeworkId: null,
|
|
|
talkFlag: false,
|
|
|
closeName: '开始录音',
|
|
|
videoList: [],
|
|
|
videoFlag: 0,
|
|
|
imgList: [],
|
|
|
- audioList:[],
|
|
|
- audioPause: false
|
|
|
+ audioList: [],
|
|
|
+ audioPause: false,
|
|
|
+ content: '',
|
|
|
+ delItems: []
|
|
|
},
|
|
|
|
|
|
getRecord: function () {
|
|
@@ -29,11 +32,11 @@ Page({
|
|
|
if (that.data.talkFlag) {
|
|
|
recordManager.stop()
|
|
|
recordManager.onStop((res) => { //监听录音停止的事件
|
|
|
- console.log("监听录音停止事件",res)
|
|
|
+ console.log("监听录音停止事件", res)
|
|
|
if (res.duration < 1000) {
|
|
|
wx.showToast({
|
|
|
title: '录音时间太短',
|
|
|
- icon: none
|
|
|
+ icon: 'none'
|
|
|
})
|
|
|
return;
|
|
|
} else {
|
|
@@ -49,12 +52,10 @@ Page({
|
|
|
wx.showToast({
|
|
|
title: '上传成功',
|
|
|
})
|
|
|
-
|
|
|
const rs = JSON.parse(JSON.parse(JSON.stringify(res.data)))
|
|
|
- console.log(rs)
|
|
|
- const list = [rs.data[0].url]
|
|
|
+ const list = [{ url: rs.data[0].url }]
|
|
|
that.setData({
|
|
|
- audioList:that.data.audioList.concat(list)
|
|
|
+ audioList: that.data.audioList.concat(list)
|
|
|
})
|
|
|
},
|
|
|
fail(res) {
|
|
@@ -65,7 +66,7 @@ Page({
|
|
|
},
|
|
|
complete(res) {
|
|
|
wx.hideLoading({
|
|
|
- success: (res) => {},
|
|
|
+ success: (res) => { },
|
|
|
})
|
|
|
}
|
|
|
})
|
|
@@ -86,7 +87,7 @@ Page({
|
|
|
const options = {}
|
|
|
recordManager.start(options)
|
|
|
},
|
|
|
- fail(){
|
|
|
+ fail() {
|
|
|
wx.openSetting({
|
|
|
withSubscriptions: true,
|
|
|
})
|
|
@@ -106,21 +107,21 @@ Page({
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- showAudio:function(e){
|
|
|
+ showAudio: function (e) {
|
|
|
const index = e.currentTarget.dataset.index
|
|
|
- if(this.data.curAudioIndex != index){
|
|
|
+ if (this.data.curAudioIndex != index) {
|
|
|
this.setData({
|
|
|
curAudioIndex: index,
|
|
|
})
|
|
|
- audioContext.src = this.data.audioList[index]
|
|
|
+ audioContext.src = this.data.audioList[index].url
|
|
|
audioContext.play()
|
|
|
- audioContext.onEnded((res)=>{
|
|
|
+ audioContext.onEnded((res) => {
|
|
|
this.setData({
|
|
|
curAudioIndex: '-1',
|
|
|
})
|
|
|
})
|
|
|
- }else{
|
|
|
- if(this.data.audioPause){
|
|
|
+ } else {
|
|
|
+ if (this.data.audioPause) {
|
|
|
audioContext.play()
|
|
|
this.setData({
|
|
|
audioPause: false
|
|
@@ -131,20 +132,27 @@ Page({
|
|
|
audioPause: true
|
|
|
})
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
- delAudio:function(e){
|
|
|
+ delAudio: function (e) {
|
|
|
const index = e.currentTarget.dataset.index
|
|
|
- this.data.audioList.splice(index,1);
|
|
|
+ // this.data.audioList.splice(index, 1);
|
|
|
+ // this.setData({
|
|
|
+ // audioList: this.data.audioList
|
|
|
+ // })
|
|
|
+
|
|
|
+ let records = this.data.audioList;
|
|
|
+ let record = records[index];
|
|
|
+ record.delete = 1
|
|
|
this.setData({
|
|
|
- audioList: this.data.audioList
|
|
|
+ audioList: records
|
|
|
})
|
|
|
},
|
|
|
|
|
|
uploadTap: function () {
|
|
|
const that = this
|
|
|
-
|
|
|
+
|
|
|
wx.chooseImage({
|
|
|
count: 6,
|
|
|
sourceType: ['album', 'camera'],
|
|
@@ -163,7 +171,7 @@ Page({
|
|
|
title: '上传成功',
|
|
|
})
|
|
|
const rs = JSON.parse(JSON.parse(JSON.stringify(res.data)))
|
|
|
- const list = [rs.data[0].url]
|
|
|
+ const list = [{ url: rs.data[0].url }]
|
|
|
that.setData({
|
|
|
imgList: that.data.imgList.concat(list)
|
|
|
})
|
|
@@ -176,7 +184,7 @@ Page({
|
|
|
},
|
|
|
complete(res) {
|
|
|
wx.hideLoading({
|
|
|
- success: (res) => {},
|
|
|
+ success: (res) => { },
|
|
|
})
|
|
|
}
|
|
|
})
|
|
@@ -187,17 +195,25 @@ Page({
|
|
|
|
|
|
showImg: function (e) {
|
|
|
const index = e.currentTarget.dataset.index
|
|
|
+ let images = this.data.imgList;
|
|
|
+ let imgs = []
|
|
|
+ images.map(i => {
|
|
|
+ imgs.push(i.url)
|
|
|
+ })
|
|
|
wx.previewImage({
|
|
|
- current: this.data.imgList[index],
|
|
|
- urls: this.data.imgList,
|
|
|
+ current: images[index].url,
|
|
|
+ urls: imgs,
|
|
|
})
|
|
|
},
|
|
|
|
|
|
delImg: function (e) {
|
|
|
const index = e.currentTarget.dataset.index
|
|
|
- this.data.imgList.splice(index, 1);
|
|
|
+ // this.data.imgList.splice(index, 1);
|
|
|
+ let images = this.data.imgList;
|
|
|
+ let image = images[index]
|
|
|
+ image.delete = 1
|
|
|
this.setData({
|
|
|
- imgList: this.data.imgList
|
|
|
+ imgList: images
|
|
|
})
|
|
|
},
|
|
|
|
|
@@ -235,7 +251,7 @@ Page({
|
|
|
|
|
|
showVideo: function (e) {
|
|
|
const index = e.currentTarget.dataset.index
|
|
|
- const curVideo = this.data.videoList[index].src
|
|
|
+ const curVideo = this.data.videoList[index].playUrl
|
|
|
this.setData({
|
|
|
curVideo
|
|
|
})
|
|
@@ -261,9 +277,15 @@ Page({
|
|
|
|
|
|
delVideo: function (e) {
|
|
|
const index = e.currentTarget.dataset.index
|
|
|
- this.data.videoList.splice(index, 1);
|
|
|
+ // this.data.videoList.splice(index, 1);
|
|
|
+ // this.setData({
|
|
|
+ // videoList: this.data.videoList
|
|
|
+ // })
|
|
|
+ let videos = this.data.videoList;
|
|
|
+ let video = videos[index]
|
|
|
+ video.delete = 1
|
|
|
this.setData({
|
|
|
- videoList: this.data.videoList
|
|
|
+ videoList: videos
|
|
|
})
|
|
|
},
|
|
|
|
|
@@ -271,6 +293,59 @@ Page({
|
|
|
* 生命周期函数--监听页面加载
|
|
|
*/
|
|
|
onLoad: function (options) {
|
|
|
+ let urls = urlDef.urls;
|
|
|
+ let stu = wx.getStorageSync('student')
|
|
|
+ let homeworkId = options.homeworkId;
|
|
|
+ let studentId = stu.studentId;
|
|
|
+ this.setData({ homeworkId: homeworkId })
|
|
|
+
|
|
|
+ let params = { 'q.homeworkId': homeworkId, 'q.studentId': studentId }
|
|
|
+
|
|
|
+ util.apiPost(urls.homework_receive, params).then(rs => {
|
|
|
+ });
|
|
|
+
|
|
|
+ util.apiPost(urls.my_homework, params).then(rs => {
|
|
|
+ if (rs.length > 0) {
|
|
|
+ let entity = rs[0]
|
|
|
+ let contents;
|
|
|
+ try {
|
|
|
+ contents = JSON.parse(entity.content);
|
|
|
+ } catch (e) {
|
|
|
+ contents = {};
|
|
|
+ console.error(e);
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setData({ content: contents.content })
|
|
|
+ let images = contents.images == null ? [] : contents.images;
|
|
|
+ images.forEach(r => {
|
|
|
+ r.url = urls.oss_file + 'image/' + r.url
|
|
|
+ });
|
|
|
+
|
|
|
+ let records = contents.records == null ? [] : contents.records;
|
|
|
+ records.forEach(r => {
|
|
|
+ r.url = urls.oss_file + 'file/' + r.url
|
|
|
+ });
|
|
|
+
|
|
|
+ let videos = contents.videos == null ? [] : contents.videos;
|
|
|
+
|
|
|
+ this.setData({
|
|
|
+ imgList: images,
|
|
|
+ audioList: records,
|
|
|
+ videoList: videos
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ videos.forEach(r => {
|
|
|
+ util.apiPost(urls.video_loadInfo + r.url).then(rs => {
|
|
|
+ r.imgUrl = rs.img
|
|
|
+ r.playUrl = rs.url
|
|
|
+ this.reloadVideos(r)
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
this.videoContext = wx.createVideoContext('play-video'); // 创建 video 上下文 VideoContext 对象。
|
|
|
const that = this
|
|
|
const createUpLoad = new VODUpload({
|
|
@@ -294,22 +369,32 @@ Page({
|
|
|
//如果uploadInfo.videoId不存在,调用获取视频上传地址和凭证接口
|
|
|
}
|
|
|
//从点播服务获取的uploadAuth、uploadAddress和videoId,设置SDK
|
|
|
- console.log(that.data)
|
|
|
+ // console.log(that.data)
|
|
|
uploader.setUploadAuthAndAddress(uploadInfo, that.data.uploadAuth, that.data.uploadAddress, that.data.videoId);
|
|
|
},
|
|
|
//文件上传成功
|
|
|
'onUploadSucceed': function (uploadInfo) {
|
|
|
- // console.log("上传成功:" + JSON.stringify(uploadInfo))
|
|
|
- var json = {
|
|
|
- src: uploadInfo.url,
|
|
|
- img: uploadInfo.coverUrl
|
|
|
- }
|
|
|
- var list = [json]
|
|
|
- that.setData({
|
|
|
- videoList: that.data.videoList.concat(list)
|
|
|
- })
|
|
|
- wx.showToast({
|
|
|
- title: '上传成功',
|
|
|
+ console.log("上传成功:" + JSON.stringify(uploadInfo))
|
|
|
+
|
|
|
+ let vid = uploadInfo.videoId
|
|
|
+ let stu = wx.getStorageSync('student')
|
|
|
+ var video = { name: vid, videoId: vid, orgId: stu.orgId, size: uploadInfo.fileSize, title: '', content: '' };
|
|
|
+ // 保存一个 video
|
|
|
+ let urls = urlDef.urls
|
|
|
+ util.apiPost(urls.video_save, video, 'application/json').then((rs) => {
|
|
|
+ var json = {
|
|
|
+ url: uploadInfo.videoId,
|
|
|
+ playUrl: uploadInfo.url,
|
|
|
+ imgUrl: uploadInfo.coverUrl
|
|
|
+ }
|
|
|
+ console.log('视频上传成功' + JSON.stringify(json))
|
|
|
+ var list = [json]
|
|
|
+ that.setData({
|
|
|
+ videoList: that.data.videoList.concat(list)
|
|
|
+ })
|
|
|
+ wx.showToast({
|
|
|
+ title: '上传成功',
|
|
|
+ })
|
|
|
})
|
|
|
// console.log("onUploadSucceed: " + uploadInfo.file.name + ", endpoint:" + uploadInfo.endpoint + ", bucket:" + uploadInfo.bucket + ", object:" + uploadInfo.object);
|
|
|
},
|
|
@@ -389,5 +474,117 @@ Page({
|
|
|
*/
|
|
|
onShareAppMessage: function () {
|
|
|
|
|
|
+ },
|
|
|
+ doConfirmComplete: function () {
|
|
|
+ console.log('homeworkId ' + this.data.homeworkId)
|
|
|
+ let contents = {};
|
|
|
+
|
|
|
+ let dlist = [];
|
|
|
+ let images = [];
|
|
|
+ if (this.data.imgList.length > 0) {
|
|
|
+ this.data.imgList.forEach(r => {
|
|
|
+ let fid = r.url.substring(r.url.lastIndexOf('/') + 1)
|
|
|
+ if (r.delete == 1) {
|
|
|
+ dlist.push({ id: fid, type: 'image' })
|
|
|
+ } else {
|
|
|
+ images.push({ url: fid })
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ let records = [];
|
|
|
+ if (this.data.audioList.length > 0) {
|
|
|
+ this.data.audioList.forEach(r => {
|
|
|
+ let fid = r.url.substring(r.url.lastIndexOf('/') + 1)
|
|
|
+ if (r.delete == 1) {
|
|
|
+ dlist.push({ id: fid, type: 'record' })
|
|
|
+ } else {
|
|
|
+ records.push({ url: fid })
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ let videos = [];
|
|
|
+ if (this.data.videoList.length > 0) {
|
|
|
+ this.data.videoList.forEach(r => {
|
|
|
+ if (r.delete == 1) {
|
|
|
+ dlist.push({ id: r.url, type: 'video' })
|
|
|
+ } else {
|
|
|
+ videos.push({ url: r.url })
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ this.setData({ delItems: dlist })
|
|
|
+ contents.images = images;
|
|
|
+ contents.videos = videos;
|
|
|
+ contents.records = records;
|
|
|
+ contents.content = this.data.content;
|
|
|
+
|
|
|
+ let stu = wx.getStorageSync('student')
|
|
|
+ let data = {
|
|
|
+ 'q.content': JSON.stringify(contents),
|
|
|
+ 'q.status': 1,
|
|
|
+ 'q.studentId': stu.studentId,
|
|
|
+ 'q.homeworkId': this.data.homeworkId
|
|
|
+ }
|
|
|
+
|
|
|
+ util.apiPost(urls.complete_homework, data).then(rs => {
|
|
|
+
|
|
|
+ const msgParams = { 'homeworkId': this.data.homeworkId, 'studentId': stu.studentId };
|
|
|
+ util.apiPost(urls.homework_complete_send_message, msgParams).then((rs) => {
|
|
|
+ console.log('发送通知 ' + JSON.stringify(rs));
|
|
|
+ });
|
|
|
+
|
|
|
+ wx.showToast({
|
|
|
+ title: '已完成作业'
|
|
|
+ })
|
|
|
+ setTimeout(() => {
|
|
|
+ wx.navigateBack({
|
|
|
+ delta: 2, // 返回上一级页面。
|
|
|
+ success: function () {
|
|
|
+ console.log('成功!')
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }, 1000)
|
|
|
+ // 删除文件
|
|
|
+ if (this.data.delItems.length > 0) {
|
|
|
+ // 视频的删除跟文件的删除不一样
|
|
|
+ let delFiles = [];
|
|
|
+ let delVideos = [];
|
|
|
+ this.data.delItems.forEach(r => {
|
|
|
+ if (r.type === 'video') {
|
|
|
+ delVideos.push(r.id);
|
|
|
+ } else {
|
|
|
+ delFiles.push(r.id);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (delFiles.length > 0) {
|
|
|
+ const params = { 'keys': delFiles };
|
|
|
+ util.apiPost(urls.file_delete, params).then((rs) => {
|
|
|
+ console.log('删除文件 ... ' + JSON.stringify(params));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (delVideos.length > 0) {
|
|
|
+ const params = { 'ids[]': delVideos }
|
|
|
+ util.apiPost(urls.video_delete, params).then((rs) => {
|
|
|
+ console.log('删除视频 ... ' + JSON.stringify(params));
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ },
|
|
|
+ reloadVideos: function (v) {
|
|
|
+ let videos = this.data.videoList
|
|
|
+ videos.map(o => {
|
|
|
+ if (o.url == v.url) {
|
|
|
+ o = v;
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.setData({ videoList: videos })
|
|
|
+ },
|
|
|
+ doInput: function (e) {
|
|
|
+ this.setData({ content: e.detail.value })
|
|
|
}
|
|
|
})
|