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,28 +189,44 @@ Page({ ...@@ -178,28 +189,44 @@ 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;
const fileType = path.substr(path.lastIndexOf('.') + 1);
cOssAccess({
school_id: this.data.sid,
ext: fileType
}).then((acc) => {
if (acc.code == 200) {
access = acc.data;
return wxUploadFile({
url: access.host, url: access.host,
formData: { formData: {
key: filename, key: access.path,
policy: access.policy, policy: access.policy,
OSSAccessKeyId: access.accessid, OSSAccessKeyId: access.accessid,
signature: access.signature, signature: access.signature,
...@@ -208,17 +235,19 @@ Page({ ...@@ -208,17 +235,19 @@ Page({
}, },
filePath: imageBox[this.data.currentIndex].src, filePath: imageBox[this.data.currentIndex].src,
name: 'file', 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,22 +466,30 @@ Page({ ...@@ -426,22 +466,30 @@ 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;
const fileType = path.substr(path.lastIndexOf('.') + 1).toLowerCase();
return cMediaOssAccess({
school_id: this.data.sid,
type: 1
})
}).then((res) => {
if (res.code == 200) {
access = res.data;
imageBox.splice(videoInsertIndex, 0, { imageBox.splice(videoInsertIndex, 0, {
src: tempFilePath, src: access.path,
status: 'resolving', status: 'resolving',
type: 'video', type: 'video',
size: size size: size,
mode: 'm3u8'
}) })
that.setData({ that.setData({
imageBox imageBox
}) })
filename = `${access.dir}${getRandomFilename(tempFilePath)}`; that.data.uploadVideoTask[`${access.path}`] = wx.uploadFile({
that.uploadVideoTask = wx.uploadFile({
url: access.host, url: access.host,
formData: { formData: {
key: filename, key: access.path,
policy: access.policy, policy: access.policy,
OSSAccessKeyId: access.accessid, OSSAccessKeyId: access.accessid,
signature: access.signature, signature: access.signature,
...@@ -454,30 +502,34 @@ Page({ ...@@ -454,30 +502,34 @@ Page({
const {data} = res; const {data} = res;
if (data == '{"status":"ok"}') { if (data == '{"status":"ok"}') {
let imageBox = that.data.imageBox; let imageBox = that.data.imageBox;
imageBox[videoInsertIndex].src = filename; imageBox[videoInsertIndex].src = access.path;
imageBox[videoInsertIndex].status = 'fullfilled'; imageBox[videoInsertIndex].status = 'fullfilled';
imageBox[videoInsertIndex].videoprogress = 100; imageBox[videoInsertIndex].videoprogress = 100;
that.setData({ that.setData({
imageBox: imageBox imageBox: imageBox
}, () => {
if (that.data.activtySchoolInfo.plan == 'planb' && that.data.activtySchoolInfo.tid == that.data.tid) {
that.judgeContentQualified();
}
}) })
} else { } else {
that.setData({ that.setData({
videostatus: 'fail' [`imageBox[${videoInsertIndex}].status`]: 'fail'
}) })
} }
}, },
fail () { fail (e) {
that.setData({
videostatus: 'fail'
})
} }
}) })
that.uploadVideoTask.onProgressUpdate((res) => { if (that.data.uploadVideoTask[`${access.path}`].onProgressUpdate) {
that.data.uploadVideoTask[`${access.path}`].onProgressUpdate((res) => {
imageBox[videoInsertIndex].videoprogress = res.progress > 95 ? 95 : res.progress; imageBox[videoInsertIndex].videoprogress = res.progress > 95 ? 95 : res.progress;
that.setData({ that.setData({
imageBox: imageBox 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