This commit is contained in:
王鹏
2026-08-28 13:15:47 +08:00
parent a1a806f266
commit 21eb026789
6 changed files with 133 additions and 3 deletions

View File

@@ -151,6 +151,13 @@ swagger:
# 请求前缀
pathMapping: /dev-api
# 博客网站文章同步配置
website-sync:
base-url: https://www.yidaima.cn/prod-api
api-key: 9628e0e5d85e541591a47a0e768fabddbf62c9d0fcc6c21da3a41ea65afd505c
connect-timeout: 5000
read-timeout: 30000
# 防止XSS攻击
xss:
# 过滤开关

View File

@@ -1,5 +1,6 @@
package com.ruoyi.office.controller;
import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
@@ -19,6 +20,8 @@ import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.office.domain.TtCode;
import com.ruoyi.office.service.ITtCodeService;
import com.ruoyi.office.service.IWebsiteArticleSyncService;
import com.ruoyi.office.service.TtScreenshotArchiveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
@@ -35,6 +38,12 @@ public class TtCodeController extends BaseController
@Autowired
private ITtCodeService ttCodeService;
@Autowired
private IWebsiteArticleSyncService websiteArticleSyncService;
@Autowired
private TtScreenshotArchiveService screenshotArchiveService;
/**
* 查询源码管理列表
*/
@@ -60,6 +69,17 @@ public class TtCodeController extends BaseController
util.exportExcel(response, list, "源码管理数据");
}
/**
* 下载所选源码项目在文件管理中关联的全部截图。
*/
@PreAuthorize("@ss.hasPermi('office:code:export')")
@Log(title = "下载项目截图", businessType = BusinessType.EXPORT)
@GetMapping("/screenshots/{codeId}/download")
public void downloadScreenshots(@PathVariable Long codeId, HttpServletResponse response) throws IOException
{
screenshotArchiveService.download(codeId, response);
}
/**
* 获取源码管理详细信息
*/
@@ -113,4 +133,17 @@ public class TtCodeController extends BaseController
String msg = ttCodeService.transToArticle1(codeId, templateId);
return success(msg);
}
/**
* 将“复制网站文案”同步为网站Markdown文章。
*/
@PreAuthorize("@ss.hasPermi('office:code:edit')")
@Log(title = "同步网站", businessType = BusinessType.UPDATE)
@PostMapping("/syncWebsite/{codeId}")
public AjaxResult syncWebsite(@PathVariable Long codeId) {
com.ruoyi.office.domain.WebsiteArticleSyncResult result =
websiteArticleSyncService.syncWebsite(codeId);
String message = result.isCreated() ? "同步网站成功,已创建文章" : "同步网站成功,已更新文章";
return AjaxResult.success(message, result);
}
}

View File

@@ -75,6 +75,9 @@ public class TtCodeServiceImpl implements ITtCodeService {
@Override
public TtCode selectTtCodeByCodeId(Long codeId) {
TtCode ttCode = ttCodeMapper.selectTtCodeByCodeId(codeId);
if (ttCode == null) {
return null;
}
TtFile file = new TtFile();
file.setCodeName(ttCode.getCodeName());
ttCode.setFileList(fileMapper.selectTtFileList(file));

View File

@@ -38,6 +38,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectTtFileByCodeName" parameterType="String" resultMap="TtFileResult">
<include refid="selectTtFileVo"/>
where code_name = #{codeName}
order by file_id asc
</select>
<insert id="insertTtFile" parameterType="TtFile" useGeneratedKeys="true" keyProperty="fileId">

View File

@@ -52,3 +52,21 @@ export function transToArticle1(codeId, templateId) {
}
})
}
// 将复制网站文案同步到博客网站
export function syncWebsite(codeId) {
return request({
url: '/office/code/syncWebsite/' + codeId,
method: 'post'
})
}
// 下载项目在文件管理中关联的全部截图
export function downloadScreenshots(codeId) {
return request({
url: '/office/code/screenshots/' + codeId + '/download',
method: 'get',
responseType: 'blob',
timeout: 120000
})
}

View File

@@ -96,6 +96,19 @@
>导出
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
plain
icon="el-icon-download"
size="mini"
:disabled="single || downloadingScreenshots"
:loading="downloadingScreenshots"
@click="handleDownloadScreenshots"
v-hasPermi="['office:code:export']"
>下载截图
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
@@ -121,7 +134,17 @@
icon="el-icon-document-copy"
@click="showCoverDialog(scope.row)"
v-hasPermi="['office:code:edit']"
>转文章(南音)
>同步小程序
</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-upload2"
:loading="syncingCodeId === scope.row.codeId"
:disabled="syncingCodeId !== null"
@click="handleSyncWebsite(scope.row)"
v-hasPermi="['office:code:edit']"
>同步网站
</el-button>
<el-button
size="mini"
@@ -284,10 +307,11 @@
</template>
<script>
import {listCode, getCode, delCode, addCode, updateCode, transToArticle1} from "@/api/office/code";
import {listCode, getCode, delCode, addCode, updateCode, transToArticle1, syncWebsite, downloadScreenshots} from "@/api/office/code";
import {listEnabledTemplates} from "@/api/office/copyTemplate";
import {html2Text} from "../../../utils";
import {getToken} from "@/utils/auth";
import {blobValidate} from "@/utils/ruoyi";
export default {
name: "Code",
@@ -299,6 +323,8 @@
loading: true,
// 选中数组
ids: [],
// 当前选中的源码项目
selectedCode: null,
// 非单个禁用
single: true,
// 非多个禁用
@@ -346,7 +372,11 @@
// 文案模板列表(动态按钮)
copyTemplates: [],
// 转文章时使用的文案模板
articleTemplateId: null
articleTemplateId: null,
// 正在同步网站的源码ID,防止重复点击
syncingCodeId: null,
// 是否正在打包下载项目截图
downloadingScreenshots: false
};
},
created() {
@@ -489,9 +519,34 @@
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.codeId)
this.selectedCode = selection.length === 1 ? selection[0] : null
this.single = selection.length !== 1
this.multiple = !selection.length
},
/** 下载所选项目在文件管理中的全部截图 */
handleDownloadScreenshots() {
if (!this.selectedCode || this.downloadingScreenshots) {
return
}
const selectedCode = this.selectedCode
this.downloadingScreenshots = true
downloadScreenshots(selectedCode.codeId).then(async data => {
if (!blobValidate(data)) {
await this.$download.printErrMsg(data)
return
}
const safeProjectName = (selectedCode.codeName || '项目')
.replace(/[\\/:*?"<>|\x00-\x1F]/g, '_')
.replace(/[. ]+$/g, '') || '项目'
const archive = new Blob([data], {type: 'application/zip'})
this.$download.saveAs(archive, safeProjectName + '截图.zip')
this.$modal.msgSuccess('项目截图已开始下载')
}).catch(error => {
console.error('下载项目截图失败:', error)
}).finally(() => {
this.downloadingScreenshots = false
})
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
@@ -594,6 +649,19 @@
});
this.coverDialogVisible = false;
},
/** 同步网站 */
handleSyncWebsite(row) {
const codeId = row.codeId;
this.$modal.confirm('确认将“' + row.codeName + '”同步并发布到网站?').then(() => {
this.syncingCodeId = codeId;
return syncWebsite(codeId);
}).then(response => {
this.$modal.msgSuccess(response.msg);
}).catch(() => {
}).finally(() => {
this.syncingCodeId = null;
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {