mirror of
				https://github.com/continew-org/continew-admin-ui.git
				synced 2025-10-31 10:57:10 +08:00 
			
		
		
		
	refactor: 重构代码生成列表
This commit is contained in:
		| @@ -7,13 +7,8 @@ export type * from './type' | ||||
| const BASE_URL = '/generator' | ||||
|  | ||||
| /** @desc 查询代码生成列表 */ | ||||
| export function listGenerator(query: T.TablePageQuery) { | ||||
|   return http.get<PageRes<T.TableResp[]>>(`${BASE_URL}/table`, query) | ||||
| } | ||||
|  | ||||
| /** @desc 查询字段配置列表 */ | ||||
| export function listFieldConfig(tableName: string, requireSync: boolean) { | ||||
|   return http.get<T.FieldConfigResp[]>(`${BASE_URL}/field/${tableName}?requireSync=${requireSync}`) | ||||
| export function listGenConfig(query: T.GenConfigPageQuery) { | ||||
|   return http.get<PageRes<T.GenConfigResp[]>>(`${BASE_URL}/config`, query) | ||||
| } | ||||
|  | ||||
| /** @desc 查询生成配置信息 */ | ||||
| @@ -21,6 +16,11 @@ export function getGenConfig(tableName: string) { | ||||
|   return http.get<T.GenConfigResp>(`${BASE_URL}/config/${tableName}`) | ||||
| } | ||||
|  | ||||
| /** @desc 查询字段配置列表 */ | ||||
| export function listFieldConfig(tableName: string, requireSync: boolean) { | ||||
|   return http.get<T.FieldConfigResp[]>(`${BASE_URL}/field/${tableName}?requireSync=${requireSync}`) | ||||
| } | ||||
|  | ||||
| /** @desc 保存配置信息 */ | ||||
| export function saveGenConfig(tableName: string, req: T.GeneratorConfigResp) { | ||||
|   return http.post(`${BASE_URL}/config/${tableName}`, req) | ||||
|   | ||||
| @@ -1,17 +1,21 @@ | ||||
| /** 工具代码生成类型 */ | ||||
| export interface TableResp { | ||||
| export interface GenConfigResp { | ||||
|   tableName: string | ||||
|   comment?: string | ||||
|   engine: string | ||||
|   charset: string | ||||
|   comment: string | ||||
|   moduleName: string | ||||
|   packageName: string | ||||
|   businessName: string | ||||
|   author: string | ||||
|   tablePrefix: string | ||||
|   isOverride: boolean | ||||
|   createTime?: string | ||||
|   isConfiged: boolean | ||||
|   disabled: boolean | ||||
|   updateTime?: string | ||||
|   classNamePrefix?: string | ||||
| } | ||||
| export interface TableQuery { | ||||
| export interface GenConfigQuery { | ||||
|   tableName?: string | ||||
| } | ||||
| export interface TablePageQuery extends PageQuery, TableQuery {} | ||||
| export interface GenConfigPageQuery extends PageQuery, GenConfigQuery {} | ||||
|  | ||||
| export interface FieldConfigResp { | ||||
|   tableName: string | ||||
| @@ -30,17 +34,6 @@ export interface FieldConfigResp { | ||||
|   dictCode: string | ||||
|   createTime?: string | ||||
| } | ||||
| export interface GenConfigResp { | ||||
|   tableName: string | ||||
|   moduleName: string | ||||
|   packageName: string | ||||
|   businessName: string | ||||
|   author: string | ||||
|   tablePrefix: string | ||||
|   isOverride: boolean | ||||
|   createTime?: string | ||||
|   updateTime?: string | ||||
| } | ||||
| export interface GeneratorConfigResp { | ||||
|   genConfig: GenConfigResp | ||||
|   fieldConfigs: FieldConfigResp[] | ||||
|   | ||||
| @@ -10,29 +10,7 @@ | ||||
|   > | ||||
|     <a-tabs v-model:active-key="activeKey"> | ||||
|       <a-tab-pane key="1" title="生成配置"> | ||||
|         <a-form ref="formRef" :model="form" :rules="rules" class="gen-config" size="large"> | ||||
|           <a-form-item label="作者名称" field="author"> | ||||
|             <a-input v-model="form.author" placeholder="请输入作者名称" /> | ||||
|           </a-form-item> | ||||
|           <a-form-item label="业务名称" field="businessName"> | ||||
|             <a-input v-model="form.businessName" placeholder="自定义业务名称,例如:用户" /> | ||||
|           </a-form-item> | ||||
|           <a-form-item label="所属模块" field="moduleName"> | ||||
|             <a-input v-model="form.moduleName" placeholder="项目模块名称,例如:continew-admin-system" /> | ||||
|           </a-form-item> | ||||
|           <a-form-item label="模块包名" field="packageName"> | ||||
|             <a-input v-model="form.packageName" placeholder="项目模块包名,例如:top.continew.admin.system" /> | ||||
|           </a-form-item> | ||||
|           <a-form-item label="去表前缀" field="tablePrefix"> | ||||
|             <a-input v-model="form.tablePrefix" placeholder="数据库表前缀,例如:sys_" /> | ||||
|           </a-form-item> | ||||
|           <a-form-item label="是否覆盖" field="isOverride"> | ||||
|             <a-radio-group v-model="form.isOverride" type="button"> | ||||
|               <a-radio :value="true">是</a-radio> | ||||
|               <a-radio :value="false">否</a-radio> | ||||
|             </a-radio-group> | ||||
|           </a-form-item> | ||||
|         </a-form> | ||||
|         <GiForm ref="formRef" v-model="form" :options="options" :columns="formColumns" /> | ||||
|       </a-tab-pane> | ||||
|       <a-tab-pane key="2" title="字段配置"> | ||||
|         <GiTable | ||||
| @@ -141,11 +119,12 @@ | ||||
| </template> | ||||
|  | ||||
| <script setup lang="ts"> | ||||
| import { type FormInstance, Message } from '@arco-design/web-vue' | ||||
| import { Message } from '@arco-design/web-vue' | ||||
| import { useWindowSize } from '@vueuse/core' | ||||
| import { type FieldConfigResp, type GeneratorConfigResp, getGenConfig, listFieldConfig, listFieldConfigDict, saveGenConfig } from '@/apis/tool' | ||||
| import type { LabelValueState } from '@/types/global' | ||||
| import type { TableInstanceColumns } from '@/components/GiTable/type' | ||||
| import { type Columns, GiForm, type Options } from '@/components/GiForm' | ||||
| import { useForm } from '@/hooks' | ||||
| import { useDict } from '@/hooks/app' | ||||
|  | ||||
| @@ -155,6 +134,68 @@ const emit = defineEmits<{ | ||||
| const { width } = useWindowSize() | ||||
| const { form_type_enum, query_type_enum } = useDict('form_type_enum', 'query_type_enum') | ||||
|  | ||||
| const options: Options = { | ||||
|   form: { size: 'large' }, | ||||
|   grid: { cols: 2 }, | ||||
|   btns: { hide: true }, | ||||
| } | ||||
| const formColumns: Columns = reactive([ | ||||
|   { | ||||
|     label: '作者名称', | ||||
|     field: 'author', | ||||
|     type: 'input', | ||||
|     props: { | ||||
|       placeholder: '请输入作者名称', | ||||
|     }, | ||||
|     rules: [{ required: true, message: '请输入作者名称' }], | ||||
|   }, | ||||
|   { | ||||
|     label: '业务名称', | ||||
|     field: 'businessName', | ||||
|     type: 'input', | ||||
|     props: { | ||||
|       placeholder: '自定义业务名称,例如:用户', | ||||
|     }, | ||||
|     rules: [{ required: true, message: '请输入业务名称' }], | ||||
|   }, | ||||
|   { | ||||
|     label: '所属模块', | ||||
|     field: 'moduleName', | ||||
|     type: 'input', | ||||
|     props: { | ||||
|       placeholder: '项目模块名称,例如:continew-system', | ||||
|     }, | ||||
|     rules: [{ required: true, message: '请输入所属模块' }], | ||||
|   }, | ||||
|   { | ||||
|     label: '模块包名', | ||||
|     field: 'packageName', | ||||
|     type: 'input', | ||||
|     props: { | ||||
|       placeholder: '项目模块包名,例如:top.continew.admin.system', | ||||
|     }, | ||||
|     rules: [{ required: true, message: '请输入模块包名' }], | ||||
|   }, | ||||
|   { | ||||
|     label: '去表前缀', | ||||
|     field: 'tablePrefix', | ||||
|     type: 'input', | ||||
|     props: { | ||||
|       placeholder: '数据库表前缀,例如:sys_', | ||||
|       width: '200', | ||||
|     }, | ||||
|   }, | ||||
|   { | ||||
|     label: '是否覆盖', | ||||
|     field: 'isOverride', | ||||
|     type: 'radio-group', | ||||
|     options: [{ label: '是', value: true }, { label: '否', value: false }], | ||||
|     props: { | ||||
|       type: 'button', | ||||
|     }, | ||||
|   }, | ||||
| ]) | ||||
|  | ||||
| // Table 字段配置 | ||||
| const columns: TableInstanceColumns[] = [ | ||||
|   { title: '名称', slotName: 'fieldName' }, | ||||
| @@ -185,22 +226,14 @@ const getDataList = async (tableName: string, requireSync: boolean) => { | ||||
|   } | ||||
| } | ||||
|  | ||||
| // Form 生成配置 | ||||
| const formRef = ref<FormInstance>() | ||||
| const rules: FormInstance['rules'] = { | ||||
|   author: [{ required: true, message: '请输入作者名称' }], | ||||
|   moduleName: [{ required: true, message: '请输入所属模块' }], | ||||
|   packageName: [{ required: true, message: '请输入模块包名' }], | ||||
|   businessName: [{ required: true, message: '请输入业务名称' }], | ||||
| } | ||||
|  | ||||
| const formRef = ref<InstanceType<typeof GiForm>>() | ||||
| const { form, resetForm } = useForm({ | ||||
|   isOverride: false, | ||||
| }) | ||||
|  | ||||
| // 重置 | ||||
| const reset = () => { | ||||
|   formRef.value?.resetFields() | ||||
|   formRef.value?.formRef?.resetFields() | ||||
|   resetForm() | ||||
| } | ||||
|  | ||||
| @@ -214,8 +247,8 @@ const onConfig = async (tableName: string, comment: string) => { | ||||
|   // 查询字段配置 | ||||
|   await getDataList(tableName, false) | ||||
|   // 查询生成配置 | ||||
|   const res = await getGenConfig(tableName) | ||||
|   Object.assign(form, res.data) | ||||
|   const { data } = await getGenConfig(tableName) | ||||
|   Object.assign(form, data) | ||||
|   form.isOverride = false | ||||
| } | ||||
|  | ||||
| @@ -233,7 +266,7 @@ const activeKey = ref('1') | ||||
| // 保存 | ||||
| const save = async () => { | ||||
|   try { | ||||
|     const isInvalid = await formRef.value?.validate() | ||||
|     const isInvalid = await formRef.value?.formRef?.validate() | ||||
|     if (isInvalid) { | ||||
|       activeKey.value = '1' | ||||
|       return false | ||||
|   | ||||
| @@ -134,8 +134,8 @@ const selectedKeys = ref() | ||||
| const onPreview = async (tableName: string) => { | ||||
|   treeData.value = [] | ||||
|   previewTableName.value = tableName | ||||
|   const res = await genPreview(tableName) | ||||
|   genPreviewList.value = res.data | ||||
|   const { data } = await genPreview(tableName) | ||||
|   genPreviewList.value = data | ||||
|   for (const genPreview of genPreviewList.value) { | ||||
|     assembleTree(genPreview) | ||||
|   } | ||||
|   | ||||
| @@ -25,8 +25,8 @@ | ||||
|         <a-space> | ||||
|           <a-link @click="onConfig(record.tableName, record.comment)">配置</a-link> | ||||
|           <a-link | ||||
|             :title="record.isConfiged ? '生成' : '请先进行生成配置'" | ||||
|             :disabled="!record.isConfiged" | ||||
|             :title="record.createTime ? '生成' : '请先进行生成配置'" | ||||
|             :disabled="!record.createTime" | ||||
|             @click="onPreview(record.tableName)" | ||||
|           > | ||||
|             生成 | ||||
| @@ -42,17 +42,16 @@ | ||||
|  | ||||
| <script setup lang="ts"> | ||||
| import GenConfigDrawer from './GenConfigDrawer.vue' | ||||
|  | ||||
| import { generate, listGenerator } from '@/apis/tool' | ||||
| import { generate, listGenConfig } from '@/apis/tool' | ||||
| import type { TableInstanceColumns } from '@/components/GiTable/type' | ||||
| import { useTable } from '@/hooks' | ||||
| import { isMobile } from '@/utils' | ||||
|  | ||||
| defineOptions({ name: 'Generator' }) | ||||
| const GenPreviewModal = defineAsyncComponent(() => import('./GenPreviewModal.vue')) | ||||
|  | ||||
| const queryForm = reactive({ | ||||
|   tableName: undefined, | ||||
|   sort: ['createTime,desc'], | ||||
| }) | ||||
|  | ||||
| const { | ||||
| @@ -60,7 +59,7 @@ const { | ||||
|   loading, | ||||
|   pagination, | ||||
|   search, | ||||
| } = useTable((page) => listGenerator({ ...queryForm, ...page }), { immediate: true }) | ||||
| } = useTable((page) => listGenConfig({ ...queryForm, ...page }), { immediate: true }) | ||||
|  | ||||
| const columns: TableInstanceColumns[] = [ | ||||
|   { | ||||
| @@ -69,11 +68,14 @@ const columns: TableInstanceColumns[] = [ | ||||
|     align: 'center', | ||||
|     render: ({ rowIndex }) => h('span', {}, rowIndex + 1 + (pagination.current - 1) * pagination.pageSize), | ||||
|   }, | ||||
|   { title: '表名称', dataIndex: 'tableName', width: 225 }, | ||||
|   { title: '描述', dataIndex: 'comment', tooltip: true }, | ||||
|   { title: '存储引擎', dataIndex: 'engine', align: 'center' }, | ||||
|   { title: '字符集', dataIndex: 'charset' }, | ||||
|   { title: '创建时间', dataIndex: 'createTime', width: 180 }, | ||||
|   { title: '表名称', dataIndex: 'tableName', minWidth: 225, ellipsis: true, tooltip: true }, | ||||
|   { title: '描述', dataIndex: 'comment', ellipsis: true, tooltip: true }, | ||||
|   { title: '类名前缀', dataIndex: 'classNamePrefix', ellipsis: true, tooltip: true }, | ||||
|   { title: '作者名称', dataIndex: 'author' }, | ||||
|   { title: '所属模块', dataIndex: 'moduleName', ellipsis: true, tooltip: true }, | ||||
|   { title: '模块包名', dataIndex: 'packageName', ellipsis: true, tooltip: true }, | ||||
|   { title: '配置时间', dataIndex: 'createTime', width: 180 }, | ||||
|   { title: '修改时间', dataIndex: 'updateTime', width: 180 }, | ||||
|   { title: '操作', slotName: 'action', width: 180, align: 'center', fixed: !isMobile() ? 'right' : undefined }, | ||||
| ] | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user