refactor: ele infra 代码生成预览优化

pull/104/head
puhui999 2025-05-14 16:42:14 +08:00
parent ad8f190bba
commit a8a34c662c
1 changed files with 24 additions and 12 deletions

View File

@ -1,14 +1,16 @@
<script lang="ts" setup>
import type { TabPaneName } from 'element-plus';
// TODO @vben2.0 CodeEditor
import type { InfraCodegenApi } from '#/api/infra/codegen';
import { h, ref } from 'vue';
import { ref } from 'vue';
import { useVbenModal } from '@vben/common-ui';
import { Copy } from '@vben/icons';
import { useClipboard } from '@vueuse/core';
import { ElButton, ElMessage, ElTabPane, ElTabs, ElTree } from 'element-plus';
import { ElMessage, ElTabPane, ElTabs, ElTree } from 'element-plus';
import hljs from 'highlight.js/lib/core';
import java from 'highlight.js/lib/languages/java';
import javascript from 'highlight.js/lib/languages/javascript';
@ -69,6 +71,22 @@ const removeCodeMapKey = (targetKey: any) => {
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 () => {
@ -245,16 +263,12 @@ const [Modal, modalApi] = useVbenModal({
</div>
<!-- 代码预览 -->
<div class="h-full w-2/3 overflow-auto pl-4">
<ElTabs
v-model="activeKey"
type="card"
closable
@tab-remove="removeCodeMapKey"
>
<ElTabs v-model="activeKey" type="card" editable @edit="handleTabsEdit">
<ElTabPane
v-for="key in codeMap.keys()"
:key="key"
:label="key.split('/').pop()"
:name="key"
>
<div
class="h-full rounded-md bg-gray-50 !p-0 text-gray-800 dark:bg-gray-800 dark:text-gray-200"
@ -266,10 +280,8 @@ const [Modal, modalApi] = useVbenModal({
></code>
</div>
</ElTabPane>
<template #extra>
<ElButton type="primary" @click="copyCode" :icon="h(Copy)">
复制代码
</ElButton>
<template #add-icon>
<Copy />
</template>
</ElTabs>
</div>