mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
增加数据库文档的 html、word、markdown 的导出
This commit is contained in:
parent
84ca9222c8
commit
2fcb54b576
@ -8,3 +8,19 @@ export function exportHtml() {
|
||||
responseType: 'blob'
|
||||
})
|
||||
}
|
||||
|
||||
export function exportWord() {
|
||||
return request({
|
||||
url: '/infra/db-doc/export-word',
|
||||
method: 'get',
|
||||
responseType: 'blob'
|
||||
})
|
||||
}
|
||||
|
||||
export function exportMarkdown() {
|
||||
return request({
|
||||
url: '/infra/db-doc/export-markdown',
|
||||
method: 'get',
|
||||
responseType: 'blob'
|
||||
})
|
||||
}
|
||||
|
@ -25,7 +25,10 @@ import {
|
||||
download,
|
||||
handleTree,
|
||||
downloadExcel,
|
||||
downloadZip
|
||||
downloadWord,
|
||||
downloadZip,
|
||||
downloadHtml,
|
||||
downloadMarkdown,
|
||||
} from "@/utils/ruoyi";
|
||||
import Pagination from "@/components/Pagination";
|
||||
// 自定义表格工具扩展
|
||||
@ -48,6 +51,9 @@ Vue.prototype.getDictDataLabel = getDictDataLabel
|
||||
Vue.prototype.DICT_TYPE = DICT_TYPE
|
||||
Vue.prototype.download = download
|
||||
Vue.prototype.downloadExcel = downloadExcel
|
||||
Vue.prototype.downloadWord = downloadWord
|
||||
Vue.prototype.downloadHtml = downloadHtml
|
||||
Vue.prototype.downloadMarkdown = downloadMarkdown
|
||||
Vue.prototype.downloadZip = downloadZip
|
||||
Vue.prototype.handleTree = handleTree
|
||||
|
||||
|
@ -120,11 +120,26 @@ export function downloadExcel(data, fileName) {
|
||||
download0(data, fileName, 'application/vnd.ms-excel');
|
||||
}
|
||||
|
||||
// 下载 Word 方法
|
||||
export function downloadWord(data, fileName) {
|
||||
download0(data, fileName, 'application/msword');
|
||||
}
|
||||
|
||||
// 下载 Zip 方法
|
||||
export function downloadZip(data, fileName) {
|
||||
download0(data, fileName, 'application/zip');
|
||||
}
|
||||
|
||||
// 下载 Html 方法
|
||||
export function downloadHtml(data, fileName) {
|
||||
download0(data, fileName, 'text/html');
|
||||
}
|
||||
|
||||
// 下载 Markdown 方法
|
||||
export function downloadMarkdown(data, fileName) {
|
||||
download0(data, fileName, 'text/markdown');
|
||||
}
|
||||
|
||||
function download0(data, fileName, mineType) {
|
||||
// 创建 blob
|
||||
let blob = new Blob([data], {type: mineType});
|
||||
|
@ -1,10 +1,21 @@
|
||||
<template>
|
||||
<div v-loading="loading" :style="'height:'+ height">
|
||||
<iframe :src="src" frameborder="no" style="width: 100%;height: 100%" scrolling="auto" />
|
||||
<div class="app-container">
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleExportHtml">导出 HTML</el-button>
|
||||
<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleExportWord">导出 Word</el-button>
|
||||
<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleExportMarkdown">导出 Markdown</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 展示文档 -->
|
||||
<div v-loading="loading" :style="'height:'+ height">
|
||||
<iframe :src="src" frameborder="no" style="width: 100%;height: 100%" scrolling="auto" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
import {exportHtml} from "@/api/infra/dbDoc";
|
||||
import { exportHtml, exportWord, exportMarkdown} from "@/api/infra/dbDoc";
|
||||
|
||||
export default {
|
||||
name: "DBDoc",
|
||||
@ -25,10 +36,31 @@ export default {
|
||||
};
|
||||
},
|
||||
created() {
|
||||
// 加载 Html,进行预览
|
||||
exportHtml().then(response => {
|
||||
// var blob = new Blob(['<a id="a"><b id="b">hey!</b></a>'], {type : 'text/html'});
|
||||
this.src = window.URL.createObjectURL(response);
|
||||
let blob = new Blob([response], {type : 'text/html'});
|
||||
this.src = window.URL.createObjectURL(blob);
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
/** 处理导出 HTML */
|
||||
handleExportHtml() {
|
||||
exportHtml().then(response => {
|
||||
this.downloadHtml(response, '数据库文档.html');
|
||||
})
|
||||
},
|
||||
/** 处理导出 Word */
|
||||
handleExportWord() {
|
||||
exportWord().then(response => {
|
||||
this.downloadWord(response, '数据库文档.doc');
|
||||
})
|
||||
},
|
||||
/** 处理导出 Markdown */
|
||||
handleExportMarkdown() {
|
||||
exportMarkdown().then(response => {
|
||||
this.downloadMarkdown(response, '数据库文档.md');
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
@ -1,10 +1,7 @@
|
||||
package cn.iocoder.dashboard.modules.infra.controller.doc;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.extra.servlet.ServletUtil;
|
||||
import cn.iocoder.dashboard.util.servlet.ServletUtils;
|
||||
import cn.smallbun.screw.core.Configuration;
|
||||
import cn.smallbun.screw.core.engine.EngineConfig;
|
||||
@ -16,11 +13,8 @@ import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@ -28,7 +22,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
@Api(tags = "数据库文档")
|
||||
@ -45,9 +40,8 @@ public class InfDbDocController {
|
||||
private static final String DOC_VERSION = "1.0.0";
|
||||
private static final String DOC_DESCRIPTION = "文档描述";
|
||||
|
||||
|
||||
@GetMapping("/export-html")
|
||||
@ApiOperation("导出html格式的数据文档")
|
||||
@ApiOperation("导出 html 格式的数据文档")
|
||||
@ApiImplicitParam(name = "deleteFile", value = "是否删除在服务器本地生成的数据库文档", example = "true", dataTypeClass = Boolean.class)
|
||||
public void exportHtml(@RequestParam(defaultValue = "true") Boolean deleteFile,
|
||||
HttpServletResponse response) throws IOException {
|
||||
@ -55,7 +49,7 @@ public class InfDbDocController {
|
||||
}
|
||||
|
||||
@GetMapping("/export-word")
|
||||
@ApiOperation("导出word格式的数据文档")
|
||||
@ApiOperation("导出 word 格式的数据文档")
|
||||
@ApiImplicitParam(name = "deleteFile", value = "是否删除在服务器本地生成的数据库文档", example = "true", dataTypeClass = Boolean.class)
|
||||
public void exportWord(@RequestParam(defaultValue = "true") Boolean deleteFile,
|
||||
HttpServletResponse response) throws IOException {
|
||||
@ -63,7 +57,7 @@ public class InfDbDocController {
|
||||
}
|
||||
|
||||
@GetMapping("/export-markdown")
|
||||
@ApiOperation("导出markdown格式的数据文档")
|
||||
@ApiOperation("导出 markdown 格式的数据文档")
|
||||
@ApiImplicitParam(name = "deleteFile", value = "是否删除在服务器本地生成的数据库文档", example = "true", dataTypeClass = Boolean.class)
|
||||
public void exportMarkdown(@RequestParam(defaultValue = "true") Boolean deleteFile,
|
||||
HttpServletResponse response) throws IOException {
|
||||
@ -77,9 +71,8 @@ public class InfDbDocController {
|
||||
String downloadFileName = DOC_FILE_NAME + fileOutputType.getFileSuffix(); //下载后的文件名
|
||||
try {
|
||||
// 读取,返回
|
||||
//这里不用hutool工具类,它的中文文件名编码有问题,导致在浏览器下载时有问题
|
||||
ServletUtils.writeAttachment(response, downloadFileName, FileUtil.readBytes(filePath));
|
||||
}finally {
|
||||
} finally {
|
||||
handleDeleteFile(deleteFile, filePath);
|
||||
}
|
||||
}
|
||||
@ -123,7 +116,6 @@ public class InfDbDocController {
|
||||
private HikariDataSource buildDataSource() {
|
||||
// 创建 HikariConfig 配置类
|
||||
HikariConfig hikariConfig = new HikariConfig();
|
||||
// hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
|
||||
hikariConfig.setJdbcUrl(dataSourceProperties.getUrl());
|
||||
hikariConfig.setUsername(dataSourceProperties.getUsername());
|
||||
hikariConfig.setPassword(dataSourceProperties.getPassword());
|
||||
|
Loading…
Reference in New Issue
Block a user