index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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 from './components/ImportTable.vue'
  10. import Preview from './components/Preview.vue'
  11. import download from '@/utils/download'
  12. import { useRouter } from 'vue-router'
  13. import { ElMessage, ElMessageBox } from 'element-plus'
  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. ElMessageBox.confirm('确认要强制同步' + tableName + '表结构吗?', t('common.reminder'), {
  41. confirmButtonText: t('common.ok'),
  42. cancelButtonText: t('common.cancel'),
  43. type: 'warning'
  44. }).then(async () => {
  45. await CodegenApi.syncCodegenFromDBApi(row.id)
  46. ElMessage.success('同步成功')
  47. })
  48. }
  49. // 生成代码操作
  50. const handleGenTable = (row: CodegenTableVO) => {
  51. const res = CodegenApi.downloadCodegenApi(row.id)
  52. download.zip(res, 'codegen-' + row.className + '.zip')
  53. }
  54. // 删除操作
  55. const handleDelete = (row: CodegenTableVO) => {
  56. delList(row.id, false)
  57. }
  58. // 查询操作
  59. const handleQuery = () => {
  60. getList()
  61. }
  62. // ========== 初始化 ==========
  63. getList()
  64. </script>
  65. <template>
  66. <!-- 搜索工作区 -->
  67. <ContentWrap>
  68. <Search :schema="allSchemas.searchSchema" @search="setSearchParams" @reset="setSearchParams" />
  69. </ContentWrap>
  70. <ContentWrap>
  71. <!-- 操作工具栏 -->
  72. <div class="mb-10px">
  73. <el-button type="primary" v-hasPermi="['infra:codegen:create']" @click="openImportTable">
  74. <Icon icon="ep:zoom-in" class="mr-5px" /> {{ t('action.import') }}
  75. </el-button>
  76. </div>
  77. <!-- 列表 -->
  78. <Table
  79. :columns="allSchemas.tableColumns"
  80. :selection="false"
  81. :data="tableObject.tableList"
  82. :loading="tableObject.loading"
  83. :pagination="{
  84. total: tableObject.total
  85. }"
  86. v-model:pageSize="tableObject.pageSize"
  87. v-model:currentPage="tableObject.currentPage"
  88. @register="register"
  89. >
  90. <template #createTime="{ row }">
  91. <span>{{ dayjs(row.createTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  92. </template>
  93. <template #updateTime="{ row }">
  94. <span>{{ dayjs(row.updateTime).format('YYYY-MM-DD HH:mm:ss') }}</span>
  95. </template>
  96. <template #action="{ row }">
  97. <el-button
  98. link
  99. type="primary"
  100. v-hasPermi="['infra:codegen:preview']"
  101. @click="handlePreview(row)"
  102. >
  103. <Icon icon="ep:view" class="mr-1px" /> {{ t('action.preview') }}
  104. </el-button>
  105. <el-button
  106. link
  107. type="primary"
  108. v-hasPermi="['infra:codegen:update']"
  109. @click="handleEditTable(row)"
  110. >
  111. <Icon icon="ep:edit" class="mr-1px" /> {{ t('action.edit') }}
  112. </el-button>
  113. <el-button
  114. link
  115. type="primary"
  116. v-hasPermi="['infra:codegen:delete']"
  117. @click="handleDelete(row)"
  118. >
  119. <Icon icon="ep:delete" class="mr-1px" /> {{ t('action.del') }}
  120. </el-button>
  121. <el-button
  122. link
  123. type="primary"
  124. v-hasPermi="['infra:codegen:update']"
  125. @click="handleSynchDb(row)"
  126. >
  127. <Icon icon="ep:refresh" class="mr-1px" /> {{ t('action.sync') }}
  128. </el-button>
  129. <el-button
  130. link
  131. type="primary"
  132. v-hasPermi="['infra:codegen:download']"
  133. @click="handleGenTable(row)"
  134. >
  135. <Icon icon="ep:download" class="mr-1px" /> {{ t('action.generate') }}
  136. </el-button>
  137. </template>
  138. </Table>
  139. </ContentWrap>
  140. <ImportTable ref="importRef" @ok="handleQuery" />
  141. <Preview ref="previewRef" />
  142. </template>