Commit 96220e6b authored by liujiangnan's avatar liujiangnan

feat

parent 9edc2e35
This diff is collapsed.
```
CoursewarePageModel(
id: '1',
type: CoursewareTemplateType.imagesActions,
content: {}
)
```
......@@ -283,6 +283,9 @@
<span>AI 编排脚本区</span>
<el-button type="text" size="mini" @click="toggleRightPanel">收起</el-button>
</div>
<div class="panel-actions">
<el-button type="primary" size="small" @click="handleAiGenerateDownload">AI生成</el-button>
</div>
<el-input
type="textarea"
:rows="16"
......
......@@ -596,10 +596,7 @@ Atmosphere and Colors: [Fill in content]
}
}
},
saveData: function () {
if (!window.courseware || !window.courseware.setData) {
return;
}
buildCoursewareData: function () {
var action = [];
if (this.audioPreviewUrl || (this.aiTagData && this.aiTagData.length)) {
action.push({
......@@ -626,15 +623,66 @@ Atmosphere and Colors: [Fill in content]
});
});
}
var data = {
return {
image: this.imagePreviewUrl,
action: action,
aiImageContent: this.aiImageContent,
ai_script: this.scriptText
};
// console.log('saveData payload', JSON.stringify(data, null, 2));
},
saveData: function () {
if (!window.courseware || !window.courseware.setData) {
return;
}
var data = this.buildCoursewareData();
window.courseware.setData(data, function () {}, key);
},
downloadTextFile: function (filename, text) {
var blob = new Blob([text], { type: 'text/markdown;charset=utf-8' });
var url = URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
},
handleAiGenerateDownload: async function () {
var _this = this;
try {
var tplRes = await fetch('./ImagesActionsTemplate.md');
if (!tplRes.ok) {
throw new Error('无法读取 ImagesActionsTemplate.md');
}
var tplText = await tplRes.text();
_this.downloadTextFile('ImagesActionsTemplate.md', tplText);
var dataRes = await fetch('./ImagesActionsTemplateData.md');
if (!dataRes.ok) {
throw new Error('无法读取 ImagesActionsTemplateData.md');
}
var dataTemplate = await dataRes.text();
var jsonPretty = JSON.stringify(this.buildCoursewareData(), null, 2);
var inner = jsonPretty.split('\n').map(function (line) {
return ' ' + line;
}).join('\n');
// 支持 content: {} 或 content: { \n } 等空对象写法
var filled = dataTemplate.replace(
/(\s*content:\s*)\{\s*\}/,
'$1{\n' + inner + '\n }'
);
if (filled === dataTemplate) {
throw new Error('ImagesActionsTemplateData.md 中未找到可替换的空 content(需为 content: {})');
}
setTimeout(function () {
_this.downloadTextFile('ImagesActionsTemplateData.md', filled);
}, 200);
this.$message.success('已开始下载两个 MD 文件');
} catch (err) {
this.$message.error((err && err.message) ? err.message : '下载失败');
}
},
validateJson: function () {
if (!this.scriptText) {
this.jsonError = '';
......
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