index.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 lang="ts" setup>
  19. import download from '@/utils/download'
  20. import * as DbDocApi from '@/api/infra/dbDoc'
  21. defineOptions({ name: 'InfraDBDoc' })
  22. const loading = ref(true) // 是否加载中
  23. const src = ref('') // HTML 的地址
  24. /** 页面加载 */
  25. const init = async () => {
  26. try {
  27. const data = await DbDocApi.exportHtml()
  28. const blob = new Blob([data], { type: 'text/html' })
  29. src.value = window.URL.createObjectURL(blob)
  30. } finally {
  31. loading.value = false
  32. }
  33. }
  34. /** 处理导出 */
  35. const handleExport = async (type: string) => {
  36. if (type === 'HTML') {
  37. const res = await DbDocApi.exportHtml()
  38. download.html(res, '数据库文档.html')
  39. }
  40. if (type === 'Word') {
  41. const res = await DbDocApi.exportWord()
  42. download.word(res, '数据库文档.doc')
  43. }
  44. if (type === 'Markdown') {
  45. const res = await DbDocApi.exportMarkdown()
  46. download.markdown(res, '数据库文档.md')
  47. }
  48. }
  49. /** 初始化 */
  50. onMounted(async () => {
  51. await init()
  52. })
  53. </script>