EditTable.vue 2.5 KB

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