123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620 |
- import VODUpload from '../../utils/aliyun-upload-sdk-1.0.1.min'
- const app = getApp()
- const util = require("../../utils/util")
- const urlDef = require("../../utils/urls")
- const recordManager = wx.getRecorderManager()
- const audioContext = wx.createInnerAudioContext()
- var uploader = null
- const urls = urlDef.urls;
- Page({
-
- data: {
- homeworkId: null,
- talkFlag: false,
- closeName: '开始录音',
- videoList: [],
- videoFlag: 0,
- imgList: [],
- audioList: [],
- audioPause: false,
- content: '',
- delItems: [],
- contents:null,
- },
- renderTime:function(date) {
- var dateee = new Date(date).toJSON();
- return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
- },
- getRecord: function () {
- const that = this
- if(that.data.audioList.length>=6){
- wx.showToast({
- title: '最多上传6段录音',
- icon: 'none'
- })
- return
- }
- if (that.data.talkFlag) {
- recordManager.stop()
- recordManager.onStop((res) => {
- console.log("监听录音停止事件", res)
- if (res.duration < 1000) {
- wx.showToast({
- title: '录音时间太短',
- icon: 'none'
- })
- return;
- } else {
- console.log(res)
- var tempFilePath = res.tempFilePath;
- console.log("文件临时路径", tempFilePath)
- wx.uploadFile({
- filePath: tempFilePath,
- name: 'name',
- url: urls.file_upload,
- header: util.getHeaders(),
- success(res) {
- wx.showToast({
- title: '上传成功',
- })
- const rs = JSON.parse(JSON.parse(JSON.stringify(res.data)))
- const list = [{ url: rs.data[0].url }]
- that.setData({
- audioList: that.data.audioList.concat(list)
- })
- },
- fail(res) {
- wx.showToast({
- title: '上传失败',
- icon: 'none'
- })
- },
- complete(res) {
- wx.hideLoading({
- success: (res) => { },
- })
- }
- })
- }
- });
- that.setData({
- talkFlag: false,
- closeName: '开始录音'
- })
- } else {
- wx.getSetting({
- success(res) {
- if (!res.authSetting['scope.record']) {
- wx.authorize({
- scope: 'scope.record',
- success() {
-
- const options = {}
- recordManager.start(options)
- },
- fail() {
- wx.openSetting({
- withSubscriptions: true,
- })
- }
- })
- } else {
- that.setData({
- talkFlag: true,
- closeName: '正在录音,再次点击结束录音'
- })
- const options = {}
- recordManager.start(options)
- }
- }
- })
- }
- },
- showAudio: function (e) {
- const index = e.currentTarget.dataset.index
- if (this.data.curAudioIndex != index) {
- this.setData({
- curAudioIndex: index,
- })
- audioContext.src = this.data.audioList[index].url
- audioContext.play()
- audioContext.onEnded((res) => {
- this.setData({
- curAudioIndex: '-1',
- })
- })
- } else {
- if (this.data.audioPause) {
- audioContext.play()
- this.setData({
- audioPause: false
- })
- } else {
- audioContext.pause()
- this.setData({
- audioPause: true
- })
- }
- }
- },
- delAudio: function (e) {
- const index = e.currentTarget.dataset.index
-
-
-
-
- let records = this.data.audioList;
- let record = records[index];
- record.delete = 1
- this.setData({
- audioList: records
- })
- },
- uploadTap: function () {
- const that = this
- if(that.data.imgList.length>=6){
- wx.showToast({
- title: '最多上传6张图片',
- icon: 'none'
- })
- return
- }
- wx.chooseImage({
- count: 6,
- sourceType: ['album', 'camera'],
- success(res) {
- wx.showLoading({
- title: '上传中...',
- })
- for (var i in res.tempFilePaths) {
- wx.uploadFile({
- filePath: res.tempFilePaths[i],
- name: 'name',
- url: urls.file_upload,
- header: util.getHeaders(),
- success(res) {
- wx.showToast({
- title: '上传成功',
- })
- const rs = JSON.parse(JSON.parse(JSON.stringify(res.data)))
- const list = [{ url: rs.data[0].url }]
- that.setData({
- imgList: that.data.imgList.concat(list)
- })
- },
- fail(res) {
- wx.showToast({
- title: '上传失败',
- icon: none
- })
- },
- complete(res) {
- wx.hideLoading({
- success: (res) => { },
- })
- }
- })
- }
- }
- })
- },
- 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: images[index].url,
- urls: imgs,
- })
- },
- delImg: function (e) {
- const index = e.currentTarget.dataset.index
-
- let images = this.data.imgList;
- let image = images[index]
- image.delete = 1
- this.setData({
- imgList: images
- })
- },
- upLoadVideo: function () {
- const that = this
- if(that.data.videoList.length>=6){
- wx.showToast({
- title: '最多上传6部视频',
- icon: 'none'
- })
- return
- }
- wx.chooseVideo({
- camera: ['album'],
- success(res) {
- var file = {
- url: res.tempFilePath,
- coverUrl: res.thumbTempFilePath
- };
- var userData = '{"Vod":{}}';
- const urls = urlDef.urls;
- let createUrl = urls.video_create_upload + '?title=' + res.tempFilePath + '&fileName=' + res.tempFilePath;
- console.log('createUploadVideo ... ');
- util.apiPost(createUrl).then((rs) => {
- let d = JSON.parse(rs.data);
-
- that.setData({
- uploadAuth: d.UploadAuth,
- uploadAddress: d.UploadAddress,
- videoId: d.VideoId,
- })
- uploader.addFile(file, null, null, null, userData)
- uploader.startUpload();
-
- }, e => {
- console.log('createUploadVideo error ' + JSON.stringify(e));
- });
- }
- })
- },
- showVideo: function (e) {
- const index = e.currentTarget.dataset.index
- const curVideo = this.data.videoList[index].playUrl
- this.setData({
- curVideo
- })
- this.videoContext.requestFullScreen({
- direction: 90
- });
- },
-
- bindfullscreenchange: function () {
- if (this.data.videoFlag == 0) {
- this.setData({
- videoFlag: 1
- })
- } else {
- this.setData({
- videoFlag: 0,
- curVideo: ""
- })
- }
- },
- delVideo: function (e) {
- const index = e.currentTarget.dataset.index
-
-
-
-
- let videos = this.data.videoList;
- let video = videos[index]
- video.delete = 1
- this.setData({
- videoList: videos
- })
- },
-
- 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 = entity
- contents.receiveDate=this.renderTime(contents.receiveDate)
- this.setData({
- contents
- })
- } 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');
- const that = this
- const createUpLoad = new VODUpload({
-
- userId: "WaWQOn6gXod13WLEp8cr4ljUdvcbXJ",
-
- retryCount: 3,
-
- retryDuration: 2,
-
- 'onUploadstarted': function (uploadInfo) {
- wx.showLoading({
- title: '上传中...',
- mask: true
- })
-
-
- if (uploadInfo.videoId) {
-
- } else {
-
- }
-
-
- uploader.setUploadAuthAndAddress(uploadInfo, that.data.uploadAuth, that.data.uploadAddress, that.data.videoId);
- },
-
- 'onUploadSucceed': function (uploadInfo) {
- 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: '' };
-
- 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: '上传成功',
- })
- })
-
- },
-
- 'onUploadFailed': function (uploadInfo, code, message) {
-
- wx.showToast({
- title: '上传失败',
- })
- },
-
- 'onUploadProgress': function (uploadInfo, totalSize, loadedPercent) {
-
- },
-
- 'onUploadTokenExpired': function (uploadInfo) {
- wx.showToast({
- title: '上传超时',
- })
- console.log("onUploadTokenExpired");
-
-
- uploader.resumeUploadWithAuth(uploadAuth);
- },
-
- 'onUploadEnd': function (uploadInfo) {
- console.log("onUploadEnd: uploaded all the files");
- }
- });
- uploader = createUpLoad
- },
-
- onReady: function () {
- },
-
- onShow: function () {
- },
-
- onHide: function () {
- },
-
- onUnload: function () {
- audioContext.stop()
- },
-
- onPullDownRefresh: function () {
- },
-
- onReachBottom: function () {
- },
-
- 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 })
- }
- })
|