EditTable.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <ContentWrap v-loading="formLoading">
  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>
  15. <el-form-item style="float: right">
  16. <el-button :loading="formLoading" type="primary" @click="submitForm">保存</el-button>
  17. <el-button @click="close">返回</el-button>
  18. </el-form-item>
  19. </el-form>
  20. </ContentWrap>
  21. </template>
  22. <script lang="ts" name="InfraCodegenEditTable" setup>
  23. import { useTagsViewStore } from '@/store/modules/tagsView'
  24. import { BasicInfoForm, ColumInfoForm, GenerateInfoForm } from './components'
  25. import * as CodegenApi from '@/api/infra/codegen'
  26. const { t } = useI18n() // 国际化
  27. const message = useMessage() // 消息弹窗
  28. const { push, currentRoute } = useRouter() // 路由
  29. const { query } = useRoute() // 查询参数
  30. const { delView } = useTagsViewStore() // 视图操作
  31. const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
  32. const activeName = ref('colum') // Tag 激活的窗口
  33. const basicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>()
  34. const columInfoRef = ref<ComponentRef<typeof ColumInfoForm>>()
  35. const generateInfoRef = ref<ComponentRef<typeof GenerateInfoForm>>()
  36. const formData = ref<CodegenApi.CodegenUpdateReqVO>({
  37. table: {},
  38. columns: []
  39. })
  40. /** 获得详情 */
  41. const getDetail = async () => {
  42. const id = query.id as unknown as number
  43. if (!id) {
  44. return
  45. }
  46. formLoading.value = true
  47. try {
  48. formData.value = await CodegenApi.getCodegenTable(id)
  49. } finally {
  50. formLoading.value = false
  51. }
  52. }
  53. /** 提交按钮 */
  54. const submitForm = async () => {
  55. // 参数校验
  56. if (!unref(formData)) return
  57. await unref(basicInfoRef)?.validate()
  58. await unref(generateInfoRef)?.validate()
  59. try {
  60. // 提交请求
  61. await CodegenApi.updateCodegenTable(formData.value)
  62. message.success(t('common.updateSuccess'))
  63. close()
  64. } catch {}
  65. }
  66. /** 关闭按钮 */
  67. const close = () => {
  68. delView(unref(currentRoute))
  69. push('/infra/codegen')
  70. }
  71. /** 初始化 */
  72. onMounted(() => {
  73. getDetail()
  74. })
  75. </script>