|
1 | 1 | <template>
|
2 |
| - <ContentWrap> |
3 |
| - <ContentDetailWrap :title="title" @back="push('/infra/codegen')"> |
4 |
| - <el-tabs v-model="activeName"> |
5 |
| - <el-tab-pane label="基本信息" name="basicInfo"> |
6 |
| - <BasicInfoForm ref="basicInfoRef" :basicInfo="tableCurrentRow" /> |
7 |
| - </el-tab-pane> |
8 |
| - <el-tab-pane label="字段信息" name="cloum"> |
9 |
| - <CloumInfoForm ref="cloumInfoRef" :info="cloumCurrentRow" /> |
10 |
| - </el-tab-pane> |
11 |
| - </el-tabs> |
12 |
| - <template #right> |
13 |
| - <XButton |
14 |
| - type="primary" |
15 |
| - :title="t('action.save')" |
16 |
| - :loading="loading" |
17 |
| - @click="submitForm()" |
18 |
| - /> |
19 |
| - </template> |
20 |
| - </ContentDetailWrap> |
21 |
| - </ContentWrap> |
| 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> |
22 | 23 | </template>
|
23 | 24 | <script setup lang="ts">
|
24 |
| -import { BasicInfoForm, CloumInfoForm } from './components' |
25 |
| -import { getCodegenTableApi, updateCodegenTableApi } from '@/api/infra/codegen' |
26 |
| -import { CodegenTableVO, CodegenColumnVO, CodegenUpdateReqVO } from '@/api/infra/codegen/types' |
| 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' |
27 | 30 |
|
28 | 31 | const { t } = useI18n() // 国际化
|
29 | 32 | const message = useMessage() // 消息弹窗
|
30 |
| -const { push } = useRouter() |
| 33 | +const { push, currentRoute } = useRouter() |
31 | 34 | const { query } = useRoute()
|
| 35 | +const { delView } = useTagsViewStore() |
32 | 36 | const loading = ref(false)
|
33 |
| -const title = ref('代码生成') |
| 37 | +const submitLoading = ref(false) |
34 | 38 | const activeName = ref('basicInfo')
|
35 |
| -const cloumInfoRef = ref(null) |
36 |
| -const tableCurrentRow = ref<CodegenTableVO>() |
37 |
| -const cloumCurrentRow = ref<CodegenColumnVO[]>([]) |
38 | 39 | const basicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>()
|
| 40 | +const columInfoRef = ref<ComponentRef<typeof ColumInfoForm>>() |
| 41 | +const generateInfoRef = ref<ComponentRef<typeof GenerateInfoForm>>() |
| 42 | +const formData = ref<CodegenUpdateReqVO>({ |
| 43 | + table: {}, |
| 44 | + columns: [] |
| 45 | +}) |
39 | 46 |
|
40 |
| -const getList = async () => { |
| 47 | +const getDetail = async () => { |
41 | 48 | const id = query.id as unknown as number
|
42 | 49 | if (id) {
|
| 50 | + loading.value = true |
43 | 51 | // 获取表详细信息
|
44 |
| - const res = await getCodegenTableApi(id) |
45 |
| - title.value = '修改[ ' + res.table.tableName + ' ]生成配置' |
46 |
| - tableCurrentRow.value = res.table |
47 |
| - cloumCurrentRow.value = res.columns |
| 52 | + formData.value = await CodegenApi.getCodegenTable(id) |
| 53 | + loading.value = false |
48 | 54 | }
|
49 | 55 | }
|
50 | 56 | const submitForm = async () => {
|
51 |
| - const basicInfo = unref(basicInfoRef) |
52 |
| - const basicForm = await basicInfo?.elFormRef?.validate()?.catch(() => {}) |
53 |
| - if (basicForm) { |
54 |
| - const basicInfoData = (await basicInfo?.getFormData()) as CodegenTableVO |
55 |
| - const genTable: CodegenUpdateReqVO = { |
56 |
| - table: basicInfoData, |
57 |
| - columns: cloumCurrentRow.value |
58 |
| - } |
59 |
| - await updateCodegenTableApi(genTable) |
| 57 | + if (!unref(formData)) return |
| 58 | + try { |
| 59 | + await unref(basicInfoRef)?.validate() |
| 60 | + await unref(generateInfoRef)?.validate() |
| 61 | + await CodegenApi.updateCodegenTable(unref(formData)) |
60 | 62 | message.success(t('common.updateSuccess'))
|
61 | 63 | push('/infra/codegen')
|
62 |
| - } |
| 64 | + } catch {} |
| 65 | +} |
| 66 | +/** 关闭按钮 */ |
| 67 | +const close = () => { |
| 68 | + delView(unref(currentRoute)) |
| 69 | + push('/infra/codegen') |
63 | 70 | }
|
64 | 71 | onMounted(() => {
|
65 |
| - getList() |
| 72 | + getDetail() |
66 | 73 | })
|
67 | 74 | </script>
|
0 commit comments