Commit 291f31be98f5586a7265413a3b084c18b241c2ac

Authored by xingyu
1 parent 607f6e4b

refactor: codegen

yudao-ui-admin-vue3/src/api/infra/codegen/index.ts
1 1 import { useAxios } from '@/hooks/web/useAxios'
2   -import type { CodegenTableVO } from './types'
  2 +import type { CodegenUpdateReqVO, CodegenCreateListReqVO } from './types'
3 3  
4 4 const request = useAxios()
5 5  
... ... @@ -14,12 +14,12 @@ export const getCodegenTableApi = (id: number) => {
14 14 }
15 15  
16 16 // 新增代码生成表定义
17   -export const createCodegenTableApi = (data: CodegenTableVO) => {
  17 +export const createCodegenTableApi = (data: CodegenCreateListReqVO) => {
18 18 return request.post({ url: '/infra/codegen/create', data })
19 19 }
20 20  
21 21 // 修改代码生成表定义
22   -export const updateCodegenTableApi = (data: CodegenTableVO) => {
  22 +export const updateCodegenTableApi = (data: CodegenUpdateReqVO) => {
23 23 return request.put({ url: '/infra/codegen/update', data })
24 24 }
25 25  
... ...
yudao-ui-admin-vue3/src/api/infra/codegen/types.ts
1 1 export type CodegenTableVO = {
2   - id: number
  2 + tableId: number
  3 + isParentMenuIdValid: boolean
3 4 dataSourceConfigId: number
4 5 scene: number
5 6 tableName: string
... ... @@ -49,3 +50,11 @@ export type CodegenPreviewVO = {
49 50 filePath: string
50 51 code: string
51 52 }
  53 +export type CodegenUpdateReqVO = {
  54 + table: CodegenTableVO
  55 + columns: CodegenColumnVO[]
  56 +}
  57 +export type CodegenCreateListReqVO = {
  58 + dataSourceConfigId: number
  59 + tableNames: string[]
  60 +}
... ...
yudao-ui-admin-vue3/src/components/DictTag/src/DictTag.vue
1   -<script lang="ts">
2   -import { defineComponent, onMounted, onUpdated, PropType, ref } from 'vue'
  1 +<script setup lang="ts">
  2 +import { onMounted, onUpdated, PropType, ref } from 'vue'
3 3 import { getDictOptions, DictDataType } from '@/utils/dict'
4 4 import { ElTag } from 'element-plus'
5   -
6   -export default defineComponent({
7   - name: 'DictTag',
8   - components: {
9   - ElTag
10   - },
11   - props: {
12   - type: {
13   - type: String as PropType<string>,
14   - required: true
15   - },
16   - value: {
17   - type: [String, Number] as PropType<string | number>,
18   - required: true
19   - }
  5 +const props = defineProps({
  6 + type: {
  7 + type: String as PropType<string>,
  8 + required: true
20 9 },
21   - setup(props) {
22   - const dictData = ref<DictDataType>()
23   - function getDictObj(dictType: string, value: string) {
24   - const dictOptions = getDictOptions(dictType)
25   - dictOptions.forEach((dict: DictDataType) => {
26   - if (dict.value === value) {
27   - dictData.value = dict
28   - }
29   - })
  10 + value: {
  11 + type: [String, Number] as PropType<string | number>,
  12 + required: true
  13 + }
  14 +})
  15 +const dictData = ref<DictDataType>()
  16 +const getDictObj = (dictType: string, value: string) => {
  17 + const dictOptions = getDictOptions(dictType)
  18 + dictOptions.forEach((dict: DictDataType) => {
  19 + if (dict.value === value) {
  20 + dictData.value = dict
30 21 }
  22 + })
  23 +}
31 24  
32   - onMounted(() => {
33   - return getDictObj(props.type, props.value?.toString())
34   - })
  25 +onMounted(() => {
  26 + return getDictObj(props.type, props.value?.toString())
  27 +})
35 28  
36   - onUpdated(() => {
37   - getDictObj(props.type, props.value?.toString())
38   - })
39   - return {
40   - props,
41   - dictData
42   - }
43   - }
  29 +onUpdated(() => {
  30 + getDictObj(props.type, props.value?.toString())
44 31 })
45 32 </script>
46 33 <template>
... ...
yudao-ui-admin-vue3/src/views/infra/codegen/components/EditTable.vue renamed to yudao-ui-admin-vue3/src/views/infra/codegen/EditTable.vue
1 1 <script setup lang="ts">
2 2 import { ref, unref, onMounted } from 'vue'
3 3 import { ContentDetailWrap } from '@/components/ContentDetailWrap'
4   -import BasicInfoForm from './BasicInfoForm.vue'
5   -import CloumInfoFormVue from './CloumInfoForm.vue'
6   -import GenInfoFormVue from './GenInfoForm.vue'
7   -import { ElTabs, ElTabPane, ElButton } from 'element-plus'
8   -import { getCodegenTableApi } from '@/api/infra/codegen'
  4 +import { BasicInfoForm, CloumInfoForm, GenInfoForm } from './components'
  5 +import { ElTabs, ElTabPane, ElButton, ElMessage } from 'element-plus'
  6 +import { getCodegenTableApi, updateCodegenTableApi } from '@/api/infra/codegen'
9 7 import { useRouter, useRoute } from 'vue-router'
10 8 import { useI18n } from '@/hooks/web/useI18n'
11   -import { CodegenColumnVO, CodegenTableVO } from '@/api/infra/codegen/types'
  9 +import { CodegenTableVO, CodegenColumnVO, CodegenUpdateReqVO } from '@/api/infra/codegen/types'
12 10 const { t } = useI18n()
13 11 const { push } = useRouter()
14 12 const { query } = useRoute()
15   -const tableCurrentRow = ref<Nullable<CodegenTableVO>>(null)
  13 +const tableCurrentRow = ref<CodegenTableVO>()
16 14 const cloumCurrentRow = ref<CodegenColumnVO[]>()
17 15 const getList = async () => {
18 16 const id = query.id as unknown as number
... ... @@ -26,17 +24,23 @@ const getList = async () =&gt; {
26 24 const loading = ref(false)
27 25 const activeName = ref('cloum')
28 26 const basicInfoRef = ref<ComponentRef<typeof BasicInfoForm>>()
29   -const genInfoRef = ref<ComponentRef<typeof GenInfoFormVue>>()
  27 +const genInfoRef = ref<ComponentRef<typeof GenInfoForm>>()
  28 +const cloumInfoRef = ref(null)
30 29 const submitForm = async () => {
31 30 const basicInfo = unref(basicInfoRef)
32 31 const genInfo = unref(genInfoRef)
33   - const basicValidate = await basicInfo?.elFormRef?.validate()?.catch(() => {})
34   - const genValidate = await genInfo?.elFormRef?.validate()?.catch(() => {})
35   - if (basicValidate && genValidate) {
  32 + const basicForm = await basicInfo?.elFormRef?.validate()?.catch(() => {})
  33 + const genForm = await genInfo?.elFormRef?.validate()?.catch(() => {})
  34 + if (basicForm && genForm) {
36 35 const basicInfoData = (await basicInfo?.getFormData()) as CodegenTableVO
37 36 const genInfoData = (await genInfo?.getFormData()) as CodegenTableVO
38   - console.info(basicInfoData)
39   - console.info(genInfoData)
  37 + const genTable: CodegenUpdateReqVO = {
  38 + table: Object.assign({}, basicInfoData, genInfoData),
  39 + columns: cloumCurrentRow.value
  40 + }
  41 + await updateCodegenTableApi(genTable)
  42 + ElMessage.success(t('common.updateSuccess'))
  43 + push('/infra/codegen')
40 44 }
41 45 }
42 46 onMounted(() => {
... ... @@ -46,14 +50,14 @@ onMounted(() =&gt; {
46 50 <template>
47 51 <ContentDetailWrap title="代码生成" @back="push('/infra/codegen')">
48 52 <el-tabs v-model="activeName">
49   - <el-tab-pane label="基本信息" name="basic">
50   - <BasicInfoForm ref="basicInfoRef" :current-row="tableCurrentRow" />
  53 + <el-tab-pane label="基本信息" name="basicInfo">
  54 + <BasicInfoForm ref="basicInfoRef" :basicInfo="tableCurrentRow" />
51 55 </el-tab-pane>
52 56 <el-tab-pane label="字段信息" name="cloum">
53   - <CloumInfoFormVue ref="cloumInfoRef" :current-row="cloumCurrentRow" />
  57 + <CloumInfoForm ref="cloumInfoRef" :info="cloumCurrentRow" />
54 58 </el-tab-pane>
55 59 <el-tab-pane label="生成信息" name="genInfo">
56   - <GenInfoFormVue ref="basicInfoRef" :current-row="tableCurrentRow" />
  60 + <GenInfoForm ref="genInfoRef" :genInfo="tableCurrentRow" />
57 61 </el-tab-pane>
58 62 </el-tabs>
59 63 <template #right>
... ...
yudao-ui-admin-vue3/src/views/infra/codegen/components/BasicInfoForm.vue
... ... @@ -5,7 +5,7 @@ import { CodegenTableVO } from &#39;@/api/infra/codegen/types&#39;
5 5 import { Form } from '@/components/Form'
6 6 import { useForm } from '@/hooks/web/useForm'
7 7 const props = defineProps({
8   - currentRow: {
  8 + basicInfo: {
9 9 type: Object as PropType<Nullable<CodegenTableVO>>,
10 10 default: () => null
11 11 }
... ... @@ -66,11 +66,11 @@ const { register, methods, elFormRef } = useForm({
66 66 schema
67 67 })
68 68 watch(
69   - () => props.currentRow,
70   - (currentRow) => {
71   - if (!currentRow) return
  69 + () => props.basicInfo,
  70 + (basicInfo) => {
  71 + if (!basicInfo) return
72 72 const { setValues } = methods
73   - setValues(currentRow)
  73 + setValues(basicInfo)
74 74 },
75 75 {
76 76 deep: true,
... ...
yudao-ui-admin-vue3/src/views/infra/codegen/components/CloumInfoForm.vue
... ... @@ -4,8 +4,8 @@ import { onMounted, PropType, ref } from &#39;vue&#39;
4 4 import { CodegenColumnVO } from '@/api/infra/codegen/types'
5 5 import { listSimpleDictTypeApi } from '@/api/system/dict/dict.type'
6 6 import { DictTypeVO } from '@/api/system/dict/types'
7   -defineProps({
8   - currentRow: {
  7 +const props = defineProps({
  8 + info: {
9 9 type: Array as unknown as PropType<CodegenColumnVO[]>,
10 10 default: () => null
11 11 }
... ... @@ -20,18 +20,21 @@ const tableHeight = document.documentElement.scrollHeight - 245 + &#39;px&#39;
20 20 onMounted(async () => {
21 21 await getDictOptions()
22 22 })
  23 +defineExpose({
  24 + info: props.info
  25 +})
23 26 </script>
24 27 <template>
25   - <el-table ref="dragTable" :data="currentRow" row-key="columnId" :max-height="tableHeight">
  28 + <el-table ref="dragTable" :data="info" row-key="columnId" :max-height="tableHeight">
26 29 <el-table-column
27 30 label="字段列名"
28 31 prop="columnName"
29 32 min-width="10%"
30 33 :show-overflow-tooltip="true"
31 34 />
32   - <el-table-column label="字段描述" min-width="10%">
33   - <template #default="scope">
34   - <el-input v-model="scope.row.columnComment" />
  35 + <el-table-column label="字段描述" min-width="10%" prop="columnComment">
  36 + <template #default="{ row }">
  37 + <el-input v-model="row.columnComment" />
35 38 </template>
36 39 </el-table-column>
37 40 <el-table-column
... ... @@ -40,9 +43,9 @@ onMounted(async () =&gt; {
40 43 min-width="10%"
41 44 :show-overflow-tooltip="true"
42 45 />
43   - <el-table-column label="Java类型" min-width="11%">
44   - <template #default="scope">
45   - <el-select v-model="scope.row.javaType">
  46 + <el-table-column label="Java类型" min-width="11%" prop="javaType">
  47 + <template #default="{ row }">
  48 + <el-select v-model="row.javaType">
46 49 <el-option label="Long" value="Long" />
47 50 <el-option label="String" value="String" />
48 51 <el-option label="Integer" value="Integer" />
... ... @@ -53,38 +56,34 @@ onMounted(async () =&gt; {
53 56 </el-select>
54 57 </template>
55 58 </el-table-column>
56   - <el-table-column label="java属性" min-width="10%">
57   - <template #default="scope">
58   - <el-input v-model="scope.row.javaField" />
  59 + <el-table-column label="java属性" min-width="10%" prop="javaField">
  60 + <template #default="{ row }">
  61 + <el-input v-model="row.javaField" />
59 62 </template>
60 63 </el-table-column>
61   - <el-table-column label="插入" min-width="4%">
62   - <template #default="scope">
63   - <el-checkbox true-label="true" false-label="false" v-model="scope.row.createOperation" />
  64 + <el-table-column label="插入" min-width="4%" prop="createOperation">
  65 + <template #default="{ row }">
  66 + <el-checkbox true-label="true" false-label="false" v-model="row.createOperation" />
64 67 </template>
65 68 </el-table-column>
66   - <el-table-column label="编辑" min-width="4%">
67   - <template #default="scope">
68   - <el-checkbox true-label="true" false-label="false" v-model="scope.row.updateOperation" />
  69 + <el-table-column label="编辑" min-width="4%" prop="updateOperation">
  70 + <template #default="{ row }">
  71 + <el-checkbox true-label="true" false-label="false" v-model="row.updateOperation" />
69 72 </template>
70 73 </el-table-column>
71   - <el-table-column label="列表" min-width="4%">
72   - <template #default="scope">
73   - <el-checkbox
74   - true-label="true"
75   - false-label="false"
76   - v-model="scope.row.listOperationResult"
77   - />
  74 + <el-table-column label="列表" min-width="4%" prop="listOperationResult">
  75 + <template #default="{ row }">
  76 + <el-checkbox true-label="true" false-label="false" v-model="row.listOperationResult" />
78 77 </template>
79 78 </el-table-column>
80   - <el-table-column label="查询" min-width="4%">
81   - <template #default="scope">
82   - <el-checkbox true-label="true" false-label="false" v-model="scope.row.listOperation" />
  79 + <el-table-column label="查询" min-width="4%" prop="listOperation">
  80 + <template #default="{ row }">
  81 + <el-checkbox true-label="true" false-label="false" v-model="row.listOperation" />
83 82 </template>
84 83 </el-table-column>
85   - <el-table-column label="查询方式" min-width="10%">
86   - <template #default="scope">
87   - <el-select v-model="scope.row.listOperationCondition">
  84 + <el-table-column label="查询方式" min-width="10%" prop="listOperationCondition">
  85 + <template #default="{ row }">
  86 + <el-select v-model="row.listOperationCondition">
88 87 <el-option label="=" value="=" />
89 88 <el-option label="!=" value="!=" />
90 89 <el-option label=">" value=">" />
... ... @@ -96,14 +95,14 @@ onMounted(async () =&gt; {
96 95 </el-select>
97 96 </template>
98 97 </el-table-column>
99   - <el-table-column label="允许空" min-width="5%">
100   - <template #default="scope">
101   - <el-checkbox true-label="true" false-label="false" v-model="scope.row.nullable" />
  98 + <el-table-column label="允许空" min-width="5%" prop="nullable">
  99 + <template #default="{ row }">
  100 + <el-checkbox true-label="true" false-label="false" v-model="row.nullable" />
102 101 </template>
103 102 </el-table-column>
104   - <el-table-column label="显示类型" min-width="12%">
105   - <template #default="scope">
106   - <el-select v-model="scope.row.htmlType">
  103 + <el-table-column label="显示类型" min-width="12%" prop="htmlType">
  104 + <template #default="{ row }">
  105 + <el-select v-model="row.htmlType">
107 106 <el-option label="文本框" value="input" />
108 107 <el-option label="文本域" value="textarea" />
109 108 <el-option label="下拉框" value="select" />
... ... @@ -116,9 +115,9 @@ onMounted(async () =&gt; {
116 115 </el-select>
117 116 </template>
118 117 </el-table-column>
119   - <el-table-column label="字典类型" min-width="12%">
120   - <template #default="scope">
121   - <el-select v-model="scope.row.dictType" clearable filterable placeholder="请选择">
  118 + <el-table-column label="字典类型" min-width="12%" prop="dictType">
  119 + <template #default="{ row }">
  120 + <el-select v-model="row.dictType" clearable filterable placeholder="请选择">
122 121 <el-option
123 122 v-for="dict in dictOptions"
124 123 :key="dict.id"
... ... @@ -128,9 +127,9 @@ onMounted(async () =&gt; {
128 127 </el-select>
129 128 </template>
130 129 </el-table-column>
131   - <el-table-column label="示例" min-width="10%">
132   - <template #default="scope">
133   - <el-input v-model="scope.row.example" />
  130 + <el-table-column label="示例" min-width="10%" prop="example">
  131 + <template #default="{ row }">
  132 + <el-input v-model="row.example" />
134 133 </template>
135 134 </el-table-column>
136 135 </el-table>
... ...
yudao-ui-admin-vue3/src/views/infra/codegen/components/GenInfoForm.vue
... ... @@ -4,9 +4,9 @@ import { required } from &#39;@/utils/formRules&#39;
4 4 import { CodegenTableVO } from '@/api/infra/codegen/types'
5 5 import { Form } from '@/components/Form'
6 6 import { useForm } from '@/hooks/web/useForm'
7   -import { DICT_TYPE, getDictOptions } from '@/utils/dict'
  7 +import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
8 8 const props = defineProps({
9   - currentRow: {
  9 + genInfo: {
10 10 type: Object as PropType<Nullable<CodegenTableVO>>,
11 11 default: () => null
12 12 }
... ... @@ -20,13 +20,15 @@ const rules = reactive({
20 20 className: [required],
21 21 classComment: [required]
22 22 })
  23 +const templateTypeOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE)
  24 +const sceneOptions = getIntDictOptions(DICT_TYPE.INFRA_CODEGEN_SCENE)
23 25 const schema = reactive<FormSchema[]>([
24 26 {
25 27 label: '生成模板',
26 28 field: 'templateType',
27 29 component: 'Select',
28 30 componentProps: {
29   - options: getDictOptions(DICT_TYPE.INFRA_CODEGEN_TEMPLATE_TYPE)
  31 + options: templateTypeOptions
30 32 },
31 33 colProps: {
32 34 span: 12
... ... @@ -37,7 +39,7 @@ const schema = reactive&lt;FormSchema[]&gt;([
37 39 field: 'scene',
38 40 component: 'Select',
39 41 componentProps: {
40   - options: getDictOptions(DICT_TYPE.INFRA_CODEGEN_SCENE)
  42 + options: sceneOptions
41 43 },
42 44 colProps: {
43 45 span: 12
... ... @@ -93,11 +95,11 @@ const { register, methods, elFormRef } = useForm({
93 95 schema
94 96 })
95 97 watch(
96   - () => props.currentRow,
97   - (currentRow) => {
98   - if (!currentRow) return
  98 + () => props.genInfo,
  99 + (genInfo) => {
  100 + if (!genInfo) return
99 101 const { setValues } = methods
100   - setValues(currentRow)
  102 + setValues(genInfo)
101 103 },
102 104 {
103 105 deep: true,
... ...
yudao-ui-admin-vue3/src/views/infra/codegen/components/ImportTable.vue
... ... @@ -21,8 +21,8 @@ const emit = defineEmits([&#39;ok&#39;])
21 21 const visible = ref(false)
22 22 const dbLoading = ref(true)
23 23 const queryParams = reactive({
24   - tableName: undefined,
25   - tableComment: undefined,
  24 + name: undefined,
  25 + comment: undefined,
26 26 dataSourceConfigId: 0
27 27 })
28 28 const dataSourceConfigs = ref<DataSourceConfigVO[]>([])
... ... @@ -49,8 +49,9 @@ const handleQuery = async () =&gt; {
49 49 }
50 50 // 重置操作
51 51 const resetQuery = async () => {
52   - queryParams.tableName = undefined
53   - queryParams.tableComment = undefined
  52 + queryParams.name = undefined
  53 + queryParams.comment = undefined
  54 + queryParams.dataSourceConfigId = 0
54 55 await getList()
55 56 }
56 57 /** 多选框选中数据 */
... ... @@ -90,11 +91,11 @@ defineExpose({
90 91 />
91 92 </el-select>
92 93 </el-form-item>
93   - <el-form-item label="表名称" prop="tableName">
94   - <el-input v-model="queryParams.tableName" placeholder="请输入表名称" clearable />
  94 + <el-form-item label="表名称" prop="name">
  95 + <el-input v-model="queryParams.name" placeholder="请输入表名称" clearable />
95 96 </el-form-item>
96   - <el-form-item label="表描述" prop="tableComment">
97   - <el-input v-model="queryParams.tableComment" placeholder="请输入表描述" clearable />
  97 + <el-form-item label="表描述" prop="comment">
  98 + <el-input v-model="queryParams.comment" placeholder="请输入表描述" clearable />
98 99 </el-form-item>
99 100 <el-form-item>
100 101 <el-button type="primary" @click="handleQuery">
... ...
yudao-ui-admin-vue3/src/views/infra/codegen/components/index.ts
1 1 import BasicInfoForm from './BasicInfoForm.vue'
2 2 import CloumInfoForm from './CloumInfoForm.vue'
3   -import EditTable from './EditTable.vue'
4 3 import GenInfoForm from './GenInfoForm.vue'
5 4 import ImportTable from './ImportTable.vue'
6 5 import Preview from './Preview.vue'
7   -export { BasicInfoForm, CloumInfoForm, EditTable, GenInfoForm, ImportTable, Preview }
  6 +export { BasicInfoForm, CloumInfoForm, GenInfoForm, ImportTable, Preview }
... ...