Commit 087f6d56 authored by wangxuelai's avatar wangxuelai

'新的富文本编辑组件把callback暴露出来'

parent 58f4b506
...@@ -22,6 +22,7 @@ var app = getApp(); ...@@ -22,6 +22,7 @@ var app = getApp();
Page({ Page({
// mixins: [deepCopy(require('../../../mixins/myMins/audioCallback'))], // mixins: [deepCopy(require('../../../mixins/myMins/audioCallback'))],
data: { data: {
editType: 1, // 1作业打卡 2 日历打卡 3 闯关打卡
maxLength: 500, maxLength: 500,
maxImgCount: 9, maxImgCount: 9,
maxVideoCount: 9, maxVideoCount: 9,
...@@ -32,12 +33,45 @@ Page({ ...@@ -32,12 +33,45 @@ Page({
id: 0, id: 0,
tid: 0, tid: 0,
sid: 0, sid: 0,
calendarparams: {
type: 0, // 0无限制 1录音 2视频 3照片
title: '',
content: [{
type: 'text',
value: '闯关打卡的描述'
}],
is_cheat: 0,
is_encrypt: 0,
force_status: 2,
force_num: 0,
push_status: 2,
text_require_status: 2,
text_require_num: 0,
image_require_status: 2,
image_require_num: 0,
video_require_status: 2,
video_require_num: 0,
audio_require_status: 2,
audio_require_num: 0,
supplement_status: 2,
supplement_num: 0,
startDate: formatDate(new Date().getTime()/1000).split(' ')[0],
startTime: formatDate(new Date().getTime()/1000).split(' ')[1],
endDate: formatDate((new Date().getTime()+86400*1000*7)/1000).split(' ')[0],
endTime: formatDate((new Date().getTime()+86400*1000*7)/1000).split(' ')[1],
clock_start_time: '00:00',
clock_end_time: '23:59',
push_time: '09:00',
join_rule_type: 1,
join_secret: '',
class_ids: '',
},
params: { params: {
type: 0, // 0无限制 1录音 2视频 3照片 type: 0, // 0无限制 1录音 2视频 3照片
title: '', title: '',
content: [{ content: [{
type: 'text', type: 'text',
value: '养成练字习惯将有助于培养耐性,同时还能陶冶情操、提升审美能力,今天起请同学们坚持!养成练字习惯将有助于培养耐性,同时还能陶冶情操、提升审美能力。今天起请同学们坚持!养成练字习惯将有助于培养耐性,同时还能陶冶情操、提升审美能力。' value: '作业打卡的描述'
}], }],
is_cheat: 0, is_cheat: 0,
// is_encrypt: 0, // is_encrypt: 0,
...@@ -113,14 +147,6 @@ Page({ ...@@ -113,14 +147,6 @@ Page({
title: '', title: '',
id: 0, id: 0,
}, },
mockTitleList: [
{type: 1,label:"课后作业",title: '请各位同学提交本次课后布置的作业'},
{type: 2,label:"周末作业",title: '请各位同学提交本周周末布置的作业'},
{type: 3,label:"演讲一段话",title: '请各位同学演讲本次作业要讲的话'},
{type: 4,label:"练习动作",title: '请各位同学练习一下动作'},
{type: 5,label:"今日练字作业",title: '请各位同学认真查看今日要练习的作业,并跟着练习'}
],
currentMockType: 0,
successDailogShow: false, successDailogShow: false,
actPalyaudioValue: '' actPalyaudioValue: ''
}, },
...@@ -133,13 +159,15 @@ Page({ ...@@ -133,13 +159,15 @@ Page({
sid, sid,
my, my,
classes, classes,
editType,
} = options; } = options;
this.setData({ this.setData({
id, id,
tid, tid,
clone: clone || '', clone: clone || '',
sid: sid || '', sid: sid || '',
my: my || 0 my: my || 0,
editType,
}); });
if (tid == 0) { if (tid == 0) {
const currentclasses = classes ? JSON.parse(decodeURIComponent(classes)) : []; const currentclasses = classes ? JSON.parse(decodeURIComponent(classes)) : [];
...@@ -413,11 +441,18 @@ Page({ ...@@ -413,11 +441,18 @@ Page({
const { const {
value value
} = e.detail; } = e.detail;
let currentMockItem = this.data.mockTitleList.filter(item=>item.title == value)[0]; const { editType } = this.data;
this.setData({ if (editType == 1) {
'params.title': value.length > 36 ? value.substr(0, 36) : value, this.setData({
currentMockType: currentMockItem? currentMockItem.type: 0 'params.title': value.length > 36 ? value.substr(0, 36) : value,
}) })
} else if (editType == 2) {
this.setData({
'calendarparams.title': value.length > 36 ? value.substr(0, 36) : value,
})
} else if (editType == 3) {
}
}, },
selectType() { selectType() {
const that = this; const that = this;
...@@ -562,6 +597,80 @@ Page({ ...@@ -562,6 +597,80 @@ Page({
this.data.submiting = false this.data.submiting = false
}) })
}, },
// 跟文本编辑器有关的操作
addeditoritem (e) {
const { editType, calendarparams, params } = this.data;
if (editType == 1) {
const content = params.content;
content.push(e.detail);
this.setData({
'params.content': content,
})
} else if (editType == 2) {
const content = calendarparams.content;
content.push(e.detail);
this.setData({
'calendarparams.content': content,
})
} else if (editType == 3) {
}
},
textChange(e) {
const { value, index } = e.detail;
const { editType, calendarparams, params } = this.data;
if (editType == 1) {
this.setData({
[`params.content[${index}].value`]: value,
})
} else if (editType == 2) {
this.setData({
[`calendarparams.content[${index}].value`]: value,
})
} else if (editType == 3) {
}
},
delitem(e) {
const { editType, calendarparams, params } = this.data;
if (editType == 1) {
const content = params.content;
content.splice(e.detail, 1);
this.setData({
'params.content': content,
})
} else if (editType == 2) {
const content = calendarparams.content;
content.splice(e.detail, 1);
this.setData({
'calendarparams.content': content,
})
} else if (editType == 3) {
}
},
exchange(e) {
// const content = this.data.content;
// content.splice(index-1, 2, content[index], content[index - 1]);
const index = e.detail;
const { editType, calendarparams, params } = this.data;
if (editType == 1) {
const content = params.content;
content.splice(index-1, 2, content[index], content[index - 1]);
this.setData({
'params.content': content,
})
} else if (editType == 2) {
const content = calendarparams.content;
content.splice(index-1, 2, content[index], content[index - 1]);
this.setData({
'calendarparams.content': content,
})
} else if (editType == 3) {
}
},
// 跟文本编辑器有关的操作
// 跟录音相关的操作 // 跟录音相关的操作
addVoice(e) { addVoice(e) {
const { const {
...@@ -577,10 +686,30 @@ Page({ ...@@ -577,10 +686,30 @@ Page({
src, src,
duration duration
} = e.detail; } = e.detail;
this.selectComponent('#sjd-media-editor').pushVoice({ const { editType, calendarparams, params } = this.data;
src, if (editType == 1) {
duration const content = params.content;
}); // 页面向组件传递参数 content.push({
type: 'voice',
value: src,
duration
});
this.setData({
'params.content': content,
})
} else if (editType == 2) {
const content = calendarparams.content;
content.push({
type: 'voice',
value: src,
duration
});
this.setData({
'calendarparams.content': content,
})
} else if (editType == 3) {
}
}, },
// 跟录音相关的操作 // 跟录音相关的操作
// 跟录音相关的操作 // 跟录音相关的操作
...@@ -1159,5 +1288,14 @@ Page({ ...@@ -1159,5 +1288,14 @@ Page({
wx.navigateTo({ wx.navigateTo({
url: `/business/pages/themead/list?sid=${this.data.sid}&id=${id}`, url: `/business/pages/themead/list?sid=${this.data.sid}&id=${id}`,
}) })
},
editTypeChange(e) {
const { type } = e.currentTarget.dataset;
if (type == this.data.editType) {
return;
}
this.setData({
editType: type,
});
} }
}) })
\ No newline at end of file
This diff is collapsed.
...@@ -91,7 +91,6 @@ Component({ ...@@ -91,7 +91,6 @@ Component({
iosPhoneWarn: false, iosPhoneWarn: false,
}, },
created () { created () {
console.log(this.data.content, 'this.data.content')
}, },
attached () { attached () {
}, },
...@@ -109,8 +108,9 @@ Component({ ...@@ -109,8 +108,9 @@ Component({
textareaChange (e) { textareaChange (e) {
const {currentTarget, detail} = e; const {currentTarget, detail} = e;
const index = currentTarget.dataset.index; const index = currentTarget.dataset.index;
this.setData({ this.triggerEvent('textchange', {
[`content[${index}].value`]: detail.value value: detail.value,
index,
}) })
}, },
addText () { // 添加文本的操作 addText () { // 添加文本的操作
...@@ -123,13 +123,10 @@ Component({ ...@@ -123,13 +123,10 @@ Component({
value: '', value: '',
style: '' style: ''
}); });
this.setData({ this.triggerEvent('additem', {
content, type: 'text',
}, () => { value: '',
// 进行textBoxLength计算 style: ''
this.setData({
textBoxLength: this.countCaculate('text', this.data.content)
})
}) })
}, },
addImg (tempFiles) { // 添加图片的操作 addImg (tempFiles) { // 添加图片的操作
...@@ -203,19 +200,12 @@ Component({ ...@@ -203,19 +200,12 @@ Component({
}) })
let uploadingIndex = this.data.uploadingIndex + 1; let uploadingIndex = this.data.uploadingIndex + 1;
let content = JSON.parse(JSON.stringify(this.data.content)); let content = JSON.parse(JSON.stringify(this.data.content));
content.push({ this.triggerEvent('additem', {
type: 'img', type: 'img',
value: filename value: filename
}) });
console.log(content,'content')
this.setData({ this.setData({
content,
uploadingIndex, uploadingIndex,
}, () => {
this.setData({
imgBoxLength: this.countCaculate('img', this.data.content),
})
}) })
this.singleUploadFile(access); this.singleUploadFile(access);
} else { // 失败的处理 } else { // 失败的处理
...@@ -253,13 +243,6 @@ Component({ ...@@ -253,13 +243,6 @@ Component({
} }
let mySystem = wx.getSystemInfoSync(); let mySystem = wx.getSystemInfoSync();
let needIosWarn = LocalStorage.getItem('needIosWarn'); let needIosWarn = LocalStorage.getItem('needIosWarn');
// if (mySystem.system && mySystem.system.toLowerCase().indexOf('ios') != -1 && !needIosWarn) {
// this.setData({
// iosPhoneWarn: true
// })
// } else {
// this.addVideoMethod();
// }
this.addVideoMethod(); this.addVideoMethod();
}, },
closeIosWarnDia () { closeIosWarnDia () {
...@@ -339,20 +322,12 @@ Component({ ...@@ -339,20 +322,12 @@ Component({
wx.showToast({ wx.showToast({
title: '上传成功' title: '上传成功'
}) })
let content = JSON.parse(JSON.stringify(this.data.content)); this.triggerEvent('additem', {
content.push({
type: 'video', type: 'video',
value: filename, value: filename,
poster: filename, poster: filename,
mode: 'm3u8' mode: 'm3u8'
}) });
this.setData({
content,
}, () => {
this.setData({
videoBoxLength: this.countCaculate('video', this.data.content)
})
})
} else { } else {
wx.hideLoading(); wx.hideLoading();
wx.showModal({ wx.showModal({
...@@ -378,58 +353,13 @@ Component({ ...@@ -378,58 +353,13 @@ Component({
const {currentTarget} = e; const {currentTarget} = e;
const index = currentTarget.dataset.index; const index = currentTarget.dataset.index;
const type = currentTarget.dataset.type; const type = currentTarget.dataset.type;
let content = JSON.parse(JSON.stringify(this.data.content)); this.triggerEvent('delitem', index);
content.splice(index, 1);
// 删除录音的操作 // 删除录音的操作
if (type == 'voice') { if (type == 'voice') {
this.triggerEvent('delvoice', { this.triggerEvent('delvoice', {
value: currentTarget.dataset.value value: currentTarget.dataset.value
}) })
} }
this.setData({
content
}, () => {
switch(type) {
case 'text':
this.setData({
textBoxLength: this.countCaculate('text', this.data.content)
})
break;
case 'img':
this.setData({
imgBoxLength: this.countCaculate('img', this.data.content)
})
break;
case 'voice':
this.setData({
voiceBoxLength: this.countCaculate('voice', this.data.content)
})
break;
case 'video':
this.setData({
videoBoxLength: this.countCaculate('video', this.data.content)
})
break;
default:
break;
}
})
},
pushVoice ({src, duration}) {
let content = JSON.parse(JSON.stringify(this.data.content));
content.push({
type: 'voice',
value: src,
duration
});
this.setData({
content,
}, () => {
// 进行textBoxLength计算
this.setData({
voiceBoxLength: this.countCaculate('voice', this.data.content)
})
})
}, },
// 播放音频的相关操作 只是作为一个触发器 所有的录音操作在视频中进行 // 播放音频的相关操作 只是作为一个触发器 所有的录音操作在视频中进行
playvoice (e) { playvoice (e) {
...@@ -480,10 +410,11 @@ Component({ ...@@ -480,10 +410,11 @@ Component({
exchangeIndex: index exchangeIndex: index
}) })
setTimeout(() => { setTimeout(() => {
const content = this.data.content; // const content = this.data.content;
content.splice(index-1, 2, content[index], content[index - 1]); // content.splice(index-1, 2, content[index], content[index - 1]);
this.triggerEvent('exchange', index)
this.setData({ this.setData({
content, // content,
exchangeIndex: -1 exchangeIndex: -1
}) })
}, 500) }, 500)
......
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