feat: 优化代码生成及文案模板渲染

This commit is contained in:
王鹏
2026-07-29 16:17:49 +08:00
parent c631d058c1
commit e9d627df9c
15 changed files with 560 additions and 199 deletions

View File

@@ -43,20 +43,12 @@ export function delCode(codeId) {
})
}
export function transToArticle(codeId) {
return request({
url: '/office/code/transToArticle/' + codeId,
method: 'get'
})
}
export function transToArticle1(codeId, coverUrl) {
export function transToArticle1(codeId, templateId) {
return request({
url: '/office/code/transToArticle1/' + codeId,
method: 'get',
params: {
coverUrl: coverUrl
templateId: templateId
}
})
}

View File

@@ -115,14 +115,6 @@
<!-- <el-table-column label="视频文件" align="center" prop="videoFile" />-->
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-document-copy"
@click="transToArticle(scope.row)"
v-hasPermi="['office:code:edit']"
>转文章
</el-button>
<el-button
size="mini"
type="text"
@@ -262,6 +254,22 @@
<!-- 封面预览对话框 -->
<el-dialog :title="'封面预览'" :visible.sync="coverDialogVisible" width="500px" append-to-body>
<el-form label-width="80px">
<el-form-item label="文案模板">
<el-select
v-model="articleTemplateId"
placeholder="请选择文案模板"
style="width: 100%"
>
<el-option
v-for="tpl in copyTemplates"
:key="tpl.templateId"
:label="tpl.templateName"
:value="tpl.templateId"
/>
</el-select>
</el-form-item>
</el-form>
<div class="cover-preview" style="text-align: center;">
<img :src="coverImageUrl" style="max-width: 100%; height: auto;" v-if="coverImageUrl"/>
<div v-else>加载中...</div>
@@ -276,11 +284,10 @@
</template>
<script>
import {listCode, getCode, delCode, addCode, updateCode, transToArticle, transToArticle1} from "@/api/office/code";
import {listCode, getCode, delCode, addCode, updateCode, transToArticle1} from "@/api/office/code";
import {listEnabledTemplates} from "@/api/office/copyTemplate";
import {html2Text} from "../../../utils";
import {getToken} from "@/utils/auth";
import request from '@/utils/request';
export default {
name: "Code",
@@ -337,7 +344,9 @@
currentFileName: '',
currentRow: '',
// 文案模板列表(动态按钮)
copyTemplates: []
copyTemplates: [],
// 转文章时使用的文案模板
articleTemplateId: null
};
},
created() {
@@ -448,8 +457,21 @@
loadCopyTemplates() {
listEnabledTemplates().then(response => {
this.copyTemplates = response.data || [];
this.selectDefaultArticleTemplate();
});
},
selectDefaultArticleTemplate() {
if (!this.copyTemplates.length) {
this.articleTemplateId = null;
return;
}
const selectedExists = this.copyTemplates.some(tpl => tpl.templateId === this.articleTemplateId);
if (selectedExists) {
return;
}
const defaultTemplate = this.copyTemplates.find(tpl => tpl.templateName === '南音');
this.articleTemplateId = (defaultTemplate || this.copyTemplates[0]).templateId;
},
cancelDetail() {
this.openDetail = false;
this.reset();
@@ -507,14 +529,9 @@
this.title = "查看源码信息";
});
},
transToArticle(row) {
transToArticle(row.codeId).then(response => {
console.log(response)
this.$modal.msgSuccess(response.msg);
});
},
showCoverDialog(row) {
this.currentRow = row
this.selectDefaultArticleTemplate()
const id = row.codeId || this.ids
const baseUrl = process.env.VUE_APP_BASE_API
fetch(`${baseUrl}/office/project/cover/${id}`, {
@@ -564,36 +581,17 @@
this.$modal.msgSuccess('封面图片已下载')
},
handleTransToArticle1() {
// 将 Blob 转换为 File 对象
const file = new File([this.previewBlob], this.currentFileName, { type: 'image/png' });
// 创建 FormData
const formData = new FormData();
formData.append('file', file);
// 上传到七牛云
request({
url: '/common/qiniuUpload',
method: 'post',
data: formData,
headers: {
'Content-Type': 'multipart/form-data'
}
}).then(response => {
if (response.code === 200) {
// 获取上传后的URL
const imageUrl = response.url;
// 调用转文章接口
transToArticle1(this.currentRow.codeId, imageUrl).then(response => {
this.$modal.msgSuccess(response.msg);
this.getList();
});
} else {
this.$modal.msgError('封面图片上传失败');
}
if (!this.articleTemplateId) {
this.$modal.msgError('请选择文案模板');
return;
}
transToArticle1(this.currentRow.codeId, this.articleTemplateId).then(response => {
this.$modal.msgSuccess(response.msg);
this.getList();
}).catch(error => {
console.error('转文章失败:', error);
this.$modal.msgError('转文章失败');
});
this.coverDialogVisible = false;
},
/** 提交按钮 */