UNIVPLMDataIntegration/Web/src/views/system/codeGen/index.vue

250 lines
9.5 KiB
Vue
Raw Normal View History

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' }">
<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">
2024-07-12 02:03:39 +08:00
<el-input placeholder="业务名" clearable @keyup.enter="handleQuery" v-model="state.queryParams.busName" @keyup.enter.native="handleQuery" />
2024-07-01 16:38:24 +08:00
</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">
2024-07-12 02:03:39 +08:00
<el-input placeholder="数据库表名" clearable @keyup.enter="handleQuery" v-model="state.queryParams.tableName" @keyup.enter.native="handleQuery" />
2024-07-01 16:38:24 +08:00
</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-12 02:03:39 +08:00
<el-button type="primary" icon="ele-Search" @click="handleQuery" :loading="options.loading"> 查询 </el-button>
2024-07-01 16:38:24 +08:00
<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-12 02:03:39 +08:00
<vxe-grid ref="xGrid" class="xGrid-style" v-bind="options" v-on="gridEvents">
2024-07-01 16:38:24 +08:00
<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>
</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';
2024-07-12 02:03:39 +08:00
import { VxeGridInstance, VxeGridListeners, VxeGridPropTypes } from 'vxe-table';
import { useVxeTable } from '/@/hooks/useVxeTableOptionsHook';
import { Local } from '/@/utils/storage';
2024-07-01 16:38:24 +08:00
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';
2024-07-12 02:03:39 +08:00
import { SysCodeGen, PageCodeGenInput } from '/@/api-services/models';
2024-06-15 13:02:35 +08:00
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,
},
2024-07-12 02:03:39 +08:00
localPageParam: {
pageSize: 50 as number,
defaultSort: { field: 'id', order: 'asc', descStr: 'desc' },
2024-06-15 13:02:35 +08:00
},
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-12 02:03:39 +08:00
// 本地存储参数
const localPageParamKey = 'localPageParam:sysCodeGen';
2024-07-01 16:38:24 +08:00
// 表格参数配置
2024-07-12 02:03:39 +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' } },
],
},
// vxeGrid配置参数(此处可覆写任何参数)参考vxe-table官方文档
{
// 代理配置
proxyConfig: { autoLoad: true, ajax: { query: ({ page, sort }) => handleQueryApi(page, sort) } },
// 排序配置
sortConfig: { defaultSort: Local.get(localPageParamKey)?.defaultSort || state.localPageParam.defaultSort },
// 分页配置
pagerConfig: { pageSize: Local.get(localPageParamKey)?.pageSize || state.localPageParam.pageSize },
// 工具栏配置
toolbarConfig: { export: false },
}
);
2024-06-15 13:02:35 +08:00
2024-07-01 16:38:24 +08:00
// 页面初始化
onMounted(async () => {
2024-07-12 02:03:39 +08:00
state.localPageParam = Local.get(localPageParamKey) || state.localPageParam;
2024-07-01 16:38:24 +08:00
await handleQuery();
2024-07-12 02:03:39 +08:00
// 获取命名空间集合
2024-06-15 13:02:35 +08:00
let res = await getAPI(SysCodeGenApi).apiSysCodeGenApplicationNamespacesGet();
state.applicationNamespaces = res.data.result as Array<string>;
});
2024-07-12 02:03:39 +08:00
// 查询api
const handleQueryApi = async (page: VxeGridPropTypes.ProxyAjaxQueryPageParams, sort: VxeGridPropTypes.ProxyAjaxQuerySortCheckedParams) => {
const params = Object.assign(state.queryParams, { page: page.currentPage, pageSize: page.pageSize, field: sort.field, order: sort.order, descStr: 'desc' }) as PageCodeGenInput;
return getAPI(SysCodeGenApi).apiSysCodeGenPagePost(params);
2024-06-15 13:02:35 +08:00
};
2024-07-12 02:03:39 +08:00
// 查询操作
const handleQuery = async () => {
await xGrid.value?.commitProxy('query');
2024-06-15 13:02:35 +08:00
};
// 重置操作
2024-07-12 02:03:39 +08:00
const resetQuery = async () => {
2024-06-15 13:02:35 +08:00
state.queryParams.busName = undefined;
state.queryParams.tableName = undefined;
2024-07-12 02:03:39 +08:00
await xGrid.value?.commitProxy('reload');
2024-06-15 13:02:35 +08:00
};
2024-07-01 16:38:24 +08:00
// 打开新增页面
const handleAdd = () => {
2024-07-12 02:45:36 +08:00
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) => {
2024-07-12 02:45:36 +08:00
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 }]);
2024-07-12 02:03:39 +08:00
await handleQuery();
2024-06-15 13:02:35 +08:00
ElMessage.success('操作成功');
})
.catch(() => {});
};
2024-07-12 02:03:39 +08:00
// 表格事件
const gridEvents: VxeGridListeners<SysCodeGen> = {
// 只对 pager-config 配置时有效,分页发生改变时会触发该事件
async pageChange({ pageSize }) {
state.localPageParam.pageSize = pageSize;
Local.set(localPageParamKey, state.localPageParam);
},
// 当排序条件发生变化时会触发该事件
async sortChange({ field, order }) {
state.localPageParam.defaultSort = { field: field, order: order!, descStr: 'desc' };
Local.set(localPageParamKey, state.localPageParam);
},
};
// 打开配置
const handleConfig = (row: any) => {
CodeConfigRef.value?.openDialog(row);
};
2024-06-15 13:02:35 +08:00
// 开始生成代码
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 });
2024-07-12 02:03:39 +08:00
await handleQuery();
2024-06-15 13:02:35 +08:00
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>