index.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <div class="app-container">
  3. <doc-alert title="数据库文档" url="https://doc.iocoder.cn/db-doc/" />
  4. <!-- 操作工作栏 -->
  5. <el-row :gutter="10" class="mb8">
  6. <el-col :span="1.5">
  7. <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleExportHtml">导出 HTML</el-button>
  8. <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleExportWord">导出 Word</el-button>
  9. <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleExportMarkdown">导出 Markdown</el-button>
  10. </el-col>
  11. </el-row>
  12. <!-- 展示文档 -->
  13. <div v-loading="loading" :style="'height:'+ height">
  14. <i-frame :src="src" />
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. import { exportHtml, exportWord, exportMarkdown} from "@/api/infra/dbDoc";
  20. import iFrame from "@/components/iFrame/index";
  21. export default {
  22. name: "DBDoc",
  23. components: { iFrame },
  24. data() {
  25. return {
  26. height: document.documentElement.clientHeight - 94.5 + "px;",
  27. loading: true,
  28. src: "undefined",
  29. };
  30. },
  31. mounted: function() {
  32. setTimeout(() => {
  33. this.loading = false;
  34. }, 230);
  35. const that = this;
  36. window.onresize = function temp() {
  37. that.height = document.documentElement.clientHeight - 94.5 + "px;";
  38. };
  39. },
  40. created() {
  41. // 加载 Html,进行预览
  42. exportHtml().then(response => {
  43. let blob = new Blob([response], {type : 'text/html'});
  44. this.src = window.URL.createObjectURL(blob);
  45. })
  46. },
  47. methods: {
  48. /** 处理导出 HTML */
  49. handleExportHtml() {
  50. exportHtml().then(response => {
  51. this.$download.html(response, '数据库文档.html');
  52. })
  53. },
  54. /** 处理导出 Word */
  55. handleExportWord() {
  56. exportWord().then(response => {
  57. this.$download.word(response, '数据库文档.doc');
  58. })
  59. },
  60. /** 处理导出 Markdown */
  61. handleExportMarkdown() {
  62. exportMarkdown().then(response => {
  63. this.$download.markdown(response, '数据库文档.md');
  64. })
  65. }
  66. }
  67. };
  68. </script>