index.vue 1.8 KB

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