index.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <template>
  2. <doc-alert title="数据库文档" url="https://doc.iocoder.cn/db-doc/" />
  3. <ContentWrap title="数据库文档">
  4. <div class="mb-10px">
  5. <el-button type="primary" plain @click="handleExport('HTML')">
  6. <Icon icon="ep:download" /> 导出 HTML
  7. </el-button>
  8. <el-button type="primary" plain @click="handleExport('Word')">
  9. <Icon icon="ep:download" /> 导出 Word
  10. </el-button>
  11. <el-button type="primary" plain @click="handleExport('Markdown')">
  12. <Icon icon="ep:download" /> 导出 Markdown
  13. </el-button>
  14. </div>
  15. <IFrame v-if="!loading" v-loading="loading" :src="src" />
  16. </ContentWrap>
  17. </template>
  18. <script setup lang="ts" name="InfraDBDoc">
  19. import download from '@/utils/download'
  20. import * as DbDocApi from '@/api/infra/dbDoc'
  21. const loading = ref(true) // 是否加载中
  22. const src = ref('') // HTML 的地址
  23. /** 页面加载 */
  24. const init = async () => {
  25. try {
  26. const data = await DbDocApi.exportHtml()
  27. const blob = new Blob([data], { type: 'text/html' })
  28. src.value = window.URL.createObjectURL(blob)
  29. } finally {
  30. loading.value = false
  31. }
  32. }
  33. /** 处理导出 */
  34. const handleExport = async (type: string) => {
  35. if (type === 'HTML') {
  36. const res = await DbDocApi.exportHtml()
  37. download.html(res, '数据库文档.html')
  38. }
  39. if (type === 'Word') {
  40. const res = await DbDocApi.exportWord()
  41. download.word(res, '数据库文档.doc')
  42. }
  43. if (type === 'Markdown') {
  44. const res = await DbDocApi.exportMarkdown()
  45. download.markdown(res, '数据库文档.md')
  46. }
  47. }
  48. /** 初始化 */
  49. onMounted(async () => {
  50. await init()
  51. })
  52. </script>