diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 9fc3e76..a69f40c 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -13,22 +13,44 @@ \ No newline at end of file diff --git a/frontend/src/components/common/layout/NavContent.vue b/frontend/src/components/common/layout/NavContent.vue index e9a1335..e73516f 100644 --- a/frontend/src/components/common/layout/NavContent.vue +++ b/frontend/src/components/common/layout/NavContent.vue @@ -165,38 +165,38 @@ const handleUserClick = () => { .nav-content { position: fixed; top: 0; - left: 14.58vw; /* 280px/1920 = 14.58vw */ + left: 280px; /* 默认:侧边栏展开状态 */ right: 0; - height: 4.17vw; /* 80px/1920 = 4.17vw */ + height: 80px; /* 使用固定高度 */ background: #FFFFFF; border-bottom: 1px solid rgba(29, 29, 29, 0.12); display: flex; align-items: center; justify-content: space-between; - padding: 1.04vw 1.25vw; /* 20px 24px/1920 = 1.04vw 1.25vw */ + padding: 20px 24px; /* 使用固定像素值 */ z-index: 2001; - transition: all 0.3s ease; + transition: left 0.3s ease; /* 只对left属性做动画 */ } /* 左侧区域 */ .nav-content__left { display: flex; align-items: center; - gap: 0.63vw; /* 12px/1920 = 0.63vw */ + gap: 12px; } /* 侧边栏切换按钮 */ .sidebar-toggle-btn { - width: 1.67vw; /* 32px/1920 = 1.67vw */ - height: 1.67vw; /* 32px/1920 = 1.67vw */ + width: 32px; + height: 32px; border: none; background: transparent; - border-radius: 0.42vw; /* 8px/1920 = 0.42vw */ + border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; - padding: 0.21vw; /* 4px/1920 = 0.21vw */ + padding: 4px; transition: all 0.2s; } @@ -208,15 +208,15 @@ const handleUserClick = () => { .breadcrumb-section { display: flex; flex-direction: column; - gap: 0.10vw; /* 2px/1920 = 0.10vw */ + gap: 2px; } /* 面包屑导航 */ .breadcrumb { display: flex; align-items: center; - gap: 0.21vw; /* 4px/1920 = 0.21vw */ - font-size: 0.63vw; /* 12px/1920 = 0.63vw */ + gap: 4px; + font-size: 12px; color: #888; flex-wrap: wrap; } @@ -224,14 +224,14 @@ const handleUserClick = () => { .breadcrumb-item { display: flex; align-items: center; - gap: 0.21vw; /* 4px/1920 = 0.21vw */ + gap: 4px; white-space: nowrap; } /* 面包屑当前页面样式,使用页面标题样式 */ .breadcrumb-current.page-title { font-family: 'OPPOSans', sans-serif; - font-size: 1.04vw; /* 20px/1920 = 1.04vw */ + font-size: 20px; font-weight: 400; color: #1D1D1D; line-height: 1.32; @@ -241,7 +241,7 @@ const handleUserClick = () => { border: none; background: none; color: #019C7C; - font-size: 0.63vw; /* 12px/1920 = 0.63vw */ + font-size: 12px; cursor: pointer; padding: 0; text-decoration: none; @@ -255,18 +255,18 @@ const handleUserClick = () => { .breadcrumb-current { color: #666; - font-size: 0.63vw; /* 12px/1920 = 0.63vw */ + font-size: 12px; } .breadcrumb-separator { color: #ccc; - margin: 0 0.21vw; /* 4px/1920 = 0.21vw */ - font-size: 0.63vw; /* 12px/1920 = 0.63vw */ + margin: 0 4px; + font-size: 12px; } .page-title { font-family: 'OPPOSans', sans-serif; - font-size: 1.04vw; /* 20px/1920 = 1.04vw */ + font-size: 20px; font-weight: 400; color: #1D1D1D; line-height: 1.32; @@ -276,13 +276,13 @@ const handleUserClick = () => { .nav-content__right { display: flex; align-items: center; - gap: 1.25vw; /* 24px/1920 = 1.25vw */ + gap: 24px; } /* 用户头像 */ .user-avatar { - width: 1.04vw; /* 20px/1920 = 1.04vw */ - height: 1.04vw; /* 20px/1920 = 1.04vw */ + width: 20px; + height: 20px; cursor: pointer; display: flex; align-items: center; @@ -297,25 +297,25 @@ const handleUserClick = () => { /* 分割线 */ .divider { width: 1px; - height: 1.25vw; /* 24px/1920 = 1.25vw */ + height: 24px; background: rgba(29, 29, 29, 0.12); - border-radius: 0.10vw; /* 2px/1920 = 0.10vw */ + border-radius: 2px; } /* 操作按钮组 */ .action-buttons { display: flex; - gap: 0.63vw; /* 12px/1920 = 0.63vw */ + gap: 12px; } /* 操作按钮 */ .action-btn { position: relative; - width: 2.08vw; /* 40px/1920 = 2.08vw */ - height: 2.08vw; /* 40px/1920 = 2.08vw */ + width: 40px; + height: 40px; border: none; background: #F7F8FA; - border-radius: 1.04vw; /* 20px/1920 = 1.04vw */ + border-radius: 20px; cursor: pointer; display: flex; align-items: center; @@ -330,15 +330,15 @@ const handleUserClick = () => { /* 通知徽章 */ .notification-badge { position: absolute; - top: -0.16vw; /* -3px/1920 = -0.16vw */ - right: -0.05vw; /* -1px/1920 = -0.05vw */ - width: 1.15vw; /* 22px/1920 = 1.15vw */ - height: 0.83vw; /* 16px/1920 = 0.83vw */ + top: -3px; + right: -1px; + width: 22px; + height: 16px; background: #00C27C; color: white; - font-size: 0.52vw; /* 10px/1920 = 0.52vw */ + font-size: 10px; font-weight: 700; - border-radius: 4.69vw; /* 90px/1920 = 4.69vw */ + border-radius: 90px; border: 1px solid #FFFFFF; display: flex; align-items: center; @@ -347,24 +347,24 @@ const handleUserClick = () => { line-height: 1.3; } -/* 侧边栏状态配合 */ +/* 侧边栏状态配合 - 桌面端 */ .nav-content--sidebar-collapsed { - left: 3.33vw; /* 64px/1920 = 3.33vw */ + left: 64px !important; /* 侧边栏收起时的宽度,使用!important确保优先级 */ } .nav-content--mobile { - left: 0; + left: 0 !important; /* 移动端从左侧边缘开始 */ } -/* 响应式设计 - 移动端切换回px单位 */ +/* 响应式设计 - 平板和移动端 */ @media (max-width: 1024px) { .nav-content { left: 0; padding: 16px 20px; - height: 80px; /* 移动端使用固定高度 */ + height: 80px; } - /* 覆盖侧边栏收起状态,移动端和平板端始终从左侧边缘开始 */ + /* 覆盖侧边栏收起状态,平板端和移动端始终从左侧边缘开始 */ .nav-content--sidebar-collapsed { left: 0; } @@ -467,5 +467,14 @@ const handleUserClick = () => { } } -/* 桌面端vw单位在基础样式中已设置,移动端通过媒体查询覆盖为px单位 */ +/* 桌面端确保导航栏正确响应侧边栏状态 */ +@media (min-width: 1025px) { + .nav-content { + left: 280px; /* 桌面端默认侧边栏展开状态 */ + + &--sidebar-collapsed { + left: 64px !important; /* 侧边栏收起状态,使用!important确保生效 */ + } + } +} \ No newline at end of file diff --git a/frontend/src/components/common/layout/Sidebar.vue b/frontend/src/components/common/layout/Sidebar.vue index 2487469..0a9af36 100644 --- a/frontend/src/components/common/layout/Sidebar.vue +++ b/frontend/src/components/common/layout/Sidebar.vue @@ -125,348 +125,307 @@ const handleNavClick = (item: NavItem, event: Event) => { } - \ No newline at end of file diff --git a/frontend/src/components/test/DeviceTest.vue b/frontend/src/components/test/DeviceTest.vue new file mode 100644 index 0000000..b09c67d --- /dev/null +++ b/frontend/src/components/test/DeviceTest.vue @@ -0,0 +1,104 @@ + + + 设备检测测试 + + + 屏幕宽度: + {{ screenWidth }}px + + + 屏幕高度: + {{ screenHeight }}px + + + 设备类型: + {{ deviceType }} + + + 屏幕方向: + {{ orientation }} + + + 是否触摸设备: + {{ isTouchDevice ? '是' : '否' }} + + + 更新次数: + {{ updateCount }} + + + + + 调整浏览器窗口大小来测试防抖功能 + 防抖延迟: 150ms(停止调整窗口后150ms才更新) + + + + + + + \ No newline at end of file diff --git a/frontend/src/store/modules/app.ts b/frontend/src/store/modules/app.ts index 2c57f40..b3a7195 100644 --- a/frontend/src/store/modules/app.ts +++ b/frontend/src/store/modules/app.ts @@ -1,15 +1,25 @@ import { defineStore } from 'pinia' import { ref, computed } from 'vue' +import { DeviceType } from '@/utils/useDevice' export const useAppStore = defineStore('app', () => { // 状态 const sidebarCollapsed = ref(false) - const isMobile = ref(false) + const deviceType = ref(DeviceType.Desktop) + const screenWidth = ref(window.innerWidth) + const screenHeight = ref(window.innerHeight) + const orientation = ref<'landscape' | 'portrait'>('landscape') + const isTouchDevice = ref(false) const theme = ref<'light' | 'dark' | 'auto'>('light') const language = ref<'zh' | 'en' | 'ja'>('zh') const loading = ref(false) // 计算属性 + const isMobile = computed(() => deviceType.value === DeviceType.Mobile) + const isTablet = computed(() => deviceType.value === DeviceType.Tablet) + const isDesktop = computed(() => deviceType.value === DeviceType.Desktop) + const isSmallScreen = computed(() => screenWidth.value < 640) + const isDark = computed(() => { if (theme.value === 'auto') { return window.matchMedia('(prefers-color-scheme: dark)').matches @@ -17,6 +27,11 @@ export const useAppStore = defineStore('app', () => { return theme.value === 'dark' }) + // 响应式侧边栏状态 + const shouldCollapseSidebar = computed(() => { + return isMobile.value || (isTablet.value && orientation.value === 'portrait') + }) + // 操作 const toggleSidebar = () => { sidebarCollapsed.value = !sidebarCollapsed.value @@ -26,8 +41,28 @@ export const useAppStore = defineStore('app', () => { sidebarCollapsed.value = collapsed } + const setDeviceInfo = (info: { + deviceType: DeviceType + screenWidth: number + screenHeight: number + orientation: 'landscape' | 'portrait' + isTouchDevice: boolean + }) => { + deviceType.value = info.deviceType + screenWidth.value = info.screenWidth + screenHeight.value = info.screenHeight + orientation.value = info.orientation + isTouchDevice.value = info.isTouchDevice + + // 自动调整侧边栏状态 + if (shouldCollapseSidebar.value && !sidebarCollapsed.value) { + setSidebarCollapsed(true) + } + } + + // 兼容性方法 const setMobile = (mobile: boolean) => { - isMobile.value = mobile + deviceType.value = mobile ? DeviceType.Mobile : DeviceType.Desktop } const setTheme = (newTheme: 'light' | 'dark' | 'auto') => { @@ -48,15 +83,25 @@ export const useAppStore = defineStore('app', () => { return { // 状态 sidebarCollapsed, - isMobile, + deviceType, + screenWidth, + screenHeight, + orientation, + isTouchDevice, theme, language, loading, // 计算属性 + isMobile, + isTablet, + isDesktop, + isSmallScreen, isDark, + shouldCollapseSidebar, // 操作 toggleSidebar, setSidebarCollapsed, + setDeviceInfo, setMobile, setTheme, setLanguage, diff --git a/frontend/src/utils/performance.ts b/frontend/src/utils/performance.ts new file mode 100644 index 0000000..a8907c6 --- /dev/null +++ b/frontend/src/utils/performance.ts @@ -0,0 +1,91 @@ +/** + * 性能优化工具函数 + * 包含防抖、节流等常用性能优化函数 + */ + +/** + * 防抖函数 + * 在事件停止触发n毫秒后才执行函数,适用于input输入、window resize等场景 + * @param func 要执行的函数 + * @param wait 延迟时间(毫秒) + * @param immediate 是否立即执行(首次触发时) + */ +export function debounce any>( + func: T, + wait: number, + immediate = false +): (...args: Parameters) => void { + let timeout: number | undefined + return function executedFunction(...args: Parameters) { + const later = () => { + timeout = undefined + if (!immediate) func(...args) + } + + const callNow = immediate && !timeout + + if (timeout !== undefined) { + clearTimeout(timeout) + } + + timeout = window.setTimeout(later, wait) + + if (callNow) func(...args) + } +} + +/** + * 节流函数 + * 限制函数在指定时间内最多执行一次,适用于scroll、mousemove等高频事件 + * @param func 要执行的函数 + * @param limit 时间间隔(毫秒) + */ +export function throttle any>( + func: T, + limit: number +): (...args: Parameters) => void { + let inThrottle: boolean + return function executedFunction(...args: Parameters) { + if (!inThrottle) { + func(...args) + inThrottle = true + setTimeout(() => (inThrottle = false), limit) + } + } +} + +/** + * requestAnimationFrame 节流 + * 使用浏览器的 requestAnimationFrame 来节流,适合动画相关的操作 + * @param func 要执行的函数 + */ +export function rafThrottle any>( + func: T +): (...args: Parameters) => void { + let rafId: number | undefined + return function executedFunction(...args: Parameters) { + if (rafId === undefined) { + rafId = requestAnimationFrame(() => { + func(...args) + rafId = undefined + }) + } + } +} + +/** + * 延迟执行函数 + * @param func 要执行的函数 + * @param delay 延迟时间(毫秒) + */ +export function delay(func: () => void, delay: number): number { + return window.setTimeout(func, delay) +} + +/** + * 取消延迟执行 + * @param timerId setTimeout 返回的 ID + */ +export function cancelDelay(timerId: number): void { + clearTimeout(timerId) +} \ No newline at end of file diff --git a/frontend/src/utils/useDevice.ts b/frontend/src/utils/useDevice.ts index 6582dc2..2c4c670 100644 --- a/frontend/src/utils/useDevice.ts +++ b/frontend/src/utils/useDevice.ts @@ -1,4 +1,5 @@ import { ref, computed, onMounted, onUnmounted } from 'vue' +import { debounce } from '@/utils/performance' // 设备类型枚举 export enum DeviceType { @@ -11,10 +12,11 @@ export enum DeviceType { const BREAKPOINTS = { mobile: 768, tablet: 1024 -} +} as const export function useDevice() { const screenWidth = ref(window.innerWidth) + const screenHeight = ref(window.innerHeight) // 设备类型判断 const deviceType = computed(() => { @@ -32,12 +34,30 @@ export function useDevice() { const isTablet = computed(() => deviceType.value === DeviceType.Tablet) const isDesktop = computed(() => deviceType.value === DeviceType.Desktop) - // 监听窗口变化 - const handleResize = () => { + // 屏幕方向 + const orientation = computed(() => { + return screenWidth.value > screenHeight.value ? 'landscape' : 'portrait' + }) + + // 是否触摸设备 + const isTouchDevice = computed(() => { + return 'ontouchstart' in window || navigator.maxTouchPoints > 0 + }) + + // 是否小屏幕(适用于密集布局调整) + const isSmallScreen = computed(() => screenWidth.value < 640) + + // 监听窗口变化(使用防抖优化性能,避免频繁更新) + const handleResize = debounce(() => { screenWidth.value = window.innerWidth - } + screenHeight.value = window.innerHeight + }, 150) onMounted(() => { + // 初始化屏幕尺寸 + screenWidth.value = window.innerWidth + screenHeight.value = window.innerHeight + window.addEventListener('resize', handleResize) }) @@ -47,9 +67,14 @@ export function useDevice() { return { screenWidth, + screenHeight, deviceType, isMobile, isTablet, - isDesktop + isDesktop, + orientation, + isTouchDevice, + isSmallScreen, + BREAKPOINTS } } \ No newline at end of file diff --git a/frontend/src/views/Customers/CustomerView.vue b/frontend/src/views/Customers/CustomerView.vue index 0f56998..9e66735 100644 --- a/frontend/src/views/Customers/CustomerView.vue +++ b/frontend/src/views/Customers/CustomerView.vue @@ -2,7 +2,7 @@ * @Author: 13895237362 2205451508@qq.com * @Date: 2025-08-20 16:00:00 * @LastEditors: 13895237362 2205451508@qq.com - * @LastEditTime: 2025-08-21 17:16:11 + * @LastEditTime: 2025-09-03 11:41:35 * @FilePath: /frontend/src/views/Customers/CustomerView.vue * @Description: 客户查看组件 --> @@ -351,7 +351,7 @@ onMounted(() => { .info-card { background: #fff; border-radius: 4px; - padding: 20px; + padding: 15px; } .basic-info { diff --git a/frontend/src/views/Customers/index.vue b/frontend/src/views/Customers/index.vue index 8ff8229..fe2236a 100644 --- a/frontend/src/views/Customers/index.vue +++ b/frontend/src/views/Customers/index.vue @@ -2,7 +2,7 @@ * @Author: 13895237362 2205451508@qq.com * @Date: 2025-08-12 00:00:00 * @LastEditors: 13895237362 2205451508@qq.com - * @LastEditTime: 2025-08-21 16:42:53 + * @LastEditTime: 2025-09-03 11:29:37 * @FilePath: /frontend/src/views/Customers/index.vue * @Description: 客户管理页面 --> @@ -95,18 +95,22 @@ style="width: 100%;" :header-cell-style="{ backgroundColor: '#F7F8FA', color: '#1D1D1D' }" :row-style="getRowStyle" - :max-height="'calc(100vh - 200px)'" + :max-height="'calc(100vh - 280px)'" > - + - {{ scope.row.customer_code }} + {{ scope.row.customer_code }} + + + + + {{ scope.row.customer_name }} - - + @@ -469,86 +473,136 @@ onMounted(async () => { }) - \ No newline at end of file diff --git a/frontend/src/views/Login.vue b/frontend/src/views/Login.vue index 0cd3f47..13c218c 100644 --- a/frontend/src/views/Login.vue +++ b/frontend/src/views/Login.vue @@ -185,7 +185,10 @@ async function handleLogin() { } - \ No newline at end of file
调整浏览器窗口大小来测试防抖功能
防抖延迟: 150ms(停止调整窗口后150ms才更新)