index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <script setup lang="ts">
  2. import { ref } from 'vue'
  3. import dayjs from 'dayjs'
  4. import * as CodegenApi from '@/api/infra/codegen'
  5. import { useTable } from '@/hooks/web/useTable'
  6. import { CodegenTableVO } from '@/api/infra/codegen/types'
  7. import { allSchemas } from './codegen.data'
  8. import { useI18n } from '@/hooks/web/useI18n'
  9. import { ImportTable, Preview } from './components'
  10. import download from '@/utils/download'
  11. import { useRouter } from 'vue-router'
  12. import { useMessage } from '@/hooks/web/useMessage'
  13. const message = useMessage()
  14. const { t } = useI18n() // 国际化
  15. const { push } = useRouter()
  16. // ========== 列表相关 ==========
  17. const { register, tableObject, methods } = useTable<CodegenTableVO>({
  18. getListApi: CodegenApi.getCodegenTablePageApi,
  19. delListApi: CodegenApi.deleteCodegenTableApi
  20. })
  21. const { getList, setSearchParams, delList } = methods
  22. // 导入操作
  23. const importRef = ref()
  24. const openImportTable = () => {
  25. importRef.value.show()
  26. }
  27. // 预览操作
  28. const previewRef = ref()
  29. const handlePreview = (row: CodegenTableVO) => {
  30. previewRef.value.show(row)
  31. }
  32. // 编辑操作
  33. const handleEditTable = (row: CodegenTableVO) => {
  34. push('/codegen/edit?id=' + row.id)
  35. }
  36. // 同步操作
  37. const handleSynchDb = (row: CodegenTableVO) => {
  38. // 基于 DB 同步
  39. const tableName = row.tableName
  40. message
  41. .confirm('确认要强制同步' + tableName + '表结构吗?', t('common.reminder'))
  42. .then(async () => {
  43. await CodegenApi.syncCodegenFromDBApi(row.id)
  44. message.success('同步成功')
  45. })
  46. }
  47. // 生成代码操作
  48. const handleGenTable = async (row: CodegenTableVO) => {
  49. const res = await CodegenApi.downloadCodegenApi(row.id)
  50. download.zip(res, 'codegen-' + row.className + '.zip')
  51. }
  52. // 查询操作
  53. const handleQuery = () => {
  54. getList()
  55. }
  56. // ========== 初始化 ==========
  57. getList()
  58. </script>
  59. <template>
  60. <!-- 搜索工作区 -->
  61. <ContentWrap>
  62. <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
  63. </ContentWrap>
  64. <ContentWrap>
  65. <!-- 操作工具栏 -->
  66. <div class="mb-10px">
  67. <el-button type="primary" v-hasPermi="['infra:codegen:create']" @click="openImportTable">
  68. <Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.import') }}
  69. </el-button>
  70. </div>
  71. <!-- 列表 -->
  72. <Table
  73. :columns="allSchemas.tableColumns"
  74. :selection="false"
  75. :data="tableObject.tableList"
  76. :loading="tableObject.loading"
  77. :pagination="{
  78. total: tableObject.total
  79. }"
  80. v-model:pageSize="tableObject.pageSize"
  81. v-model:currentPage="tableObject.currentPage"
  82. @register="register"
  83. >
  84. <template #createTime="{ row }">
  85. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  86. </template>
  87. <template #updateTime="{ row }">
  88. <span>{{ dayjs(row.updateTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  89. </template>
  90. <template #action="{ row }">
  91. <el-button
  92. link
  93. type="primary"
  94. v-hasPermi="['infra:codegen:preview']"
  95. @click="handlePreview(row)"
  96. >
  97. <Icon icon="ep:view" class="mr-1px" /> {{ t('action.preview') }}
  98. </el-button>
  99. <el-button
  100. link
  101. type="primary"
  102. v-hasPermi="['infra:codegen:update']"
  103. @click="handleEditTable(row)"
  104. >
  105. <Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }}
  106. </el-button>
  107. <el-button
  108. link
  109. type="primary"
  110. v-hasPermi="['infra:codegen:delete']"
  111. @click="delList(row.id, false)"
  112. >
  113. <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
  114. </el-button>
  115. <el-button
  116. link
  117. type="primary"
  118. v-hasPermi="['infra:codegen:update']"
  119. @click="handleSynchDb(row)"
  120. >
  121. <Icon icon="ep:refresh" class="mr-1px" /> {{ t('action.sync') }}
  122. </el-button>
  123. <el-button
  124. link
  125. type="primary"
  126. v-hasPermi="['infra:codegen:download']"
  127. @click="handleGenTable(row)"
  128. >
  129. <Icon icon="ep:download" class="mr-1px" /> {{ t('action.generate') }}
  130. </el-button>
  131. </template>
  132. </Table>
  133. </ContentWrap>
  134. <ImportTable ref="importRef" @ok="handleQuery" />
  135. <Preview ref="previewRef" />
  136. </template>