Commit 8ab90d40 authored by wangxuelai's avatar wangxuelai

's'

parent 8636be9c
...@@ -225,7 +225,7 @@ Component({ ...@@ -225,7 +225,7 @@ Component({
const customerId = LocalStorage.getItem('visitor') && LocalStorage.getItem('visitor').studentId; const customerId = LocalStorage.getItem('visitor') && LocalStorage.getItem('visitor').studentId;
const that = this; const that = this;
wx.navigateTo({ wx.navigateTo({
url: `/src/pages/commenteditor/index?id=${that.data.cid}&ptype=2&&tid=${that.data.tid}&cid=${that.data.clock.id}&eid=${dataset.eid}&roottype=${dataset.roottype}`, url: `/src/pages/commenteditor/index?id=${that.data.cid}&ptype=2&tid=${that.data.tid}&cid=${that.data.clock.id}&eid=${dataset.eid}&roottype=${dataset.roottype}&sid=${this.data.clock.school_id}`,
}) })
}, },
// 关于老师的点评回复操作 // 关于老师的点评回复操作
......
...@@ -35,7 +35,8 @@ Page({ ...@@ -35,7 +35,8 @@ Page({
imageRoot: app.globalData.imageRoot, imageRoot: app.globalData.imageRoot,
imageVersion: app.globalData.imageVersion, imageVersion: app.globalData.imageVersion,
tid: 0, // 主题ID tid: 0, // 主题ID
cid: 0, // 打卡记录ID cid: 0, // 打卡记录ID\
sid: 0,
maxLength: 200, maxLength: 200,
maxImgCount: 9, maxImgCount: 9,
maxVideoCount: 9, maxVideoCount: 9,
...@@ -87,13 +88,14 @@ Page({ ...@@ -87,13 +88,14 @@ Page({
}, },
}, },
onLoad: function(options) { // Do some initialize when page load. onLoad: function(options) { // Do some initialize when page load.
const {cid, tid,ptype, eid, roottype} = options; const {sid, cid, tid,ptype, eid, roottype} = options;
this.setData({ this.setData({
cid, cid,
tid, tid,
p_type: ptype, p_type: ptype,
pid: eid, pid: eid,
roottype roottype,
sid
}) })
}, },
onShow: function() { // Do something when page show. onShow: function() { // Do something when page show.
...@@ -123,9 +125,13 @@ Page({ ...@@ -123,9 +125,13 @@ Page({
}) })
}, },
addImg () { // 添加图片的操作 addImg (e, wxFile) { // 添加图片的操作
let imgCount = this.data.imageBox.filter(ele => ele.type == 'image').length; let imgCount = this.data.imageBox.filter(ele => ele.type == 'image').length;
if (imgCount >= this.data.maxImgCount) { // 当等于10条了不能继续添加 if (imgCount >= this.data.maxImgCount) { // 当等于10条了不能继续添加
wx.showToast({
title: `上传图片不能超过${this.data.maxImgCount}张`,
icon: 'none'
})
return return
} else { } else {
if (!this.data.imageUploaded) { if (!this.data.imageUploaded) {
...@@ -146,12 +152,17 @@ Page({ ...@@ -146,12 +152,17 @@ Page({
this.setData({ this.setData({
imageUploaded: false imageUploaded: false
}) })
cOssAccess().then((acc) => { let myPromise = null;
access = acc.data; if (wxFile) {
return wxChooseImage({ myPromise = new Promise((resolve) => {
resolve(wxFile);
})
} else {
myPromise = wxChooseImage({
count: this.data.maxImgCount - imgCount count: this.data.maxImgCount - imgCount
}) })
}).then((res) => { }
myPromise.then((res) => {
const {tempFiles} = res; const {tempFiles} = res;
let imageBox = this.data.imageBox; let imageBox = this.data.imageBox;
this.setData({ this.setData({
...@@ -178,47 +189,65 @@ Page({ ...@@ -178,47 +189,65 @@ Page({
this.setData({ this.setData({
imageBox: res.imageBox, imageBox: res.imageBox,
}) })
this.singleUploadFile(access) this.singleUploadFile()
}).catch((e) => { }).catch((e) => {
wx.hideLoading() wx.hideLoading()
}) })
}, },
singleUploadFile(access) { singleUploadFile() {
wx.showLoading({
title: '图片上传中...',
mask: true
})
let access = {};
let imageBox = this.data.imageBox; let imageBox = this.data.imageBox;
if (this.data.currentIndex == (imageBox.length)) { if (this.data.currentIndex == (imageBox.length)) {
wx.hideLoading();
this.setData({ this.setData({
imageUploaded: true imageUploaded: true
}) })
if (this.data.activtySchoolInfo.plan == 'planb' && this.data.activtySchoolInfo.tid == this.data.tid) {
this.judgeContentQualified();
}
return; return;
} }
let filename = `${access.dir}${getRandomFilename(imageBox[this.data.currentIndex].src)}`;
imageBox[this.data.currentIndex].status = 'resolving'; imageBox[this.data.currentIndex].status = 'resolving';
this.setData({ this.setData({
imageBox imageBox
}) })
wxUploadFile({ const path = imageBox[this.data.currentIndex].src;
url: access.host, const fileType = path.substr(path.lastIndexOf('.') + 1);
formData: { cOssAccess({
key: filename, school_id: this.data.sid,
policy: access.policy, ext: fileType
OSSAccessKeyId: access.accessid, }).then((acc) => {
signature: access.signature, if (acc.code == 200) {
callback: access.callback, access = acc.data;
success_action_status: '200' return wxUploadFile({
}, url: access.host,
filePath: imageBox[this.data.currentIndex].src, formData: {
name: 'file', key: access.path,
policy: access.policy,
OSSAccessKeyId: access.accessid,
signature: access.signature,
callback: access.callback,
success_action_status: '200'
},
filePath: imageBox[this.data.currentIndex].src,
name: 'file',
})
}
}).then((res) => { }).then((res) => {
let data = JSON.parse(res.data); let data = JSON.parse(res.data);
if (data.status == 'ok') { if (data.status == 'ok') {
imageBox[this.data.currentIndex].status = 'fullfilled'; imageBox[this.data.currentIndex].status = 'fullfilled';
imageBox[this.data.currentIndex].src = filename; imageBox[this.data.currentIndex].src = access.path;
let currentIndex = this.data.currentIndex + 1; let currentIndex = this.data.currentIndex + 1;
this.setData({ this.setData({
imageBox, imageBox,
currentIndex currentIndex
}) })
this.singleUploadFile(access); this.singleUploadFile();
} else { } else {
imageBox[this.data.currentIndex].status = 'fail'; imageBox[this.data.currentIndex].status = 'fail';
let currentIndex = this.data.currentIndex + 1; let currentIndex = this.data.currentIndex + 1;
...@@ -226,16 +255,17 @@ Page({ ...@@ -226,16 +255,17 @@ Page({
imageBox, imageBox,
currentIndex currentIndex
}) })
this.singleUploadFile(access); this.singleUploadFile();
} }
}).catch(() => { }).catch((e) => {
console.log('ddddddddddddddddddddd失败')
imageBox[this.data.currentIndex].status = 'fail'; imageBox[this.data.currentIndex].status = 'fail';
let currentIndex = this.data.currentIndex + 1; let currentIndex = this.data.currentIndex + 1;
this.setData({ this.setData({
imageBox, imageBox,
currentIndex currentIndex
}) })
this.singleUploadFile(access); this.singleUploadFile();
}) })
}, },
delimg (e) { delimg (e) {
...@@ -396,18 +426,28 @@ Page({ ...@@ -396,18 +426,28 @@ Page({
}) })
this.addVideoMethod(); this.addVideoMethod();
}, },
addVideoMethod () { // 添加视频的操作 addVideoMethod (e, wxFile) { // 添加视频的操作
const that = this; const that = this;
let access = {}; let access = {};
let filename = ''; let filename = '';
cMediaOssAccess({ let videoInsertIndex = 0;
type: 1 let imageBox = this.data.imageBox;
}).then((res) => { let size = 0;
access = res.data; let duration = 0;
return wxChooseVideo({ let tempFilePath ='';
let myPromise = null;
if (wxFile) {
myPromise = new Promise((resolve) => {
resolve(wxFile);
}) })
}).then((res) => { } else {
const {tempFilePath, duration, size} = res; myPromise = wxChooseVideo({
})
}
myPromise.then((res) => {
size = res.size;
duration = res.duration;
tempFilePath = res.tempFilePath;
if (duration > constants.videoConf.duration) { if (duration > constants.videoConf.duration) {
wx.showModal({ wx.showModal({
title: '提示', title: '提示',
...@@ -426,58 +466,70 @@ Page({ ...@@ -426,58 +466,70 @@ Page({
}) })
return return
} }
let imageBox = this.data.imageBox videoInsertIndex = imageBox.filter(ele => ele.type == 'video').length;
let videoInsertIndex = imageBox.filter(ele => ele.type == 'video').length; const path = tempFilePath;
imageBox.splice(videoInsertIndex, 0, { const fileType = path.substr(path.lastIndexOf('.') + 1).toLowerCase();
src: tempFilePath, return cMediaOssAccess({
status: 'resolving', school_id: this.data.sid,
type: 'video', type: 1
size: size
}) })
that.setData({ }).then((res) => {
imageBox if (res.code == 200) {
}) access = res.data;
filename = `${access.dir}${getRandomFilename(tempFilePath)}`; imageBox.splice(videoInsertIndex, 0, {
that.uploadVideoTask = wx.uploadFile({ src: access.path,
url: access.host, status: 'resolving',
formData: { type: 'video',
key: filename, size: size,
policy: access.policy, mode: 'm3u8'
OSSAccessKeyId: access.accessid, })
signature: access.signature, that.setData({
callback: access.callback, imageBox
success_action_status: '200' })
}, that.data.uploadVideoTask[`${access.path}`] = wx.uploadFile({
filePath: tempFilePath, url: access.host,
name: 'file', formData: {
success (res) { key: access.path,
const {data} = res; policy: access.policy,
if (data == '{"status":"ok"}') { OSSAccessKeyId: access.accessid,
let imageBox = that.data.imageBox; signature: access.signature,
imageBox[videoInsertIndex].src = filename; callback: access.callback,
imageBox[videoInsertIndex].status = 'fullfilled'; success_action_status: '200'
imageBox[videoInsertIndex].videoprogress = 100; },
filePath: tempFilePath,
name: 'file',
success (res) {
const {data} = res;
if (data == '{"status":"ok"}') {
let imageBox = that.data.imageBox;
imageBox[videoInsertIndex].src = access.path;
imageBox[videoInsertIndex].status = 'fullfilled';
imageBox[videoInsertIndex].videoprogress = 100;
that.setData({
imageBox: imageBox
}, () => {
if (that.data.activtySchoolInfo.plan == 'planb' && that.data.activtySchoolInfo.tid == that.data.tid) {
that.judgeContentQualified();
}
})
} else {
that.setData({
[`imageBox[${videoInsertIndex}].status`]: 'fail'
})
}
},
fail (e) {
}
})
if (that.data.uploadVideoTask[`${access.path}`].onProgressUpdate) {
that.data.uploadVideoTask[`${access.path}`].onProgressUpdate((res) => {
imageBox[videoInsertIndex].videoprogress = res.progress > 95 ? 95 : res.progress;
that.setData({ that.setData({
imageBox: imageBox imageBox: imageBox
}) })
} else {
that.setData({
videostatus: 'fail'
})
}
},
fail () {
that.setData({
videostatus: 'fail'
}) })
} }
}) }
that.uploadVideoTask.onProgressUpdate((res) => {
imageBox[videoInsertIndex].videoprogress = res.progress > 95 ? 95 : res.progress;
that.setData({
imageBox: imageBox
})
})
}).catch((err) => { }).catch((err) => {
wx.hideLoading(); wx.hideLoading();
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment