2024-06-15 13:02:35 +08:00
|
|
|
<template>
|
2024-07-01 16:38:24 +08:00
|
|
|
<div class="sys-codeGen-container" v-loading="options.loading">
|
|
|
|
|
<el-card shadow="hover" :body-style="{ padding: '5px 5px 0 5px', display: 'flex', width: '100%', height: '100%', alignItems: 'start' }">
|
2024-07-06 00:56:24 +08:00
|
|
|
<el-form :model="state.queryParams" ref="queryForm" :show-message="false" :inlineMessage="true" label-width="auto" style="flex: 1 1 0%">
|
2024-07-01 16:38:24 +08:00
|
|
|
<el-row :gutter="10">
|
|
|
|
|
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
|
|
|
|
|
<el-form-item label="业务名" prop="busName">
|
|
|
|
|
<el-input placeholder="业务名" clearable @keyup.enter="handleQuery" v-model="state.queryParams.busName" @keyup.enter.native="handleQuery(true)" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
<el-col class="mb5" :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
|
|
|
|
|
<el-form-item label="数据库表名" prop="tableName">
|
|
|
|
|
<el-input placeholder="数据库表名" clearable @keyup.enter="handleQuery" v-model="state.queryParams.tableName" @keyup.enter.native="handleQuery(true)" />
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
|
|
|
|
</el-form>
|
|
|
|
|
|
|
|
|
|
<el-divider style="height: calc(100% - 5px); margin: 0 10px" direction="vertical" />
|
|
|
|
|
|
|
|
|
|
<el-row>
|
|
|
|
|
<el-col>
|
2024-06-15 13:02:35 +08:00
|
|
|
<el-button-group>
|
2024-07-01 16:38:24 +08:00
|
|
|
<el-button type="primary" icon="ele-Search" @click="handleQuery(true)" :loading="options.loading"> 查询 </el-button>
|
|
|
|
|
<el-button icon="ele-Refresh" @click="resetQuery" :loading="options.loading"> 重置 </el-button>
|
2024-06-15 13:02:35 +08:00
|
|
|
</el-button-group>
|
2024-07-01 16:38:24 +08:00
|
|
|
</el-col>
|
|
|
|
|
</el-row>
|
2024-06-15 13:02:35 +08:00
|
|
|
</el-card>
|
|
|
|
|
|
|
|
|
|
<el-card class="full-table" shadow="hover" style="margin-top: 5px">
|
2024-07-01 16:38:24 +08:00
|
|
|
<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options" @sort-change="sortChange">
|
|
|
|
|
<template #toolbar_buttons>
|
|
|
|
|
<el-button type="primary" icon="ele-Plus" @click="handleAdd"> 新增 </el-button>
|
|
|
|
|
</template>
|
|
|
|
|
<template #toolbar_tools> </template>
|
|
|
|
|
<template #empty>
|
|
|
|
|
<el-empty :image-size="200" />
|
|
|
|
|
</template>
|
|
|
|
|
<template #row_generateType="{ row }">
|
|
|
|
|
<el-tag v-if="row.generateType == 100"> 下载压缩包 </el-tag>
|
|
|
|
|
<el-tag v-else-if="row.generateType == 111"> 下载压缩包(前端) </el-tag>
|
|
|
|
|
<el-tag v-else-if="row.generateType == 121"> 下载压缩包(后端) </el-tag>
|
|
|
|
|
<el-tag v-else-if="row.generateType == 211"> 生成到本项目(前端) </el-tag>
|
|
|
|
|
<el-tag v-else-if="row.generateType == 221"> 生成到本项目(后端) </el-tag>
|
|
|
|
|
<el-tag type="danger" v-else> 生成到本项目 </el-tag>
|
|
|
|
|
</template>
|
|
|
|
|
<template #row_buttons="{ row }">
|
|
|
|
|
<el-tooltip content="编辑" placement="top">
|
|
|
|
|
<el-button icon="ele-Edit" text type="primary" @click="handleEdit(row)"> </el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
<el-tooltip content="删除" placement="top">
|
|
|
|
|
<el-button icon="ele-Delete" text type="danger" @click="handleDelete(row)"> </el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
<el-tooltip content="配置" placement="top">
|
|
|
|
|
<el-button icon="ele-Setting" text type="danger" @click="handleConfig(row)">配置</el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
<el-tooltip content="预览" placement="top">
|
|
|
|
|
<el-button icon="ele-Camera" text type="primary" @click="handlePreview(row)">预览</el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
<el-tooltip content="开始生成" placement="top">
|
|
|
|
|
<el-button icon="ele-Cpu" text type="primary" @click="handleGenerate(row)">生成</el-button>
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
</template>
|
|
|
|
|
<template #pager>
|
|
|
|
|
<vxe-pager
|
|
|
|
|
:loading="options.loading"
|
|
|
|
|
v-model:current-page="state.tableParams.page"
|
|
|
|
|
v-model:page-size="state.tableParams.pageSize"
|
|
|
|
|
:total="state.tableParams.total"
|
|
|
|
|
@page-change="pageChange"
|
|
|
|
|
/>
|
|
|
|
|
</template>
|
|
|
|
|
</vxe-grid>
|
2024-06-15 13:02:35 +08:00
|
|
|
</el-card>
|
|
|
|
|
|
2024-07-01 16:38:24 +08:00
|
|
|
<EditCodeGenDialog :title="state.title" ref="EditCodeGenRef" @handleQuery="handleQuery" :application-namespaces="state.applicationNamespaces" />
|
2024-06-15 13:02:35 +08:00
|
|
|
<CodeConfigDialog ref="CodeConfigRef" @handleQuery="handleQuery" />
|
2024-07-01 16:38:24 +08:00
|
|
|
<PreviewDialog :title="state.title" ref="PreviewRef" />
|
2024-06-15 13:02:35 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts" setup name="sysCodeGen">
|
|
|
|
|
import { onMounted, reactive, ref, defineAsyncComponent } from 'vue';
|
|
|
|
|
import { ElMessageBox, ElMessage } from 'element-plus';
|
2024-07-01 16:38:24 +08:00
|
|
|
import { auth } from '/@/utils/authFunction';
|
|
|
|
|
import { VxeGridInstance, VxePagerEvents, VxePagerDefines } from 'vxe-table';
|
|
|
|
|
import { useVxeTable } from '/@/hooks/vxeTableOptionsHook';
|
|
|
|
|
import { downloadByUrl } from '/@/utils/download';
|
|
|
|
|
|
2024-06-15 13:02:35 +08:00
|
|
|
import EditCodeGenDialog from './component/editCodeGenDialog.vue';
|
|
|
|
|
import CodeConfigDialog from './component/genConfigDialog.vue';
|
|
|
|
|
|
|
|
|
|
import { getAPI } from '/@/utils/axios-utils';
|
|
|
|
|
import { SysCodeGenApi } from '/@/api-services/api';
|
|
|
|
|
import { SysCodeGen } from '/@/api-services/models';
|
|
|
|
|
|
|
|
|
|
const PreviewDialog = defineAsyncComponent(() => import('./component/previewDialog.vue'));
|
2024-07-01 16:38:24 +08:00
|
|
|
const xGrid = ref<VxeGridInstance>();
|
2024-06-15 13:02:35 +08:00
|
|
|
const EditCodeGenRef = ref<InstanceType<typeof EditCodeGenDialog>>();
|
|
|
|
|
const CodeConfigRef = ref<InstanceType<typeof CodeConfigDialog>>();
|
|
|
|
|
const PreviewRef = ref<InstanceType<typeof PreviewDialog>>();
|
|
|
|
|
const state = reactive({
|
|
|
|
|
dbData: [] as any,
|
|
|
|
|
configId: '',
|
|
|
|
|
tableName: '',
|
|
|
|
|
queryParams: {
|
|
|
|
|
name: undefined,
|
|
|
|
|
code: undefined,
|
|
|
|
|
tableName: undefined,
|
|
|
|
|
busName: undefined,
|
|
|
|
|
},
|
|
|
|
|
tableParams: {
|
|
|
|
|
page: 1,
|
2024-07-01 16:38:24 +08:00
|
|
|
pageSize: 50,
|
|
|
|
|
field: 'id', // 默认的排序字段
|
|
|
|
|
order: 'aes', // 排序方向
|
|
|
|
|
descStr: 'desc', // 降序排序的关键字符
|
2024-06-15 13:02:35 +08:00
|
|
|
total: 0 as any,
|
|
|
|
|
},
|
2024-07-01 16:38:24 +08:00
|
|
|
visible: false,
|
|
|
|
|
title: '',
|
2024-06-15 13:02:35 +08:00
|
|
|
applicationNamespaces: [] as Array<string>,
|
|
|
|
|
});
|
|
|
|
|
|
2024-07-01 16:38:24 +08:00
|
|
|
// 表格参数配置
|
|
|
|
|
const options = useVxeTable<SysCodeGen>({
|
|
|
|
|
id: 'sysCodeGen',
|
|
|
|
|
name: '代码生成',
|
|
|
|
|
columns: [
|
|
|
|
|
// { type: 'checkbox', width: 40, fixed: 'left' },
|
|
|
|
|
{ type: 'seq', title: '序号', width: 60, fixed: 'left' },
|
|
|
|
|
{ field: 'configId', title: '库定位器', minWidth: 200, showOverflow: 'tooltip' },
|
|
|
|
|
{ field: 'tableName', title: '表名称', minWidth: 200, showOverflow: 'tooltip' },
|
|
|
|
|
{ field: 'busName', title: '业务名', minWidth: 200, showOverflow: 'tooltip' },
|
|
|
|
|
{ field: 'nameSpace', title: '命名空间', minWidth: 200, showOverflow: 'tooltip' },
|
|
|
|
|
{ field: 'authorName', title: '作者姓名', minWidth: 200, showOverflow: 'tooltip' },
|
|
|
|
|
{ field: 'generateType', title: '生成方式', minWidth: 140, showOverflow: 'tooltip', slots: { default: 'row_generateType' } },
|
|
|
|
|
{ title: '操作', fixed: 'right', width: 280, showOverflow: true, slots: { default: 'row_buttons' } },
|
|
|
|
|
],
|
|
|
|
|
enableExport: auth('sysCodeGen:export'),
|
|
|
|
|
searchCallback: () => handleQuery(),
|
|
|
|
|
queryAllCallback: () => fetchData({ pageSize: 99999 }),
|
|
|
|
|
});
|
2024-06-15 13:02:35 +08:00
|
|
|
|
2024-07-01 16:38:24 +08:00
|
|
|
// 页面初始化
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
await handleQuery();
|
2024-06-15 13:02:35 +08:00
|
|
|
let res = await getAPI(SysCodeGenApi).apiSysCodeGenApplicationNamespacesGet();
|
|
|
|
|
state.applicationNamespaces = res.data.result as Array<string>;
|
|
|
|
|
});
|
|
|
|
|
|
2024-07-01 16:38:24 +08:00
|
|
|
// 查询操作
|
|
|
|
|
const handleQuery = async (reset = false) => {
|
|
|
|
|
options.loading = true;
|
|
|
|
|
if (reset) state.tableParams.page = 1;
|
|
|
|
|
var res = await fetchData(null);
|
|
|
|
|
xGrid.value?.loadData(res.data.result?.items ?? []);
|
|
|
|
|
state.tableParams.total = res.data.result?.total;
|
|
|
|
|
options.loading = false;
|
2024-06-15 13:02:35 +08:00
|
|
|
};
|
|
|
|
|
|
2024-07-01 16:38:24 +08:00
|
|
|
// 获取数据
|
|
|
|
|
const fetchData = async (tableParams: any) => {
|
|
|
|
|
let params = Object.assign(state.queryParams, state.tableParams, tableParams);
|
|
|
|
|
return getAPI(SysCodeGenApi).apiSysCodeGenPagePost(params);
|
2024-06-15 13:02:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 重置操作
|
|
|
|
|
const resetQuery = () => {
|
|
|
|
|
state.queryParams.busName = undefined;
|
|
|
|
|
state.queryParams.tableName = undefined;
|
2024-07-01 16:38:24 +08:00
|
|
|
handleQuery(true);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleConfig = (row: any) => {
|
|
|
|
|
CodeConfigRef.value?.openDialog(row);
|
2024-06-15 13:02:35 +08:00
|
|
|
};
|
|
|
|
|
|
2024-07-01 16:38:24 +08:00
|
|
|
// 改变页码序号或页面容量
|
|
|
|
|
const pageChange: VxePagerEvents.PageChange = ({ currentPage, pageSize }: VxePagerDefines.PageChangeEventParams) => {
|
|
|
|
|
state.tableParams.page = currentPage;
|
|
|
|
|
state.tableParams.pageSize = pageSize;
|
2024-06-15 13:02:35 +08:00
|
|
|
handleQuery();
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-01 16:38:24 +08:00
|
|
|
// 列排序
|
|
|
|
|
const sortChange = (options: any) => {
|
|
|
|
|
state.tableParams.field = options.field;
|
|
|
|
|
state.tableParams.order = options.order;
|
2024-06-15 13:02:35 +08:00
|
|
|
handleQuery();
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-01 16:38:24 +08:00
|
|
|
// 打开新增页面
|
|
|
|
|
const handleAdd = () => {
|
|
|
|
|
state.title = '增加';
|
2024-06-15 13:02:35 +08:00
|
|
|
EditCodeGenRef.value?.openDialog({
|
|
|
|
|
authorName: 'Admin.NET',
|
|
|
|
|
generateType: '200',
|
|
|
|
|
printType: 'off',
|
|
|
|
|
menuIcon: 'ele-Menu',
|
|
|
|
|
pagePath: 'main',
|
|
|
|
|
nameSpace: state.applicationNamespaces[0],
|
2024-07-01 16:38:24 +08:00
|
|
|
generateMenu: false,
|
2024-06-15 13:02:35 +08:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-01 16:38:24 +08:00
|
|
|
// 打开编辑页面
|
|
|
|
|
const handleEdit = (row: any) => {
|
|
|
|
|
state.title = '编辑';
|
2024-06-15 13:02:35 +08:00
|
|
|
EditCodeGenRef.value?.openDialog(row);
|
|
|
|
|
};
|
|
|
|
|
|
2024-07-01 16:38:24 +08:00
|
|
|
// 删除
|
|
|
|
|
const handleDelete = (row: any) => {
|
2024-06-15 13:02:35 +08:00
|
|
|
ElMessageBox.confirm(`确定删除吗?`, '提示', {
|
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
type: 'warning',
|
|
|
|
|
})
|
|
|
|
|
.then(async () => {
|
|
|
|
|
await getAPI(SysCodeGenApi).apiSysCodeGenDeletePost([{ id: row.id }]);
|
|
|
|
|
handleQuery();
|
|
|
|
|
ElMessage.success('操作成功');
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 开始生成代码
|
|
|
|
|
const handleGenerate = (row: any) => {
|
|
|
|
|
ElMessageBox.confirm(`确定要生成吗?`, '提示', {
|
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
type: 'warning',
|
|
|
|
|
})
|
|
|
|
|
.then(async () => {
|
|
|
|
|
var res = await getAPI(SysCodeGenApi).apiSysCodeGenRunLocalPost(row);
|
|
|
|
|
if (res.data.result != null && res.data.result.url != null) downloadByUrl({ url: res.data.result.url });
|
|
|
|
|
handleQuery();
|
|
|
|
|
ElMessage.success('操作成功');
|
|
|
|
|
})
|
|
|
|
|
.catch(() => {});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// 预览代码
|
|
|
|
|
const handlePreview = (row: any) => {
|
2024-07-01 16:38:24 +08:00
|
|
|
state.title = '预览代码';
|
2024-06-15 13:02:35 +08:00
|
|
|
PreviewRef.value?.openDialog(row);
|
|
|
|
|
};
|
|
|
|
|
</script>
|