EditTable.vue 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <template>
  2. <ContentWrap>
  3. <ContentDetailWrap :title="title" @back="push('/infra/codegen')">
  4. <el-tabs v-model="activeName">
  5. <el-tab-pane label="基本信息" name="basicInfo">
  6. <BasicInfoForm ref="basicInfoRef" :basicInfo="tableCurrentRow" />
  7. </el-tab-pane>
  8. <el-tab-pane label="字段信息" name="cloum">
  9. <CloumInfoForm ref="cloumInfoRef" :info="cloumCurrentRow" />
  10. </el-tab-pane>
  11. </el-tabs>
  12. <template #right>
  13. <XButton
  14. type="primary"
  15. :title="t('action.save')"
  16. :loading="loading"
  17. @click="submitForm()"
  18. />
  19. </template>
  20. </ContentDetailWrap>
  21. </ContentWrap>
  22. </template>
  23. <script setup lang="ts">
  24. import { ref, unref, onMounted } from 'vue'
  25. import { useRouter, useRoute } from 'vue-router'
  26. import { ElTabs, ElTabPane } from 'element-plus'
  27. import { useI18n } from '@/hooks/web/useI18n'
  28. import { useMessage } from '@/hooks/web/useMessage'
  29. import { ContentDetailWrap } from '@/components/ContentDetailWrap'
  30. import { BasicInfoForm, CloumInfoForm } from './components'
  31. import { getCodegenTableApi, updateCodegenTableApi } from '@/api/infra/codegen'
  32. import { CodegenTableVO, CodegenColumnVO, CodegenUpdateReqVO } from '@/api/infra/codegen/types'
  33. const { t } = useI18n() // 国际化
  34. const message = useMessage() // 消息弹窗
  35. const { push } = useRouter()
  36. const { query } = useRoute()
  37. const loading = ref(false)
  38. const title = ref('代码生成')
  39. const activeName = ref('basicInfo')
  40. const cloumInfoRef = ref(null)
  41. const tableCurrentRow = ref<CodegenTableVO>()
  42. const cloumCurrentRow = ref<CodegenColumnVO[]>([])
  43. const basicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>()
  44. const getList = async () => {
  45. const id = query.id as unknown as number
  46. if (id) {
  47. // 获取表详细信息
  48. const res = await getCodegenTableApi(id)
  49. title.value = '修改[ ' + res.table.tableName + ' ]生成配置'
  50. tableCurrentRow.value = res.table
  51. cloumCurrentRow.value = res.columns
  52. }
  53. }
  54. const submitForm = async () => {
  55. const basicInfo = unref(basicInfoRef)
  56. const basicForm = await basicInfo?.elFormRef?.validate()?.catch(() => {})
  57. if (basicForm) {
  58. const basicInfoData = (await basicInfo?.getFormData()) as CodegenTableVO
  59. const genTable: CodegenUpdateReqVO = {
  60. table: basicInfoData,
  61. columns: cloumCurrentRow.value
  62. }
  63. await updateCodegenTableApi(genTable)
  64. message.success(t('common.updateSuccess'))
  65. push('/infra/codegen')
  66. }
  67. }
  68. onMounted(() => {
  69. getList()
  70. })
  71. </script>