ShiShiYiBan/yudao-ui-admin-vue3/src/views/infra/codegen/EditTable.vue

79 lines
2.9 KiB
Vue
Raw Normal View History

2022-07-18 19:06:37 +08:00
<script setup lang="ts">
import { ref, unref, onMounted } from 'vue'
import { ContentDetailWrap } from '@/components/ContentDetailWrap'
2022-07-28 21:40:15 +08:00
import { BasicInfoForm, CloumInfoForm, GenInfoForm } from './components'
import { ElTabs, ElTabPane, ElButton, ElMessage } from 'element-plus'
import { getCodegenTableApi, updateCodegenTableApi } from '@/api/infra/codegen'
2022-07-18 19:06:37 +08:00
import { useRouter, useRoute } from 'vue-router'
import { useI18n } from '@/hooks/web/useI18n'
2022-07-28 21:40:15 +08:00
import { CodegenTableVO, CodegenColumnVO, CodegenUpdateReqVO } from '@/api/infra/codegen/types'
2022-07-18 19:06:37 +08:00
const { t } = useI18n()
const { push } = useRouter()
const { query } = useRoute()
2022-07-28 21:40:15 +08:00
const tableCurrentRow = ref<CodegenTableVO>()
2022-08-08 19:06:46 +08:00
const cloumCurrentRow = ref<CodegenColumnVO[]>([])
2022-07-18 19:06:37 +08:00
const getList = async () => {
const id = query.id as unknown as number
if (id) {
// 获取表详细信息
const res = await getCodegenTableApi(id)
tableCurrentRow.value = res.table
cloumCurrentRow.value = res.columns
}
}
const loading = ref(false)
const activeName = ref('cloum')
const basicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>()
2022-07-28 21:40:15 +08:00
const genInfoRef = ref<ComponentRef<typeof GenInfoForm>>()
const cloumInfoRef = ref(null)
2022-10-14 17:52:04 +08:00
const parentMenuId = ref<number>()
const menu = (id: number) => {
parentMenuId.value = id
}
2022-07-18 19:06:37 +08:00
const submitForm = async () => {
const basicInfo = unref(basicInfoRef)
const genInfo = unref(genInfoRef)
2022-07-28 21:40:15 +08:00
const basicForm = await basicInfo?.elFormRef?.validate()?.catch(() => {})
const genForm = await genInfo?.elFormRef?.validate()?.catch(() => {})
if (basicForm && genForm) {
2022-07-18 19:06:37 +08:00
const basicInfoData = (await basicInfo?.getFormData()) as CodegenTableVO
const genInfoData = (await genInfo?.getFormData()) as CodegenTableVO
2022-07-28 21:40:15 +08:00
const genTable: CodegenUpdateReqVO = {
table: Object.assign({}, basicInfoData, genInfoData),
columns: cloumCurrentRow.value
}
2022-10-14 17:52:04 +08:00
if (parentMenuId.value) {
genInfoData.parentMenuId = parentMenuId.value
} else {
genInfoData.parentMenuId = 0
}
2022-07-28 21:40:15 +08:00
await updateCodegenTableApi(genTable)
ElMessage.success(t('common.updateSuccess'))
push('/infra/codegen')
2022-07-18 19:06:37 +08:00
}
}
onMounted(() => {
getList()
})
</script>
<template>
<ContentDetailWrap title="代码生成" @back="push('/infra/codegen')">
<el-tabs v-model="activeName">
2022-07-28 21:40:15 +08:00
<el-tab-pane label="基本信息" name="basicInfo">
<BasicInfoForm ref="basicInfoRef" :basicInfo="tableCurrentRow" />
2022-07-18 19:06:37 +08:00
</el-tab-pane>
<el-tab-pane label="字段信息" name="cloum">
2022-07-28 21:40:15 +08:00
<CloumInfoForm ref="cloumInfoRef" :info="cloumCurrentRow" />
2022-07-18 19:06:37 +08:00
</el-tab-pane>
<el-tab-pane label="生成信息" name="genInfo">
2022-10-14 17:52:04 +08:00
<GenInfoForm ref="genInfoRef" :genInfo="tableCurrentRow" @menu="menu" />
2022-07-18 19:06:37 +08:00
</el-tab-pane>
</el-tabs>
<template #right>
<el-button type="primary" :loading="loading" @click="submitForm">
{{ t('action.save') }}
</el-button>
</template>
</ContentDetailWrap>
</template>