mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-26 22:31:21 +00:00
fix(gencode): 修复代码生成模块的多处问题
refactor(backend): 重构代码生成服务层和控制器层逻辑 feat(backend): 添加SQL模板文件后缀 fix(backend): 修复用户服务中的用户名空值检查 style(backend): 优化导入和代码格式 refactor(frontend): 重构代码生成前端组件和API fix(frontend): 修复用户信息表单的可选字段 feat(frontend): 添加Python和SQL图标资源 style(frontend): 调整样式和布局 chore: 更新依赖版本和配置文件 docs: 更新注释和文档内容
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,48 +0,0 @@
|
||||
<template>
|
||||
<el-form ref="basicInfoForm" :model="info" :rules="rules" label-width="150px">
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="表名称" prop="tableName">
|
||||
<el-input v-model="info.table_name" placeholder="请输入仓库名称"/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="表描述" prop="tableComment">
|
||||
<el-input v-model="info.table_comment" placeholder="请输入"/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="实体类名称" prop="className">
|
||||
<el-input v-model="info.class_name" placeholder="请输入"/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="作者" prop="functionAuthor">
|
||||
<el-input v-model="info.function_author" placeholder="请输入"/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="info.remark" type="textarea" :rows="3"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
defineProps({
|
||||
info: {
|
||||
type: Object,
|
||||
default: null
|
||||
}
|
||||
});
|
||||
|
||||
// 表单校验
|
||||
const rules = ref({
|
||||
table_name: [{ required: true, message: "请输入表名称", trigger: "blur" }],
|
||||
table_comment: [{ required: true, message: "请输入表描述", trigger: "blur" }],
|
||||
class_name: [{ required: true, message: "请输入实体类名称", trigger: "blur" }],
|
||||
function_author: [{ required: true, message: "请输入作者", trigger: "blur" }]
|
||||
});
|
||||
</script>
|
||||
@@ -1,46 +0,0 @@
|
||||
<template>
|
||||
<!-- 创建表 -->
|
||||
<el-dialog v-model="visible" title="创建表" width="800px" top="5vh" append-to-body>
|
||||
<span>创建表语句(支持多个建表语句):</span>
|
||||
<el-input v-model="content" type="textarea" :rows="10" placeholder="请输入文本"></el-input>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button type="primary" @click="handleImportTable">确 定</el-button>
|
||||
<el-button @click="visible = false">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import GencodeAPI from "@/api/generator/gencode";
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
const visible = ref(false);
|
||||
const content = ref("");
|
||||
const emit = defineEmits(["ok"]);
|
||||
|
||||
/** 显示弹框 */
|
||||
function show() {
|
||||
visible.value = true;
|
||||
}
|
||||
|
||||
/** 导入按钮操作 */
|
||||
function handleImportTable() {
|
||||
if (content.value === "") {
|
||||
ElMessage.error("请输入建表语句");
|
||||
return;
|
||||
}
|
||||
GencodeAPI.createTable(content.value).then(res => {
|
||||
ElMessage.success(res.data.msg || "创建成功");
|
||||
if (res.data.code === 200) {
|
||||
visible.value = false;
|
||||
emit("ok");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
show,
|
||||
});
|
||||
</script>
|
||||
@@ -1,235 +0,0 @@
|
||||
<template>
|
||||
<el-card>
|
||||
<el-tabs v-model="activeName">
|
||||
<el-tab-pane label="基本信息" name="basic">
|
||||
<basic-info-form ref="basicInfo" :info="info" />
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="字段信息" name="columnInfo">
|
||||
<el-table ref="dragTable" :data="columns" row-key="columnId" :max-height="tableHeight">
|
||||
<el-table-column label="序号" type="index" min-width="5%"/>
|
||||
<el-table-column
|
||||
label="字段列名"
|
||||
prop="columnName"
|
||||
min-width="10%"
|
||||
:show-overflow-tooltip="true"
|
||||
/>
|
||||
<el-table-column label="字段描述" min-width="10%">
|
||||
<template #default="scope">
|
||||
<el-input v-model="scope.row.columnComment"></el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column
|
||||
label="物理类型"
|
||||
prop="columnType"
|
||||
min-width="10%"
|
||||
:show-overflow-tooltip="true"
|
||||
/>
|
||||
<el-table-column label="Python类型" min-width="11%">
|
||||
<template #default="scope">
|
||||
<el-select v-model="scope.row.pythonType">
|
||||
<el-option label="str" value="str" />
|
||||
<el-option label="int" value="int" />
|
||||
<el-option label="float" value="float" />
|
||||
<el-option label="Decimal" value="Decimal" />
|
||||
<el-option label="date" value="date" />
|
||||
<el-option label="time" value="time" />
|
||||
<el-option label="datetime" value="datetime" />
|
||||
<el-option label="bytes" value="bytes" />
|
||||
<el-option label="dict" value="dict" />
|
||||
<el-option label="list" value="list" />
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="Python属性" min-width="10%">
|
||||
<template #default="scope">
|
||||
<el-input v-model="scope.row.pythonField"></el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="插入" min-width="5%">
|
||||
<template #default="scope">
|
||||
<el-checkbox v-model="scope.row.isInsert" true-label="1" false-label="0"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="编辑" min-width="5%">
|
||||
<template #default="scope">
|
||||
<el-checkbox v-model="scope.row.isEdit" true-label="1" false-label="0"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="列表" min-width="5%">
|
||||
<template #default="scope">
|
||||
<el-checkbox v-model="scope.row.isList" true-label="1" false-label="0"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="查询" min-width="5%">
|
||||
<template #default="scope">
|
||||
<el-checkbox v-model="scope.row.isQuery" true-label="1" false-label="0"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="查询方式" min-width="10%">
|
||||
<template #default="scope">
|
||||
<el-select v-model="scope.row.queryType">
|
||||
<el-option label="=" value="EQ" />
|
||||
<el-option label="!=" value="NE" />
|
||||
<el-option label=">" value="GT" />
|
||||
<el-option label=">=" value="GTE" />
|
||||
<el-option label="<" value="LT" />
|
||||
<el-option label="<=" value="LTE" />
|
||||
<el-option label="LIKE" value="LIKE" />
|
||||
<el-option label="BETWEEN" value="BETWEEN" />
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="必填" min-width="5%">
|
||||
<template #default="scope">
|
||||
<el-checkbox v-model="scope.row.isRequired" true-label="1" false-label="0"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="唯一" min-width="5%">
|
||||
<template #default="scope">
|
||||
<el-checkbox v-model="scope.row.isUnique" true-label="1" false-label="0"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="显示类型" min-width="12%">
|
||||
<template #default="scope">
|
||||
<el-select v-model="scope.row.htmlType">
|
||||
<el-option label="文本框" value="input" />
|
||||
<el-option label="文本域" value="textarea" />
|
||||
<el-option label="下拉框" value="select" />
|
||||
<el-option label="单选框" value="radio" />
|
||||
<el-option label="复选框" value="checkbox" />
|
||||
<el-option label="日期控件" value="datetime" />
|
||||
<el-option label="图片上传" value="imageUpload" />
|
||||
<el-option label="文件上传" value="fileUpload" />
|
||||
<el-option label="富文本控件" value="editor" />
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="字典类型" min-width="12%">
|
||||
<template #default="scope">
|
||||
<el-select v-model="scope.row.dictType" clearable filterable placeholder="请选择">
|
||||
<el-option
|
||||
v-for="dict in dictOptions"
|
||||
:key="dict.dictType"
|
||||
:label="dict.dictName"
|
||||
:value="dict.dictType">
|
||||
<span style="float: left">{{ dict.dictName }}</span>
|
||||
<span style="float: right; color: #8492a6; font-size: 13px">{{ dict.dictType }}</span>
|
||||
</el-option>
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="生成信息" name="genInfo">
|
||||
<!-- 将GenTableSchema类型转换为GenInfo类型 -->
|
||||
<gen-info-form
|
||||
ref="genInfo"
|
||||
:info="convertToGenInfo(info)"
|
||||
:tables="tables"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<el-form label-width="100px">
|
||||
<div style="text-align: center;margin-left:-100px;margin-top:10px;">
|
||||
<el-button type="primary" @click="submitForm()">提交</el-button>
|
||||
<el-button @click="close()">返回</el-button>
|
||||
</div>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="GenEdit">
|
||||
import GencodeAPI from "@/api/generator/gencode";
|
||||
import DictAPI from "@/api/system/dict";
|
||||
import { ElMessage } from 'element-plus';
|
||||
import router from '@/router';
|
||||
import type { GenTableSchema, GenTableDetailResult } from '@/api/generator/gencode';
|
||||
|
||||
const route = useRoute();
|
||||
const basicInfoRef = ref();
|
||||
const genInfoRef = ref();
|
||||
|
||||
const activeName = ref("columnInfo");
|
||||
const tableHeight = ref(document.documentElement.scrollHeight - 245 + "px");
|
||||
const tables = ref<Array<any>>([]);
|
||||
const columns = ref<Array<any>>([]);
|
||||
const dictOptions = ref<Array<any>>([]);
|
||||
const info = ref<GenTableSchema>({} as GenTableSchema);
|
||||
|
||||
/**
|
||||
* 将对象转换为GenInfo类型
|
||||
*/
|
||||
function convertToGenInfo(tableSchema: any): any {
|
||||
if (!tableSchema) {
|
||||
return {};
|
||||
}
|
||||
return {
|
||||
tplCategory: tableSchema.tpl_category,
|
||||
tplWebType: tableSchema.tpl_web_type,
|
||||
packageName: tableSchema.package_name,
|
||||
moduleName: tableSchema.module_name,
|
||||
businessName: tableSchema.business_name,
|
||||
functionName: tableSchema.function_name,
|
||||
genType: tableSchema.gen_type,
|
||||
parentMenuId: tableSchema.parent_menu_id,
|
||||
genPath: tableSchema.gen_path,
|
||||
subTableName: tableSchema.sub_table_name,
|
||||
subTableFkName: tableSchema.sub_table_fk_name,
|
||||
treeCode: tableSchema.tree_code,
|
||||
treeParentCode: tableSchema.tree_parent_code,
|
||||
treeName: tableSchema.tree_name
|
||||
};
|
||||
}
|
||||
|
||||
/** 提交按钮 */
|
||||
function submitForm() {
|
||||
// 简化表单验证逻辑
|
||||
const genTable = Object.assign({}, info.value);
|
||||
genTable.columns = columns.value;
|
||||
genTable.tree_code = info.value.tree_code;
|
||||
genTable.tree_name = info.value.tree_name;
|
||||
genTable.tree_parent_code = info.value.tree_parent_code;
|
||||
genTable.parent_menu_id = info.value.parent_menu_id;
|
||||
|
||||
// 确保id存在且为number类型
|
||||
if (info.value && info.value.id !== undefined) {
|
||||
GencodeAPI.updateGenTable(Number(info.value.id), genTable).then((res: any) => {
|
||||
ElMessage.success(res.data.message || "更新成功");
|
||||
if (res.data.code === 200) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ElMessage.error("表ID不存在,无法更新");
|
||||
}
|
||||
}
|
||||
|
||||
function close() {
|
||||
const pageNum = route.query.page_no || route.query.pageNum;
|
||||
router.push({ path: "/tool/gen", query: { t: Date.now(), page_no: pageNum } });
|
||||
}
|
||||
|
||||
(() => {
|
||||
const tableId = route.params && route.params.tableId;
|
||||
if (tableId) {
|
||||
// 获取表详细信息
|
||||
GencodeAPI.getGenTableDetail(Number(tableId)).then(res => {
|
||||
if (res.data && res.data.data) {
|
||||
columns.value = res.data.data.rows || [];
|
||||
// 确保info包含所有必要的字段,特别是columns
|
||||
const tableInfo = res.data.data.info || {};
|
||||
info.value = {
|
||||
...tableInfo,
|
||||
columns: columns.value
|
||||
};
|
||||
tables.value = res.data.data.tables || [];
|
||||
}
|
||||
});
|
||||
/** 查询字典下拉列表 */
|
||||
DictAPI.getDictTypeOptionselect().then((response: any) => {
|
||||
dictOptions.value = response.data.data || [];
|
||||
});
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
@@ -1,424 +0,0 @@
|
||||
<template>
|
||||
<el-form ref="genInfoForm" :model="info" :rules="rules" label-width="150px">
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item prop="tplCategory">
|
||||
<template #label>生成模板</template>
|
||||
<el-select v-model="info.tplCategory" @change="tplSelectChange">
|
||||
<el-option label="单表(增删改查)" value="crud" />
|
||||
<el-option label="树表(增删改查)" value="tree" />
|
||||
<el-option label="主子表(增删改查)" value="sub" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item prop="tplWebType">
|
||||
<template #label>前端类型</template>
|
||||
<el-select v-model="info.tplWebType">
|
||||
<el-option label="Vue2 Element UI 模版" value="element-ui" />
|
||||
<el-option label="Vue3 Element Plus 模版" value="element-plus" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item prop="packageName">
|
||||
<template #label>
|
||||
生成包路径
|
||||
<el-tooltip content="生成在哪个java包下,例如 com.ruoyi.system" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-input v-model="info.packageName" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item prop="moduleName">
|
||||
<template #label>
|
||||
生成模块名
|
||||
<el-tooltip content="可理解为子系统名,例如 system" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-input v-model="info.moduleName" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item prop="businessName">
|
||||
<template #label>
|
||||
生成业务名
|
||||
<el-tooltip content="可理解为功能英文名,例如 user" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-input v-model="info.businessName" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item prop="functionName">
|
||||
<template #label>
|
||||
生成功能名
|
||||
<el-tooltip content="用作类描述,例如 用户" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-input v-model="info.functionName" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item prop="genType">
|
||||
<template #label>
|
||||
生成代码方式
|
||||
<el-tooltip content="默认为zip压缩包下载,也可以自定义生成路径" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-radio v-model="info.genType" value="0">zip压缩包</el-radio>
|
||||
<el-radio v-model="info.genType" value="1">自定义路径</el-radio>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col :span="12">
|
||||
<el-form-item>
|
||||
<template #label>
|
||||
上级菜单
|
||||
<el-tooltip content="分配到指定菜单下,例如 系统管理" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-tree-select
|
||||
v-model="info.parentMenuId"
|
||||
:data="menuOptions"
|
||||
:props="{ value: 'menuId', label: 'menuName', children: 'children' }"
|
||||
value-key="menuId"
|
||||
placeholder="请选择系统菜单"
|
||||
check-strictly
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
|
||||
<el-col v-if="info.genType == '1'" :span="24">
|
||||
<el-form-item prop="genPath">
|
||||
<template #label>
|
||||
自定义路径
|
||||
<el-tooltip content="填写磁盘绝对路径,若不填写,则生成到当前Web项目下" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-input v-model="info.genPath">
|
||||
<template #append>
|
||||
<el-dropdown>
|
||||
<el-button type="primary">
|
||||
最近路径快速选择
|
||||
<i class="el-icon-arrow-down el-icon--right"></i>
|
||||
</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item @click="handleResetGenPath">恢复默认的生成基础路径</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</template>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<template v-if="info.tplCategory == 'tree'">
|
||||
<h4 class="form-header">其他信息</h4>
|
||||
<el-row v-show="info.tplCategory == 'tree'">
|
||||
<el-col :span="12">
|
||||
<el-form-item>
|
||||
<template #label>
|
||||
树编码字段
|
||||
<el-tooltip content="树显示的编码字段名, 如:dept_id" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-select v-model="info.treeCode" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="(column, index) in info.columns || []"
|
||||
:key="index"
|
||||
:label="column.columnName + ':' + column.columnComment"
|
||||
:value="column.columnName"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item>
|
||||
<template #label>
|
||||
树父编码字段
|
||||
<el-tooltip content="树显示的父编码字段名, 如:parent_Id" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-select v-model="info.treeParentCode" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="(column, index) in info.columns || []"
|
||||
:key="index"
|
||||
:label="column.columnName + ':' + column.columnComment"
|
||||
:value="column.columnName"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item>
|
||||
<template #label>
|
||||
树名称字段
|
||||
<el-tooltip content="树节点的显示名称字段名, 如:dept_name" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-select v-model="info.treeName" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="(column, index) in info.columns || []"
|
||||
:key="index"
|
||||
:label="column.columnName + ':' + column.columnComment"
|
||||
:value="column.columnName"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<template v-if="info.tplCategory == 'sub'">
|
||||
<h4 class="form-header">关联信息</h4>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item>
|
||||
<template #label>
|
||||
关联子表的表名
|
||||
<el-tooltip content="关联子表的表名, 如:sys_user" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-select v-model="info.subTableName" placeholder="请选择" @change="subSelectChange">
|
||||
<el-option
|
||||
v-for="(table, index) in tables || []"
|
||||
:key="index"
|
||||
:label="(table.tableName || '') + ':' + (table.tableComment || '')"
|
||||
:value="table.tableName || ''"
|
||||
:disabled="!table.tableName"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item>
|
||||
<template #label>
|
||||
子表关联的外键名
|
||||
<el-tooltip content="子表关联的外键名, 如:user_id" placement="top">
|
||||
<el-icon><question-filled /></el-icon>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
<el-select v-model="info.subTableFkName" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="(column, index) in subColumns"
|
||||
:key="index"
|
||||
:label="column.columnName + ':' + column.columnComment"
|
||||
:value="column.columnName"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
</el-form>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import MenuAPI from "@/api/system/menu";
|
||||
import { ref, computed, onMounted, watch } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
const subColumns = ref<Array<{ columnName: string; columnComment: string }>>([]);
|
||||
const menuOptions = ref<Array<{ id: number; menuId: number; menuName: string; parent_id: number; children: Array<any> }>>([]);
|
||||
const router = useRouter();
|
||||
|
||||
// 定义类型接口
|
||||
interface TableColumn {
|
||||
columnName: string;
|
||||
columnComment: string;
|
||||
}
|
||||
|
||||
interface TableInfo {
|
||||
tableName?: string;
|
||||
tableComment?: string;
|
||||
columns?: TableColumn[];
|
||||
}
|
||||
|
||||
interface GenInfo {
|
||||
tplCategory?: string;
|
||||
tplWebType?: string;
|
||||
packageName?: string;
|
||||
moduleName?: string;
|
||||
businessName?: string;
|
||||
functionName?: string;
|
||||
genType?: string;
|
||||
parentMenuId?: number;
|
||||
genPath?: string;
|
||||
subTableName?: string;
|
||||
subTableFkName?: string;
|
||||
columns?: TableColumn[];
|
||||
treeCode?: string;
|
||||
treeParentCode?: string;
|
||||
treeName?: string;
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
info?: GenInfo;
|
||||
tables?: TableInfo[];
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'update:info', value: GenInfo): void;
|
||||
}>();
|
||||
|
||||
// 使用computed创建一个安全的info对象,确保所有属性都有默认值
|
||||
const info = computed<GenInfo>({
|
||||
get() {
|
||||
return {
|
||||
tplCategory: '',
|
||||
tplWebType: 'element-plus',
|
||||
packageName: '',
|
||||
moduleName: '',
|
||||
businessName: '',
|
||||
functionName: '',
|
||||
genType: '0',
|
||||
parentMenuId: undefined,
|
||||
genPath: '',
|
||||
subTableName: '',
|
||||
subTableFkName: '',
|
||||
columns: [],
|
||||
treeCode: '',
|
||||
treeParentCode: '',
|
||||
treeName: '',
|
||||
...props.info
|
||||
};
|
||||
},
|
||||
set(newValue: GenInfo) {
|
||||
emit('update:info', newValue);
|
||||
}
|
||||
});
|
||||
|
||||
// 表单校验
|
||||
const rules = ref({
|
||||
tplCategory: [{ required: true, message: "请选择生成模板", trigger: "blur" }],
|
||||
packageName: [{ required: true, message: "请输入生成包路径", trigger: "blur" }],
|
||||
moduleName: [{ required: true, message: "请输入生成模块名", trigger: "blur" }],
|
||||
businessName: [{ required: true, message: "请输入生成业务名", trigger: "blur" }],
|
||||
functionName: [{ required: true, message: "请输入生成功能名", trigger: "blur" }]
|
||||
});
|
||||
|
||||
function subSelectChange() {
|
||||
emit('update:info', {
|
||||
...info.value,
|
||||
subTableFkName: ""
|
||||
});
|
||||
}
|
||||
|
||||
function tplSelectChange(value: string) {
|
||||
if (value !== "sub") {
|
||||
emit('update:info', {
|
||||
...info.value,
|
||||
subTableName: "",
|
||||
subTableFkName: ""
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function setSubTableColumns(value?: string) {
|
||||
if (!value || !props.tables) {
|
||||
subColumns.value = [];
|
||||
return;
|
||||
}
|
||||
|
||||
for (const item of props.tables) {
|
||||
if (item.tableName === value && item.columns) {
|
||||
subColumns.value = item.columns;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 恢复默认生成路径的方法
|
||||
function handleResetGenPath() {
|
||||
emit('update:info', {
|
||||
...info.value,
|
||||
genPath: '/'
|
||||
});
|
||||
}
|
||||
|
||||
/** 查询菜单下拉树结构 */
|
||||
function getMenuTreeselect() {
|
||||
MenuAPI.getMenuList().then((response: any) => {
|
||||
// 简单的树形结构处理逻辑
|
||||
function buildTree(data: any[], idField: string): any[] {
|
||||
const result: any[] = [];
|
||||
const map: Record<string, any> = {};
|
||||
|
||||
// 构建id映射
|
||||
data.forEach(item => {
|
||||
map[item[idField]] = item;
|
||||
item.children = [];
|
||||
// 转换属性名以匹配tree-select的期望格式
|
||||
if (item.id !== undefined) {
|
||||
item.menuId = item.id;
|
||||
}
|
||||
if (item.menu_name !== undefined) {
|
||||
item.menuName = item.menu_name;
|
||||
}
|
||||
});
|
||||
|
||||
// 构建树
|
||||
data.forEach(item => {
|
||||
if (item.parent_id === 0 || !map[item.parent_id]) {
|
||||
result.push(item);
|
||||
} else {
|
||||
map[item.parent_id].children.push(item);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
if (response && response.data && response.data.data) {
|
||||
menuOptions.value = buildTree(response.data.data, "id");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getMenuTreeselect();
|
||||
// 初始化时检查tplWebType是否为空
|
||||
if (!props.info?.tplWebType) {
|
||||
emit('update:info', {
|
||||
...info.value,
|
||||
tplWebType: "element-plus"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
watch(() => props.info?.subTableName, (val) => {
|
||||
setSubTableColumns(val);
|
||||
});
|
||||
|
||||
watch(() => props.info?.tplWebType, (val) => {
|
||||
if (val === '' || val === undefined) {
|
||||
emit('update:info', {
|
||||
...info.value,
|
||||
tplWebType: "element-plus"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
</script>
|
||||
@@ -1,139 +0,0 @@
|
||||
<template>
|
||||
<!-- 导入表 -->
|
||||
<el-dialog v-model="visible" title="导入表" width="800px" top="5vh" append-to-body>
|
||||
<el-form ref="queryRef" :model="queryFormData" :inline="true">
|
||||
<el-form-item label="表名称" prop="tableName">
|
||||
<el-input
|
||||
v-model="queryFormData.table_name"
|
||||
placeholder="请输入表名称"
|
||||
clearable
|
||||
style="width: 180px"
|
||||
@keyup.enter="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="表描述" prop="tableComment">
|
||||
<el-input
|
||||
v-model="queryFormData.table_comment"
|
||||
placeholder="请输入表描述"
|
||||
clearable
|
||||
style="width: 180px"
|
||||
@keyup.enter="handleQuery"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-row>
|
||||
<el-table ref="table" :data="dbTableList" height="300px" @row-click="clickRow" @selection-change="handleSelectionChange">
|
||||
<template #empty>
|
||||
<el-empty :image-size="80" description="暂无数据" />
|
||||
</template>
|
||||
<el-table-column type="selection" width="55"></el-table-column>
|
||||
<el-table-column label="序号" type="index" min-width="55" align="center" fixed>
|
||||
<template #default="scope">
|
||||
<span>{{(queryFormData.page_no - 1) * queryFormData.page_size + scope.$index + 1}}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="database_name" label="数据库名称" :show-overflow-tooltip="true"></el-table-column>
|
||||
<el-table-column prop="table_name" label="表名称" :show-overflow-tooltip="true"></el-table-column>
|
||||
<el-table-column prop="table_comment" label="表描述" :show-overflow-tooltip="true"></el-table-column>
|
||||
<el-table-column prop="table_type" label="表类型"></el-table-column>
|
||||
</el-table>
|
||||
<pagination
|
||||
v-model:page="queryFormData.page_no"
|
||||
v-model:limit="queryFormData.page_size"
|
||||
:total="total"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</el-row>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button type="primary" @click="handleImportTable">确 定</el-button>
|
||||
<el-button @click="visible = false">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import GencodeAPI from "@/api/generator/gencode";
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
const total = ref(0);
|
||||
const visible = ref(false);
|
||||
const tables = ref<Array<string>>([]);
|
||||
const dbTableList = ref<Array<any>>([]);
|
||||
const queryRef = ref();
|
||||
const table = ref();
|
||||
|
||||
const queryFormData = reactive({
|
||||
page_no: 1,
|
||||
page_size: 10,
|
||||
table_name: undefined,
|
||||
table_comment: undefined
|
||||
});
|
||||
|
||||
const emit = defineEmits(["ok"]);
|
||||
|
||||
/** 查询参数列表 */
|
||||
function show() {
|
||||
getList();
|
||||
visible.value = true;
|
||||
}
|
||||
|
||||
/** 单击选择行 */
|
||||
function clickRow(row: any) {
|
||||
table.value?.toggleRowSelection(row);
|
||||
}
|
||||
|
||||
/** 多选框选中数据 */
|
||||
function handleSelectionChange(selection: Array<any>) {
|
||||
tables.value = selection.map(item => item.table_name);
|
||||
}
|
||||
|
||||
/** 查询表数据 */
|
||||
function getList() {
|
||||
GencodeAPI.listDbTable(queryFormData).then(res => {
|
||||
console.log(res.data);
|
||||
dbTableList.value = res.data.data.items;
|
||||
total.value = res.data.data.total;
|
||||
});
|
||||
}
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
function handleQuery() {
|
||||
queryFormData.page_no = 1;
|
||||
getList();
|
||||
}
|
||||
|
||||
/** 重置按钮操作 */
|
||||
function resetQuery() {
|
||||
if (queryRef.value) {
|
||||
queryRef.value.resetFields();
|
||||
}
|
||||
handleQuery();
|
||||
}
|
||||
|
||||
/** 导入按钮操作 */
|
||||
function handleImportTable() {
|
||||
const tableNames = tables.value.join(",");
|
||||
if (tableNames == "") {
|
||||
ElMessage.error("请选择要导入的表");
|
||||
return;
|
||||
}
|
||||
// 传递逗号分隔的字符串格式
|
||||
GencodeAPI.importTable(tableNames.split(",")).then((res: any) => {
|
||||
ElMessage.success(res.data.message);
|
||||
if (res.data.code === 200) {
|
||||
visible.value = false;
|
||||
emit("ok");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
show,
|
||||
});
|
||||
</script>
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user