index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <ContentWrap>
  3. <!-- 列表 -->
  4. <vxe-grid ref="xGrid" v-bind="gridOptions" class="xtable-scrollbar">
  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="handleDelete(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. </vxe-grid>
  53. </ContentWrap>
  54. <!-- 弹窗:导入表 -->
  55. <ImportTable ref="importRef" @ok="handleQuery()" />
  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 { VxeGridInstance } from 'vxe-table'
  63. import { useI18n } from '@/hooks/web/useI18n'
  64. import { useMessage } from '@/hooks/web/useMessage'
  65. import { useVxeGrid } from '@/hooks/web/useVxeGrid'
  66. import download from '@/utils/download'
  67. import * as CodegenApi from '@/api/infra/codegen'
  68. import { CodegenTableVO } from '@/api/infra/codegen/types'
  69. import { allSchemas } from './codegen.data'
  70. import { ImportTable, Preview } from './components'
  71. const { t } = useI18n() // 国际化
  72. const message = useMessage() // 消息弹窗
  73. const { push } = useRouter()
  74. // 列表相关的变量
  75. const xGrid = ref<VxeGridInstance>() // 列表 Grid Ref
  76. const { gridOptions, getList, deleteData } = useVxeGrid<CodegenTableVO>({
  77. allSchemas: allSchemas,
  78. getListApi: CodegenApi.getCodegenTablePageApi,
  79. deleteApi: CodegenApi.deleteCodegenTableApi
  80. })
  81. // 导入操作
  82. const importRef = ref()
  83. const openImportTable = () => {
  84. importRef.value.show()
  85. }
  86. // 预览操作
  87. const previewRef = ref()
  88. const handlePreview = (row: CodegenTableVO) => {
  89. previewRef.value.show(row)
  90. }
  91. // 编辑操作
  92. const handleUpdate = (rowId: number) => {
  93. // TODO 星语:修改某个的时候,tab 要展示名字。例如说:"修改[" + tableName + "]生成配置"
  94. // TODO 星语:【暗黑模式】编辑界面,周边有白色的边框,不太好看
  95. push('/codegen/edit?id=' + rowId)
  96. }
  97. // 同步操作
  98. const handleSynchDb = (row: CodegenTableVO) => {
  99. // 基于 DB 同步
  100. const tableName = row.tableName
  101. message
  102. .confirm('确认要强制同步' + tableName + '表结构吗?', t('common.reminder'))
  103. .then(async () => {
  104. await CodegenApi.syncCodegenFromDBApi(row.id)
  105. message.success('同步成功')
  106. })
  107. }
  108. // 生成代码操作
  109. const handleGenTable = async (row: CodegenTableVO) => {
  110. const res = await CodegenApi.downloadCodegenApi(row.id)
  111. download.zip(res, 'codegen-' + row.className + '.zip')
  112. }
  113. // 删除操作
  114. const handleDelete = async (rowId: number) => {
  115. await deleteData(xGrid, rowId)
  116. }
  117. // 查询操作
  118. const handleQuery = async () => {
  119. await getList(xGrid)
  120. }
  121. </script>