feat: ✨ 代码生成 Beta 版
This commit is contained in:
@@ -51,9 +51,10 @@ module.exports = {
|
|||||||
{ value: "perf", name: "性能: 🚀 性能优化", emoji: ":zap:" },
|
{ value: "perf", name: "性能: 🚀 性能优化", emoji: ":zap:" },
|
||||||
{ value: "test", name: "测试: 🧪 添加疏漏测试或已有测试改动", emoji: ":white_check_mark:"},
|
{ value: "test", name: "测试: 🧪 添加疏漏测试或已有测试改动", emoji: ":white_check_mark:"},
|
||||||
{ value: "build", name: "构建: 📦️ 构建流程、外部依赖变更(如升级 npm 包、修改 vite 配置等)", emoji: ":package:"},
|
{ value: "build", name: "构建: 📦️ 构建流程、外部依赖变更(如升级 npm 包、修改 vite 配置等)", emoji: ":package:"},
|
||||||
{ value: "ci", name: "集成: ⚙️ 修改 CI 配置、脚本", emoji: ":ferris_wheel:"},
|
{ value: "ci", name: "集成: ⚙️ 修改 CI 配置、脚本", emoji: ":ferris_wheel:"},
|
||||||
{ value: "revert", name: "回退: ↩️ 回滚 commit",emoji: ":rewind:"},
|
{ value: "revert", name: "回退: ↩️ 回滚 commit",emoji: ":rewind:"},
|
||||||
{ value: "chore", name: "其他: 🛠️ 对构建过程或辅助工具和库的更改(不影响源文件、测试用例)", emoji: ":hammer:"},
|
{ value: "chore", name: "其他: 🛠️ 对构建过程或辅助工具和库的更改(不影响源文件、测试用例)", emoji: ":hammer:"},
|
||||||
|
{ value: "wip", name: "开发中: 🚧 开发阶段临时提交", emoji: ":construction:"},
|
||||||
],
|
],
|
||||||
useEmoji: true,
|
useEmoji: true,
|
||||||
emojiAlign: "center",
|
emojiAlign: "center",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "vue3-element-admin",
|
"name": "vue3-element-admin",
|
||||||
"version": "2.12.0",
|
"version": "2.13.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,35 +1,46 @@
|
|||||||
import request from "@/utils/request";
|
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) {
|
static getTablePage(params: TablePageQuery) {
|
||||||
return request<any, PageResult<TablePageVO[]>>({
|
return request<any, PageResult<TablePageVO[]>>({
|
||||||
url: `${DATABASE_BASE_URL}/table/page`,
|
url: `${GENERATOR_BASE_URL}/table/page`,
|
||||||
method: "get",
|
method: "get",
|
||||||
params: params,
|
params: params,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 获取代码生成预览数据 */
|
/** 获取代码生成配置 */
|
||||||
static getTableColumns(tableName: string) {
|
static getGenConfig(tableName: string) {
|
||||||
return request<any, TableColumnVO[]>({
|
return request<any, GenConfigForm>({
|
||||||
url: `${DATABASE_BASE_URL}/table/${tableName}/columns`,
|
url: `${GENERATOR_BASE_URL}/${tableName}/config`,
|
||||||
method: "get",
|
method: "get",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 获取代码生成配置 */
|
||||||
|
static saveGenConfig(tableName: string, data: GenConfigForm) {
|
||||||
|
return request({
|
||||||
|
url: `${GENERATOR_BASE_URL}/${tableName}/config`,
|
||||||
|
method: "post",
|
||||||
|
data: data,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/** 获取代码生成预览数据 */
|
/** 获取代码生成预览数据 */
|
||||||
static getPreviewData(tableName: string) {
|
static getPreviewData(tableName: string) {
|
||||||
return request<any, GeneratorPreviewVO[]>({
|
return request<any, GeneratorPreviewVO[]>({
|
||||||
url: `${DATABASE_BASE_URL}/table/${tableName}/preview`,
|
url: `${GENERATOR_BASE_URL}/${tableName}/preview`,
|
||||||
method: "get",
|
method: "get",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default DatabaseAPI;
|
export default GeneratorAPI;
|
||||||
|
|
||||||
/** 代码生成预览对象 */
|
/** 代码生成预览对象 */
|
||||||
export interface GeneratorPreviewVO {
|
export interface GeneratorPreviewVO {
|
||||||
@@ -65,49 +76,68 @@ export interface TablePageVO {
|
|||||||
createTime: string;
|
createTime: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 数据表字段VO */
|
/** 代码生成配置表单 */
|
||||||
export interface TableColumnVO {
|
export interface GenConfigForm {
|
||||||
/** 字段名称 */
|
/** 主键 */
|
||||||
columnName: string;
|
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;
|
formType?: number;
|
||||||
}
|
|
||||||
|
/** 查询类型 */
|
||||||
interface GeneratorConfigForm {
|
queryType?: number;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|||||||
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"
|
type="primary"
|
||||||
size="small"
|
size="small"
|
||||||
link
|
link
|
||||||
@click="handleOpenDialog('config', scope.row.tableName)"
|
@click="handleOpenDialog(scope.row.tableName)"
|
||||||
>
|
>
|
||||||
<i-ep-MagicStick />
|
<i-ep-MagicStick />
|
||||||
生成
|
生成
|
||||||
@@ -75,10 +75,187 @@
|
|||||||
@close="handleCloseDialog"
|
@close="handleCloseDialog"
|
||||||
size="80%"
|
size="80%"
|
||||||
>
|
>
|
||||||
<div v-if="dialog.type === 'preview'">
|
<el-steps :active="active" align-center finish-status="success" simple>
|
||||||
<el-row>
|
<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-col :span="6">
|
||||||
<el-scrollbar max-height="80vh">
|
<el-scrollbar max-height="72vh">
|
||||||
<el-tree
|
<el-tree
|
||||||
:data="treeData"
|
:data="treeData"
|
||||||
default-expand-all
|
default-expand-all
|
||||||
@@ -93,11 +270,11 @@
|
|||||||
</el-scrollbar>
|
</el-scrollbar>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="18">
|
<el-col :span="18">
|
||||||
<el-scrollbar max-height="80vh">
|
<el-scrollbar max-height="72vh">
|
||||||
<div class="absolute-rt z-36 right-5 top-2">
|
<div class="absolute-rt z-36 right-5 top-2">
|
||||||
<el-link @click="handleCopyCode" type="primary">
|
<el-link @click="handleCopyCode" type="primary">
|
||||||
<el-icon><CopyDocument /></el-icon>
|
<el-icon><CopyDocument /></el-icon>
|
||||||
复制
|
一键复制
|
||||||
</el-link>
|
</el-link>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -114,140 +291,17 @@
|
|||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
</div>
|
</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>
|
<template #footer>
|
||||||
<el-button @click="handleCloseDialog">取 消</el-button>
|
<el-button type="success" @click="handlePrevClick" v-if="active !== 1">
|
||||||
<el-button type="primary" @click="handleSubmit">确 定</el-button>
|
<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>
|
</template>
|
||||||
</el-drawer>
|
</el-drawer>
|
||||||
</div>
|
</div>
|
||||||
@@ -263,23 +317,19 @@ import Codemirror from "codemirror-editor-vue3";
|
|||||||
import type { CmComponentRef } from "codemirror-editor-vue3";
|
import type { CmComponentRef } from "codemirror-editor-vue3";
|
||||||
import type { Editor, EditorConfiguration } from "codemirror";
|
import type { Editor, EditorConfiguration } from "codemirror";
|
||||||
const { copy, copied } = useClipboard();
|
const { copy, copied } = useClipboard();
|
||||||
|
import { FormTypeEnum } from "@/enums/FormTypeEnum";
|
||||||
const code = ref();
|
import { QueryTypeEnum } from "@/enums/QueryTypeEnum";
|
||||||
const cmRef = ref<CmComponentRef>();
|
|
||||||
const cmOptions: EditorConfiguration = {
|
|
||||||
mode: "text/javascript",
|
|
||||||
};
|
|
||||||
|
|
||||||
import GeneratorAPI, {
|
import GeneratorAPI, {
|
||||||
TablePageVO,
|
TablePageVO,
|
||||||
TableColumnVO,
|
GenConfigForm,
|
||||||
TablePageQuery,
|
TablePageQuery,
|
||||||
GeneratorPreviewVO,
|
|
||||||
} from "@/api/generator";
|
} from "@/api/generator";
|
||||||
|
|
||||||
const queryFormRef = ref(ElForm);
|
const queryFormRef = ref(ElForm);
|
||||||
|
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
|
const loadingText = ref("loading...");
|
||||||
const total = ref(0);
|
const total = ref(0);
|
||||||
|
|
||||||
const queryParams = reactive<TablePageQuery>({
|
const queryParams = reactive<TablePageQuery>({
|
||||||
@@ -289,14 +339,68 @@ const queryParams = reactive<TablePageQuery>({
|
|||||||
|
|
||||||
const pageData = ref<TablePageVO[]>([]);
|
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({
|
const dialog = reactive({
|
||||||
type: "",
|
|
||||||
visible: false,
|
visible: false,
|
||||||
title: "",
|
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() {
|
function handleQuery() {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
@@ -329,34 +433,41 @@ interface TreeNode {
|
|||||||
const treeData = ref<TreeNode[]>([]);
|
const treeData = ref<TreeNode[]>([]);
|
||||||
|
|
||||||
/** 打开弹窗 */
|
/** 打开弹窗 */
|
||||||
function handleOpenDialog(type: string, tableName: string) {
|
function handleOpenDialog(tableName: string) {
|
||||||
dialog.visible = true;
|
dialog.visible = true;
|
||||||
dialog.type = type;
|
GeneratorAPI.getGenConfig(tableName).then((data) => {
|
||||||
if (type === "config") {
|
dialog.title = `${tableName} 代码生成`;
|
||||||
GeneratorAPI.getTableColumns(tableName).then((data) => {
|
formData.value = data;
|
||||||
dialog.title = `配置 ${tableName}`;
|
if (formData.value.id) {
|
||||||
tableColumns.value = data;
|
active.value = 3;
|
||||||
});
|
handlePreview(tableName);
|
||||||
} else if (type === "preview") {
|
} else {
|
||||||
treeData.value = [];
|
active.value = 1;
|
||||||
GeneratorAPI.getPreviewData(tableName).then((data) => {
|
}
|
||||||
dialog.title = `预览 ${tableName}`;
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// 组装树形结构完善代码
|
/** 获取生成预览 */
|
||||||
const tree = buildTree(data);
|
function handlePreview(tableName: string) {
|
||||||
treeData.value = [tree];
|
treeData.value = [];
|
||||||
|
GeneratorAPI.getPreviewData(tableName).then((data) => {
|
||||||
|
dialog.title = `预览 ${tableName}`;
|
||||||
|
|
||||||
// 默认选中第一个叶子节点并设置 code 值
|
// 组装树形结构完善代码
|
||||||
const firstLeafNode = findFirstLeafNode(tree);
|
const tree = buildTree(data);
|
||||||
if (firstLeafNode) {
|
treeData.value = [tree];
|
||||||
code.value = firstLeafNode.content || "";
|
|
||||||
}
|
// 默认选中第一个叶子节点并设置 code 值
|
||||||
});
|
const firstLeafNode = findFirstLeafNode(tree);
|
||||||
}
|
if (firstLeafNode) {
|
||||||
|
code.value = firstLeafNode.content || "";
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 递归构建树形结构
|
* 递归构建树形结构
|
||||||
|
*
|
||||||
* @param data - 数据数组
|
* @param data - 数据数组
|
||||||
* @returns 树形结构根节点
|
* @returns 树形结构根节点
|
||||||
*/
|
*/
|
||||||
@@ -372,24 +483,22 @@ function buildTree(
|
|||||||
const parts = item.path.split(separator);
|
const parts = item.path.split(separator);
|
||||||
|
|
||||||
// 定义特殊路径
|
// 定义特殊路径
|
||||||
|
// TODO: 如果菜单有多个节点,需要将此菜单作为独立一级的节点,而不是合并到上一级。 按照此规则, com.youlai.system 则是三个节点,而不是合并到一起,但是这里需要将 com.youlai.system 合并到一起,所以需要特殊处理
|
||||||
const specialPaths = [
|
const specialPaths = [
|
||||||
|
"com\\youlai\\system",
|
||||||
"src\\main",
|
"src\\main",
|
||||||
|
"java",
|
||||||
"youlai-boot",
|
"youlai-boot",
|
||||||
"vue3-element-admin",
|
"vue3-element-admin",
|
||||||
"java",
|
|
||||||
"com\\youlai\\system",
|
|
||||||
];
|
];
|
||||||
|
|
||||||
// 检查路径中的特殊部分并合并它们
|
// 检查路径中的特殊部分并合并它们
|
||||||
const mergedParts: string[] = [];
|
const mergedParts: string[] = [];
|
||||||
let buffer: string[] = [];
|
let buffer: string[] = [];
|
||||||
|
|
||||||
console.log("parts", parts);
|
|
||||||
|
|
||||||
parts.forEach((part) => {
|
parts.forEach((part) => {
|
||||||
buffer.push(part);
|
buffer.push(part);
|
||||||
const currentPath = buffer.join(separator);
|
const currentPath = buffer.join(separator);
|
||||||
console.log("currentPath", currentPath);
|
|
||||||
if (specialPaths.includes(currentPath)) {
|
if (specialPaths.includes(currentPath)) {
|
||||||
mergedParts.push(currentPath);
|
mergedParts.push(currentPath);
|
||||||
buffer = [];
|
buffer = [];
|
||||||
@@ -483,8 +592,6 @@ watch(copied, () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function handleSubmit() {}
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
handleQuery();
|
handleQuery();
|
||||||
cmRef.value?.destroy();
|
cmRef.value?.destroy();
|
||||||
|
|||||||
Reference in New Issue
Block a user