EditTable.vue 2.9 KB

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