EditTable.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 { useI18n } from '@/hooks/web/useI18n'
  25. import { useMessage } from '@/hooks/web/useMessage'
  26. import { BasicInfoForm, CloumInfoForm } from './components'
  27. import { getCodegenTableApi, updateCodegenTableApi } from '@/api/infra/codegen'
  28. import { CodegenTableVO, CodegenColumnVO, CodegenUpdateReqVO } from '@/api/infra/codegen/types'
  29. const { t } = useI18n() // 国际化
  30. const message = useMessage() // 消息弹窗
  31. const { push } = useRouter()
  32. const { query } = useRoute()
  33. const loading = ref(false)
  34. const title = ref('代码生成')
  35. const activeName = ref('basicInfo')
  36. const cloumInfoRef = ref(null)
  37. const tableCurrentRow = ref<CodegenTableVO>()
  38. const cloumCurrentRow = ref<CodegenColumnVO[]>([])
  39. const basicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>()
  40. const getList = async () => {
  41. const id = query.id as unknown as number
  42. if (id) {
  43. // 获取表详细信息
  44. const res = await getCodegenTableApi(id)
  45. title.value = '修改[ ' + res.table.tableName + ' ]生成配置'
  46. tableCurrentRow.value = res.table
  47. cloumCurrentRow.value = res.columns
  48. }
  49. }
  50. const submitForm = async () => {
  51. const basicInfo = unref(basicInfoRef)
  52. const basicForm = await basicInfo?.elFormRef?.validate()?.catch(() => {})
  53. if (basicForm) {
  54. const basicInfoData = (await basicInfo?.getFormData()) as CodegenTableVO
  55. const genTable: CodegenUpdateReqVO = {
  56. table: basicInfoData,
  57. columns: cloumCurrentRow.value
  58. }
  59. await updateCodegenTableApi(genTable)
  60. message.success(t('common.updateSuccess'))
  61. push('/infra/codegen')
  62. }
  63. }
  64. onMounted(() => {
  65. getList()
  66. })
  67. </script>