diff --git a/src/api/codegen/index.ts b/src/api/codegen/index.ts index f568b393..8ac840c1 100644 --- a/src/api/codegen/index.ts +++ b/src/api/codegen/index.ts @@ -3,6 +3,18 @@ import type { GeneratorPreviewItem, TableQueryParams, TableItem, GenConfigForm } const GENERATOR_BASE_URL = "/api/v1/codegen"; +// 构建预览和下载接口的查询参数 +const buildCodegenParams = (pageType?: "classic" | "curd", type?: "ts" | "js") => { + const params: Record = {}; + if (pageType) { + params.pageType = pageType; + } + if (type) { + params.type = type; + } + return Object.keys(params).length ? params : undefined; +}; + const GeneratorAPI = { /** 获取数据表分页列表 */ getTablePage(params: TableQueryParams) { @@ -21,7 +33,7 @@ const GeneratorAPI = { }); }, - /** 获取代码生成配置 */ + /** 保存代码生成配置 */ saveGenConfig(tableName: string, data: GenConfigForm) { return request({ url: `${GENERATOR_BASE_URL}/${tableName}/config`, @@ -32,17 +44,10 @@ const GeneratorAPI = { /** 获取代码生成预览数据 */ getPreviewData(tableName: string, pageType?: "classic" | "curd", type?: "ts" | "js") { - const params: Record = {}; - if (pageType) { - params.pageType = pageType; - } - if (type) { - params.type = type; - } return request({ url: `${GENERATOR_BASE_URL}/${tableName}/preview`, method: "get", - params: Object.keys(params).length ? params : undefined, + params: buildCodegenParams(pageType, type), }); }, @@ -54,23 +59,12 @@ const GeneratorAPI = { }); }, - /** - * 下载 ZIP 文件 - * @param url - * @param fileName - */ + /** 下载代码生成 ZIP 文件 */ download(tableName: string, pageType?: "classic" | "curd", type?: "ts" | "js") { - const params: Record = {}; - if (pageType) { - params.pageType = pageType; - } - if (type) { - params.type = type; - } return request({ url: `${GENERATOR_BASE_URL}/${tableName}/download`, method: "get", - params: Object.keys(params).length ? params : undefined, + params: buildCodegenParams(pageType, type), responseType: "blob", }).then((response) => { const contentDisposition = response?.headers?.["content-disposition"] as string | undefined; @@ -89,12 +83,12 @@ const GeneratorAPI = { const blob = new Blob([response.data], { type: "application/zip" }); const a = document.createElement("a"); - const url = window.URL.createObjectURL(blob); - a.href = url; + const downloadUrl = window.URL.createObjectURL(blob); + a.href = downloadUrl; a.download = fileName; a.click(); - window.URL.revokeObjectURL(url); + window.URL.revokeObjectURL(downloadUrl); }); }, }; diff --git a/src/components/Upload/MultiImageUpload.vue b/src/components/Upload/MultiImageUpload.vue index 691b923e..2f4c08ce 100644 --- a/src/components/Upload/MultiImageUpload.vue +++ b/src/components/Upload/MultiImageUpload.vue @@ -223,4 +223,3 @@ watch( } ); - diff --git a/src/composables/sse/useOnlineCount.ts b/src/composables/sse/useOnlineCount.ts index 3ef9c3f7..edcd1e48 100644 --- a/src/composables/sse/useOnlineCount.ts +++ b/src/composables/sse/useOnlineCount.ts @@ -11,11 +11,11 @@ function createOnlineCountComposable() { let unsubscribe: (() => void) | null = null; + // 处理在线人数变更消息 const handleOnlineCountMessage = (count: number) => { - if (count !== undefined && !isNaN(count)) { - onlineUserCount.value = count; - lastUpdateTime.value = Date.now(); - } + if (!Number.isFinite(count) || count < 0) return; + onlineUserCount.value = count; + lastUpdateTime.value = Date.now(); }; const initialize = () => { diff --git a/src/layouts/MixLayout.vue b/src/layouts/MixLayout.vue index 90612fa6..e73c7dec 100644 --- a/src/layouts/MixLayout.vue +++ b/src/layouts/MixLayout.vue @@ -184,7 +184,7 @@ function extractTopMenuPath(path: string): string { function handleTopMenuSelect(menuPath: string) { if (menuPath === activeTopMenuPath.value) return; - appStore.activeTopMenu(menuPath); + appStore.setActiveTopMenuPath(menuPath); permissionStore.setMixLayoutSideMenus(menuPath); navigateToFirstMenu(permissionStore.mixLayoutSideMenus); } @@ -215,7 +215,7 @@ watch( const isTopMenuChanged = topMenuPath !== activeTopMenuPath.value; if (isTopMenuChanged) { - appStore.activeTopMenu(topMenuPath); + appStore.setActiveTopMenuPath(topMenuPath); } // 切换布局(如左侧 -> 混合)时,activeTopMenuPath 可能已是正确值, diff --git a/src/layouts/useLayout.ts b/src/layouts/useLayout.ts index c162fd2c..fab4c286 100644 --- a/src/layouts/useLayout.ts +++ b/src/layouts/useLayout.ts @@ -31,9 +31,9 @@ export function useLayout() { appStore.toggleDevice(device); if (isDesktop.value) { - appStore.openSideBar(); + appStore.openSidebar(); } else { - appStore.closeSideBar(); + appStore.closeSidebar(); } }); @@ -82,7 +82,7 @@ export function useLayout() { } function closeSidebar() { - appStore.closeSideBar(); + appStore.closeSidebar(); } return { diff --git a/src/stores/app.ts b/src/stores/app.ts index c6cabe7e..973df83c 100644 --- a/src/stores/app.ts +++ b/src/stores/app.ts @@ -6,50 +6,104 @@ import { STORAGE_KEYS } from "@/constants"; import { defaults } from "@/settings"; export const useAppStore = defineStore("app", () => { + /** + * 当前设备类型 + */ const device = useStorage(STORAGE_KEYS.DEVICE, DeviceEnum.DESKTOP); + + /** + * 组件默认尺寸 + */ const size = useStorage(STORAGE_KEYS.SIZE, defaults.size); + + /** + * 当前语言 + */ const language = useStorage(STORAGE_KEYS.LANGUAGE, defaults.language); + + /** + * 侧边栏持久化状态 + */ const sidebarStatus = useStorage(STORAGE_KEYS.SIDEBAR_STATUS, SidebarStatus.CLOSED); + + /** + * 侧边栏显示状态 + */ const sidebar = reactive({ opened: sidebarStatus.value === SidebarStatus.OPENED, withoutAnimation: false, }); + + /** + * 当前激活的顶部菜单路径 + */ const activeTopMenuPath = useStorage(STORAGE_KEYS.ACTIVE_TOP_MENU_PATH, ""); + + /** + * 内容区是否全屏 + */ const contentFullscreen = ref(false); + /** + * Element Plus 当前语言包 + */ const locale = computed(() => (language?.value === "en" ? en : zhCn)); + /** + * 切换侧边栏展开状态 + */ function toggleSidebar() { sidebar.opened = !sidebar.opened; sidebarStatus.value = sidebar.opened ? SidebarStatus.OPENED : SidebarStatus.CLOSED; } - function closeSideBar() { + /** + * 关闭侧边栏 + */ + function closeSidebar() { sidebar.opened = false; sidebarStatus.value = SidebarStatus.CLOSED; } - function openSideBar() { + /** + * 打开侧边栏 + */ + function openSidebar() { sidebar.opened = true; sidebarStatus.value = SidebarStatus.OPENED; } + /** + * 切换设备类型 + */ function toggleDevice(val: string) { device.value = val; } + /** + * 切换组件尺寸 + */ function changeSize(val: string) { size.value = val; } + /** + * 切换语言 + */ function changeLanguage(val: string) { language.value = val; } - function activeTopMenu(val: string) { - activeTopMenuPath.value = val; + /** + * 设置顶部菜单激活路径 + */ + function setActiveTopMenuPath(path: string) { + activeTopMenuPath.value = path; } + /** + * 切换内容区全屏状态 + */ function toggleContentFullscreen() { contentFullscreen.value = !contentFullscreen.value; } @@ -60,14 +114,14 @@ export const useAppStore = defineStore("app", () => { language, locale, size, - activeTopMenu, contentFullscreen, toggleDevice, changeSize, changeLanguage, toggleSidebar, - closeSideBar, - openSideBar, + closeSidebar, + openSidebar, + setActiveTopMenuPath, toggleContentFullscreen, activeTopMenuPath, }; diff --git a/src/views/demo/route-param.vue b/src/views/demo/route-param.vue index a904ee23..a74b7d19 100644 --- a/src/views/demo/route-param.vue +++ b/src/views/demo/route-param.vue @@ -12,5 +12,3 @@ import { useRoute } from "vue-router"; // 获取query参数 const query = useRoute().query.type as string; - - diff --git a/src/views/demo/vxe-table/index.vue b/src/views/demo/vxe-table/index.vue index 5be856ab..e5922a56 100644 --- a/src/views/demo/vxe-table/index.vue +++ b/src/views/demo/vxe-table/index.vue @@ -623,5 +623,3 @@ const curd = { }, }; - - diff --git a/src/views/system/tenant/index.vue b/src/views/system/tenant/index.vue index db2e028d..956600f2 100644 --- a/src/views/system/tenant/index.vue +++ b/src/views/system/tenant/index.vue @@ -1010,5 +1010,3 @@ onMounted(() => { fetchPlanOptions(); }); - - diff --git a/src/views/system/tenant/plan.vue b/src/views/system/tenant/plan.vue index 1a309f27..33e27292 100644 --- a/src/views/system/tenant/plan.vue +++ b/src/views/system/tenant/plan.vue @@ -495,5 +495,3 @@ onMounted(() => { fetchData(); }); - - diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index dde2d155..458e41dc 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -528,5 +528,3 @@ onMounted(() => { handleQuery(); }); - -