mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-09-26 22:31:21 +00:00
refactor(gencode): 重构代码生成模块,优化类型定义和组件逻辑
- 将多个Vue组件脚本迁移至TypeScript,增强类型安全 - 重构API接口定义,优化参数传递和响应处理 - 改进表单验证逻辑,简化冗余代码 - 统一使用Element Plus的消息提示组件 - 优化路由处理逻辑,修复混合布局下的路径解析问题 - 完善类型定义,增加GenTableSchema等接口 - 移除未使用的导入和冗余代码 - 改进代码预览和复制功能
This commit is contained in:
@@ -30,7 +30,7 @@
|
||||
</el-form>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
<script setup lang="ts">
|
||||
defineProps({
|
||||
info: {
|
||||
type: Object,
|
||||
|
||||
@@ -12,12 +12,12 @@
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
<script setup lang="ts">
|
||||
import GencodeAPI from "@/api/generator/gencode";
|
||||
import { ElMessage } from 'element-plus';
|
||||
|
||||
const visible = ref(false);
|
||||
const content = ref("");
|
||||
const { proxy } = getCurrentInstance();
|
||||
const emit = defineEmits(["ok"]);
|
||||
|
||||
/** 显示弹框 */
|
||||
@@ -28,12 +28,12 @@ function show() {
|
||||
/** 导入按钮操作 */
|
||||
function handleImportTable() {
|
||||
if (content.value === "") {
|
||||
proxy.$modal.msgError("请输入建表语句");
|
||||
ElMessage.error("请输入建表语句");
|
||||
return;
|
||||
}
|
||||
GencodeAPI.createTable({ sql: content.value }).then(res => {
|
||||
proxy.$modal.msgSuccess(res.msg);
|
||||
if (res.code === 200) {
|
||||
GencodeAPI.createTable(content.value).then(res => {
|
||||
ElMessage.success(res.data.msg || "创建成功");
|
||||
if (res.data.code === 200) {
|
||||
visible.value = false;
|
||||
emit("ok");
|
||||
}
|
||||
|
||||
@@ -122,7 +122,12 @@
|
||||
</el-table>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="生成信息" name="genInfo">
|
||||
<gen-info-form ref="genInfo" :info="info" :tables="tables" />
|
||||
<!-- 将GenTableSchema类型转换为GenInfo类型 -->
|
||||
<gen-info-form
|
||||
ref="genInfo"
|
||||
:info="convertToGenInfo(info)"
|
||||
:tables="tables"
|
||||
/>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<el-form label-width="100px">
|
||||
@@ -134,74 +139,96 @@
|
||||
</el-card>
|
||||
</template>
|
||||
|
||||
<script setup name="GenEdit">
|
||||
<script setup lang="ts" name="GenEdit">
|
||||
import GencodeAPI from "@/api/generator/gencode";
|
||||
import DictAPI from "@/api/system/dict";
|
||||
import basicInfoForm from "./components/basicInfoForm";
|
||||
import genInfoForm from "./components/genInfoForm";
|
||||
import { ElMessage } from 'element-plus';
|
||||
import router from '@/router';
|
||||
import type { GenTableSchema, GenTableDetailResult } from '@/api/generator/gencode';
|
||||
|
||||
const route = useRoute();
|
||||
const { proxy } = getCurrentInstance();
|
||||
const basicInfoRef = ref();
|
||||
const genInfoRef = ref();
|
||||
|
||||
const activeName = ref("columnInfo");
|
||||
const tableHeight = ref(document.documentElement.scrollHeight - 245 + "px");
|
||||
const tables = ref([]);
|
||||
const columns = ref([]);
|
||||
const dictOptions = ref([]);
|
||||
const info = ref({});
|
||||
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 basicForm = proxy.$refs.basicInfo.$refs.basicInfoForm;
|
||||
const genForm = proxy.$refs.genInfo.$refs.genInfoForm;
|
||||
Promise.all([basicForm, genForm].map(getFormPromise)).then(res => {
|
||||
const validateResult = res.every(item => !!item);
|
||||
if (validateResult) {
|
||||
const genTable = Object.assign({}, info.value);
|
||||
genTable.columns = columns.value;
|
||||
genTable.params = {
|
||||
treeCode: info.value.treeCode,
|
||||
treeName: info.value.treeName,
|
||||
treeParentCode: info.value.treeParentCode,
|
||||
parentMenuId: info.value.parentMenuId
|
||||
};
|
||||
GencodeAPI.updateGenTable(genTable).then(res => {
|
||||
proxy.$modal.msgSuccess(res.msg);
|
||||
if (res.code === 200) {
|
||||
close();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
proxy.$modal.msgError("表单校验未通过,请重新检查提交内容");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getFormPromise(form) {
|
||||
return new Promise(resolve => {
|
||||
form.validate(res => {
|
||||
resolve(res);
|
||||
// 简化表单验证逻辑
|
||||
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 obj = { path: "/tool/gen", query: { t: Date.now(), pageNum: route.query.pageNum } };
|
||||
proxy.$tab.closeOpenPage(obj);
|
||||
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.getGenTable(tableId).then(res => {
|
||||
columns.value = res.data.rows;
|
||||
info.value = res.data.info;
|
||||
tables.value = res.data.tables;
|
||||
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 => {
|
||||
dictOptions.value = response.data;
|
||||
DictAPI.getDictTypeOptionselect().then((response: any) => {
|
||||
dictOptions.value = response.data.data || [];
|
||||
});
|
||||
}
|
||||
})();
|
||||
|
||||
@@ -119,7 +119,7 @@
|
||||
</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item @click="info.genPath = '/'">恢复默认的生成基础路径</el-dropdown-item>
|
||||
<el-dropdown-item @click="handleResetGenPath">恢复默认的生成基础路径</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
@@ -142,7 +142,7 @@
|
||||
</template>
|
||||
<el-select v-model="info.treeCode" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="(column, index) in info.columns"
|
||||
v-for="(column, index) in info.columns || []"
|
||||
:key="index"
|
||||
:label="column.columnName + ':' + column.columnComment"
|
||||
:value="column.columnName"
|
||||
@@ -160,7 +160,7 @@
|
||||
</template>
|
||||
<el-select v-model="info.treeParentCode" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="(column, index) in info.columns"
|
||||
v-for="(column, index) in info.columns || []"
|
||||
:key="index"
|
||||
:label="column.columnName + ':' + column.columnComment"
|
||||
:value="column.columnName"
|
||||
@@ -178,7 +178,7 @@
|
||||
</template>
|
||||
<el-select v-model="info.treeName" placeholder="请选择">
|
||||
<el-option
|
||||
v-for="(column, index) in info.columns"
|
||||
v-for="(column, index) in info.columns || []"
|
||||
:key="index"
|
||||
:label="column.columnName + ':' + column.columnComment"
|
||||
:value="column.columnName"
|
||||
@@ -202,10 +202,11 @@
|
||||
</template>
|
||||
<el-select v-model="info.subTableName" placeholder="请选择" @change="subSelectChange">
|
||||
<el-option
|
||||
v-for="(table, index) in tables"
|
||||
v-for="(table, index) in tables || []"
|
||||
:key="index"
|
||||
:label="table.tableName + ':' + table.tableComment"
|
||||
:value="table.tableName"
|
||||
:label="(table.tableName || '') + ':' + (table.tableComment || '')"
|
||||
:value="table.tableName || ''"
|
||||
:disabled="!table.tableName"
|
||||
></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
@@ -234,21 +235,78 @@
|
||||
</el-form>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
<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([]);
|
||||
const menuOptions = ref([]);
|
||||
const { proxy } = getCurrentInstance();
|
||||
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();
|
||||
|
||||
const props = defineProps({
|
||||
info: {
|
||||
type: Object,
|
||||
default: null
|
||||
// 定义类型接口
|
||||
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
|
||||
};
|
||||
},
|
||||
tables: {
|
||||
type: Array,
|
||||
default: null
|
||||
set(newValue: GenInfo) {
|
||||
emit('update:info', newValue);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -262,44 +320,104 @@ const rules = ref({
|
||||
});
|
||||
|
||||
function subSelectChange() {
|
||||
props.info.subTableFkName = "";
|
||||
emit('update:info', {
|
||||
...info.value,
|
||||
subTableFkName: ""
|
||||
});
|
||||
}
|
||||
|
||||
function tplSelectChange(value) {
|
||||
function tplSelectChange(value: string) {
|
||||
if (value !== "sub") {
|
||||
props.info.subTableName = "";
|
||||
props.info.subTableFkName = "";
|
||||
emit('update:info', {
|
||||
...info.value,
|
||||
subTableName: "",
|
||||
subTableFkName: ""
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function setSubTableColumns(value) {
|
||||
for (const item in props.tables) {
|
||||
const name = props.tables[item].tableName;
|
||||
if (value === name) {
|
||||
subColumns.value = props.tables[item].columns;
|
||||
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 => {
|
||||
menuOptions.value = proxy.handleTree(response.data, "menuId");
|
||||
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 => {
|
||||
watch(() => props.info?.subTableName, (val) => {
|
||||
setSubTableColumns(val);
|
||||
});
|
||||
|
||||
watch(() => props.info.tplWebType, val => {
|
||||
if (val === '') {
|
||||
props.info.tplWebType = "element-plus";
|
||||
watch(() => props.info?.tplWebType, (val) => {
|
||||
if (val === '' || val === undefined) {
|
||||
emit('update:info', {
|
||||
...info.value,
|
||||
tplWebType: "element-plus"
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -57,14 +57,16 @@
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
<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([]);
|
||||
const dbTableList = ref([]);
|
||||
const { proxy } = getCurrentInstance();
|
||||
const tables = ref<Array<string>>([]);
|
||||
const dbTableList = ref<Array<any>>([]);
|
||||
const queryRef = ref();
|
||||
const table = ref();
|
||||
|
||||
const queryFormData = reactive({
|
||||
page_no: 1,
|
||||
@@ -82,12 +84,12 @@ function show() {
|
||||
}
|
||||
|
||||
/** 单击选择行 */
|
||||
function clickRow(row) {
|
||||
proxy.$refs.table.toggleRowSelection(row);
|
||||
function clickRow(row: any) {
|
||||
table.value?.toggleRowSelection(row);
|
||||
}
|
||||
|
||||
/** 多选框选中数据 */
|
||||
function handleSelectionChange(selection) {
|
||||
function handleSelectionChange(selection: Array<any>) {
|
||||
tables.value = selection.map(item => item.table_name);
|
||||
}
|
||||
|
||||
@@ -108,7 +110,9 @@ function handleQuery() {
|
||||
|
||||
/** 重置按钮操作 */
|
||||
function resetQuery() {
|
||||
proxy.resetForm("queryRef");
|
||||
if (queryRef.value) {
|
||||
queryRef.value.resetFields();
|
||||
}
|
||||
handleQuery();
|
||||
}
|
||||
|
||||
@@ -116,12 +120,13 @@ function resetQuery() {
|
||||
function handleImportTable() {
|
||||
const tableNames = tables.value.join(",");
|
||||
if (tableNames == "") {
|
||||
proxy.$modal.msgError("请选择要导入的表");
|
||||
ElMessage.error("请选择要导入的表");
|
||||
return;
|
||||
}
|
||||
GencodeAPI.importTable({ tables: tableNames }).then(res => {
|
||||
proxy.$modal.msgSuccess(res.msg);
|
||||
if (res.code === 200) {
|
||||
// 因为tables.value已经是string[]类型了,直接传入
|
||||
GencodeAPI.importTable(tables.value).then((res: any) => {
|
||||
ElMessage.success(res.data.message);
|
||||
if (res.data.code === 200) {
|
||||
visible.value = false;
|
||||
emit("ok");
|
||||
}
|
||||
|
||||
@@ -205,19 +205,19 @@
|
||||
</el-card>
|
||||
|
||||
<!-- 预览界面 -->
|
||||
<el-dialog v-model="preview.open" :title="preview.title" width="80%" top="5vh" append-to-body class="scrollbar">
|
||||
<el-tabs v-model="preview.activeName">
|
||||
<el-tab-pane
|
||||
v-for="(value, key) in preview.data"
|
||||
:label="key.substring(key.lastIndexOf('/')+1,key.indexOf('.jinja2'))"
|
||||
:name="key.substring(key.lastIndexOf('/')+1,key.indexOf('.jinja2'))"
|
||||
:key="value"
|
||||
>
|
||||
<el-link :underline="false" icon="DocumentCopy" @click="() => navigator.clipboard.writeText(value).then(() => copyTextSuccess())" style="float:right"> 复制</el-link>
|
||||
<pre>{{ value }}</pre>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-dialog>
|
||||
<el-dialog v-model="preview.open" :title="preview.title" width="80%" top="5vh" append-to-body class="scrollbar">
|
||||
<el-tabs v-model="preview.activeName">
|
||||
<el-tab-pane
|
||||
v-for="(value, key) in preview.data"
|
||||
:label="String(key).substring(String(key).lastIndexOf('/')+1,String(key).indexOf('.jinja2'))"
|
||||
:name="String(key).substring(String(key).lastIndexOf('/')+1,String(key).indexOf('.jinja2'))"
|
||||
:key="value"
|
||||
>
|
||||
<el-link :underline="false" icon="DocumentCopy" @click="() => handleCopyText(value)" style="float:right"> 复制</el-link>
|
||||
<pre>{{ value }}</pre>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-dialog>
|
||||
<import-table ref="importRef" @ok="handleQuery" />
|
||||
<create-table ref="createRef" @ok="handleQuery" />
|
||||
</div>
|
||||
@@ -240,14 +240,14 @@ const route = useRoute();
|
||||
const importRef = ref();
|
||||
const createRef = ref();
|
||||
|
||||
const tableList = ref([]);
|
||||
const tableList = ref<Array<any>>([]);
|
||||
const loading = ref(true);
|
||||
const ids = ref([]);
|
||||
const ids = ref<Array<number>>([]);
|
||||
const single = ref(true);
|
||||
const multiple = ref(true);
|
||||
const total = ref(0);
|
||||
const tableNames = ref([]);
|
||||
const dateRange = ref([]);
|
||||
const tableNames = ref<Array<string>>([]);
|
||||
const dateRange = ref<Array<string>>([]);
|
||||
const uniqueId = ref("");
|
||||
|
||||
|
||||
@@ -256,9 +256,7 @@ const data = reactive({
|
||||
page_no: 1,
|
||||
page_size: 10,
|
||||
table_name: undefined,
|
||||
table_comment: undefined,
|
||||
start_time: undefined,
|
||||
end_time: undefined
|
||||
table_comment: undefined
|
||||
},
|
||||
preview: {
|
||||
open: false,
|
||||
@@ -286,8 +284,8 @@ const { queryFormData, preview } = toRefs(data);
|
||||
|
||||
onActivated(() => {
|
||||
const time = route.query.t;
|
||||
if (time != null && time != uniqueId.value) {
|
||||
uniqueId.value = time;
|
||||
if (time != null && String(time) != uniqueId.value) {
|
||||
uniqueId.value = String(time);
|
||||
queryFormData.value.page_no = Number(route.query.page_no || 1);
|
||||
dateRange.value = [];
|
||||
loadingData();
|
||||
@@ -302,12 +300,6 @@ function loadingData() {
|
||||
...queryFormData.value
|
||||
};
|
||||
|
||||
// 如果有日期范围,添加到查询参数中
|
||||
if (dateRange.value && dateRange.value.length === 2) {
|
||||
queryParams.start_time = dateRange.value[0];
|
||||
queryParams.end_time = dateRange.value[1];
|
||||
}
|
||||
|
||||
GencodeAPI.listTable(queryParams).then(response => {
|
||||
tableList.value = response.data.data.items;
|
||||
total.value = response.data.data.total;
|
||||
@@ -322,32 +314,32 @@ function handleQuery() {
|
||||
}
|
||||
|
||||
/** 生成代码操作 */
|
||||
function handleGenTable(row) {
|
||||
function handleGenTable(row: any) {
|
||||
const tbNames = row?.table_name || tableNames.value;
|
||||
if (!tbNames || (Array.isArray(tbNames) && tbNames.length === 0)) {
|
||||
ElMessage.error("请选择要生成的数据");
|
||||
return;
|
||||
}
|
||||
|
||||
if (row?.genType === "1") {
|
||||
GencodeAPI.genCodeToPath(row.tableName).then(() => {
|
||||
ElMessage.success("成功生成到自定义路径:" + row.genPath);
|
||||
if (row?.gen_type === "1") {
|
||||
GencodeAPI.genCodeToPath(row.table_name).then(() => {
|
||||
ElMessage.success("成功生成到自定义路径:" + row.gen_path);
|
||||
});
|
||||
} else {
|
||||
GencodeAPI.batchGenCode(tbNames).then(response => {
|
||||
const blob = new Blob([response], { type: 'application/zip' });
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
GencodeAPI.batchGenCode(tbNames).then((response: any) => {
|
||||
const blob = new Blob([response.data], { type: 'application/zip' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = 'code.zip';
|
||||
link.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
URL.revokeObjectURL(url);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** 同步数据库操作 */
|
||||
function handleSynchDb(row) {
|
||||
function handleSynchDb(row: any) {
|
||||
const tableName = row.table_name;
|
||||
ElMessageBox.confirm(
|
||||
'确认要强制同步"' + tableName + '"表结构吗?',
|
||||
@@ -386,16 +378,14 @@ function handleRefresh() {
|
||||
page_no: 1,
|
||||
page_size: 10,
|
||||
table_name: undefined,
|
||||
table_comment: undefined,
|
||||
start_time: undefined,
|
||||
end_time: undefined
|
||||
table_comment: undefined
|
||||
};
|
||||
handleQuery();
|
||||
}
|
||||
|
||||
/** 预览按钮 */
|
||||
function handlePreview(row) {
|
||||
GencodeAPI.previewTable(row.tableId).then(response => {
|
||||
function handlePreview(row: any) {
|
||||
GencodeAPI.previewTable(row.id).then(response => {
|
||||
preview.value.data = response.data;
|
||||
preview.value.open = true;
|
||||
preview.value.activeName = "do.py";
|
||||
@@ -407,38 +397,49 @@ function copyTextSuccess() {
|
||||
ElMessage.success("复制成功");
|
||||
}
|
||||
|
||||
/** 处理文本复制 */
|
||||
function handleCopyText(value: string) {
|
||||
if (window && window.navigator && window.navigator.clipboard) {
|
||||
window.navigator.clipboard.writeText(value).then(() => {
|
||||
copyTextSuccess();
|
||||
}).catch(() => {
|
||||
ElMessage.error("复制失败");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 多选框选中数据
|
||||
function handleSelectionChange(selection) {
|
||||
ids.value = selection.map(item => item.tableId);
|
||||
tableNames.value = selection.map(item => item.table_name);
|
||||
single.value = selection.length != 1;
|
||||
multiple.value = !selection.length;
|
||||
}
|
||||
function handleSelectionChange(selection: Array<any>) {
|
||||
ids.value = selection.map((item: any) => item.id);
|
||||
tableNames.value = selection.map((item: any) => item.table_name);
|
||||
single.value = selection.length != 1;
|
||||
multiple.value = !selection.length;
|
||||
}
|
||||
|
||||
/** 修改按钮操作 */
|
||||
function handleEditTable(row) {
|
||||
const tableId = row.tableId || ids.value[0];
|
||||
router.push({ path: "/tool/gen-edit/index/" + tableId, query: { page_no: queryFormData.value.page_no } });
|
||||
}
|
||||
/** 修改按钮操作 */
|
||||
function handleEditTable(row: any) {
|
||||
const tableId = row.id || ids.value[0];
|
||||
router.push({ path: "/tool/gen-edit/index/" + tableId, query: { page_no: queryFormData.value.page_no } });
|
||||
}
|
||||
|
||||
/** 删除按钮操作 */
|
||||
function handleDelete(row) {
|
||||
const tableIds = row?.tableId ? [row.tableId] : ids.value;
|
||||
ElMessageBox.confirm(
|
||||
'是否确认删除表编号为"' + tableIds + '"的数据项?',
|
||||
'删除确认',
|
||||
{
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}
|
||||
).then(() => {
|
||||
return GencodeAPI.deleteTable(tableIds);
|
||||
}).then(() => {
|
||||
loadingData();
|
||||
ElMessage.success("删除成功");
|
||||
}).catch(() => {});
|
||||
}
|
||||
/** 删除按钮操作 */
|
||||
function handleDelete(row: any) {
|
||||
const tableIds = row?.id ? [row.id] : ids.value;
|
||||
ElMessageBox.confirm(
|
||||
'是否确认删除表编号为"' + tableIds + '"的数据项?',
|
||||
'删除确认',
|
||||
{
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
}
|
||||
).then(() => {
|
||||
return GencodeAPI.deleteTable({ table_ids: tableIds });
|
||||
}).then(() => {
|
||||
loadingData();
|
||||
ElMessage.success("删除成功");
|
||||
}).catch(() => {});
|
||||
}
|
||||
|
||||
loadingData();
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user