reactor:【infra 基础设施】codegen 进一步统一代码风格(50%)

pull/210/MERGE
YunaiV 2025-09-09 22:58:58 +08:00
parent 08b4176fb3
commit 044db12224
12 changed files with 91 additions and 86 deletions

View File

@ -71,7 +71,7 @@ export namespace InfraCodegenApi {
} }
/** 创建代码生成请求 */ /** 创建代码生成请求 */
export interface CodegenCreateListReq { export interface CodegenCreateListReqVO {
dataSourceConfigId?: number; dataSourceConfigId?: number;
tableNames: string[]; tableNames: string[];
} }
@ -136,7 +136,7 @@ export function getSchemaTableList(params: any) {
} }
/** 基于数据库的表结构,创建代码生成器的表定义 */ /** 基于数据库的表结构,创建代码生成器的表定义 */
export function createCodegenList(data: InfraCodegenApi.CodegenCreateListReq) { export function createCodegenList(data: InfraCodegenApi.CodegenCreateListReqVO) {
return requestClient.post('/infra/codegen/create-list', data); return requestClient.post('/infra/codegen/create-list', data);
} }

View File

@ -61,7 +61,7 @@ async function submitForm() {
// //
const hideLoading = message.loading({ const hideLoading = message.loading({
content: $t('ui.actionMessage.updating'), content: $t('ui.actionMessage.updating'),
key: 'action_process_msg', duration: 0,
}); });
try { try {
// //
@ -73,10 +73,7 @@ async function submitForm() {
columns, columns,
}); });
// //
message.success({ message.success($t('ui.actionMessage.operationSuccess'));
content: $t('ui.actionMessage.operationSuccess'),
key: 'action_key_msg',
});
close(); close();
} catch (error) { } catch (error) {
console.error('保存失败', error); console.error('保存失败', error);
@ -84,8 +81,9 @@ async function submitForm() {
hideLoading(); hideLoading();
} }
} }
const tabs = useTabs();
/** 返回列表 */ /** 返回列表 */
const tabs = useTabs();
function close() { function close() {
tabs.closeCurrentTab(); tabs.closeCurrentTab();
router.push('/infra/codegen'); router.push('/infra/codegen');

View File

@ -73,7 +73,6 @@ async function handleDelete(row: InfraCodegenApi.CodegenTable) {
const hideLoading = message.loading({ const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting', [row.tableName]), content: $t('ui.actionMessage.deleting', [row.tableName]),
duration: 0, duration: 0,
key: 'action_process_msg',
}); });
try { try {
await deleteCodegenTable(row.id); await deleteCodegenTable(row.id);
@ -98,7 +97,6 @@ async function handleDeleteBatch() {
const hideLoading = message.loading({ const hideLoading = message.loading({
content: $t('ui.actionMessage.deleting'), content: $t('ui.actionMessage.deleting'),
duration: 0, duration: 0,
key: 'action_process_msg',
}); });
try { try {
await deleteCodegenTableList(checkedIds.value); await deleteCodegenTableList(checkedIds.value);
@ -114,14 +112,11 @@ async function handleDeleteBatch() {
async function handleSync(row: InfraCodegenApi.CodegenTable) { async function handleSync(row: InfraCodegenApi.CodegenTable) {
const hideLoading = message.loading({ const hideLoading = message.loading({
content: $t('ui.actionMessage.updating', [row.tableName]), content: $t('ui.actionMessage.updating', [row.tableName]),
key: 'action_key_msg', duration: 0,
}); });
try { try {
await syncCodegenFromDB(row.id); await syncCodegenFromDB(row.id);
message.success({ message.success($t('ui.actionMessage.updateSuccess', [row.tableName]));
content: $t('ui.actionMessage.updateSuccess', [row.tableName]),
key: 'action_key_msg',
});
onRefresh(); onRefresh();
} finally { } finally {
hideLoading(); hideLoading();
@ -132,7 +127,7 @@ async function handleSync(row: InfraCodegenApi.CodegenTable) {
async function handleGenerate(row: InfraCodegenApi.CodegenTable) { async function handleGenerate(row: InfraCodegenApi.CodegenTable) {
const hideLoading = message.loading({ const hideLoading = message.loading({
content: '正在生成代码...', content: '正在生成代码...',
key: 'action_key_msg', duration: 0,
}); });
try { try {
const res = await downloadCodegen(row.id); const res = await downloadCodegen(row.id);
@ -143,10 +138,7 @@ async function handleGenerate(row: InfraCodegenApi.CodegenTable) {
link.download = `codegen-${row.className}.zip`; link.download = `codegen-${row.className}.zip`;
link.click(); link.click();
window.URL.revokeObjectURL(url); window.URL.revokeObjectURL(url);
message.success({ message.success('代码生成成功');
content: '代码生成成功',
key: 'action_key_msg',
});
} finally { } finally {
hideLoading(); hideLoading();
} }
@ -187,6 +179,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}); });
/** 获取数据源配置列表 */ /** 获取数据源配置列表 */
// TODO @
async function initDataSourceConfig() { async function initDataSourceConfig() {
try { try {
dataSourceConfigList.value = await getDataSourceConfigList(); dataSourceConfigList.value = await getDataSourceConfigList();

View File

@ -25,6 +25,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
keepSource: true, keepSource: true,
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
pagerConfig: { pagerConfig: {
enabled: false, enabled: false,

View File

@ -21,7 +21,7 @@ const emit = defineEmits<{
(e: 'success'): void; (e: 'success'): void;
}>(); }>();
const formData = reactive<InfraCodegenApi.CodegenCreateListReq>({ const formData = reactive<InfraCodegenApi.CodegenCreateListReqVO>({
dataSourceConfigId: 0, dataSourceConfigId: 0,
tableNames: [], // tableNames: [], //
}); });
@ -53,6 +53,7 @@ const [Grid] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'name', keyField: 'name',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
enabled: false, enabled: false,
@ -96,17 +97,14 @@ const [Modal, modalApi] = useVbenModal({
// 2. // 2.
const hideLoading = message.loading({ const hideLoading = message.loading({
content: '导入中...', content: '导入中...',
key: 'action_key_msg', duration: 0,
}); });
try { try {
await createCodegenList(formData); await createCodegenList(formData);
// //
await modalApi.close(); await modalApi.close();
emit('success'); emit('success');
message.success({ message.success($t('ui.actionMessage.operationSuccess'));
content: $t('ui.actionMessage.operationSuccess'),
key: 'action_key_msg',
});
} finally { } finally {
hideLoading(); hideLoading();
modalApi.unlock(); modalApi.unlock();

View File

@ -86,19 +86,23 @@ async function copyCode() {
/** 文件节点点击事件 */ /** 文件节点点击事件 */
function handleNodeClick(_: any[], e: any) { function handleNodeClick(_: any[], e: any) {
if (!e.node.isLeaf) return; if (!e.node.isLeaf) {
return;
}
activeKey.value = e.node.key; activeKey.value = e.node.key;
const file = previewFiles.value.find((item) => { const file = previewFiles.value.find((item) => {
const list = activeKey.value.split('.'); const list = activeKey.value.split('.');
// - // -
if (list.length > 2) { if (list.length > 2) {
const lang = list.pop(); const lang = list.pop();
return item.filePath === `${list.join('/')}.${lang}`; return item.filePath === `${list.join('/')}.${lang}`;
} }
return item.filePath === activeKey.value; return item.filePath === activeKey.value;
}); });
if (!file) return; if (!file) {
return;
}
const lang = file.filePath.split('.').pop() || ''; const lang = file.filePath.split('.').pop() || '';
setCodeMap(activeKey.value, lang, file.code); setCodeMap(activeKey.value, lang, file.code);
@ -119,7 +123,7 @@ function handleFiles(data: InfraCodegenApi.CodegenPreview[]): FileNode[] {
const path = paths[cursor] || ''; const path = paths[cursor] || '';
const oldFullPath = fullPath; const oldFullPath = fullPath;
// Java // Java
if (path === 'java' && cursor + 1 < paths.length) { if (path === 'java' && cursor + 1 < paths.length) {
fullPath = fullPath ? `${fullPath}/${path}` : path; fullPath = fullPath ? `${fullPath}/${path}` : path;
cursor++; cursor++;
@ -202,7 +206,9 @@ const [Modal, modalApi] = useVbenModal({
} }
const row = modalApi.getData<InfraCodegenApi.CodegenTable>(); const row = modalApi.getData<InfraCodegenApi.CodegenTable>();
if (!row) return; if (!row) {
return;
}
// //
loading.value = true; loading.value = true;

View File

@ -8,15 +8,14 @@ import type { SystemMenuApi } from '#/api/system/menu';
import { h } from 'vue'; import { h } from 'vue';
import { useAccess } from '@vben/access'; import { useAccess } from '@vben/access';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { IconifyIcon } from '@vben/icons'; import { IconifyIcon } from '@vben/icons';
import { handleTree } from '@vben/utils'; import { handleTree } from '@vben/utils';
import { getDataSourceConfigList } from '#/api/infra/data-source-config'; import { getDataSourceConfigList } from '#/api/infra/data-source-config';
import { getMenuList } from '#/api/system/menu'; import { getMenuList } from '#/api/system/menu';
import { $t } from '#/locales'; import { $t } from '#/locales';
import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';
import { getRangePickerDefaultProps } from '#/utils'; import { getRangePickerDefaultProps } from '#/utils';
const { hasAccessByCodes } = useAccess(); const { hasAccessByCodes } = useAccess();

View File

@ -31,7 +31,7 @@ const columnInfoRef = ref<InstanceType<typeof ColumnInfo>>();
const generateInfoRef = ref<InstanceType<typeof GenerationInfo>>(); const generateInfoRef = ref<InstanceType<typeof GenerationInfo>>();
/** 获取详情数据 */ /** 获取详情数据 */
const getDetail = async () => { async function getDetail() {
const id = route.query.id as any; const id = route.query.id as any;
if (!id) { if (!id) {
return; return;
@ -42,10 +42,10 @@ const getDetail = async () => {
} finally { } finally {
loading.value = false; loading.value = false;
} }
}; }
/** 提交表单 */ /** 提交表单 */
const submitForm = async () => { async function submitForm() {
// //
const basicInfoValid = await basicInfoRef.value?.validate(); const basicInfoValid = await basicInfoRef.value?.validate();
if (!basicInfoValid) { if (!basicInfoValid) {
@ -79,25 +79,26 @@ const submitForm = async () => {
} finally { } finally {
loadingInstance.close(); loadingInstance.close();
} }
}; }
const tabs = useTabs();
/** 返回列表 */ /** 返回列表 */
const close = () => { const tabs = useTabs();
function close() {
tabs.closeCurrentTab(); tabs.closeCurrentTab();
router.push('/infra/codegen'); router.push('/infra/codegen');
}; }
/** 下一步 */ /** 下一步 */
const nextStep = async () => { function nextStep() {
currentStep.value += 1; currentStep.value += 1;
}; }
/** 上一步 */ /** 上一步 */
const prevStep = () => { function prevStep() {
if (currentStep.value > 0) { if (currentStep.value > 0) {
currentStep.value -= 1; currentStep.value -= 1;
} }
}; }
/** 步骤配置 */ /** 步骤配置 */
const steps = [ const steps = [
@ -118,14 +119,8 @@ getDetail();
<template> <template>
<Page auto-content-height v-loading="loading"> <Page auto-content-height v-loading="loading">
<div <div class="bg-card flex h-[95%] flex-col rounded-md p-4">
class="flex h-[95%] flex-col rounded-md bg-white p-4 dark:bg-[#1f1f1f] dark:text-gray-300" <ElSteps :active="currentStep" class="mb-8 rounded shadow-sm" simple>
>
<ElSteps
:active="currentStep"
class="mb-8 rounded shadow-sm dark:bg-[#141414]"
simple
>
<ElStep <ElStep
v-for="(step, index) in steps" v-for="(step, index) in steps"
:key="index" :key="index"

View File

@ -181,6 +181,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
refresh: true, refresh: true,

View File

@ -25,6 +25,7 @@ const [Grid, gridApi] = useVbenVxeGrid({
keepSource: true, keepSource: true,
rowConfig: { rowConfig: {
keyField: 'id', keyField: 'id',
isHover: true,
}, },
pagerConfig: { pagerConfig: {
enabled: false, enabled: false,

View File

@ -53,6 +53,7 @@ const [Grid] = useVbenVxeGrid({
}, },
rowConfig: { rowConfig: {
keyField: 'name', keyField: 'name',
isHover: true,
}, },
toolbarConfig: { toolbarConfig: {
enabled: false, enabled: false,

View File

@ -46,7 +46,7 @@ const activeKey = ref<string>('');
/** 代码地图 */ /** 代码地图 */
const codeMap = ref<Map<string, string>>(new Map<string, string>()); const codeMap = ref<Map<string, string>>(new Map<string, string>());
const setCodeMap = (key: string, lang: string, code: string) => { function setCodeMap(key: string, lang: string, code: string) {
// Java // Java
const trimmedCode = code.trimStart(); const trimmedCode = code.trimStart();
// //
@ -61,8 +61,10 @@ const setCodeMap = (key: string, lang: string, code: string) => {
} catch { } catch {
codeMap.value.set(key, trimmedCode); codeMap.value.set(key, trimmedCode);
} }
}; }
const removeCodeMapKey = (targetKey: any) => {
/** 删除代码地图 */
function removeCodeMapKey(targetKey: any) {
// //
if (codeMap.value.size === 1) { if (codeMap.value.size === 1) {
return; return;
@ -70,26 +72,10 @@ const removeCodeMapKey = (targetKey: any) => {
if (codeMap.value.has(targetKey)) { if (codeMap.value.has(targetKey)) {
codeMap.value.delete(targetKey); codeMap.value.delete(targetKey);
} }
}; }
const handleTabsEdit = (
targetName: TabPaneName | undefined,
action: 'add' | 'remove',
) => {
switch (action) {
case 'add': {
// el-tab
copyCode();
break;
}
case 'remove': {
removeCodeMapKey(targetName);
break;
}
}
};
/** 复制代码 */ /** 复制代码 */
const copyCode = async () => { async function copyCode() {
const { copy } = useClipboard(); const { copy } = useClipboard();
const file = previewFiles.value.find( const file = previewFiles.value.find(
(item) => item.filePath === activeKey.value, (item) => item.filePath === activeKey.value,
@ -98,30 +84,34 @@ const copyCode = async () => {
await copy(file.code); await copy(file.code);
ElMessage.success('复制成功'); ElMessage.success('复制成功');
} }
}; }
/** 文件节点点击事件 */ /** 文件节点点击事件 */
const handleNodeClick = (node: FileNode) => { function handleNodeClick(node: FileNode) {
if (!node.isLeaf) return; if (!node.isLeaf) {
return;
}
activeKey.value = node.key; activeKey.value = node.key;
const file = previewFiles.value.find((item) => { const file = previewFiles.value.find((item) => {
const list = activeKey.value.split('.'); const list = activeKey.value.split('.');
// - // -
if (list.length > 2) { if (list.length > 2) {
const lang = list.pop(); const lang = list.pop();
return item.filePath === `${list.join('/')}.${lang}`; return item.filePath === `${list.join('/')}.${lang}`;
} }
return item.filePath === activeKey.value; return item.filePath === activeKey.value;
}); });
if (!file) return; if (!file) {
return;
}
const lang = file.filePath.split('.').pop() || ''; const lang = file.filePath.split('.').pop() || '';
setCodeMap(activeKey.value, lang, file.code); setCodeMap(activeKey.value, lang, file.code);
}; }
/** 处理文件树 */ /** 处理文件树 */
const handleFiles = (data: InfraCodegenApi.CodegenPreview[]): FileNode[] => { function handleFiles(data: InfraCodegenApi.CodegenPreview[]): FileNode[] {
const exists: Record<string, boolean> = {}; const exists: Record<string, boolean> = {};
const files: FileNode[] = []; const files: FileNode[] = [];
@ -135,7 +125,7 @@ const handleFiles = (data: InfraCodegenApi.CodegenPreview[]): FileNode[] => {
const path = paths[cursor] || ''; const path = paths[cursor] || '';
const oldFullPath = fullPath; const oldFullPath = fullPath;
// Java // Java
if (path === 'java' && cursor + 1 < paths.length) { if (path === 'java' && cursor + 1 < paths.length) {
fullPath = fullPath ? `${fullPath}/${path}` : path; fullPath = fullPath ? `${fullPath}/${path}` : path;
cursor++; cursor++;
@ -194,17 +184,35 @@ const handleFiles = (data: InfraCodegenApi.CodegenPreview[]): FileNode[] => {
} }
/** 构建树形结构 */ /** 构建树形结构 */
const buildTree = (parentKey: string): FileNode[] => { function buildTree(parentKey: string): FileNode[] {
return files return files
.filter((file) => file.parentKey === parentKey) .filter((file) => file.parentKey === parentKey)
.map((file) => ({ .map((file) => ({
...file, ...file,
children: buildTree(file.key), children: buildTree(file.key),
})); }));
}; }
return buildTree('/'); return buildTree('/');
}; }
/** 处理标签页编辑事件 */
function handleTabsEdit(
targetName: TabPaneName | undefined,
action: 'add' | 'remove',
) {
switch (action) {
case 'add': {
// el-tab
copyCode();
break;
}
case 'remove': {
removeCodeMapKey(targetName);
break;
}
}
}
/** 模态框实例 */ /** 模态框实例 */
const [Modal, modalApi] = useVbenModal({ const [Modal, modalApi] = useVbenModal({
@ -218,7 +226,9 @@ const [Modal, modalApi] = useVbenModal({
} }
const row = modalApi.getData<InfraCodegenApi.CodegenTable>(); const row = modalApi.getData<InfraCodegenApi.CodegenTable>();
if (!row) return; if (!row) {
return;
}
// //
loading.value = true; loading.value = true;
@ -273,6 +283,7 @@ const [Modal, modalApi] = useVbenModal({
<div <div
class="h-full rounded-md bg-gray-50 !p-0 text-gray-800 dark:bg-gray-800 dark:text-gray-200" class="h-full rounded-md bg-gray-50 !p-0 text-gray-800 dark:bg-gray-800 dark:text-gray-200"
> >
<!-- eslint-disable-next-line vue/no-v-html -->
<code <code
v-html="codeMap.get(activeKey)" v-html="codeMap.get(activeKey)"
class="code-highlight" class="code-highlight"
@ -280,6 +291,7 @@ const [Modal, modalApi] = useVbenModal({
</div> </div>
</ElTabPane> </ElTabPane>
<template #add-icon> <template #add-icon>
<!-- TODO @芋艿这里会报错 -->
<Copy /> <Copy />
</template> </template>
</ElTabs> </ElTabs>