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