index.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <doc-alert title="数据库文档" url="https://doc.iocoder.cn/db-doc/" />
  3. <ContentWrap title="数据库文档">
  4. <!-- 操作工具栏 -->
  5. <div class="mb-10px">
  6. <XButton
  7. type="primary"
  8. preIcon="ep:download"
  9. :title="t('action.export') + ' HTML'"
  10. @click="handleExport('HTML')"
  11. />
  12. <XButton
  13. type="primary"
  14. preIcon="ep:download"
  15. :title="t('action.export') + ' Word'"
  16. @click="handleExport('Word')"
  17. />
  18. <XButton
  19. type="primary"
  20. preIcon="ep:download"
  21. :title="t('action.export') + ' Markdown'"
  22. @click="handleExport('Markdown')"
  23. />
  24. </div>
  25. <IFrame v-if="!loding" v-loading="loding" :src="src" />
  26. </ContentWrap>
  27. </template>
  28. <script setup lang="ts" name="DbDoc">
  29. import download from '@/utils/download'
  30. import * as DbDocApi from '@/api/infra/dbDoc'
  31. const { t } = useI18n() // 国际化
  32. const src = ref('')
  33. const loding = ref(true)
  34. /** 页面加载 */
  35. const init = async () => {
  36. const res = await DbDocApi.exportHtml()
  37. let blob = new Blob([res], { type: 'text/html' })
  38. let blobUrl = window.URL.createObjectURL(blob)
  39. src.value = blobUrl
  40. loding.value = false
  41. }
  42. /** 处理导出 */
  43. const handleExport = async (type: string) => {
  44. if (type === 'HTML') {
  45. const res = await DbDocApi.exportHtml()
  46. download.html(res, '数据库文档.html')
  47. }
  48. if (type === 'Word') {
  49. const res = await DbDocApi.exportWord()
  50. download.word(res, '数据库文档.doc')
  51. }
  52. if (type === 'Markdown') {
  53. const res = await DbDocApi.exportMarkdown()
  54. download.markdown(res, '数据库文档.md')
  55. }
  56. }
  57. onMounted(async () => {
  58. await init()
  59. })
  60. </script>