Commit 6b4e0b80 authored by 李维's avatar 李维

feat: 修改表单结构

parent ee8a8474
This diff is collapsed.
...@@ -16,8 +16,42 @@ new Vue({ ...@@ -16,8 +16,42 @@ new Vue({
el: '.edit-data', el: '.edit-data',
created() { created() {
window.courseware.getData((data) => { window.courseware.getData((data) => {
this.data = data || []; this.data = data || {
form_id: '',
form_name: '',
item_number: '',
item_type: '',
ims_id: '',
word_count: '',
passage_text: {
text: '',
audio: {
url: '',
name: '',
size: '',
duration: ''
},
image: {
url: '',
},
},
stem: {
text: '',
audio: {
url: '',
name: '',
size: '',
duration: ''
},
image: {
url: '',
},
},
options: []
};
}, key); }, key);
console.log("========== data ==========")
console.log(this.data)
window['air'].getUploadCallback = (url, data) => { window['air'].getUploadCallback = (url, data) => {
this.uploadUrl = url; this.uploadUrl = url;
this.uploadData = data; this.uploadData = data;
...@@ -31,55 +65,18 @@ new Vue({ ...@@ -31,55 +65,18 @@ new Vue({
} }
}, },
methods: { methods: {
handleAudioSuccess(res, file, index) { handleAudioSuccess(res, file, obj) {
// 假设上传接口返回的音频URL在 res.url 中 // 假设上传接口返回的音频URL在 res.url 中
this.data[index].audio_url = res.url; obj.url = res.url;
this.data[index].audio_name = file.name; obj.name = file.name;
// 计算文件大小 // 计算文件大小
const size = file.size; obj.size = file.size;
if (size < 1024) {
this.data[index].audio_size = size + 'B';
} else if (size < 1024 * 1024) {
this.data[index].audio_size = (size / 1024).toFixed(2) + 'KB';
} else {
this.data[index].audio_size = (size / (1024 * 1024)).toFixed(2) + 'MB';
}
// 获取音频时长 // 获取音频时长
const audio = new Audio(res.url); const audio = new Audio(res.url);
audio.addEventListener('loadedmetadata', () => { audio.addEventListener('loadedmetadata', () => {
const duration = audio.duration; obj.duration = audio.duration;
const minutes = Math.floor(duration / 60); this.save();
const seconds = Math.floor(duration % 60);
this.data[index].audio_duration = `${minutes}:${seconds.toString().padStart(2, '0')}`;
});
this.save();
},
handleOptionAudioSuccess(res, file, index, optionIndex) {
// 假设上传接口返回的音频URL在 res.url 中
this.data[index].options[optionIndex].audio_url = res.url;
this.data[index].options[optionIndex].audio_name = file.name;
// 计算文件大小
const size = file.size;
if (size < 1024) {
this.data[index].options[optionIndex].audio_size = size + 'B';
} else if (size < 1024 * 1024) {
this.data[index].options[optionIndex].audio_size = (size / 1024).toFixed(2) + 'KB';
} else {
this.data[index].options[optionIndex].audio_size = (size / (1024 * 1024)).toFixed(2) + 'MB';
}
// 获取音频时长
const audio = new Audio(res.url);
audio.addEventListener('loadedmetadata', () => {
const duration = audio.duration;
const minutes = Math.floor(duration / 60);
const seconds = Math.floor(duration % 60);
this.data[index].options[optionIndex].audio_duration = `${minutes}:${seconds.toString().padStart(2, '0')}`;
}); });
this.save(); this.save();
...@@ -87,10 +84,10 @@ new Vue({ ...@@ -87,10 +84,10 @@ new Vue({
// 播放/暂停音频 // 播放/暂停音频
togglePlay(index) { togglePlay(index) {
const audio = this.$refs['audio' + index][0]; const audio = this.$refs['audio'][0];
if (this.data[index].isPlaying) { if (this.data.isPlaying) {
audio.pause(); audio.pause();
this.data[index].isPlaying = false; this.data.isPlaying = false;
} else { } else {
// 先停止其他正在播放的音频 // 先停止其他正在播放的音频
this.data.forEach((item, i) => { this.data.forEach((item, i) => {
...@@ -100,7 +97,7 @@ new Vue({ ...@@ -100,7 +97,7 @@ new Vue({
} }
}); });
audio.play(); audio.play();
this.data[index].isPlaying = true; this.data.isPlaying = true;
} }
}, },
...@@ -128,7 +125,7 @@ new Vue({ ...@@ -128,7 +125,7 @@ new Vue({
}, },
audioOptionEnded(index, optionIndex) { audioOptionEnded(index, optionIndex) {
this.data[index].options[optionIndex].isPlaying = false; this.data.options[optionIndex].isPlaying = false;
}, },
beforeAudioUpload(file) { beforeAudioUpload(file) {
...@@ -152,46 +149,34 @@ new Vue({ ...@@ -152,46 +149,34 @@ new Vue({
this.$message.success("实时保存成功"); this.$message.success("实时保存成功");
}, key); }, key);
}, },
deleteConf(index) { addOption() {
this.data.splice(index, 1); this.data.options.push({
this.save();
},
addConfig() {
this.data.push({
question: '',
audio_url: '',
image_url: '',
audio_name: '',
audio_size: '',
audio_duration: '',
isPlaying: false,
options: [],
});
this.save();
},
addOption(index) {
this.data[index].options.push({
image_url: '',
audio_url: '',
audio_name: '',
text: '', text: '',
audio: {
url: '',
name: '',
size: '',
duration: ''
},
image: {
url: '',
},
is_correct: false, is_correct: false,
}); });
this.save(); this.save();
}, },
deleteOption(index, optionIndex) { deleteOption(optionIndex) {
this.data[index].options.splice(optionIndex, 1); this.data.options.splice(optionIndex, 1);
this.save(); this.save();
}, },
// 图片上传成功的回调 // 图片上传成功的回调
handleImageSuccess(res, file, index) { handleImageSuccess(res, file, obj) {
// 假设上传接口返回的图片URL在 res.url 中 // 假设上传接口返回的图片URL在 res.url 中
console.log(res, file, index); obj.url = res.url;
this.data[index].image_url = res.url;
this.save(); this.save();
}, },
handleOptionImageSuccess(res, file, index, optionIndex) { handleOptionImageSuccess(res, file, obj) {
this.data[index].options[optionIndex].image_url = res.url; obj.url = res.url;
this.save(); this.save();
}, },
...@@ -227,13 +212,13 @@ new Vue({ ...@@ -227,13 +212,13 @@ new Vue({
confirmButtonText: '关闭' confirmButtonText: '关闭'
}); });
}, },
removeImage(index) { removeImage(obj) {
this.$confirm('确定要删除这张图片吗?', '提示', { this.$confirm('确定要删除这张图片吗?', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(() => { }).then(() => {
this.data[index].image_url = ''; obj.url = '';
this.save(); this.save();
this.$message({ this.$message({
type: 'success', type: 'success',
...@@ -241,8 +226,8 @@ new Vue({ ...@@ -241,8 +226,8 @@ new Vue({
}); });
}).catch(() => { }); }).catch(() => { });
}, },
removeOptionImage(index, optionIndex) { removeOptionImage(obj) {
this.data[index].options[optionIndex].image_url = ''; obj.url = '';
this.save(); this.save();
} }
}, },
......
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