這段程式碼看起來是一個非常酷的賽博朋克風(Cyberpunk)微型應用程式產生器(App Creator)! 不過,從你貼出的程式碼結尾來看,它在最尾端的 return 渲染部分被切斷了(卡在 import React... 的混雜以及最後的 div className="min-h-screen... 和 div classNam)。 這正是為什麼你上傳到 Hugging Face 或其他地方時完全無法跑出來的原因。因為 JavaScript/React 的語法沒有閉合(例如缺少閉合的 和 }),這在編譯時會直接噴出嚴重的語法錯誤(Syntax Error)。 為了讓你這個漂亮的 App 能完美跑出來,我幫你把這段程式碼中殘缺的 UI 渲染(JSX)與所有子 App 運作邏輯(記帳本、番茄鐘、幸運輪盤、猜數字、喝水追蹤器、習慣打卡)全部補齊了! ## 🛠️ 完整且修正後的 App.js (或 app.py 內使用的程式碼) 你可以直接複製下方這段完全閉合、內建完整手機沙盒介面的 React 程式碼。它包含了上方所有的狀態,並完美實作了點擊切換、建立新 App 與刪除的功能: import React, { useState, useEffect } from 'react'; // 預設的 Demo App 列表 const DEFAULT_APPS = [ { id: 'app-default-1', name: '極簡極速記帳本', type: 'expense', createdAt: '2026/10/03 16:36', icon: '💰', description: '輕量級個人收支追蹤,支援分類與即時結算。', data: { transactions: [ { id: '1', title: '特調美式咖啡', amount: -110, category: '餐飲', date: '16:30' }, { id: '2', title: '自由接案尾款', amount: 3500, category: '收入', date: '14:00' }, ], }, }, { id: 'app-default-2', name: '賽博專注番茄鐘', type: 'pomodoro', createdAt: '2026/10/03 15:20', icon: '⏱️', description: '經典 25 分鐘工作 / 5 分鐘休息循環定時器。', data: { workDuration: 25, breakDuration: 5, completedSessions: 3 }, }, { id: 'app-default-3', name: '幸運決策輪盤', type: 'wheel', createdAt: '2026/10/03 12:10', icon: '🎰', description: '解決選擇困難症!隨機抽籤與決策工具。', data: { options: ['吃火鍋', '吃日料', '健康沙拉', '漢堡炸雞', '自己煮'] }, }, ]; const INSPIRATION_PROMPTS = [ '我想做一個每日飲水追蹤器 💧', '幫我生一個心靈猜數字遊戲 🎮', '今天想來個重要事件倒數計時 ⏳', '我需要一個習慣打卡簽到板 📅', '製作一個隨機靈感快記閃卡 ⚡', ]; export default function App() { const [activeTab, setActiveTab] = useState('home'); const [apps, setApps] = useState(() => { try { const saved = localStorage.getItem('cyber_apps_list'); return saved ? JSON.parse(saved) : DEFAULT_APPS; } catch { return DEFAULT_APPS; } }); const [activeAppId, setActiveAppId] = useState(null); const [stickyNote, setStickyNote] = useState(() => { return localStorage.getItem('cyber_sticky_note') || '💡 閃念備忘:記得今晚檢查 AI 產出的子 App 功能...'; }); const [promptInput, setPromptInput] = useState(''); const [isGenerating, setIsGenerating] = useState(false); const [generationLogs, setGenerationLogs] = useState([]); const [genProgress, setGenProgress] = useState(0); const [apiKey, setApiKey] = useState(() => localStorage.getItem('cyber_api_key') || ''); const [apiModel, setApiModel] = useState('gpt-4o-mini'); const [toastMsg, setToastMsg] = useState(null); const [currentTime, setCurrentTime] = useState(new Date()); // 子 App 內部使用的臨時輸入狀態 const [customInput, setCustomInput] = useState(''); useEffect(() => { const timer = setInterval(() => setCurrentTime(new Date()), 1000); return () => clearInterval(timer); }, []); useEffect(() => { localStorage.setItem('cyber_apps_list', JSON.stringify(apps)); }, [apps]); useEffect(() => { localStorage.setItem('cyber_sticky_note', stickyNote); }, [stickyNote]); useEffect(() => { localStorage.setItem('cyber_api_key', apiKey); }, [apiKey]); const showToast = (msg) => { setToastMsg(msg); setTimeout(() => setToastMsg(null), 3000); }; const triggerAiGeneration = (customPrompt) => { const finalPrompt = (customPrompt || promptInput).trim(); setIsGenerating(true); setGenProgress(0); setGenerationLogs([]); const logsList = [ '⚡ [Core] 正在解析使用者心境與指令需求...', '🧬 [Synthesizer] 提取特徵:' + (finalPrompt ? `"${finalPrompt}"` : '隨機觸發靈感模式'), '⚙️ [AST Parser] 動態構建動態 React 組件狀態機...', '🎨 [Tailwind Core] 注入深色賽博高對比視覺 Token...', '🚀 [Sandbox] 沙盒虛擬機編譯完成,準備挂載執行!', ]; let currentStep = 0; const interval = setInterval(() => { if (currentStep < logsList.length) { setGenerationLogs((prev) => [...prev, logsList[currentStep]]); setGenProgress(((currentStep + 1) / logsList.length) * 100); currentStep++; } else { clearInterval(interval); finishAppCreation(finalPrompt); } }, 600); }; const finishAppCreation = (prompt) => { let appType = 'timer'; let appName = '全新 AI 助理工具'; let icon = '⚡'; let description = 'AI 智慧生成的專屬微型應用程式。'; let initialData = {}; const p = prompt.toLowerCase(); if (p.includes('記帳') || p.includes('花費') || p.includes('錢') || p.includes('預算')) { appType = 'expense'; appName = 'AI 智慧隨手記帳'; icon = '💳'; description = '追蹤個人日常收支狀況與類別分析。'; initialData = { transactions: [{ id: '101', title: '開工餐點', amount: -250, category: '餐飲', date: '剛才' }] }; } else if (p.includes('水') || p.includes('喝水') || p.includes('飲用')) { appType = 'water'; appName = '全天候補水監測員'; icon = '💧'; description = '設定每日目標,輕鬆點擊紀錄補充水分。'; initialData = { targetMl: 2000, currentMl: 600, logs: [{ time: '09:00', amount: 300 }] }; } else if (p.includes('猜') || p.includes('遊戲') || p.includes('數字')) { appType = 'game_guess'; appName = '心靈數字神算界'; icon = '🎯'; description = 'AI 隨機生成 1-100 數字,挑戰最少次數猜中!'; initialData = { target: Math.floor(Math.random() * 100) + 1, attempts: [], status: 'playing' }; } else if (p.includes('倒數') || p.includes('計時') || p.includes('時間')) { appType = 'countdown'; appName = '極限倒數計時儀'; icon = '⌛'; description = '精確倒數指定秒數,支援警報觸發視覺效果。'; initialData = { totalSeconds: 60, currentSeconds: 60, isRunning: false }; } else if (p.includes('習慣') || p.includes('打卡') || p.includes('簽到')) { appType = 'habit'; appName = '高能習慣育成卡'; icon = '🔥'; description = '紀錄每日原子習慣,保持連勝紀錄。'; initialData = { habits: [{ id: 'h1', name: '閱讀 15 分鐘', done: true }, { id: 'h2', name: '深蹲 30 次', done: false }] }; } else if (p.includes('轉盤') || p.includes('抽籤') || p.includes('決定') || p.includes('選')) { appType = 'wheel'; appName = '無限決策聖杯'; icon = '🎲'; description = '輸入選項,由 AI 隨機概率演算法替你做選擇。'; initialData = { options: ['A 方案', 'B 方案', '再想想', '交給命運'] }; } else { const randThemes = [ { name: '靈感快記卡', type: 'note', icon: '📝', desc: '記錄突如其來的專案與生活靈感卡片。' }, { name: '微型專注鬧鐘', type: 'pomodoro', icon: '⏰', desc: '保持高度專注力的高效時間模組。' }, ]; const selected = randThemes[Math.floor(Math.random() * randThemes.length)]; appType = selected.type; appName = prompt ? `「${prompt.slice(0, 8)}」工具` : selected.name; icon = selected.icon; description = selected.desc; initialData = { text: '點擊編輯此靈感備忘錄...' }; } const now = new Date(); const timeFormatted = `${now.getFullYear()}/${String(now.getMonth() + 1).padStart(2, '0')}/${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`; const newApp = { id: `app-${Date.now()}`, name: appName, type: appType, createdAt: timeFormatted, icon, description, data: initialData, }; setApps((prev) => [newApp, ...prev]); setIsGenerating(false); setPromptInput(''); setActiveAppId(newApp.id); setActiveTab('gallery'); showToast(`🎉 子 App《${appName}》創作成功!已掛載至沙盒。`); }; const deleteApp = (id, e) => { e.stopPropagation(); setApps((prev) => prev.filter((a) => a.id !== id)); if (activeAppId === id) setActiveAppId(null); showToast('🗑️ 工具已從作品庫中移除'); }; const updateAppData = (id, newData) => { setApps((prev) => prev.map((app) => (app.id === id ? { ...app, data: typeof newData === 'function' ? newData(app.data) : newData } : app)) ); }; const currentActiveApp = apps.find((a) => a.id === activeAppId); // 渲染獨立子 App 的微前端沙盒 const renderAppSandbox = (app) => { if (!app) return
請在作品庫選擇一個 App 啟動
; switch (app.type) { case 'expense': return (
當前結餘 ${app.data.transactions?.reduce((acc, t) => acc + t.amount, 0) || 0}
{app.data.transactions?.map((t) => (
{t.title} ({t.category}) 0 ? 'text-emerald-400' : 'text-rose-400'}>{t.amount > 0 ? `+${t.amount}` : t.amount}
))}
); case 'pomodoro': return (
25:00

已專注任務:{app.data.completedSessions || 0} 次