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

feat: 修改表单结构

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