EditTable.vue 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <content-wrap v-loading="loading">
  3. <el-tabs v-model="activeName">
  4. <el-tab-pane label="基本信息" name="basicInfo">
  5. <basic-info-form ref="basicInfoRef" :table="formData.table" />
  6. </el-tab-pane>
  7. <el-tab-pane label="字段信息" name="colum">
  8. <colum-info-form ref="columInfoRef" :columns="formData.columns" />
  9. </el-tab-pane>
  10. <el-tab-pane label="生成信息" name="generateInfo">
  11. <generate-info-form ref="generateInfoRef" :table="formData.table" />
  12. </el-tab-pane>
  13. </el-tabs>
  14. <el-form label-width="100px">
  15. <el-form-item style="text-align: center; margin-left: -100px; margin-top: 10px">
  16. <el-button type="primary" @click="submitForm" :loading="submitLoading">
  17. {{ t('action.save') }}
  18. </el-button>
  19. <el-button @click="close">{{ t('action.back') }}</el-button>
  20. </el-form-item>
  21. </el-form>
  22. </content-wrap>
  23. </template>
  24. <script setup lang="ts">
  25. import { BasicInfoForm, ColumInfoForm, GenerateInfoForm } from './components'
  26. import * as CodegenApi from '@/api/infra/codegen'
  27. import ContentWrap from '@/components/ContentWrap/src/ContentWrap.vue'
  28. import { useTagsViewStore } from '@/store/modules/tagsView'
  29. import { CodegenUpdateReqVO } from '@/api/infra/codegen/types'
  30. const { t } = useI18n() // 国际化
  31. const message = useMessage() // 消息弹窗
  32. const { push, currentRoute } = useRouter()
  33. const { query } = useRoute()
  34. const { delView } = useTagsViewStore()
  35. const loading = ref(false)
  36. const submitLoading = ref(false)
  37. const activeName = ref('basicInfo')
  38. const basicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>()
  39. const columInfoRef = ref<ComponentRef<typeof ColumInfoForm>>()
  40. const generateInfoRef = ref<ComponentRef<typeof GenerateInfoForm>>()
  41. const formData = ref<CodegenUpdateReqVO>({
  42. table: {},
  43. columns: []
  44. })
  45. const getDetail = async () => {
  46. const id = query.id as unknown as number
  47. if (id) {
  48. loading.value = true
  49. // 获取表详细信息
  50. formData.value = await CodegenApi.getCodegenTable(id)
  51. loading.value = false
  52. }
  53. }
  54. const submitForm = async () => {
  55. if (!unref(formData)) return
  56. try {
  57. await unref(basicInfoRef)?.validate()
  58. await unref(generateInfoRef)?.validate()
  59. await CodegenApi.updateCodegenTable(unref(formData))
  60. message.success(t('common.updateSuccess'))
  61. push('/infra/codegen')
  62. } catch {}
  63. }
  64. /** 关闭按钮 */
  65. const close = () => {
  66. delView(unref(currentRoute))
  67. push('/infra/codegen')
  68. }
  69. onMounted(() => {
  70. getDetail()
  71. })
  72. </script>