mirror of
https://github.com/fastapiadmin/FastapiAdmin.git
synced 2026-10-11 03:49:33 +00:00
refactor(gencode): 重构代码生成模块,优化类型定义和组件逻辑
- 将多个Vue组件脚本迁移至TypeScript,增强类型安全 - 重构API接口定义,优化参数传递和响应处理 - 改进表单验证逻辑,简化冗余代码 - 统一使用Element Plus的消息提示组件 - 优化路由处理逻辑,修复混合布局下的路径解析问题 - 完善类型定义,增加GenTableSchema等接口 - 移除未使用的导入和冗余代码 - 改进代码预览和复制功能
This commit is contained in:
@@ -95,7 +95,7 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
import { DeviceEnum } from "@/enums/settings/device.enum";
|
||||
import { useAppStore, useSettingsStore, useUserStore, useLockStore } from "@/store";
|
||||
@@ -111,7 +111,7 @@ import Notification from "@/components/Notification/index.vue";
|
||||
import LockDialog from './LockDialog.vue'
|
||||
import LockPage from './LockPage.vue'
|
||||
import Guide from '@/components/Guide/index.vue'
|
||||
import ConfigInfoDrawer from "@/views/system/config/components/ConfigInfoDrawer.vue"
|
||||
import ConfigInfoDrawer from "@/views/system/param/components/ConfigInfoDrawer.vue"
|
||||
|
||||
|
||||
const { t } = useI18n();
|
||||
@@ -119,7 +119,6 @@ const appStore = useAppStore();
|
||||
const settingStore = useSettingsStore();
|
||||
const userStore = useUserStore();
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
// 是否为桌面设备
|
||||
@@ -225,7 +224,6 @@ function logout() {
|
||||
lockScroll: false,
|
||||
}).then(() => {
|
||||
userStore.logout().then(() => {
|
||||
// router.push(`/login?redirect=${route.fullPath}`);
|
||||
router.push(`/login`);
|
||||
});
|
||||
}).catch(() => {
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
<router-link
|
||||
v-for="tag in displayedViews" :key="tag.fullPath"
|
||||
:class="['tags-item', { active: tagsViewStore.isActive(tag) }]" :to="{ path: tag.path, query: tag.query }"
|
||||
@click="handleTabClick(tag)"
|
||||
@click="router.push({path: tag.fullPath, query: tag.query})"
|
||||
@click.middle="handleMiddleClick(tag)">
|
||||
<!-- 为所有标签添加右键菜单 -->
|
||||
<el-dropdown
|
||||
@@ -343,10 +343,10 @@ const updateCurrentTag = () => {
|
||||
/**
|
||||
* 处理标签点击
|
||||
*/
|
||||
const handleTabClick = (tag: TagView) => {
|
||||
// 设置标签切换来源为标签容器点击
|
||||
tagSwitchSource.value = 'tab';
|
||||
};
|
||||
// const handleTabClick = (tag: TagView) => {
|
||||
// // 设置标签切换来源为标签容器点击
|
||||
// tagSwitchSource.value = 'tab';
|
||||
// };
|
||||
|
||||
/**
|
||||
* 处理中键点击
|
||||
@@ -386,13 +386,14 @@ const handleScroll = (event: WheelEvent) => {
|
||||
* 刷新标签
|
||||
*/
|
||||
const refreshSelectedTag = (tag: TagView | null) => {
|
||||
if (!tag) return;
|
||||
// 总是使用当前路由对应的标签
|
||||
const currentTag = routePathMap.value.get(route.path);
|
||||
if (!currentTag) return;
|
||||
// const currentTag = routePathMap.value.get(route.path);
|
||||
// if (!currentTag) return;
|
||||
|
||||
tagsViewStore.delCachedView(currentTag);
|
||||
tagsViewStore.delCachedView(tag);
|
||||
nextTick(() => {
|
||||
router.replace("/redirect" + currentTag.fullPath);
|
||||
router.replace("/redirect" + tag.fullPath);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ import { useAppStore } from "@/store";
|
||||
import { DeviceEnum } from "@/enums/settings/device.enum";
|
||||
|
||||
/**
|
||||
* 布局响应式处理逻辑
|
||||
* 设备检测和响应式处理
|
||||
* 监听屏幕尺寸变化,自动调整设备类型和侧边栏状态
|
||||
*/
|
||||
export function useLayoutResponsive() {
|
||||
const appStore = useAppStore();
|
||||
@@ -13,16 +14,19 @@ export function useLayoutResponsive() {
|
||||
// 定义响应式断点
|
||||
const WIDTH_DESKTOP = 992; // 桌面设备断点 (>=992px)
|
||||
|
||||
// 计算设备类型
|
||||
const isDesktop = computed(() => width.value >= WIDTH_DESKTOP);
|
||||
const isMobile = computed(() => appStore.device === DeviceEnum.MOBILE);
|
||||
|
||||
// 设置当前设备类型并调整侧边栏状态
|
||||
watchEffect(() => {
|
||||
const isDesktop = width.value >= WIDTH_DESKTOP;
|
||||
const deviceType = isDesktop ? DeviceEnum.DESKTOP : DeviceEnum.MOBILE;
|
||||
const deviceType = isDesktop.value ? DeviceEnum.DESKTOP : DeviceEnum.MOBILE;
|
||||
|
||||
// 更新设备类型
|
||||
appStore.toggleDevice(deviceType);
|
||||
|
||||
// 根据设备类型调整侧边栏状态
|
||||
if (isDesktop) {
|
||||
if (isDesktop.value) {
|
||||
appStore.openSideBar();
|
||||
} else {
|
||||
appStore.closeSideBar();
|
||||
@@ -30,7 +34,7 @@ export function useLayoutResponsive() {
|
||||
});
|
||||
|
||||
return {
|
||||
isDesktop: computed(() => width.value >= WIDTH_DESKTOP),
|
||||
isMobile: computed(() => appStore.device === DeviceEnum.MOBILE),
|
||||
isDesktop,
|
||||
isMobile,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
<script setup lang="ts">
|
||||
import { useLayout } from "../composables/useLayout";
|
||||
import { useLayoutResponsive } from "../composables/useLayoutResponsive";
|
||||
import { defaultSettings } from "@/settings";
|
||||
import { useSettingsStore } from "@/store";
|
||||
|
||||
const settingStore = useSettingsStore();
|
||||
|
||||
@@ -109,31 +109,30 @@ function resolvePath(routePath: string) {
|
||||
}
|
||||
|
||||
if (routePath.startsWith("/")) {
|
||||
return routePath;
|
||||
return activeTopMenuPath.value + routePath;
|
||||
}
|
||||
return `${routePath}`;
|
||||
return `${activeTopMenuPath.value}/${routePath}`;
|
||||
}
|
||||
|
||||
// 优化后的路由监听逻辑,仅在顶级路径实际变化时更新菜单
|
||||
let prevTopMenuPath = '';
|
||||
|
||||
watch(
|
||||
() => route.path,
|
||||
(newPath) => {
|
||||
// 获取顶级路径
|
||||
const topMenuPath =
|
||||
newPath.split("/").filter(Boolean).length > 1 ? newPath.match(/^\/[^/]+/)?.[0] || "/" : "/";
|
||||
const topMenuPath = newPath.split("/").filter(Boolean).length > 1 ? newPath.match(/^\/[^/]+/)?.[0] || "/" : "/";
|
||||
|
||||
// 如果当前路径属于当前激活的顶部菜单
|
||||
if (newPath.startsWith(activeTopMenuPath.value)) {
|
||||
// no-op
|
||||
}
|
||||
|
||||
// 仅在顶级路径实际变化时才执行更新
|
||||
if (topMenuPath !== prevTopMenuPath) {
|
||||
prevTopMenuPath = topMenuPath;
|
||||
|
||||
else if (topMenuPath !== activeTopMenuPath.value) {
|
||||
// 主动更新顶部菜单和左侧菜单
|
||||
const appStore = useAppStore();
|
||||
const permissionStore = usePermissionStore();
|
||||
|
||||
appStore.activeTopMenu(topMenuPath);
|
||||
permissionStore.updateSideMenu(topMenuPath);
|
||||
permissionStore.setMixLayoutSideMenus(topMenuPath);
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
|
||||
Reference in New Issue
Block a user