Merge branch 'develop'

This commit is contained in:
ray
2024-07-29 00:25:55 +08:00
16 changed files with 845 additions and 27 deletions

View File

@@ -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",

View File

@@ -1,6 +1,6 @@
{
"name": "vue3-element-admin",
"version": "2.12.0",
"version": "2.13.0",
"private": true,
"type": "module",
"scripts": {
@@ -50,6 +50,8 @@
"@wangeditor/editor-for-vue": "5.1.10",
"animate.css": "^4.1.1",
"axios": "^1.7.2",
"codemirror": "^5",
"codemirror-editor-vue3": "^2.7.0",
"color": "^4.2.3",
"echarts": "^5.5.1",
"element-plus": "^2.7.6",
@@ -71,6 +73,7 @@
"@commitlint/cli": "^18.6.1",
"@commitlint/config-conventional": "^18.6.3",
"@iconify-json/ep": "^1.1.15",
"@types/codemirror": "^5.60.15",
"@types/color": "^3.0.6",
"@types/lodash": "^4.17.6",
"@types/node": "^20.14.10",

143
src/api/generator.ts Normal file
View File

@@ -0,0 +1,143 @@
import request from "@/utils/request";
import { FormTypeEnum } from "@/enums/FormTypeEnum";
import { QueryTypeEnum } from "@/enums/QueryTypeEnum";
const GENERATOR_BASE_URL = "/api/v1/generator";
class GeneratorAPI {
/** 获取数据表分页列表 */
static getTablePage(params: TablePageQuery) {
return request<any, PageResult<TablePageVO[]>>({
url: `${GENERATOR_BASE_URL}/table/page`,
method: "get",
params: params,
});
}
/** 获取代码生成配置 */
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: `${GENERATOR_BASE_URL}/${tableName}/preview`,
method: "get",
});
}
}
export default GeneratorAPI;
/** 代码生成预览对象 */
export interface GeneratorPreviewVO {
/** 文件生成路径 */
path: string;
/** 文件名称 */
fileName: string;
/** 文件内容 */
content: string;
}
/** 数据表分页查询参数 */
export interface TablePageQuery extends PageQuery {
/** 关键字(表名) */
keywords?: string;
}
/** 数据表分页对象 */
export interface TablePageVO {
/** 表名称 */
tableName: string;
/** 表描述 */
tableComment: string;
/** 存储引擎 */
engine: string;
/** 字符集排序规则 */
tableCollation: string;
/** 创建时间 */
createTime: 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;
/** 字段类型 */
fieldType?: string;
/** 字段描述 */
fieldComment?: string;
/** 是否在列表显示 */
isShowInList?: number;
/** 是否在表单显示 */
isShowInForm?: number;
/** 是否在查询条件显示 */
isShowInQuery?: number;
/** 是否必填 */
isRequired?: number;
/** 表单类型 */
formType?: number;
/** 查询类型 */
queryType?: number;
}

View File

@@ -0,0 +1 @@
<svg t="1720831003829" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5159" width="200" height="200"><path d="M438.4 849.1l222.7-646.7c0.2-0.5 0.3-1.1 0.4-1.6L438.4 849.1z" opacity=".224" p-id="5160"></path><path d="M661.2 168.7h-67.5c-3.4 0-6.5 2.2-7.6 5.4L354.7 846c-0.3 0.8-0.4 1.7-0.4 2.6 0 4.4 3.6 8 8 8h67.8c3.4 0 6.5-2.2 7.6-5.4l0.7-2.1 223.1-648.3 7.4-21.4c0.3-0.8 0.4-1.7 0.4-2.6-0.1-4.5-3.6-8.1-8.1-8.1zM954.6 502.1c-0.8-1-1.7-1.9-2.7-2.7l-219-171.3c-3.5-2.7-8.5-2.1-11.2 1.4-1.1 1.4-1.7 3.1-1.7 4.9v81.3c0 2.5 1.1 4.8 3.1 6.3l115 90-115 90c-1.9 1.5-3.1 3.8-3.1 6.3v81.3c0 4.4 3.6 8 8 8 1.8 0 3.5-0.6 4.9-1.7l219-171.3c6.9-5.4 8.2-15.5 2.7-22.5zM291.1 328.1l-219 171.3c-1 0.8-1.9 1.7-2.7 2.7-5.4 7-4.2 17 2.7 22.5l219 171.3c1.4 1.1 3.1 1.7 4.9 1.7 4.4 0 8-3.6 8-8v-81.3c0-2.5-1.1-4.8-3.1-6.3l-115-90 115-90c1.9-1.5 3.1-3.8 3.1-6.3v-81.3c0-1.8-0.6-3.5-1.7-4.9-2.7-3.5-7.7-4.1-11.2-1.4z" p-id="5161"></path></svg>

After

Width:  |  Height:  |  Size: 967 B

View File

@@ -0,0 +1 @@
<svg t="1721541550402" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="1592" width="200" height="200"><path d="M979.096493 980.950486H44.904061C19.829898 980.950486 0.000277 960.442811 0.000277 935.839135v-740.047567c0-25.184865 20.410811-45.111351 44.903784-45.111352h934.192432c25.074162 0 44.903784 20.507676 44.903784 45.111352v740.047567c0 25.184865-20.410811 45.111351-44.903784 45.111351z" fill="#FFA000" p-id="1593"></path><path d="M512.000277 344.409946H0.000277V112.902919a45.097514 45.097514 0 0 1 44.903784-45.24973h350.470918c19.829622 0 37.320649 12.924541 43.146379 32.311352L512.000277 344.423784z" fill="#FFA000" p-id="1594"></path><path d="M909.699736 925.599135H114.300817c-25.184865 0-45.111351-20.134054-45.111351-44.281081v-603.32973c0-24.728216 20.493838-44.281081 45.111351-44.281081h795.398919c25.184865 0 45.111351 20.134054 45.111352 44.281081v603.32973c0.567351 24.147027-19.926486 44.281081-45.111352 44.281081z" fill="#FFFFFF" p-id="1595"></path><path d="M979.096493 980.950486H44.904061C19.829898 980.950486 0.000277 960.802595 0.000277 936.627892V361.056865c0-24.755892 20.410811-44.322595 44.903784-44.322595h934.192432c25.074162 0 44.903784 20.147892 44.903784 44.322595v575.571027c0 24.755892-20.410811 44.322595-44.903784 44.322594z" fill="#FFCA28" p-id="1596"></path><path d="M364.46125 485.708108H106.634655C93.917682 485.708108 83.027304 476.021622 83.027304 463.512216c0-11.96973 10.295351-22.223568 23.607351-22.223567h257.21773c12.716973 0 23.607351 9.686486 23.607351 22.223567 0 11.955892-10.295351 22.223568-22.998486 22.223568z m0 149.296433H106.634655c-12.716973 0-23.607351-9.686486-23.607351-22.223568 0-12.537081 10.295351-22.223568 23.607351-22.223568h257.21773c12.716973 0 23.607351 9.686486 23.607351 22.223568 0 12.537081-10.295351 22.223568-22.998486 22.223568z" fill="#FFF8E1" p-id="1597"></path></svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -0,0 +1 @@
<svg t="1721534999310" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2348" width="200" height="200"><path d="M558.08 472.064c48.128 53.248-13.312 103.424-13.312 103.424s119.808-61.44 65.536-139.264c-51.2-71.68-91.136-107.52 122.88-232.448 0 1.024-335.872 86.016-175.104 268.288" fill="#FF0000" p-id="2349"></path><path d="M610.304 5.12s101.376 101.376-96.256 258.048C356.352 389.12 478.208 460.8 514.048 543.744 420.864 459.776 354.304 386.048 399.36 317.44 463.872 216.064 651.264 166.912 610.304 5.12" fill="#FF0000" p-id="2350"></path><path d="M720.896 757.76c183.296-95.232 98.304-188.416 39.936-175.104-15.36 3.072-21.504 5.12-21.504 5.12s5.12-8.192 16.384-11.264c117.76-40.96 207.872 120.832-37.888 186.368-1.024 0 2.048-3.072 3.072-5.12m-337.92 38.912s-37.888 21.504 26.624 29.696c76.8 8.192 117.76 8.192 202.752-8.192 0 0 23.552 15.36 53.248 26.624-191.488 80.896-433.152-5.12-282.624-48.128m-23.552-106.496s-43.008 31.744 23.552 37.888c82.944 8.192 149.504 10.24 261.12-13.312 0 0 16.384 16.384 40.96 24.576-231.424 68.608-490.496 5.12-325.632-49.152" fill="#6699FF" p-id="2351"></path><path d="M811.008 876.544s27.648 23.552-31.744 40.96c-111.616 34.816-460.8 45.056-558.08 2.048-34.816-15.36 31.744-35.84 51.2-40.96 21.504-5.12 34.816-3.072 34.816-3.072-38.912-28.672-251.904 52.224-107.52 75.776 390.144 62.464 712.704-28.672 611.328-74.752M400.384 578.56s-178.176 43.008-63.488 56.32c49.152 6.144 146.432 5.12 235.52-3.072 73.728-6.144 147.456-19.456 147.456-19.456s-26.624 11.264-45.056 24.576c-181.248 48.128-530.432 26.624-430.08-23.552 88.064-39.936 155.648-34.816 155.648-34.816" fill="#6699FF" p-id="2352"></path><path d="M418.816 1015.808c176.128 11.264 446.464-6.144 453.632-90.112 0 0-13.312 31.744-146.432 56.32-150.528 27.648-336.896 24.576-446.464 6.144 2.048 1.024 24.576 20.48 139.264 27.648" fill="#6699FF" p-id="2353"></path></svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -0,0 +1 @@
<svg t="1721541160105" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="13856" width="200" height="200"><path d="M762.464 263.776a141.568 141.568 0 0 1 71.136 40.992 187.296 187.296 0 0 1 27.264 36.576c0.352 1.44-49.088 34.656-79.072 53.184-1.088 0.736-5.408-3.968-10.304-11.2a64.448 64.448 0 0 0-53.44-32c-34.464-2.368-56.672 15.68-56.512 45.856a41.6 41.6 0 0 0 4.896 21.312c7.584 15.68 21.664 25.088 65.888 44.256 81.408 35.04 116.352 58.144 137.92 90.976a165.056 165.056 0 0 1 13.312 138.656 152.448 152.448 0 0 1-125.824 90.08 348.8 348.8 0 0 1-86.656-0.896 208.992 208.992 0 0 1-115.712-60.288 200.896 200.896 0 0 1-29.632-43.872 84.96 84.96 0 0 1 10.464-6.656c5.056-2.88 24.192-13.888 42.24-24.352l32.768-19.2 6.848 9.984a152.672 152.672 0 0 0 43.2 41.344 105.6 105.6 0 0 0 110.656-5.6 49.44 49.44 0 0 0 6.4-63.168c-8.832-12.64-26.88-23.264-78.176-45.504a281.6 281.6 0 0 1-107.168-65.76 149.984 149.984 0 0 1-31.232-56.864 227.712 227.712 0 0 1-1.984-72.576 138.624 138.624 0 0 1 116.608-107.968 288 288 0 0 1 86.112 2.688z m-266.976 47.456l0.352 46.528h-148.16v420.736H243.2V357.856H95.04V312.16a447.552 447.552 0 0 1 1.28-46.912c0.544-0.736 90.624-1.088 199.84-0.896l198.752 0.544z" fill="#007ACC" p-id="13857"></path></svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

1
src/assets/icons/vue.svg Normal file
View File

@@ -0,0 +1 @@
<svg t="1721541029594" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3336" width="200" height="200"><path d="M615.6 123.6h165.5L512 589.7 242.9 123.6H63.5L512 900.4l448.5-776.9z" fill="#41B883" p-id="3337"></path><path d="M781.1 123.6H615.6L512 303 408.4 123.6H242.9L512 589.7z" fill="#34495E" p-id="3338"></path></svg>

After

Width:  |  Height:  |  Size: 366 B

1
src/assets/icons/xml.svg Normal file
View File

@@ -0,0 +1 @@
<svg t="1721557951693" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="19605" width="200" height="200"><path d="M692.497067 546.133333h52.087466l40.482134-260.642133V273.066667h-63.624534L605.730133 471.722667 542.037333 279.210667V273.066667h-63.6928L443.733333 546.133333h52.087467l23.1424-161.3824L570.9824 546.133333h46.2848l98.372267-155.170133-23.1424 148.957867z" fill="#FF7D19" p-id="19606"></path><path d="M845.2096 572.074667c-12.0832 0-18.090667 0-24.1664 11.400533-6.007467 5.7344-12.0832 17.2032-12.0832 22.9376v85.8112H597.674667c-54.340267 0-96.597333 40.004267-96.597334 91.477333v165.888H150.869333c-18.0224 0-36.181333-5.666133-48.264533-17.066666-12.014933-11.4688-24.098133-28.672-24.098133-45.806934V137.216c0-40.004267 36.181333-68.608 72.362666-68.608h585.728c42.1888 0 72.362667 28.603733 72.362667 68.608v51.473067c0 17.2032 18.158933 34.338133 36.2496 34.338133s36.181333-11.400533 42.257067-34.338133v-51.473067C887.466667 62.8736 821.0432 0 742.6048 0H144.861867C66.3552 0 0 57.207467 0 137.284267V886.784C0 961.1264 66.423467 1024 144.861867 1024H615.765333c12.0832 0 18.158933-5.7344 24.1664-11.4688l229.376-211.626667c6.144-5.7344 12.151467-17.2032 12.151467-22.869333v-165.888c0-22.9376-18.158933-40.072533-36.2496-40.072533z m-42.325333 183.022933l-205.2096 188.8256h-24.1664v-165.888c0-5.7344 0-11.4688 6.075733-17.2032 6.007467-5.7344 12.0832-5.7344 18.090667-5.7344h205.277866z" fill="#FF7D19" p-id="19607"></path><path d="M372.804267 273.066667L303.650133 366.1824 251.767467 273.066667H182.613333l80.6912 136.533333L136.533333 546.133333h74.888534L292.181333 453.0176 344.064 546.133333h69.154133L332.458667 409.6l115.234133-136.533333H372.804267z m501.3504 229.649066l28.808533-217.224533V273.066667h-51.882667l-40.277333 266.922666V546.133333h207.4624L1024 502.715733h-149.845333z" fill="#FF7D19" p-id="19608"></path></svg>

After

Width:  |  Height:  |  Size: 1.9 KiB

14
src/enums/FormTypeEnum.ts Normal file
View 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: "日期框" },
};

View File

@@ -5,18 +5,18 @@ export const enum MenuTypeEnum {
/**
* 目录
*/
CATALOG = "CATALOG",
CATALOG,
/**
* 菜单
*/
MENU = "MENU",
MENU,
/**
* 按钮
*/
BUTTON = "BUTTON",
BUTTON,
/**
* 外链
*/
EXTLINK = "EXTLINK",
EXTLINK,
}

View 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%'" },
};

View File

@@ -10,7 +10,10 @@ import "element-plus/theme-chalk/dark/css-vars.css";
import "@/styles/index.scss";
import "uno.css";
import "animate.css";
import { InstallCodemirro } from "codemirror-editor-vue3";
const app = createApp(App);
// 注册插件
app.use(setupPlugins);
app.use(InstallCodemirro);
app.mount("#app");

View File

@@ -0,0 +1,599 @@
<template>
<div class="app-container">
<div class="search-container">
<el-form ref="queryFormRef" :model="queryParams" :inline="true">
<el-form-item prop="keywords" label="关键字">
<el-input
v-model="queryParams.keywords"
placeholder="表名"
clearable
@keyup.enter="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handleQuery">
<i-ep-search />
搜索
</el-button>
<el-button @click="handleResetQuery">
<i-ep-refresh />
重置
</el-button>
</el-form-item>
</el-form>
</div>
<el-card shadow="never" class="table-container">
<el-table
ref="dataTableRef"
v-loading="loading"
:data="pageData"
highlight-current-row
border
>
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="表名" prop="tableName" min-width="100" />
<el-table-column label="描述" prop="tableComment" width="150" />
<el-table-column label="存储引擎" align="center" prop="engine" />
<el-table-column
label="排序规则"
align="center"
prop="tableCollation"
/>
<el-table-column label="创建时间" align="center" prop="createTime" />
<el-table-column fixed="right" label="操作" width="150">
<template #default="scope">
<el-button
type="primary"
size="small"
link
@click="handleOpenDialog(scope.row.tableName)"
>
<i-ep-MagicStick />
生成
</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-if="total > 0"
v-model:total="total"
v-model:page="queryParams.pageNum"
v-model:limit="queryParams.pageSize"
@pagination="handleQuery"
/>
</el-card>
<el-drawer
v-model="dialog.visible"
:title="dialog.title"
@close="handleCloseDialog"
size="80%"
>
<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="72vh">
<el-tree
:data="treeData"
default-expand-all
highlight-current
@node-click="handleFileTreeNodeClick"
>
<template #default="{ data }">
<svg-icon :icon-class="getFileTreeNodeIcon(data.label)" />
<span class="ml-1">{{ data.label }}</span>
</template>
</el-tree>
</el-scrollbar>
</el-col>
<el-col :span="18">
<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>
<Codemirror
v-model:value="code"
:options="cmOptions"
border
ref="cmRef"
:readonly="true"
height="100%"
width="100%"
/>
</el-scrollbar>
</el-col>
</el-row>
</div>
<template #footer>
<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>
</template>
<script setup lang="ts">
defineOptions({
name: "Generator",
});
import "codemirror/mode/javascript/javascript.js";
import Codemirror from "codemirror-editor-vue3";
import type { CmComponentRef } from "codemirror-editor-vue3";
import type { Editor, EditorConfiguration } from "codemirror";
const { copy, copied } = useClipboard();
import { FormTypeEnum } from "@/enums/FormTypeEnum";
import { QueryTypeEnum } from "@/enums/QueryTypeEnum";
import GeneratorAPI, {
TablePageVO,
GenConfigForm,
TablePageQuery,
} from "@/api/generator";
const queryFormRef = ref(ElForm);
const loading = ref(false);
const loadingText = ref("loading...");
const total = ref(0);
const queryParams = reactive<TablePageQuery>({
pageNum: 1,
pageSize: 10,
});
const pageData = ref<TablePageVO[]>([]);
const formData = ref<GenConfigForm>({});
const formTypeOptions: Record<string, OptionType> = FormTypeEnum;
const queryTypeOptions: Record<string, OptionType> = QueryTypeEnum;
const dialog = reactive({
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;
GeneratorAPI.getTablePage(queryParams)
.then((data) => {
pageData.value = data.list;
total.value = data.total;
})
.finally(() => {
loading.value = false;
});
}
/** 重置查询 */
function handleResetQuery() {
queryFormRef.value.resetFields();
queryParams.pageNum = 1;
handleQuery();
}
function handleCloseDialog() {
dialog.visible = false;
}
interface TreeNode {
label: string;
content?: string;
children?: TreeNode[];
}
const treeData = ref<TreeNode[]>([]);
/** 打开弹窗 */
function handleOpenDialog(tableName: string) {
dialog.visible = true;
GeneratorAPI.getGenConfig(tableName).then((data) => {
dialog.title = `${tableName} 代码生成`;
formData.value = data;
if (formData.value.id) {
active.value = 3;
handlePreview(tableName);
} else {
active.value = 1;
}
});
}
/** 获取生成预览 */
function handlePreview(tableName: string) {
treeData.value = [];
GeneratorAPI.getPreviewData(tableName).then((data) => {
dialog.title = `预览 ${tableName}`;
// 组装树形结构完善代码
const tree = buildTree(data);
treeData.value = [tree];
// 默认选中第一个叶子节点并设置 code 值
const firstLeafNode = findFirstLeafNode(tree);
if (firstLeafNode) {
code.value = firstLeafNode.content || "";
}
});
}
/**
* 递归构建树形结构
*
* @param data - 数据数组
* @returns 树形结构根节点
*/
function buildTree(
data: { path: string; fileName: string; content: string }[]
): TreeNode {
// 动态获取根节点
const root: TreeNode = { label: "前后端工程代码", children: [] };
data.forEach((item) => {
// 将路径分成数组
const separator = item.path.includes("/") ? "/" : "\\";
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",
];
// 检查路径中的特殊部分并合并它们
const mergedParts: string[] = [];
let buffer: string[] = [];
parts.forEach((part) => {
buffer.push(part);
const currentPath = buffer.join(separator);
if (specialPaths.includes(currentPath)) {
mergedParts.push(currentPath);
buffer = [];
}
});
// 将 mergedParts 路径中的分隔符\替换为/
mergedParts.forEach((part, index) => {
mergedParts[index] = part.replace(/\\/g, "/");
});
if (buffer.length > 0) {
mergedParts.push(...buffer);
}
let currentNode = root;
mergedParts.forEach((part) => {
// 查找或创建当前部分的子节点
let node = currentNode.children?.find((child) => child.label === part);
if (!node) {
node = { label: part, children: [] };
currentNode.children?.push(node);
}
currentNode = node;
});
// 添加文件节点
currentNode.children?.push({
label: item.fileName,
content: item?.content,
});
});
return root;
}
/**
* 递归查找第一个叶子节点
* @param node - 树形节点
* @returns 第一个叶子节点
*/
function findFirstLeafNode(node: TreeNode): TreeNode | null {
if (!node.children || node.children.length === 0) {
return node;
}
for (const child of node.children) {
const leafNode = findFirstLeafNode(child);
if (leafNode) {
return leafNode;
}
}
return null;
}
/** 文件树节点 Click */
function handleFileTreeNodeClick(data: TreeNode) {
if (!data.children || data.children.length === 0) {
code.value = data.content || "";
}
}
function getFileTreeNodeIcon(label: string) {
if (label.endsWith(".java")) {
return "java";
}
if (label.endsWith(".html")) {
return "html";
}
if (label.endsWith(".vue")) {
return "vue";
}
if (label.endsWith(".ts")) {
return "typescript";
}
if (label.endsWith(".xml")) {
return "xml";
}
return "file";
}
const handleCopyCode = () => {
if (code.value) {
copy(code.value);
}
};
watch(copied, () => {
if (copied.value) {
ElMessage.success("复制成功");
}
});
onMounted(() => {
handleQuery();
cmRef.value?.destroy();
});
</script>

View File

@@ -12,25 +12,32 @@
</el-form-item>
<el-form-item>
<el-button type="primary" @click="handleQuery"
><i-ep-search />搜索</el-button
>
<el-button @click="handleResetQuery"><i-ep-refresh />重置</el-button>
<el-button type="primary" @click="handleQuery">
<i-ep-search />
搜索
</el-button>
<el-button @click="handleResetQuery">
<i-ep-refresh />
重置
</el-button>
</el-form-item>
</el-form>
</div>
<el-card shadow="never" class="table-container">
<template #header>
<el-button type="success" @click="handleOpenDialog()"
><i-ep-plus />新增</el-button
>
<el-button type="success" @click="handleOpenDialog()">
<i-ep-plus />
新增
</el-button>
<el-button
type="danger"
:disabled="ids.length === 0"
@click="handleDelete()"
><i-ep-delete />删除</el-button
>
<i-ep-delete />
删除
</el-button>
</template>
<el-table
@@ -62,7 +69,8 @@
link
@click="handleOpenAssignPermDialog(scope.row)"
>
<i-ep-position />分配权限
<i-ep-position />
分配权限
</el-button>
<el-button
type="primary"
@@ -70,7 +78,8 @@
link
@click="handleOpenDialog(scope.row.id)"
>
<i-ep-edit />编辑
<i-ep-edit />
编辑
</el-button>
<el-button
type="danger"
@@ -78,7 +87,8 @@
link
@click="handleDelete(scope.row.id)"
>
<i-ep-delete />删除
<i-ep-delete />
删除
</el-button>
</template>
</el-table-column>
@@ -167,14 +177,16 @@
</el-input>
<div class="flex-center">
<el-button type="primary" size="small" plain @click="togglePermTree"
><i-ep-switch />{{ isExpanded ? "收缩" : "展开" }}</el-button
>
<el-button type="primary" size="small" plain @click="togglePermTree">
<i-ep-switch />
{{ isExpanded ? "收缩" : "展开" }}
</el-button>
<el-checkbox
v-model="parentChildLinked"
@change="handleparentChildLinkedChange"
class="ml-5"
>父子联动
>
父子联动
</el-checkbox>
<el-tooltip placement="bottom">
@@ -205,9 +217,9 @@
<template #footer>
<div class="dialog-footer">
<el-button type="primary" @click="handleAssignPermSubmit"
> </el-button
>
<el-button type="primary" @click="handleAssignPermSubmit">
</el-button>
<el-button @click="assignPermDialogVisible = false"> </el-button>
</div>
</template>
@@ -287,6 +299,7 @@ function handleQuery() {
loading.value = false;
});
}
/** 重置查询 */
function handleResetQuery() {
queryFormRef.value.resetFields();

View File

@@ -207,7 +207,6 @@
append-to-body
@close="handleCloseDialog"
>
<!-- 用户新增/编辑表单 -->
<el-form
ref="userFormRef"
:model="formData"