index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <template>
  2. <ContentWrap>
  3. <!-- 列表 -->
  4. <XTable @register="registerTable">
  5. <template #toolbar_buttons>
  6. <!-- 操作:导入 -->
  7. <XButton
  8. type="primary"
  9. preIcon="ep:zoom-in"
  10. :title="t('action.import')"
  11. v-hasPermi="['infra:codegen:create']"
  12. @click="openImportTable()"
  13. />
  14. </template>
  15. <template #actionbtns_default="{ row }">
  16. <!-- 操作:预览 -->
  17. <XTextButton
  18. preIcon="ep:view"
  19. :title="t('action.preview')"
  20. v-hasPermi="['infra:codegen:query']"
  21. @click="handlePreview(row)"
  22. />
  23. <!-- 操作:编辑 -->
  24. <XTextButton
  25. preIcon="ep:edit"
  26. :title="t('action.edit')"
  27. v-hasPermi="['infra:codegen:update']"
  28. @click="handleUpdate(row.id)"
  29. />
  30. <!-- 操作:删除 -->
  31. <XTextButton
  32. preIcon="ep:delete"
  33. :title="t('action.del')"
  34. v-hasPermi="['infra:codegen:delete']"
  35. @click="deleteData(row.id)"
  36. />
  37. <!-- 操作:同步 -->
  38. <XTextButton
  39. preIcon="ep:refresh"
  40. :title="t('action.sync')"
  41. v-hasPermi="['infra:codegen:update']"
  42. @click="handleSynchDb(row)"
  43. />
  44. <!-- 操作:生成 -->
  45. <XTextButton
  46. preIcon="ep:download"
  47. :title="t('action.generate')"
  48. v-hasPermi="['infra:codegen:download']"
  49. @click="handleGenTable(row)"
  50. />
  51. </template>
  52. </XTable>
  53. </ContentWrap>
  54. <!-- 弹窗:导入表 -->
  55. <ImportTable ref="importRef" @ok="reload()" />
  56. <!-- 弹窗:预览代码 -->
  57. <Preview ref="previewRef" />
  58. </template>
  59. <script setup lang="ts" name="Codegen">
  60. import { ref } from 'vue'
  61. import { useRouter } from 'vue-router'
  62. import { useI18n } from '@/hooks/web/useI18n'
  63. import { useMessage } from '@/hooks/web/useMessage'
  64. import { useXTable } from '@/hooks/web/useXTable'
  65. import download from '@/utils/download'
  66. import * as CodegenApi from '@/api/infra/codegen'
  67. import { CodegenTableVO } from '@/api/infra/codegen/types'
  68. import { allSchemas } from './codegen.data'
  69. import { ImportTable, Preview } from './components'
  70. const { t } = useI18n() // 国际化
  71. const message = useMessage() // 消息弹窗
  72. const { push } = useRouter() // 路由跳转
  73. // 列表相关的变量
  74. const [registerTable, { reload, deleteData }] = useXTable({
  75. allSchemas: allSchemas,
  76. getListApi: CodegenApi.getCodegenTablePageApi,
  77. deleteApi: CodegenApi.deleteCodegenTableApi
  78. })
  79. // 导入操作
  80. const importRef = ref()
  81. const openImportTable = () => {
  82. importRef.value.show()
  83. }
  84. // 预览操作
  85. const previewRef = ref()
  86. const handlePreview = (row: CodegenTableVO) => {
  87. previewRef.value.show(row)
  88. }
  89. // 编辑操作
  90. const handleUpdate = (rowId: number) => {
  91. push('/codegen/edit?id=' + rowId)
  92. }
  93. // 同步操作
  94. const handleSynchDb = (row: CodegenTableVO) => {
  95. // 基于 DB 同步
  96. const tableName = row.tableName
  97. message
  98. .confirm('确认要强制同步' + tableName + '表结构吗?', t('common.reminder'))
  99. .then(async () => {
  100. await CodegenApi.syncCodegenFromDBApi(row.id)
  101. message.success('同步成功')
  102. })
  103. }
  104. // 生成代码操作
  105. const handleGenTable = async (row: CodegenTableVO) => {
  106. const res = await CodegenApi.downloadCodegenApi(row.id)
  107. download.zip(res, 'codegen-' + row.className + '.zip')
  108. }
  109. </script>