EditTable.vue 2.2 KB

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