EditTable.vue 2.5 KB

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