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

74 lines
2.5 KiB
Vue
Raw Normal View History

2022-11-23 13:59:13 +08:00
<template>
2022-12-08 23:02:47 +08:00
<ContentWrap>
<ContentDetailWrap :title="title" @back="push('/infra/codegen')">
<el-tabs v-model="activeName">
<el-tab-pane label="基本信息" name="basicInfo">
<BasicInfoForm ref="basicInfoRef" :basicInfo="tableCurrentRow" />
</el-tab-pane>
<el-tab-pane label="字段信息" name="cloum">
<CloumInfoForm ref="cloumInfoRef" :info="cloumCurrentRow" />
</el-tab-pane>
</el-tabs>
<template #right>
<XButton
type="primary"
:title="t('action.save')"
:loading="loading"
@click="submitForm()"
/>
</template>
</ContentDetailWrap>
</ContentWrap>
2022-11-23 13:59:13 +08:00
</template>
2022-07-18 19:06:37 +08:00
<script setup lang="ts">
import { ref, unref, onMounted } from 'vue'
2022-11-23 13:59:13 +08:00
import { useRouter, useRoute } from 'vue-router'
import { ElTabs, ElTabPane } from 'element-plus'
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { ContentDetailWrap } from '@/components/ContentDetailWrap'
2023-01-13 23:58:14 +08:00
import { BasicInfoForm, CloumInfoForm } from './components'
2022-07-28 21:40:15 +08:00
import { getCodegenTableApi, updateCodegenTableApi } from '@/api/infra/codegen'
import { CodegenTableVO, CodegenColumnVO, CodegenUpdateReqVO } from '@/api/infra/codegen/types'
2022-11-23 13:59:13 +08:00
const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
2022-07-18 19:06:37 +08:00
const { push } = useRouter()
const { query } = useRoute()
2022-11-28 22:20:12 +08:00
const loading = ref(false)
const title = ref('代码生成')
2023-01-13 23:58:14 +08:00
const activeName = ref('basicInfo')
2022-11-28 22:20:12 +08:00
const cloumInfoRef = ref(null)
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-11-28 22:20:12 +08:00
const basicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>()
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)
2022-11-28 22:20:12 +08:00
title.value = '修改[ ' + res.table.tableName + ' ]生成配置'
2023-01-14 00:03:02 +08:00
tableCurrentRow.value = res.table
2022-07-18 19:06:37 +08:00
cloumCurrentRow.value = res.columns
}
}
const submitForm = async () => {
const basicInfo = unref(basicInfoRef)
2022-07-28 21:40:15 +08:00
const basicForm = await basicInfo?.elFormRef?.validate()?.catch(() => {})
2023-01-13 23:58:14 +08:00
if (basicForm) {
2022-07-18 19:06:37 +08:00
const basicInfoData = (await basicInfo?.getFormData()) as CodegenTableVO
const genTable: CodegenUpdateReqVO = {
2023-01-13 23:58:14 +08:00
table: basicInfoData,
columns: cloumCurrentRow.value
}
2022-07-28 21:40:15 +08:00
await updateCodegenTableApi(genTable)
2022-11-23 13:59:13 +08:00
message.success(t('common.updateSuccess'))
2022-07-28 21:40:15 +08:00
push('/infra/codegen')
2022-07-18 19:06:37 +08:00
}
}
onMounted(() => {
getList()
})
</script>