From 6de525d3494f8ac623071e185629467e9fab75ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8C=97=E6=9E=B3?=
<7854742+wang_rumeng@user.noreply.gitee.com>
Date: Sat, 6 Sep 2025 22:58:54 +0800
Subject: [PATCH] =?UTF-8?q?=E5=B8=83=E5=B1=80=20H5=E9=80=82=E9=85=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.env.development | 8 ++--
components/layout/dashboard-layout.tsx | 36 ++++++++++++---
components/layout/top-bar.tsx | 10 ++--
hooks/useDeviceType.ts | 64 ++++++++++++++++++++++++++
4 files changed, 104 insertions(+), 14 deletions(-)
create mode 100644 hooks/useDeviceType.ts
diff --git a/.env.development b/.env.development
index 07a7c41..c4b938b 100644
--- a/.env.development
+++ b/.env.development
@@ -1,8 +1,8 @@
-#NEXT_PUBLIC_JAVA_URL = https://77.app.java.auth.qikongjian.com
-#NEXT_PUBLIC_BASE_URL = https://77.smartvideo.py.qikongjian.com
-NEXT_PUBLIC_JAVA_URL = https://test.java.movieflow.ai
-NEXT_PUBLIC_BASE_URL = https://test.video.movieflow.ai
+NEXT_PUBLIC_JAVA_URL = https://77.app.java.auth.qikongjian.com
+NEXT_PUBLIC_BASE_URL = https://77.smartvideo.py.qikongjian.com
+# NEXT_PUBLIC_JAVA_URL = https://test.java.movieflow.ai
+# NEXT_PUBLIC_BASE_URL = https://test.video.movieflow.ai
# 失败率
NEXT_PUBLIC_ERROR_CONFIG = 0.2
\ No newline at end of file
diff --git a/components/layout/dashboard-layout.tsx b/components/layout/dashboard-layout.tsx
index 5e1ad14..0b7e5b9 100644
--- a/components/layout/dashboard-layout.tsx
+++ b/components/layout/dashboard-layout.tsx
@@ -3,6 +3,7 @@
import { useState } from 'react';
import { Sidebar } from './sidebar';
import { TopBar } from './top-bar';
+import { useDeviceType } from '@/hooks/useDeviceType';
interface DashboardLayoutProps {
children: React.ReactNode;
@@ -10,15 +11,38 @@ interface DashboardLayoutProps {
export function DashboardLayout({ children }: DashboardLayoutProps) {
const [sidebarCollapsed, setSidebarCollapsed] = useState(true); // 默认收起状态
+ const { deviceType, isMobile, isTablet, isDesktop } = useDeviceType();
+
+ // 根据设备类型设置布局样式
+ const getLayoutStyles = () => {
+ if (isMobile) {
+ return {
+ left: '0',
+ width: '100vw'
+ };
+ }
+
+ if (isTablet) {
+ return {
+ left: sidebarCollapsed ? '3rem' : '12rem',
+ width: sidebarCollapsed ? 'calc(100vw - 3rem)' : 'calc(100vw - 12rem)'
+ };
+ }
+
+ // 桌面端
+ return {
+ left: sidebarCollapsed ? '4rem' : '16rem',
+ width: sidebarCollapsed ? 'calc(100vw - 4rem)' : 'calc(100vw - 16rem)'
+ };
+ };
return (
-
-
-
+
+ {isDesktop &&
}
+
{children}
diff --git a/components/layout/top-bar.tsx b/components/layout/top-bar.tsx
index b09c22b..7f60d92 100644
--- a/components/layout/top-bar.tsx
+++ b/components/layout/top-bar.tsx
@@ -35,7 +35,7 @@ interface User {
plan_name?: string;
}
-export function TopBar({ collapsed }: { collapsed: boolean }) {
+export function TopBar({ collapsed, isDesktop=true }: { collapsed: boolean, isDesktop?: boolean }) {
const router = useRouter();
const [isOpen, setIsOpen] = React.useState(false);
const menuRef = useRef
(null);
@@ -169,10 +169,10 @@ export function TopBar({ collapsed }: { collapsed: boolean }) {
className="fixed right-0 top-0 h-16 header z-[999]"
style={{
isolation: "isolate",
- left: pathname === "/" ? "0" : (collapsed ? "2.5rem" : "16rem")
+ left: (pathname === "/" || !isDesktop) ? "0" : (collapsed ? "2.5rem" : "16rem")
}}
>
-
+
-
+
{currentUser.username ? currentUser.username.charAt(0) : "MF"}
diff --git a/hooks/useDeviceType.ts b/hooks/useDeviceType.ts
new file mode 100644
index 0000000..a46721f
--- /dev/null
+++ b/hooks/useDeviceType.ts
@@ -0,0 +1,64 @@
+import { useState, useEffect } from 'react';
+
+// 定义设备类型枚举
+export enum DeviceType {
+ MOBILE = 'mobile', // 手机
+ TABLET = 'tablet', // 平板
+ DESKTOP = 'desktop' // 桌面端
+}
+
+// 定义屏幕断点
+const BREAKPOINTS = {
+ MOBILE: 480, // 0-480px 为手机
+ TABLET: 1024, // 481-1024px 为平板
+ DESKTOP: 1025 // 1025px 及以上为桌面端
+};
+
+export function useDeviceType() {
+ const [deviceType, setDeviceType] = useState
(DeviceType.DESKTOP);
+ const [windowSize, setWindowSize] = useState({
+ width: typeof window !== 'undefined' ? window.innerWidth : 0,
+ height: typeof window !== 'undefined' ? window.innerHeight : 0
+ });
+
+ useEffect(() => {
+ /**
+ * 根据窗口宽度判断设备类型
+ */
+ const getDeviceType = (width: number): DeviceType => {
+ if (width <= BREAKPOINTS.MOBILE) return DeviceType.MOBILE;
+ if (width <= BREAKPOINTS.TABLET) return DeviceType.TABLET;
+ return DeviceType.DESKTOP;
+ };
+
+ /**
+ * 处理窗口大小变化
+ */
+ const handleResize = () => {
+ const width = window.innerWidth;
+ const height = window.innerHeight;
+
+ setWindowSize({ width, height });
+ setDeviceType(getDeviceType(width));
+ };
+
+ // 初始化设备类型
+ handleResize();
+
+ // 添加窗口大小变化监听
+ window.addEventListener('resize', handleResize);
+
+ // 清理监听器
+ return () => {
+ window.removeEventListener('resize', handleResize);
+ };
+ }, []);
+
+ return {
+ deviceType,
+ windowSize,
+ isMobile: deviceType === DeviceType.MOBILE,
+ isTablet: deviceType === DeviceType.TABLET,
+ isDesktop: deviceType === DeviceType.DESKTOP
+ };
+}
\ No newline at end of file