review:代码生成,相关功能

This commit is contained in:
YunaiV
2025-04-11 18:43:25 +08:00
parent 17734ab040
commit b67f1b1ecd
12 changed files with 138 additions and 119 deletions

View File

@@ -61,6 +61,7 @@ const copyCode = async () => {
/** 文件节点点击事件 */
const handleNodeClick = (_: any[], e: any) => {
// TODO @puhui999可以简化if return减少括号
if (e.node.isLeaf) {
activeKey.value = e.node.key;
const file = previewFiles.value.find(
@@ -80,6 +81,7 @@ const handleNodeClick = (_: any[], e: any) => {
};
/** 处理文件树 */
// TODO @puhui999看看能不能用 cursor 优化下这个方法;= = 比较冗余
const handleFiles = (data: InfraCodegenApi.CodegenPreview[]): FileNode[] => {
const exists: Record<string, boolean> = {};
const files: FileNode[] = [];
@@ -161,6 +163,7 @@ const [Modal, modalApi] = useVbenModal({
class: 'w-3/5',
async onOpenChange(isOpen: boolean) {
if (!isOpen) {
// TODO @puhui999貌似下面不要也没关系
previewFiles.value = [];
fileTree.value = [];
activeKey.value = '';
@@ -176,9 +179,9 @@ const [Modal, modalApi] = useVbenModal({
try {
const data = await previewCodegen(row.id);
previewFiles.value = data;
fileTree.value = handleFiles(data);
// 默认选中第一个文件
// 构建代码树,并默认选中第一个文件
fileTree.value = handleFiles(data);
if (data.length > 0) {
activeKey.value = data[0]?.filePath || '';
const lang = activeKey.value.split('.').pop() || '';
@@ -200,9 +203,11 @@ const [Modal, modalApi] = useVbenModal({
<template>
<Modal title="代码预览">
<div class="h-1/1 flex" v-loading="loading">
<div class="h-full flex" v-loading="loading">
<!-- 文件树 -->
<div class="w-1/3 border-r border-gray-200 pr-4 dark:border-gray-700">
<!-- TODO @puhui999树默认展示 -->
<!-- TODO @puhui999默认节点点击可以展开 -->
<Tree
:selected-keys="[activeKey]"
:tree-data="fileTree"
@@ -210,14 +215,18 @@ const [Modal, modalApi] = useVbenModal({
/>
</div>
<!-- 代码预览 -->
<!-- TODO @puhui999可以顶部有个 tab -->
<!-- TODO @puhui999貌似 java 的缩进不太对首行空了很长 -->
<div class="w-2/3 pl-4">
<div class="mb-2 flex justify-between">
<div class="text-lg font-medium dark:text-gray-200">
{{ activeKey.split('/').pop() }}
<!-- TODO @puhui999貌似不用 activeLanguage -->
<span class="ml-2 text-xs text-gray-500 dark:text-gray-400">
({{ activeLanguage }})
</span>
</div>
<!-- TODO @芋艿貌似别的模块也可以通过 :icon="h(Copy)" -->
<Button type="primary" ghost @click="copyCode" :icon="h(Copy)">
复制代码
</Button>