feat: ✨ 代码生成 Beta 版
This commit is contained in:
@@ -51,9 +51,10 @@ module.exports = {
|
||||
{ value: "perf", name: "性能: 🚀 性能优化", emoji: ":zap:" },
|
||||
{ value: "test", name: "测试: 🧪 添加疏漏测试或已有测试改动", emoji: ":white_check_mark:"},
|
||||
{ value: "build", name: "构建: 📦️ 构建流程、外部依赖变更(如升级 npm 包、修改 vite 配置等)", emoji: ":package:"},
|
||||
{ value: "ci", name: "集成: ⚙️ 修改 CI 配置、脚本", emoji: ":ferris_wheel:"},
|
||||
{ value: "revert", name: "回退: ↩️ 回滚 commit",emoji: ":rewind:"},
|
||||
{ value: "chore", name: "其他: 🛠️ 对构建过程或辅助工具和库的更改(不影响源文件、测试用例)", emoji: ":hammer:"},
|
||||
{ value: "ci", name: "集成: ⚙️ 修改 CI 配置、脚本", emoji: ":ferris_wheel:"},
|
||||
{ value: "revert", name: "回退: ↩️ 回滚 commit",emoji: ":rewind:"},
|
||||
{ value: "chore", name: "其他: 🛠️ 对构建过程或辅助工具和库的更改(不影响源文件、测试用例)", emoji: ":hammer:"},
|
||||
{ value: "wip", name: "开发中: 🚧 开发阶段临时提交", emoji: ":construction:"},
|
||||
],
|
||||
useEmoji: true,
|
||||
emojiAlign: "center",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vue3-element-admin",
|
||||
"version": "2.12.0",
|
||||
"version": "2.13.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -1,35 +1,46 @@
|
||||
import request from "@/utils/request";
|
||||
import { FormTypeEnum } from "@/enums/FormTypeEnum";
|
||||
import { QueryTypeEnum } from "@/enums/QueryTypeEnum";
|
||||
|
||||
const DATABASE_BASE_URL = "/api/v1/generator";
|
||||
const GENERATOR_BASE_URL = "/api/v1/generator";
|
||||
|
||||
class DatabaseAPI {
|
||||
class GeneratorAPI {
|
||||
/** 获取数据表分页列表 */
|
||||
static getTablePage(params: TablePageQuery) {
|
||||
return request<any, PageResult<TablePageVO[]>>({
|
||||
url: `${DATABASE_BASE_URL}/table/page`,
|
||||
url: `${GENERATOR_BASE_URL}/table/page`,
|
||||
method: "get",
|
||||
params: params,
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取代码生成预览数据 */
|
||||
static getTableColumns(tableName: string) {
|
||||
return request<any, TableColumnVO[]>({
|
||||
url: `${DATABASE_BASE_URL}/table/${tableName}/columns`,
|
||||
/** 获取代码生成配置 */
|
||||
static getGenConfig(tableName: string) {
|
||||
return request<any, GenConfigForm>({
|
||||
url: `${GENERATOR_BASE_URL}/${tableName}/config`,
|
||||
method: "get",
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取代码生成配置 */
|
||||
static saveGenConfig(tableName: string, data: GenConfigForm) {
|
||||
return request({
|
||||
url: `${GENERATOR_BASE_URL}/${tableName}/config`,
|
||||
method: "post",
|
||||
data: data,
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取代码生成预览数据 */
|
||||
static getPreviewData(tableName: string) {
|
||||
return request<any, GeneratorPreviewVO[]>({
|
||||
url: `${DATABASE_BASE_URL}/table/${tableName}/preview`,
|
||||
url: `${GENERATOR_BASE_URL}/${tableName}/preview`,
|
||||
method: "get",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default DatabaseAPI;
|
||||
export default GeneratorAPI;
|
||||
|
||||
/** 代码生成预览对象 */
|
||||
export interface GeneratorPreviewVO {
|
||||
@@ -65,49 +76,68 @@ export interface TablePageVO {
|
||||
createTime: string;
|
||||
}
|
||||
|
||||
/** 数据表字段VO */
|
||||
export interface TableColumnVO {
|
||||
/** 字段名称 */
|
||||
columnName: string;
|
||||
/** 代码生成配置表单 */
|
||||
export interface GenConfigForm {
|
||||
/** 主键 */
|
||||
id?: number;
|
||||
|
||||
/** 表名 */
|
||||
tableName?: string;
|
||||
|
||||
/** 业务名 */
|
||||
businessName?: string;
|
||||
|
||||
/** 模块名 */
|
||||
moduleName?: string;
|
||||
|
||||
/** 包名 */
|
||||
packageName?: string;
|
||||
|
||||
/** 实体名 */
|
||||
entityName?: string;
|
||||
|
||||
/** 作者 */
|
||||
author?: string;
|
||||
|
||||
/** 字段配置列表 */
|
||||
fieldConfigs?: FieldConfig[];
|
||||
}
|
||||
|
||||
/** 字段配置 */
|
||||
interface FieldConfig {
|
||||
/** 主键 */
|
||||
id?: number;
|
||||
|
||||
/** 列名 */
|
||||
columnName?: string;
|
||||
|
||||
/** 列类型 */
|
||||
columnType?: string;
|
||||
|
||||
/** 字段名 */
|
||||
fieldName?: string;
|
||||
|
||||
/** 字段类型 */
|
||||
dataType: string;
|
||||
fieldType?: string;
|
||||
|
||||
/** 字段描述 */
|
||||
columnComment: string;
|
||||
fieldComment?: string;
|
||||
|
||||
/** 字段长度 */
|
||||
characterMaximumLength: number;
|
||||
/** 是否在列表显示 */
|
||||
isShowInList?: number;
|
||||
|
||||
/** 是否主键(1-是 0-否) */
|
||||
isPrimaryKey: number;
|
||||
/** 是否在表单显示 */
|
||||
isShowInForm?: number;
|
||||
|
||||
/** 是否可为空(1-是 0-否) */
|
||||
isNullable: string;
|
||||
/** 是否在查询条件显示 */
|
||||
isShowInQuery?: number;
|
||||
|
||||
/** 字符集 */
|
||||
characterSetName: string;
|
||||
/** 是否必填 */
|
||||
isRequired?: number;
|
||||
|
||||
/** 字符集排序规则 */
|
||||
collationName: string;
|
||||
}
|
||||
|
||||
interface GeneratorConfigForm {
|
||||
tableName: string;
|
||||
entityName: string;
|
||||
packageName: string;
|
||||
moduleName: string;
|
||||
author: string;
|
||||
fieldConfigs: FieldConfig[];
|
||||
}
|
||||
|
||||
interface FieldConfig {
|
||||
name: string;
|
||||
type: string;
|
||||
description: string;
|
||||
showInList: boolean;
|
||||
showInForm: boolean;
|
||||
showInQuery: boolean;
|
||||
formType: string;
|
||||
queryMethod: string;
|
||||
/** 表单类型 */
|
||||
formType?: number;
|
||||
|
||||
/** 查询类型 */
|
||||
queryType?: number;
|
||||
}
|
||||
|
||||
14
src/enums/FormTypeEnum.ts
Normal file
14
src/enums/FormTypeEnum.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* 表单类型枚举
|
||||
*/
|
||||
export const FormTypeEnum: Record<string, OptionType> = {
|
||||
INPUT: { value: 1, label: "输入框" },
|
||||
SELECT: { value: 2, label: "下拉框" },
|
||||
RADIO: { value: 3, label: "单选框" },
|
||||
CHECK_BOX: { value: 4, label: "复选框" },
|
||||
INPUT_NUMBER: { value: 5, label: "数字输入框" },
|
||||
SWITCH: { value: 6, label: "开关" },
|
||||
TEXT_AREA: { value: 7, label: "文本域" },
|
||||
DATE_TIME: { value: 8, label: "日期时间框" },
|
||||
DATE: { value: 9, label: "日期框" },
|
||||
};
|
||||
@@ -5,18 +5,18 @@ export const enum MenuTypeEnum {
|
||||
/**
|
||||
* 目录
|
||||
*/
|
||||
CATALOG = "CATALOG",
|
||||
CATALOG,
|
||||
/**
|
||||
* 菜单
|
||||
*/
|
||||
MENU = "MENU",
|
||||
MENU,
|
||||
|
||||
/**
|
||||
* 按钮
|
||||
*/
|
||||
BUTTON = "BUTTON",
|
||||
BUTTON,
|
||||
/**
|
||||
* 外链
|
||||
*/
|
||||
EXTLINK = "EXTLINK",
|
||||
EXTLINK,
|
||||
}
|
||||
|
||||
37
src/enums/QueryTypeEnum.ts
Normal file
37
src/enums/QueryTypeEnum.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* 查询类型枚举
|
||||
*/
|
||||
export const QueryTypeEnum: Record<string, OptionType> = {
|
||||
/** 等于 */
|
||||
EQ: { value: 1, label: "=" },
|
||||
|
||||
/** 模糊匹配 */
|
||||
LIKE: { value: 2, label: "LIKE '%s%'" },
|
||||
|
||||
/** 包含 */
|
||||
IN: { value: 3, label: "IN" },
|
||||
|
||||
/** 范围 */
|
||||
BETWEEN: { value: 4, label: "BETWEEN" },
|
||||
|
||||
/** 大于 */
|
||||
GT: { value: 5, label: ">" },
|
||||
|
||||
/** 大于等于 */
|
||||
GE: { value: 6, label: ">=" },
|
||||
|
||||
/** 小于 */
|
||||
LT: { value: 7, label: "<" },
|
||||
|
||||
/** 小于等于 */
|
||||
LE: { value: 8, label: "<=" },
|
||||
|
||||
/** 不等于 */
|
||||
NE: { value: 9, label: "!=" },
|
||||
|
||||
/** 左模糊匹配 */
|
||||
LIKE_LEFT: { value: 10, label: "LIKE '%s'" },
|
||||
|
||||
/** 右模糊匹配 */
|
||||
LIKE_RIGHT: { value: 11, label: "LIKE 's%'" },
|
||||
};
|
||||
@@ -51,7 +51,7 @@
|
||||
type="primary"
|
||||
size="small"
|
||||
link
|
||||
@click="handleOpenDialog('config', scope.row.tableName)"
|
||||
@click="handleOpenDialog(scope.row.tableName)"
|
||||
>
|
||||
<i-ep-MagicStick />
|
||||
生成
|
||||
@@ -75,10 +75,187 @@
|
||||
@close="handleCloseDialog"
|
||||
size="80%"
|
||||
>
|
||||
<div v-if="dialog.type === 'preview'">
|
||||
<el-row>
|
||||
<el-steps :active="active" align-center finish-status="success" simple>
|
||||
<el-step title="基础配置" />
|
||||
<el-step title="字段配置" />
|
||||
<el-step title="预览生成" />
|
||||
</el-steps>
|
||||
|
||||
<div class="mt-5">
|
||||
<el-form v-show="active == 1" :model="formData" :label-width="100">
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="表名">
|
||||
<el-input v-model="formData.tableName" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="业务名">
|
||||
<el-input v-model="formData.businessName" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="模块名">
|
||||
<el-input v-model="formData.moduleName" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="包名">
|
||||
<el-input v-model="formData.packageName" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="实体名">
|
||||
<el-input v-model="formData.entityName" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="作者">
|
||||
<el-input v-model="formData.author" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
|
||||
<el-table
|
||||
v-show="active == 2"
|
||||
v-loading="loading"
|
||||
:element-loading-text="loadingText"
|
||||
highlight--currentrow
|
||||
:data="formData.fieldConfigs"
|
||||
>
|
||||
<el-table-column label="字段列名" width="100">
|
||||
<template #default="scope">
|
||||
<el-form-item>
|
||||
{{ scope.row.columnName }}
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="字段类型" width="100">
|
||||
<template #default="scope">
|
||||
<el-form-item>
|
||||
{{ scope.row.columnType }}
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="Java属性" width="120">
|
||||
<template #default="scope">
|
||||
<el-form-item
|
||||
:prop="'fieldConfigs.' + scope.$index + '.fieldName'"
|
||||
>
|
||||
<el-input v-model="scope.row.fieldName" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="Java类型" width="120">
|
||||
<template #default="scope">
|
||||
<el-form-item
|
||||
:prop="'fieldConfigs.' + scope.$index + '.fieldType'"
|
||||
>
|
||||
<el-input v-model="scope.row.fieldType" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="字段描述">
|
||||
<template #default="scope">
|
||||
<el-form-item
|
||||
:prop="'fieldConfigs.' + scope.$index + '.fieldComment'"
|
||||
>
|
||||
<el-input v-model="scope.row.fieldComment" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="查询" width="70">
|
||||
<template #default="scope">
|
||||
<el-form-item>
|
||||
<el-checkbox
|
||||
v-model="scope.row.isShowInQuery"
|
||||
:true-value="1"
|
||||
:false-value="0"
|
||||
/>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="列表" width="70">
|
||||
<template #default="scope">
|
||||
<el-form-item>
|
||||
<el-checkbox
|
||||
v-model="scope.row.isShowInList"
|
||||
:true-value="1"
|
||||
:false-value="0"
|
||||
/>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="表单" width="70">
|
||||
<template #default="scope">
|
||||
<el-form-item>
|
||||
<el-checkbox
|
||||
v-model="scope.row.isShowInForm"
|
||||
:true-value="1"
|
||||
:false-value="0"
|
||||
/>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="是否必填" width="100">
|
||||
<template #default="scope">
|
||||
<el-form-item>
|
||||
<el-checkbox
|
||||
v-model="scope.row.isRequired"
|
||||
:true-value="1"
|
||||
:false-value="0"
|
||||
:disabled="scope.row.isShowInForm !== 1"
|
||||
/>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="表单类型">
|
||||
<template #default="scope">
|
||||
<el-form-item>
|
||||
<el-select v-model="scope.row.formType" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="(option, key) in formTypeOptions"
|
||||
:key="key"
|
||||
:label="option.label"
|
||||
:value="option.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="查询方式">
|
||||
<template #default="scope">
|
||||
<el-form-item>
|
||||
<el-select v-model="scope.row.queryType" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="(option, key) in queryTypeOptions"
|
||||
:key="key"
|
||||
:label="option.label"
|
||||
:value="option.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<el-row v-show="active == 3">
|
||||
<el-col :span="6">
|
||||
<el-scrollbar max-height="80vh">
|
||||
<el-scrollbar max-height="72vh">
|
||||
<el-tree
|
||||
:data="treeData"
|
||||
default-expand-all
|
||||
@@ -93,11 +270,11 @@
|
||||
</el-scrollbar>
|
||||
</el-col>
|
||||
<el-col :span="18">
|
||||
<el-scrollbar max-height="80vh">
|
||||
<el-scrollbar max-height="72vh">
|
||||
<div class="absolute-rt z-36 right-5 top-2">
|
||||
<el-link @click="handleCopyCode" type="primary">
|
||||
<el-icon><CopyDocument /></el-icon>
|
||||
复制
|
||||
一键复制
|
||||
</el-link>
|
||||
</div>
|
||||
|
||||
@@ -114,140 +291,17 @@
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
<div v-else-if="dialog.type === 'config'">
|
||||
<el-tabs type="border-card">
|
||||
<el-tab-pane label="基础信息">
|
||||
<el-form :label-width="100">
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="表名称">
|
||||
<el-input v-model="dialog.title" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="表描述">
|
||||
<el-input v-model="dialog.title" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="包路径">
|
||||
<el-input v-model="dialog.title" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="实体类名称">
|
||||
<el-input v-model="dialog.title" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="实体类名称">
|
||||
<el-input v-model="dialog.title" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="上级菜单">
|
||||
<el-input v-model="dialog.title" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="字段配置">
|
||||
<el-table
|
||||
v-loading="loading"
|
||||
highlight--currentrow
|
||||
:data="tableColumns"
|
||||
>
|
||||
<el-table-column label="名称" width="200">
|
||||
<template #default="scope">
|
||||
<el-form-item>
|
||||
{{ scope.row.columnName }}
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="类型" width="200">
|
||||
<template #default="scope">
|
||||
<el-form-item>
|
||||
{{ scope.row.dataType }}
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="描述">
|
||||
<template #default="scope">
|
||||
<el-form-item
|
||||
:prop="'tableColumns.' + scope.$index + '.columnComment'"
|
||||
>
|
||||
<el-input v-model="scope.row.columnComment" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="列表" width="70">
|
||||
<template #default="scope">
|
||||
<el-form-item>
|
||||
<el-checkbox v-model="scope.row.showList" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="表单" width="70">
|
||||
<template #default="scope">
|
||||
<el-form-item>
|
||||
<el-checkbox v-model="scope.row.showForm" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="查询" width="70">
|
||||
<template #default="scope">
|
||||
<el-form-item>
|
||||
<el-checkbox v-model="scope.row.showQuerys" />
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="表单类型">
|
||||
<template #default="scope">
|
||||
<el-form-item>
|
||||
<el-select
|
||||
v-model="scope.row.htmlType"
|
||||
placeholder="请选择"
|
||||
>
|
||||
<el-option label="输入框" value="input" />
|
||||
<el-option label="下拉框" value="select" />
|
||||
<el-option label="日期选择" value="date" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="查询方式">
|
||||
<template #default="scope">
|
||||
<el-form-item>
|
||||
<el-select
|
||||
v-model="scope.row.queryType"
|
||||
placeholder="请选择"
|
||||
>
|
||||
<el-option label="等于" value="eq" />
|
||||
<el-option label="模糊" value="like" />
|
||||
<el-option label="范围" value="range" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
<el-button @click="handleCloseDialog">取 消</el-button>
|
||||
<el-button type="primary" @click="handleSubmit">确 定</el-button>
|
||||
<el-button type="success" @click="handlePrevClick" v-if="active !== 1">
|
||||
<el-icon><Back /></el-icon>
|
||||
{{ prevBtnText }}
|
||||
</el-button>
|
||||
<el-button type="primary" @click="handleNextClick">
|
||||
{{ nextBtnText }}
|
||||
<el-icon v-if="active !== 3"><Right /></el-icon>
|
||||
<el-icon v-else><Download /></el-icon>
|
||||
</el-button>
|
||||
</template>
|
||||
</el-drawer>
|
||||
</div>
|
||||
@@ -263,23 +317,19 @@ import Codemirror from "codemirror-editor-vue3";
|
||||
import type { CmComponentRef } from "codemirror-editor-vue3";
|
||||
import type { Editor, EditorConfiguration } from "codemirror";
|
||||
const { copy, copied } = useClipboard();
|
||||
|
||||
const code = ref();
|
||||
const cmRef = ref<CmComponentRef>();
|
||||
const cmOptions: EditorConfiguration = {
|
||||
mode: "text/javascript",
|
||||
};
|
||||
import { FormTypeEnum } from "@/enums/FormTypeEnum";
|
||||
import { QueryTypeEnum } from "@/enums/QueryTypeEnum";
|
||||
|
||||
import GeneratorAPI, {
|
||||
TablePageVO,
|
||||
TableColumnVO,
|
||||
GenConfigForm,
|
||||
TablePageQuery,
|
||||
GeneratorPreviewVO,
|
||||
} from "@/api/generator";
|
||||
|
||||
const queryFormRef = ref(ElForm);
|
||||
|
||||
const loading = ref(false);
|
||||
const loadingText = ref("loading...");
|
||||
const total = ref(0);
|
||||
|
||||
const queryParams = reactive<TablePageQuery>({
|
||||
@@ -289,14 +339,68 @@ const queryParams = reactive<TablePageQuery>({
|
||||
|
||||
const pageData = ref<TablePageVO[]>([]);
|
||||
|
||||
const tableColumns = ref<TableColumnVO[]>([]);
|
||||
const formData = ref<GenConfigForm>({});
|
||||
|
||||
const formTypeOptions: Record<string, OptionType> = FormTypeEnum;
|
||||
const queryTypeOptions: Record<string, OptionType> = QueryTypeEnum;
|
||||
|
||||
const dialog = reactive({
|
||||
type: "",
|
||||
visible: false,
|
||||
title: "",
|
||||
});
|
||||
|
||||
const code = ref();
|
||||
const cmRef = ref<CmComponentRef>();
|
||||
const cmOptions: EditorConfiguration = {
|
||||
mode: "text/javascript",
|
||||
};
|
||||
|
||||
const prevBtnText = ref("");
|
||||
const nextBtnText = ref("下一步,字段配置");
|
||||
const active = ref(1);
|
||||
|
||||
function handlePrevClick() {
|
||||
if (active.value-- <= 1) active.value = 1;
|
||||
}
|
||||
|
||||
function handleNextClick() {
|
||||
if (active.value === 2) {
|
||||
// 保存生成配置
|
||||
const tableName = formData.value.tableName;
|
||||
if (!tableName) {
|
||||
ElMessage.error("表名不能为空");
|
||||
return;
|
||||
}
|
||||
loading.value = true;
|
||||
loadingText.value = "代码生成中,请稍后...";
|
||||
GeneratorAPI.saveGenConfig(tableName, formData.value)
|
||||
.then(() => {
|
||||
handlePreview(tableName);
|
||||
})
|
||||
.then(() => {
|
||||
if (active.value++ >= 3) active.value = 3;
|
||||
})
|
||||
.finally(() => {
|
||||
loading.value = false;
|
||||
loadingText.value = "loading...";
|
||||
});
|
||||
} else {
|
||||
if (active.value++ >= 3) active.value = 3;
|
||||
}
|
||||
}
|
||||
|
||||
watch(active, (val) => {
|
||||
if (val === 1) {
|
||||
nextBtnText.value = "下一步,字段配置";
|
||||
} else if (val === 2) {
|
||||
prevBtnText.value = "上一步,基础配置";
|
||||
nextBtnText.value = "下一步,确认生成";
|
||||
} else if (val === 3) {
|
||||
prevBtnText.value = "上一步,字段配置";
|
||||
nextBtnText.value = "下载代码";
|
||||
}
|
||||
});
|
||||
|
||||
/** 查询 */
|
||||
function handleQuery() {
|
||||
loading.value = true;
|
||||
@@ -329,34 +433,41 @@ interface TreeNode {
|
||||
const treeData = ref<TreeNode[]>([]);
|
||||
|
||||
/** 打开弹窗 */
|
||||
function handleOpenDialog(type: string, tableName: string) {
|
||||
function handleOpenDialog(tableName: string) {
|
||||
dialog.visible = true;
|
||||
dialog.type = type;
|
||||
if (type === "config") {
|
||||
GeneratorAPI.getTableColumns(tableName).then((data) => {
|
||||
dialog.title = `配置 ${tableName}`;
|
||||
tableColumns.value = data;
|
||||
});
|
||||
} else if (type === "preview") {
|
||||
treeData.value = [];
|
||||
GeneratorAPI.getPreviewData(tableName).then((data) => {
|
||||
dialog.title = `预览 ${tableName}`;
|
||||
GeneratorAPI.getGenConfig(tableName).then((data) => {
|
||||
dialog.title = `${tableName} 代码生成`;
|
||||
formData.value = data;
|
||||
if (formData.value.id) {
|
||||
active.value = 3;
|
||||
handlePreview(tableName);
|
||||
} else {
|
||||
active.value = 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 组装树形结构完善代码
|
||||
const tree = buildTree(data);
|
||||
treeData.value = [tree];
|
||||
/** 获取生成预览 */
|
||||
function handlePreview(tableName: string) {
|
||||
treeData.value = [];
|
||||
GeneratorAPI.getPreviewData(tableName).then((data) => {
|
||||
dialog.title = `预览 ${tableName}`;
|
||||
|
||||
// 默认选中第一个叶子节点并设置 code 值
|
||||
const firstLeafNode = findFirstLeafNode(tree);
|
||||
if (firstLeafNode) {
|
||||
code.value = firstLeafNode.content || "";
|
||||
}
|
||||
});
|
||||
}
|
||||
// 组装树形结构完善代码
|
||||
const tree = buildTree(data);
|
||||
treeData.value = [tree];
|
||||
|
||||
// 默认选中第一个叶子节点并设置 code 值
|
||||
const firstLeafNode = findFirstLeafNode(tree);
|
||||
if (firstLeafNode) {
|
||||
code.value = firstLeafNode.content || "";
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归构建树形结构
|
||||
*
|
||||
* @param data - 数据数组
|
||||
* @returns 树形结构根节点
|
||||
*/
|
||||
@@ -372,24 +483,22 @@ function buildTree(
|
||||
const parts = item.path.split(separator);
|
||||
|
||||
// 定义特殊路径
|
||||
// TODO: 如果菜单有多个节点,需要将此菜单作为独立一级的节点,而不是合并到上一级。 按照此规则, com.youlai.system 则是三个节点,而不是合并到一起,但是这里需要将 com.youlai.system 合并到一起,所以需要特殊处理
|
||||
const specialPaths = [
|
||||
"com\\youlai\\system",
|
||||
"src\\main",
|
||||
"java",
|
||||
"youlai-boot",
|
||||
"vue3-element-admin",
|
||||
"java",
|
||||
"com\\youlai\\system",
|
||||
];
|
||||
|
||||
// 检查路径中的特殊部分并合并它们
|
||||
const mergedParts: string[] = [];
|
||||
let buffer: string[] = [];
|
||||
|
||||
console.log("parts", parts);
|
||||
|
||||
parts.forEach((part) => {
|
||||
buffer.push(part);
|
||||
const currentPath = buffer.join(separator);
|
||||
console.log("currentPath", currentPath);
|
||||
if (specialPaths.includes(currentPath)) {
|
||||
mergedParts.push(currentPath);
|
||||
buffer = [];
|
||||
@@ -483,8 +592,6 @@ watch(copied, () => {
|
||||
}
|
||||
});
|
||||
|
||||
function handleSubmit() {}
|
||||
|
||||
onMounted(() => {
|
||||
handleQuery();
|
||||
cmRef.value?.destroy();
|
||||
|
||||
Reference in New Issue
Block a user