index.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 lang="ts" setup>
  60. import download from '@/utils/download'
  61. import * as CodegenApi from '@/api/infra/codegen'
  62. import { CodegenTableVO } from '@/api/infra/codegen/types'
  63. import { allSchemas } from './codegen.data'
  64. import { ImportTable, Preview } from './components'
  65. defineOptions({ name: 'InfraCodegen' })
  66. const { t } = useI18n() // 国际化
  67. const message = useMessage() // 消息弹窗
  68. const { push } = useRouter() // 路由跳转
  69. // 列表相关的变量
  70. const [registerTable, { reload, deleteData }] = useXTable({
  71. allSchemas: allSchemas,
  72. getListApi: CodegenApi.getCodegenTablePageApi,
  73. deleteApi: CodegenApi.deleteCodegenTableApi
  74. })
  75. // 导入操作
  76. const importRef = ref()
  77. const openImportTable = () => {
  78. importRef.value.show()
  79. }
  80. // 预览操作
  81. const previewRef = ref()
  82. const handlePreview = (row: CodegenTableVO) => {
  83. previewRef.value.show(row)
  84. }
  85. // 编辑操作
  86. const handleUpdate = (rowId: number) => {
  87. push('/codegen/edit?id=' + rowId)
  88. }
  89. // 同步操作
  90. const handleSynchDb = (row: CodegenTableVO) => {
  91. // 基于 DB 同步
  92. const tableName = row.tableName
  93. message
  94. .confirm('确认要强制同步' + tableName + '表结构吗?', t('common.reminder'))
  95. .then(async () => {
  96. await CodegenApi.syncCodegenFromDBApi(row.id)
  97. message.success('同步成功')
  98. })
  99. }
  100. // 生成代码操作
  101. const handleGenTable = async (row: CodegenTableVO) => {
  102. const res = await CodegenApi.downloadCodegenApi(row.id)
  103. download.zip(res, 'codegen-' + row.className + '.zip')
  104. }
  105. </script>