refactor: 重构代码生成列表

This commit is contained in:
2024-11-13 22:38:01 +08:00
parent 3b74b5c7bf
commit 293718f670
5 changed files with 104 additions and 76 deletions

View File

@@ -7,13 +7,8 @@ export type * from './type'
const BASE_URL = '/generator' const BASE_URL = '/generator'
/** @desc 查询代码生成列表 */ /** @desc 查询代码生成列表 */
export function listGenerator(query: T.TablePageQuery) { export function listGenConfig(query: T.GenConfigPageQuery) {
return http.get<PageRes<T.TableResp[]>>(`${BASE_URL}/table`, query) return http.get<PageRes<T.GenConfigResp[]>>(`${BASE_URL}/config`, query)
}
/** @desc 查询字段配置列表 */
export function listFieldConfig(tableName: string, requireSync: boolean) {
return http.get<T.FieldConfigResp[]>(`${BASE_URL}/field/${tableName}?requireSync=${requireSync}`)
} }
/** @desc 查询生成配置信息 */ /** @desc 查询生成配置信息 */
@@ -21,6 +16,11 @@ export function getGenConfig(tableName: string) {
return http.get<T.GenConfigResp>(`${BASE_URL}/config/${tableName}`) 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 保存配置信息 */ /** @desc 保存配置信息 */
export function saveGenConfig(tableName: string, req: T.GeneratorConfigResp) { export function saveGenConfig(tableName: string, req: T.GeneratorConfigResp) {
return http.post(`${BASE_URL}/config/${tableName}`, req) return http.post(`${BASE_URL}/config/${tableName}`, req)

View File

@@ -1,17 +1,21 @@
/** 工具代码生成类型 */ /** 工具代码生成类型 */
export interface TableResp { export interface GenConfigResp {
tableName: string tableName: string
comment?: string comment: string
engine: string moduleName: string
charset: string packageName: string
businessName: string
author: string
tablePrefix: string
isOverride: boolean
createTime?: string createTime?: string
isConfiged: boolean updateTime?: string
disabled: boolean classNamePrefix?: string
} }
export interface TableQuery { export interface GenConfigQuery {
tableName?: string tableName?: string
} }
export interface TablePageQuery extends PageQuery, TableQuery {} export interface GenConfigPageQuery extends PageQuery, GenConfigQuery {}
export interface FieldConfigResp { export interface FieldConfigResp {
tableName: string tableName: string
@@ -30,17 +34,6 @@ export interface FieldConfigResp {
dictCode: string dictCode: string
createTime?: 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 { export interface GeneratorConfigResp {
genConfig: GenConfigResp genConfig: GenConfigResp
fieldConfigs: FieldConfigResp[] fieldConfigs: FieldConfigResp[]

View File

@@ -10,29 +10,7 @@
> >
<a-tabs v-model:active-key="activeKey"> <a-tabs v-model:active-key="activeKey">
<a-tab-pane key="1" title="生成配置"> <a-tab-pane key="1" title="生成配置">
<a-form ref="formRef" :model="form" :rules="rules" class="gen-config" size="large"> <GiForm ref="formRef" v-model="form" :options="options" :columns="formColumns" />
<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>
</a-tab-pane> </a-tab-pane>
<a-tab-pane key="2" title="字段配置"> <a-tab-pane key="2" title="字段配置">
<GiTable <GiTable
@@ -141,11 +119,12 @@
</template> </template>
<script setup lang="ts"> <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 { useWindowSize } from '@vueuse/core'
import { type FieldConfigResp, type GeneratorConfigResp, getGenConfig, listFieldConfig, listFieldConfigDict, saveGenConfig } from '@/apis/tool' import { type FieldConfigResp, type GeneratorConfigResp, getGenConfig, listFieldConfig, listFieldConfigDict, saveGenConfig } from '@/apis/tool'
import type { LabelValueState } from '@/types/global' import type { LabelValueState } from '@/types/global'
import type { TableInstanceColumns } from '@/components/GiTable/type' import type { TableInstanceColumns } from '@/components/GiTable/type'
import { type Columns, GiForm, type Options } from '@/components/GiForm'
import { useForm } from '@/hooks' import { useForm } from '@/hooks'
import { useDict } from '@/hooks/app' import { useDict } from '@/hooks/app'
@@ -155,6 +134,68 @@ const emit = defineEmits<{
const { width } = useWindowSize() const { width } = useWindowSize()
const { form_type_enum, query_type_enum } = useDict('form_type_enum', 'query_type_enum') 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 字段配置 // Table 字段配置
const columns: TableInstanceColumns[] = [ const columns: TableInstanceColumns[] = [
{ title: '名称', slotName: 'fieldName' }, { title: '名称', slotName: 'fieldName' },
@@ -185,22 +226,14 @@ const getDataList = async (tableName: string, requireSync: boolean) => {
} }
} }
// Form 生成配置 const formRef = ref<InstanceType<typeof GiForm>>()
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 { form, resetForm } = useForm({ const { form, resetForm } = useForm({
isOverride: false, isOverride: false,
}) })
// 重置 // 重置
const reset = () => { const reset = () => {
formRef.value?.resetFields() formRef.value?.formRef?.resetFields()
resetForm() resetForm()
} }
@@ -214,8 +247,8 @@ const onConfig = async (tableName: string, comment: string) => {
// 查询字段配置 // 查询字段配置
await getDataList(tableName, false) await getDataList(tableName, false)
// 查询生成配置 // 查询生成配置
const res = await getGenConfig(tableName) const { data } = await getGenConfig(tableName)
Object.assign(form, res.data) Object.assign(form, data)
form.isOverride = false form.isOverride = false
} }
@@ -233,7 +266,7 @@ const activeKey = ref('1')
// 保存 // 保存
const save = async () => { const save = async () => {
try { try {
const isInvalid = await formRef.value?.validate() const isInvalid = await formRef.value?.formRef?.validate()
if (isInvalid) { if (isInvalid) {
activeKey.value = '1' activeKey.value = '1'
return false return false

View File

@@ -134,8 +134,8 @@ const selectedKeys = ref()
const onPreview = async (tableName: string) => { const onPreview = async (tableName: string) => {
treeData.value = [] treeData.value = []
previewTableName.value = tableName previewTableName.value = tableName
const res = await genPreview(tableName) const { data } = await genPreview(tableName)
genPreviewList.value = res.data genPreviewList.value = data
for (const genPreview of genPreviewList.value) { for (const genPreview of genPreviewList.value) {
assembleTree(genPreview) assembleTree(genPreview)
} }

View File

@@ -25,8 +25,8 @@
<a-space> <a-space>
<a-link @click="onConfig(record.tableName, record.comment)">配置</a-link> <a-link @click="onConfig(record.tableName, record.comment)">配置</a-link>
<a-link <a-link
:title="record.isConfiged ? '生成' : '请先进行生成配置'" :title="record.createTime ? '生成' : '请先进行生成配置'"
:disabled="!record.isConfiged" :disabled="!record.createTime"
@click="onPreview(record.tableName)" @click="onPreview(record.tableName)"
> >
生成 生成
@@ -42,17 +42,16 @@
<script setup lang="ts"> <script setup lang="ts">
import GenConfigDrawer from './GenConfigDrawer.vue' import GenConfigDrawer from './GenConfigDrawer.vue'
import { generate, listGenConfig } from '@/apis/tool'
import { generate, listGenerator } from '@/apis/tool'
import type { TableInstanceColumns } from '@/components/GiTable/type' import type { TableInstanceColumns } from '@/components/GiTable/type'
import { useTable } from '@/hooks' import { useTable } from '@/hooks'
import { isMobile } from '@/utils' import { isMobile } from '@/utils'
defineOptions({ name: 'Generator' }) defineOptions({ name: 'Generator' })
const GenPreviewModal = defineAsyncComponent(() => import('./GenPreviewModal.vue')) const GenPreviewModal = defineAsyncComponent(() => import('./GenPreviewModal.vue'))
const queryForm = reactive({ const queryForm = reactive({
tableName: undefined, tableName: undefined,
sort: ['createTime,desc'],
}) })
const { const {
@@ -60,7 +59,7 @@ const {
loading, loading,
pagination, pagination,
search, search,
} = useTable((page) => listGenerator({ ...queryForm, ...page }), { immediate: true }) } = useTable((page) => listGenConfig({ ...queryForm, ...page }), { immediate: true })
const columns: TableInstanceColumns[] = [ const columns: TableInstanceColumns[] = [
{ {
@@ -69,11 +68,14 @@ const columns: TableInstanceColumns[] = [
align: 'center', align: 'center',
render: ({ rowIndex }) => h('span', {}, rowIndex + 1 + (pagination.current - 1) * pagination.pageSize), render: ({ rowIndex }) => h('span', {}, rowIndex + 1 + (pagination.current - 1) * pagination.pageSize),
}, },
{ title: '表名称', dataIndex: 'tableName', width: 225 }, { title: '表名称', dataIndex: 'tableName', minWidth: 225, ellipsis: true, tooltip: true },
{ title: '描述', dataIndex: 'comment', tooltip: true }, { title: '描述', dataIndex: 'comment', ellipsis: true, tooltip: true },
{ title: '存储引擎', dataIndex: 'engine', align: 'center' }, { title: '类名前缀', dataIndex: 'classNamePrefix', ellipsis: true, tooltip: true },
{ title: '字符集', dataIndex: 'charset' }, { title: '作者名称', dataIndex: 'author' },
{ title: '创建时间', dataIndex: 'createTime', width: 180 }, { 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 }, { title: '操作', slotName: 'action', width: 180, align: 'center', fixed: !isMobile() ? 'right' : undefined },
] ]