未来科技-Windows 13风格界面
1.先看效果
2.源代码(TypeScript和React组件)
import React, { useState, useEffect } from 'react'
import { Button } from "@/components/ui/button"
import { Input } from "@/components/ui/input"
// 图标组件
const Icon = ({ name }: { name: string }) => {
const iconStyle = "w-6 h-6 flex items-center justify-center text-white bg-blue-500 rounded-sm";
return (
{name.charAt(0).toUpperCase()}
);
};
// 应用窗口组件
const AppWindow = ({ app, onClose, onMinimize, onMaximize, isActive, setActiveApp }) => {
const [content, setContent] = useState(app.content || "");
const [isMaximized, setIsMaximized] = useState(false);
const handleMaximize = () => {
setIsMaximized(!isMaximized);
onMaximize();
};
return (
className={`absolute bg-white shadow-lg rounded-lg overflow-hidden ${
isMaximized ? 'w-full h-full top-0 left-0' : 'w-96 h-64'
} ${isActive ? 'z-10' : 'z-0'}`}
style={!isMaximized ? {top: `${50 + app.id * 30}px`, left: `${50 + app.id * 30}px`} : {}}
onClick={() => setActiveApp(app.id)}
>
{app.name}
_
□
X
{app.name === "Notepad" && (
)}
{app.name === "File Explorer" && (
Documents
Pictures
Music
)}
);
};
// 主组件
export default function Windows13() {
const [isStartMenuOpen, setIsStartMenuOpen] = useState(false);
const [openApps, setOpenApps] = useState([]);
const [activeApp, setActiveApp] = useState(null);
const [time, setTime] = useState(new Date());
useEffect(() => {
const timer = setInterval(() => setTime(new Date()), 1000);
return () => clearInterval(timer);
}, []);
const toggleStartMenu = () => setIsStartMenuOpen(!isStartMenuOpen);
const openApp = (appName) => {
const newApp = { id: openApps.length, name: appName };
setOpenApps([...openApps, newApp]);
setActiveApp(newApp.id);
setIsStartMenuOpen(false);
};
const closeApp = (appId) => {
setOpenApps(openApps.filter(app => app.id !== appId));
if (activeApp === appId) {
setActiveApp(null);
}
};
const minimizeApp = (appId) => {
// 在实际应用中,这里可以添加最小化的逻辑
console.log("Minimize app", appId);
};
const maximizeApp = (appId) => {
// 在实际应用中,这里可以添加最大化的逻辑
console.log("Maximize app", appId);
};
return (
{/* 桌面 */}
{["My Computer", "Recycle Bin", "Control Panel"].map((icon) => (
))}
{/* 应用窗口 */}
{openApps.map((app) => (
key={app.id} app={app} isActive={activeApp === app.id} onClose={() => closeApp(app.id)} onMinimize={() => minimizeApp(app.id)} onMaximize={() => maximizeApp(app.id)} setActiveApp={setActiveApp} /> ))} {/* 任务栏 */} type="search" placeholder="Type here to search" className="w-64 bg-gray-800 border-gray-700" /> {openApps.map(app => ( ))} {time.toLocaleTimeString()}
{/* 开始菜单 */}
{isStartMenuOpen && (
{["Notepad", "Calculator", "File Explorer"].map((app) => (
))}
)}
);
}
扫描二维码分享
评论区
请登录后发表评论。