人生轨迹代码初始化

This commit is contained in:
2025-12-21 16:57:54 +08:00
parent 06a3638c29
commit f3c06ce6af
42 changed files with 7746 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
# 人生轨迹 (Life Trajectory)
一款结合数字疗愈美学与人工智能的人生管理工具。
## 核心功能
1. **深度入站**:分步式采集人设与重要回忆。
2. **人生回溯**:记录大事件,AI辅助分析与疗愈。
3. **剧本生成**:将过去经历转化为高能爽文人生。
4. **路径规划**:基于剧本反推现实可行的执行方案。
## 技术栈
- 架构:原生 ES Modules 模块化开发
- UITailwind CSS + Glassmorphism 拟态
- 动画:GSAP
- AIOpenRouter (DeepSeek)
- 存储:LocalStorage
+47
View File
@@ -0,0 +1,47 @@
const API_KEY = "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";
const BASE_URL = "https://openrouter.ai/api/v1/chat/completions";
export const AIService = {
async fetchAI(prompt, systemMsg) {
try {
const response = await fetch(BASE_URL, {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: "deepseek/deepseek-chat-v3-0324:free",
messages: [
{ role: "system", content: systemMsg },
{ role: "user", content: prompt }
]
})
});
const data = await response.json();
return data.choices[0].message.content;
} catch (e) {
console.error(e);
return "(AI 暂时陷入了沉思,请稍后再试)";
}
},
async analyzeLifeEvent(event) {
const system = "你是一位温柔的生命引路人,擅长从平凡事件中发掘成长的力量。请分析用户记录的事件,提供情感价值、成长总结和疗愈鼓励。保持字数在150字左右。";
const prompt = `事件标题:${event.title}\n时间:${event.time}\n内容:${event.content}`;
return this.fetchAI(prompt, system);
},
async generateEpicScript(params, events) {
const system = `你是一位金牌爽文编剧。根据用户的角色设定和过往经历,生成一段符合用户设定、充满爽感的未来人生剧本。剧本必须包含起承转合,使用【标题】标记段落。`;
const charInfo = `姓名:${params.character.nickname}, 性格:${params.character.mbti}, 兴趣:${params.character.hobbies.join(',')}, 星座:${params.character.zodiac}`;
const eventSummary = events.map(e => e.title).join(', ');
const prompt = `角色信息:${charInfo}\n过往经历关键词:${eventSummary}\n用户指定主题:${params.theme}\n指定风格:${params.style}\n篇幅要求:${params.length}\n\n请以此创作一段热血、精彩的人生剧本。`;
return this.fetchAI(prompt, system);
},
async generatePath(script) {
const system = "你是一位人生规划导师。请将用户生成的剧本拆解为现实中可操作的路径。使用【阶段名称】加上具体建议。务必客观、可执行。";
return this.fetchAI(script, system);
}
};
+74
View File
@@ -0,0 +1,74 @@
export const UI = {
inspirationClusters: {
childhood: ['秋千', '晚霞', '糖果', '奔跑', '蝉鸣', '雨后泥土', '旧书包', '风筝'],
joy: ['海浪', '拥抱', '掌声', '晨曦', '破土而出', '默契', '星空', '释放'],
low: ['落叶', '雨伞', '长廊', '深呼吸', '自愈', '沉潜', '坚韧', '等待', '破茧']
},
renderInspiration(type, targetId) {
const words = this.inspirationClusters[type];
return words.map(word => `
<span class="prompt-tag px-3 py-1 bg-white/5 border border-white/5 rounded-full text-[10px] text-white/40 cursor-pointer hover:bg-orange-200/10 hover:text-orange-200 transition-all"
onclick="document.getElementById('${targetId}').value += '${word}'">${word}</span>
`).join('');
},
renderInput(label, id, type = 'text', placeholder = '', value = '') {
return `
<div class="flex flex-col gap-2 mb-4 w-full">
<label class="text-[10px] text-white/30 uppercase tracking-widest font-bold">${label}</label>
<input type="${type}" id="${id}" value="${value}" placeholder="${placeholder}"
class="glass-input w-full focus:ring-2 focus:ring-orange-200/50">
</div>
`;
},
renderTextArea(label, id, placeholder = '', value = '') {
return `
<div class="flex flex-col gap-2 mb-4 w-full">
<label class="text-[10px] text-white/30 uppercase tracking-widest font-bold">${label}</label>
<textarea id="${id}" rows="4" placeholder="${placeholder}"
class="glass-input w-full resize-none focus:ring-2 focus:ring-orange-200/50">${value}</textarea>
</div>
`;
},
renderSelect(label, id, options, selectedValue = '') {
return `
<div class="flex flex-col gap-2 mb-4 w-full">
<label class="text-[10px] text-white/30 uppercase tracking-widest font-bold">${label}</label>
<select id="${id}" class="glass-input w-full appearance-none">
${options.map(opt => `<option value="${opt.value}" ${opt.value === selectedValue ? 'selected' : ''}>${opt.label}</option>`).join('')}
</select>
</div>
`;
},
renderAccountSettings(data) {
return `
<div class="space-y-6 animate-fade-in">
<div class="flex items-center gap-4 mb-8">
<div class="w-12 h-12 rounded-full bg-orange-200/10 flex items-center justify-center">
<i data-lucide="settings-2" class="text-orange-200 w-5 h-5"></i>
</div>
<div>
<h4 class="text-xl font-serif">个人设定</h4>
<p class="text-xs text-white/40">在这里调整你的人生航向基础信息</p>
</div>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-x-6">
${this.renderInput('昵称', 'edit-nickname', 'text', '你想被如何称呼?', data.nickname)}
${this.renderInput('职业', 'edit-profession', 'text', '你当下的社会锚点', data.profession || '')}
${this.renderInput('MBTI', 'edit-mbti', 'text', '性格色彩', data.mbti)}
${this.renderInput('星座', 'edit-zodiac', 'text', '星辰指引', data.zodiac)}
</div>
${this.renderInput('兴趣爱好', 'edit-hobbies', 'text', '让灵魂起舞的事物', data.hobbies.join(', '))}
<div class="flex gap-4 mt-8 pt-6 border-t border-white/5">
<button id="save-profile-btn" class="flex-1 glass-btn py-3 bg-orange-200/10 text-orange-100 font-bold tracking-widest">保存修改</button>
<button id="cancel-edit-btn" class="px-6 glass-btn py-3 text-white/40">返回</button>
</div>
</div>
`;
}
};
+396
View File
@@ -0,0 +1,396 @@
import { state } from './state.js';
import { UI } from './components.js';
import { AIService } from './api.js';
export const Dashboard = {
render() {
const container = document.getElementById('view-container');
const nav = document.getElementById('top-nav');
if (nav) nav.classList.remove('hidden');
container.innerHTML = `
<div class="grid grid-cols-1 md:grid-cols-12 h-full">
<!-- Sidebar Nav -->
<aside class="md:col-span-3 border-r border-white/5 p-6 flex flex-col gap-6 bg-black/20">
<div class="space-y-2">
<div class="px-3 py-2 text-[10px] text-white/30 uppercase tracking-[0.2em] font-bold">回溯过去</div>
<button class="nav-item active w-full flex items-center gap-3 p-4 rounded-2xl glass-btn text-white/50" data-view="timeline">
<i data-lucide="history" class="w-5 h-5"></i> <span>生命长河</span>
</button>
</div>
<div class="space-y-2">
<div class="px-3 py-2 text-[10px] text-white/30 uppercase tracking-[0.2em] font-bold">创造未来</div>
<button class="nav-item w-full flex items-center gap-3 p-4 rounded-2xl glass-btn text-white/50" data-view="script">
<i data-lucide="sparkles" class="w-5 h-5"></i> <span>爽文剧本</span>
</button>
<button class="nav-item w-full flex items-center gap-3 p-4 rounded-2xl glass-btn text-white/50" data-view="path">
<i data-lucide="map" class="w-5 h-5"></i> <span>实现路径</span>
</button>
</div>
<div class="mt-auto p-4 bg-white/[0.02] rounded-2xl border border-white/5">
<p class="text-[10px] text-white/20 italic leading-relaxed">
“回溯过去、记录当下、创造未来。”
</p>
</div>
</aside>
<!-- Content Area -->
<section id="dash-content" class="md:col-span-9 p-8 overflow-y-auto custom-scrollbar relative">
</section>
</div>
`;
this.initEventListeners();
this.loadTimeline();
lucide.createIcons();
},
initEventListeners() {
document.querySelectorAll('.nav-item').forEach(btn => {
btn.onclick = () => {
if (btn.classList.contains('active')) return;
document.querySelectorAll('.nav-item').forEach(b => b.classList.remove('active'));
btn.classList.add('active');
const view = btn.dataset.view;
this.animateTransition(() => {
if(view === 'timeline') this.loadTimeline();
if(view === 'script') this.loadScriptGenerator();
if(view === 'path') this.loadPathGenerator();
});
};
});
const profileBtn = document.getElementById('user-profile-btn');
if (profileBtn) profileBtn.onclick = () => this.showProfile();
},
animateTransition(callback) {
const content = document.getElementById('dash-content');
gsap.to(content, { opacity: 0, y: 10, duration: 0.3, onComplete: () => {
callback();
gsap.to(content, { opacity: 1, y: 0, duration: 0.6, ease: "power2.out" });
lucide.createIcons();
}});
},
loadTimeline() {
const content = document.getElementById('dash-content');
const hasEvents = state.lifeEvents.length > 0;
content.innerHTML = `
<div class="flex justify-between items-end mb-12">
<div>
<h3 class="text-4xl font-serif text-white/90">生命长河</h3>
<p class="text-sm text-white/30 mt-2">塑造你的每一刻,都被星辰见证。</p>
</div>
<button id="add-event-btn" class="glass-btn px-6 py-3 rounded-full text-sm font-bold flex items-center gap-2 bg-orange-200/5 text-orange-200 border-orange-200/20 shadow-lg">
<i data-lucide="plus" class="w-4 h-4"></i> 记录足迹
</button>
</div>
<div id="timeline-container" class="relative pl-8">
${hasEvents ? '<div class="timeline-line"></div>' : ''}
<div class="space-y-10">
${hasEvents ? state.lifeEvents.sort((a,b) => new Date(b.time) - new Date(a.time)).map(ev => this.renderEventCard(ev)).join('') : this.renderEmpty()}
</div>
</div>
`;
document.getElementById('add-event-btn').onclick = () => this.showEventModal();
},
renderEventCard(ev) {
return `
<div class="relative group">
<div class="timeline-dot absolute left-[-39px] top-6 z-10"></div>
<div class="glass-card p-6 border-white/5 hover:border-orange-200/20 transition-all duration-700">
<div class="flex justify-between items-start mb-4">
<h4 class="text-xl font-medium text-white/80">${ev.title}</h4>
<span class="text-[10px] font-mono tracking-widest text-white/30 uppercase">${ev.time}</span>
</div>
<p class="text-sm text-white/60 leading-relaxed mb-6">${ev.content}</p>
<div class="ai-glow-card p-5 rounded-2xl bg-orange-200/[0.02] border border-orange-200/5">
<div class="flex items-center gap-2 mb-2">
<i data-lucide="sparkles" class="w-3 h-3 text-orange-200"></i>
<span class="text-[9px] uppercase tracking-[0.2em] text-orange-200/60 font-bold">引路人洞察</span>
</div>
<p class="text-xs italic text-white/50 leading-loose">${ev.aiFeedback}</p>
</div>
</div>
</div>
`;
},
showEventModal() {
const modal = document.getElementById('modal-overlay');
const body = document.getElementById('modal-body');
modal.classList.remove('hidden');
body.innerHTML = `
<div class="space-y-6">
<div class="mb-4"><h3 class="text-2xl font-serif">记录足迹</h3></div>
${UI.renderInput('事件标题', 'ev-title', 'text', '给这段经历起个名字')}
${UI.renderInput('发生时间', 'ev-time', 'date')}
${UI.renderTextArea('经历详情', 'ev-content', '当时发生了什么?你的感受如何?')}
<button id="save-event" class="w-full glass-btn py-4 rounded-2xl bg-orange-200/10 text-orange-200 font-bold tracking-[0.2em]">开启 AI 疗愈</button>
</div>
`;
document.getElementById('save-event').onclick = async () => {
const btn = document.getElementById('save-event');
const event = { title: document.getElementById('ev-title').value, time: document.getElementById('ev-time').value, content: document.getElementById('ev-content').value, aiFeedback: "分析中..." };
if(!event.title || !event.time || !event.content) return alert("请完整填写记录。");
btn.disabled = true;
btn.innerHTML = `<span class="animate-pulse">正在共鸣生命轨迹...</span>`;
event.aiFeedback = await AIService.analyzeLifeEvent(event);
state.addLifeEvent(event);
modal.classList.add('hidden');
this.loadTimeline();
};
lucide.createIcons();
},
loadScriptGenerator() {
const content = document.getElementById('dash-content');
const userData = state.registrationData;
const styles = [
{value:'都市', label:'都市沉浮'}, {value:'古风', label:'快意恩仇'},
{value:'爱情', label:'唯美浪漫'}, {value:'科幻', label:'星际远征'},
{value:'喜剧', label:'荒诞不经'}, {value:'悬疑', label:'迷雾重重'}, {value:'恐怖', label:'午夜回响'}
];
const lengths = [{value:'短', label:'极简'}, {value:'中', label:'连载'}, {value:'长', label:'史诗'}];
content.innerHTML = `
<div class="grid grid-cols-1 lg:grid-cols-12 gap-8">
<div class="lg:col-span-4 space-y-6">
<div class="glass-card p-6 border-white/10 space-y-4">
<div class="flex items-center gap-2 pb-2 border-b border-white/5">
<i data-lucide="user-cog" class="w-4 h-4 text-orange-200"></i>
<h4 class="text-sm font-bold tracking-widest text-white/80 uppercase">角色设定</h4>
</div>
<div class="grid grid-cols-2 gap-x-2 gap-y-4 text-[11px]">
<div><label class="text-white/20 block">昵称</label><span class="text-white/70">${userData.nickname}</span></div>
<div><label class="text-white/20 block">星座</label><span class="text-white/70">${userData.zodiac}</span></div>
<div><label class="text-white/20 block">MBTI</label><span class="text-white/70">${userData.mbti}</span></div>
<div class="col-span-2"><label class="text-white/20 block">兴趣爱好</label><span class="text-white/70">${userData.hobbies.join(', ')}</span></div>
</div>
<button onclick="document.getElementById('user-profile-btn').click()" class="w-full py-2 text-[10px] text-orange-200/50 hover:text-orange-200 border border-white/5 rounded-xl transition-all">修改人设</button>
</div>
<div class="glass-card p-6 border-white/10 space-y-6">
<div class="flex items-center gap-2 pb-2 border-b border-white/5">
<i data-lucide="pen-tool" class="w-4 h-4 text-orange-200"></i>
<h4 class="text-sm font-bold tracking-widest text-white/80 uppercase">创作需求</h4>
</div>
${UI.renderInput('剧本主题', 'sc-theme', 'text', '例如:我在职场逆袭了')}
${UI.renderSelect('叙事风格', 'sc-style', styles)}
${UI.renderSelect('剧本篇幅', 'sc-length', lengths)}
<button id="gen-script-btn" class="w-full glass-btn py-4 bg-orange-200/5 text-orange-200 font-bold text-sm tracking-widest border-orange-200/20">
开启天命编撰
</button>
</div>
<div class="space-y-4">
<h5 class="text-[10px] text-white/20 uppercase tracking-widest font-bold px-2">历史卷轴</h5>
<div class="space-y-2 max-h-[25vh] overflow-y-auto custom-scrollbar">
${state.scripts.length > 0 ? state.scripts.map(s => `
<div class="script-item p-3 glass-card text-left cursor-pointer hover:bg-white/5 border-white/5 transition-all ${s.id === state.selectedScriptId ? 'border-orange-200/30 bg-orange-200/5' : ''}" data-id="${s.id}">
<div class="text-[11px] text-white/80 truncate">${s.theme}</div>
<div class="text-[9px] text-white/30 flex justify-between mt-1"><span>${s.style} | ${s.length}</span><span>${s.date}</span></div>
</div>
`).join('') : '<p class="text-center text-xs text-white/10 py-4 italic">暂无卷轴</p>'}
</div>
</div>
</div>
<div class="lg:col-span-8">
<div id="script-target" class="h-full">
${state.selectedScriptId ? this.renderScript(state.getSelectedScript()) : this.renderEmptyScript()}
</div>
</div>
</div>
`;
document.getElementById('gen-script-btn').onclick = async () => {
const theme = document.getElementById('sc-theme').value;
if(!theme) return alert('请输入主题');
const btn = document.getElementById('gen-script-btn');
btn.disabled = true;
btn.innerHTML = `<i data-lucide="loader" class="animate-spin w-4 h-4 mr-2"></i> 编撰中...`;
lucide.createIcons();
const params = {
theme,
style: document.getElementById('sc-style').value,
length: document.getElementById('sc-length').value,
character: state.registrationData
};
const content = await AIService.generateEpicScript(params, state.lifeEvents);
state.addScript({ ...params, content });
this.animateTransition(() => this.loadScriptGenerator());
};
document.querySelectorAll('.script-item').forEach(item => {
item.onclick = () => {
state.selectedScriptId = parseInt(item.dataset.id);
state.save();
this.animateTransition(() => this.loadScriptGenerator());
};
});
lucide.createIcons();
},
renderScript(script) {
return `
<div class="glass-card p-10 h-full overflow-y-auto custom-scrollbar border-orange-200/20 shadow-2xl relative animate-fade-in">
<div class="prose prose-invert max-w-none">
<div class="flex justify-between items-center mb-8 pb-4 border-b border-white/5">
<div>
<h4 class="text-2xl font-serif text-orange-200">${script.theme}</h4>
<p class="text-[10px] text-white/30 mt-1 uppercase tracking-widest">${script.style}篇 · ${script.length}卷</p>
</div>
<i data-lucide="book-open" class="text-white/20"></i>
</div>
<div class="text-white/70 leading-loose whitespace-pre-wrap space-y-6 text-sm">
${script.content.replace(/【/g, '<div class="mt-8 mb-4 text-orange-100 font-bold text-lg border-l-2 border-orange-400 pl-4">【').replace(/】/g, '】</div>')}
</div>
</div>
</div>
`;
},
renderEmptyScript() {
return `
<div class="flex flex-col items-center justify-center h-full text-center opacity-20 py-32">
<i data-lucide="sparkles" class="w-20 h-20 mb-6"></i>
<p class="text-xl font-serif">请在左侧设定需求,开启你的天命爽文</p>
</div>
`;
},
loadPathGenerator() {
const content = document.getElementById('dash-content');
const script = state.getSelectedScript();
if (!script) {
content.innerHTML = `
<div class="flex flex-col items-center justify-center py-32 opacity-30 text-center">
<i data-lucide="map" class="w-16 h-16 mb-4"></i>
<p class="font-serif italic text-xl">先生成剧本,方能洞察路径。</p>
<button onclick="document.querySelector('[data-view=script]').click()" class="mt-6 glass-btn px-6 py-2 rounded-full text-xs">去生成剧本</button>
</div>
`;
return;
}
content.innerHTML = `
<div class="max-w-3xl mx-auto space-y-12 pb-20">
<div class="flex justify-between items-end">
<div>
<h3 class="text-4xl font-serif">实现路径</h3>
<p class="text-sm text-white/30 mt-2">基于《${script.theme}》,拆解达成目标的每一步。</p>
</div>
<button id="gen-path-btn" class="glass-btn px-8 py-3 rounded-full text-sm font-bold bg-blue-400/5 text-blue-300 border-blue-400/20">
${state.selectedPath ? '重新推演' : '开启人生导航'}
</button>
</div>
<div id="path-target" class="space-y-6">
${state.selectedPath ? this.renderPath(state.selectedPath) : this.renderEmptyPath()}
</div>
</div>
`;
document.getElementById('gen-path-btn').onclick = async () => {
const btn = document.getElementById('gen-path-btn');
btn.disabled = true;
btn.innerHTML = `<i data-lucide="loader" class="animate-spin w-4 h-4 mr-2"></i> 规划中...`;
const path = await AIService.generatePath(script.content);
state.setPath(path);
this.animateTransition(() => this.loadPathGenerator());
};
},
renderPath(path) {
return path.split(/【/).filter(s => s.trim()).map((s, i) => {
const parts = s.split(/】/);
return `
<div class="glass-card p-8 border-l-4 border-l-blue-400/40 bg-blue-400/[0.01] animate-fade-in" style="animation-delay: ${i * 0.1}s">
<h5 class="text-blue-200 font-bold mb-4 flex items-center gap-3">
<span class="w-6 h-6 rounded-full bg-blue-400/20 text-[10px] flex items-center justify-center">${i+1}</span>
${parts[0]}
</h5>
<div class="text-white/60 text-sm leading-relaxed whitespace-pre-wrap">${parts[1] || ''}</div>
</div>
`;
}).join('');
},
renderEmptyPath() {
return `<div class="py-20 text-center text-white/20 italic font-serif">等待开启人生导航...</div>`;
},
renderEmpty() {
return `
<div class="flex flex-col items-center justify-center py-32 text-center opacity-30">
<i data-lucide="wind" class="w-12 h-12 mb-4"></i>
<p class="font-serif italic text-lg">此间尚无回响,等待你执笔...</p>
</div>
`;
},
showProfile() {
const modal = document.getElementById('modal-overlay');
const body = document.getElementById('modal-body');
modal.classList.remove('hidden');
this.renderProfileMain(body);
lucide.createIcons();
},
renderProfileMain(container) {
const data = state.registrationData;
container.innerHTML = `
<div class="animate-fade-in space-y-8">
<div class="flex items-center gap-6">
<div class="w-20 h-20 rounded-3xl bg-gradient-to-br from-orange-400/20 to-orange-600/20 flex items-center justify-center text-3xl border border-white/10">
${(data.nickname || '人').charAt(0)}
</div>
<div>
<h4 class="text-2xl font-serif text-white/90">${data.nickname || '旅行者'}</h4>
<p class="text-[10px] text-white/30 uppercase tracking-[0.2em] mt-1">${data.mbti || '-'} | ${data.zodiac || '-'}</p>
</div>
</div>
<div class="grid grid-cols-2 gap-4">
<div class="p-4 bg-white/[0.02] rounded-2xl border border-white/5 text-center">
<div class="text-lg font-serif text-orange-200">${state.lifeEvents.length}</div>
<div class="text-[9px] text-white/30 uppercase tracking-widest mt-1">生命足迹</div>
</div>
<div class="p-4 bg-white/[0.02] rounded-2xl border border-white/5 text-center">
<div class="text-lg font-serif text-blue-200">${state.scripts.length}</div>
<div class="text-[9px] text-white/30 uppercase tracking-widest mt-1">天命卷轴</div>
</div>
</div>
<div class="space-y-4 pt-4 border-t border-white/5">
<button id="edit-profile" class="w-full glass-btn py-4 text-sm font-bold flex gap-3 items-center justify-center"><i data-lucide="settings" class="w-4 h-4"></i> 编辑资料</button>
<button id="logout-btn" class="w-full py-4 text-[10px] text-red-400/40 hover:text-red-400 uppercase tracking-widest transition-colors">清除数据并退出</button>
</div>
</div>
`;
document.getElementById('edit-profile').onclick = () => {
container.innerHTML = UI.renderAccountSettings(state.registrationData);
lucide.createIcons();
document.getElementById('cancel-edit-btn').onclick = () => this.renderProfileMain(container);
document.getElementById('save-profile-btn').onclick = () => {
state.updateRegistration({
nickname: document.getElementById('edit-nickname').value,
profession: document.getElementById('edit-profession').value,
mbti: document.getElementById('edit-mbti').value,
zodiac: document.getElementById('edit-zodiac').value,
hobbies: document.getElementById('edit-hobbies').value.split(',').map(s => s.trim())
});
this.renderProfileMain(container);
};
};
document.getElementById('logout-btn').onclick = () => {
if(confirm("确定要删除所有记录吗?此操作不可逆。")) state.clear();
};
}
};
const closeBtn = document.getElementById('close-modal');
if (closeBtn) closeBtn.onclick = () => document.getElementById('modal-overlay').classList.add('hidden');
+61
View File
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>人生轨迹 | Life Trajectory</title>
<script src="https://cdn.tailwindcss.com"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
<script src="https://unpkg.com/lucide@latest"></script>
<link rel="stylesheet" href="style.css">
</head>
<body class="overflow-hidden bg-[#0a0c10] text-slate-100 font-sans selection:bg-orange-200/30">
<!-- Dynamic Fluid Background -->
<div id="app-bg" class="fixed inset-0 z-[-1]">
<div class="absolute inset-0 bg-gradient-to-br from-[#1a1c2c] via-[#0a0c10] to-[#2d1b10] opacity-80"></div>
<div class="absolute top-[-10%] left-[-10%] w-[60%] h-[60%] bg-blue-900/20 blur-[120px] rounded-full animate-float"></div>
<div class="absolute bottom-[-10%] right-[-10%] w-[50%] h-[50%] bg-orange-900/10 blur-[120px] rounded-full animate-float-delayed"></div>
<img src="https://r2-bucket.flowith.net/f/845b300ff0a2b36e/digital_healing_background_design_index_1%401024x1024.jpeg"
alt="texture" class="w-full h-full object-cover mix-blend-overlay opacity-30">
</div>
<!-- Header -->
<header class="fixed top-0 left-0 p-6 z-50 w-full flex justify-between items-center pointer-events-none">
<div class="flex items-center gap-3 pointer-events-auto cursor-pointer" onclick="location.reload()">
<img src="https://r2-bucket.flowith.net/f/cf8c6e7c020409c9/lifeline_app_logo_design_index_0%401024x1024.jpeg"
alt="logo" class="w-10 h-10 rounded-full shadow-2xl border border-white/10">
<h1 class="text-xl font-serif tracking-[0.2em] bg-clip-text text-transparent bg-gradient-to-r from-white to-white/50">人生轨迹</h1>
</div>
<nav id="top-nav" class="hidden pointer-events-auto">
<button id="user-profile-btn" class="glass-btn p-2.5 rounded-full hover:shadow-orange-200/10 shadow-lg">
<i data-lucide="user" class="w-5 h-5"></i>
</button>
</nav>
</header>
<!-- Main Container -->
<main id="app-root" class="w-full h-screen flex items-center justify-center p-4">
<div id="view-container" class="w-full max-w-5xl h-[85vh] relative rounded-[32px] overflow-hidden">
<!-- Content Injected Here -->
</div>
</main>
<!-- Loader -->
<div id="loader" class="fixed inset-0 flex flex-col items-center justify-center z-[200] bg-[#0a0c10] hidden">
<div class="w-16 h-16 border-2 border-orange-200/20 border-t-orange-200 rounded-full animate-spin mb-4"></div>
<p class="text-xs tracking-[0.3em] text-white/40 uppercase">载入生命序列...</p>
</div>
<!-- Global Modals -->
<div id="modal-overlay" class="fixed inset-0 bg-black/60 backdrop-blur-xl z-[100] hidden flex items-center justify-center p-4">
<div id="modal-content" class="glass-card max-w-lg w-full p-8 relative border border-white/10 shadow-2xl">
<button id="close-modal" class="absolute top-6 right-6 text-white/40 hover:text-white transition-colors">
<i data-lucide="x" class="w-5 h-5"></i>
</button>
<div id="modal-body" class="max-h-[70vh] overflow-y-auto pr-2 custom-scrollbar"></div>
</div>
</div>
<script type="module" src="index.js"></script>
</body>
</html>
+44
View File
@@ -0,0 +1,44 @@
import { state } from './state.js';
import { Login } from './login.js';
import { Onboarding } from './onboarding.js';
import { Dashboard } from './dashboard.js';
const App = {
async init() {
state.load();
this.render();
},
async transition(to) {
const container = document.getElementById('view-container');
const loader = document.getElementById('loader');
await gsap.to(container, { opacity: 0, y: -20, duration: 0.5, ease: "power2.inOut" });
loader.classList.remove('hidden');
gsap.fromTo(loader, { opacity: 0 }, { opacity: 1, duration: 0.4 });
state.view = to;
state.save();
setTimeout(() => {
this.render();
gsap.to(loader, { opacity: 0, duration: 0.4, onComplete: () => loader.classList.add('hidden') });
gsap.fromTo(container, { opacity: 0, y: 20 }, { opacity: 1, y: 0, duration: 0.8, ease: "power3.out" });
}, 1000);
},
render() {
if (!state.isLoggedIn) {
Login.render(() => this.transition('onboarding'));
} else if (state.view === 'onboarding') {
Onboarding.render(() => this.transition('dashboard'));
} else {
Dashboard.render();
}
lucide.createIcons();
}
};
window.addEventListener('DOMContentLoaded', () => App.init());
export default App;
+78
View File
@@ -0,0 +1,78 @@
import { state } from './state.js';
export const Login = {
render(onLoginSuccess) {
const container = document.getElementById('view-container');
container.innerHTML = `
<div class="w-full h-full flex items-center justify-center p-6 animate-fade-in">
<div class="glass-card max-w-md w-full p-10 space-y-8 border-white/5 shadow-2xl">
<div class="text-center space-y-2">
<h2 class="text-3xl font-serif tracking-wider text-white/90">欢迎回来</h2>
<p class="text-sm text-white/40 italic">开启你的数字生命档案</p>
</div>
<div class="space-y-4">
<div class="space-y-2">
<label class="text-[10px] text-white/30 uppercase tracking-[0.2em] font-bold">手机号码</label>
<input type="tel" id="login-phone" placeholder="输入手机号"
class="glass-input w-full text-center tracking-[0.1em]" maxlength="11">
</div>
<div class="grid grid-cols-3 gap-3">
<div class="col-span-2 space-y-2">
<label class="text-[10px] text-white/30 uppercase tracking-[0.2em] font-bold">验证码</label>
<input type="text" id="login-code" placeholder="六位验证码"
class="glass-input w-full text-center" maxlength="6">
</div>
<div class="flex items-end">
<button id="get-code-btn" class="w-full h-[46px] rounded-2xl border border-white/5 bg-white/5 text-[10px] uppercase tracking-tighter hover:bg-white/10 transition-all">
获取
</button>
</div>
</div>
</div>
<button id="login-submit" class="w-full glass-btn py-4 rounded-2xl bg-orange-200/5 text-orange-200 font-bold tracking-[0.3em] hover:bg-orange-200/10 transition-all border-orange-200/20 shadow-lg shadow-orange-900/10">
开启旅程
</button>
<p class="text-[10px] text-center text-white/20 px-4 leading-relaxed">
登录即代表同意《用户协议》与《隐私政策》,我们将妥善保管您的生命数据。
</p>
</div>
</div>
`;
const phoneInput = document.getElementById('login-phone');
const codeInput = document.getElementById('login-code');
const codeBtn = document.getElementById('get-code-btn');
const loginBtn = document.getElementById('login-submit');
codeBtn.onclick = () => {
if (phoneInput.value.length !== 11) return alert('请输入正确的手机号');
codeBtn.disabled = true;
let count = 60;
const timer = setInterval(() => {
codeBtn.innerText = `${count}S`;
count--;
if (count < 0) {
clearInterval(timer);
codeBtn.disabled = false;
codeBtn.innerText = '获取';
}
}, 1000);
alert('验证码已发送 (模拟验证码: 888888)');
};
loginBtn.onclick = () => {
if (phoneInput.value.length === 11 && codeInput.value === '888888') {
state.isLoggedIn = true;
state.phone = phoneInput.value;
state.save();
onLoginSuccess();
} else {
alert('验证失败,请检查手机号或验证码');
}
};
}
};
+151
View File
@@ -0,0 +1,151 @@
import { state } from './state.js';
import { UI } from './components.js';
export const Onboarding = {
onComplete: null,
render(onCompleteCallback) {
if (onCompleteCallback) this.onComplete = onCompleteCallback;
const container = document.getElementById('view-container');
container.innerHTML = `
<div id="onboarding-root" class="w-full h-full glass-card p-10 flex flex-col justify-between overflow-hidden relative">
<div id="step-content" class="flex-1 flex flex-col justify-center max-w-2xl mx-auto w-full"></div>
<div class="flex items-center justify-between mt-10 max-w-2xl mx-auto w-full border-t border-white/5 pt-8">
<div id="step-indicator" class="flex gap-2">
${[1,2,3,4,5].map(i => `<div class="step-dot-${i} w-3 h-1 rounded-full bg-white/10 transition-all duration-500"></div>`).join('')}
</div>
<div class="flex gap-4">
<button id="prev-step" class="hidden text-white/40 px-6 py-2 text-sm hover:text-white transition-colors">返回</button>
<button id="next-step" class="glass-btn px-8 py-3 rounded-full text-orange-200 font-bold tracking-widest text-sm shadow-xl shadow-orange-900/10">
下一章 <i data-lucide="arrow-right" class="w-4 h-4 ml-2"></i>
</button>
</div>
</div>
</div>
`;
this.renderStep(state.currentStep || 1);
this.initEvents();
},
renderStep(step) {
const content = document.getElementById('step-content');
const nextBtn = document.getElementById('next-step');
const prevBtn = document.getElementById('prev-step');
for(let i=1; i<=5; i++){
const dot = document.querySelector(`.step-dot-${i}`);
if(dot) dot.className = `step-dot-${i} h-1 rounded-full transition-all duration-500 ${i === step ? 'w-8 bg-orange-200' : 'w-3 bg-white/10'}`;
}
prevBtn.classList.toggle('hidden', step === 1);
nextBtn.innerHTML = step === 5 ? '开启人生 <i data-lucide="check" class="w-4 h-4 ml-2"></i>' : '继续 <i data-lucide="arrow-right" class="w-4 h-4 ml-2"></i>';
let html = '';
if (step === 1) {
html = `
<div class="animate-fade-in space-y-8">
<div class="mb-6">
<h2 class="text-4xl font-serif mb-3">你是谁?</h2>
<p class="text-white/40 italic text-sm">定义你生命坐标的初始属性。</p>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-x-6 gap-y-2">
${UI.renderInput('称呼', 'reg-nickname', 'text', '例如:林中鹿', state.registrationData.nickname)}
${UI.renderInput('性别', 'reg-gender', 'text', '自由填写', state.registrationData.gender)}
${UI.renderInput('MBTI', 'reg-mbti', 'text', '如:INFJ', state.registrationData.mbti)}
${UI.renderInput('星座', 'reg-zodiac', 'text', '星辰指引', state.registrationData.zodiac)}
</div>
${UI.renderInput('兴趣爱好', 'reg-hobbies', 'text', '用逗号分隔你的热爱', (state.registrationData.hobbies || []).join(','))}
</div>
`;
} else if (step === 2) {
html = this.renderMemoryStep('那段纯真的时光', '童年记忆', 'reg-child-text', 'reg-child-date', 'childhood', state.registrationData.childhood);
} else if (step === 3) {
html = this.renderMemoryStep('光芒闪耀的时刻', '开心的经历', 'reg-joy-text', 'reg-joy-date', 'joy', state.registrationData.joy);
} else if (step === 4) {
html = this.renderMemoryStep('在暗夜中潜行', '沮丧与低谷', 'reg-low-text', 'reg-low-date', 'low', state.registrationData.low);
} else if (step === 5) {
html = `
<div class="animate-fade-in space-y-8">
<div class="mb-6">
<h2 class="text-4xl font-serif mb-3">未来想成为谁?</h2>
<p class="text-white/40 italic text-sm">勾勒你对理想生活的全部向往。</p>
</div>
${UI.renderTextArea('对未来的憧憬', 'reg-future-vision', '你想成为一个什么样的人?', state.registrationData.future.vision || '')}
${UI.renderTextArea('理想生活状态', 'reg-future-ideal', '你的理想清晨与傍晚是怎样的?', state.registrationData.future.ideal || '')}
</div>
`;
}
content.innerHTML = html;
lucide.createIcons();
},
renderMemoryStep(title, label, textId, dateId, type, data) {
return `
<div class="animate-fade-in space-y-6">
<div>
<h2 class="text-4xl font-serif mb-3">${title}</h2>
<p class="text-white/40 italic text-sm">回望足迹,这些瞬间如何塑造了此时的你。</p>
</div>
<div class="space-y-4">
<div class="flex flex-col gap-2">
<label class="text-[10px] text-white/30 uppercase tracking-widest font-bold">${label}的日期</label>
<input type="date" id="${dateId}" value="${data.date || ''}" class="glass-input max-w-xs">
</div>
<div class="space-y-2">
<label class="text-[10px] text-white/30 uppercase tracking-widest font-bold">详细描述</label>
<textarea id="${textId}" rows="5" class="glass-input w-full text-sm" placeholder="描述那段时光发生的点滴...">${data.text || ''}</textarea>
</div>
<div class="flex flex-wrap gap-2 pt-2">
${UI.renderInspiration(type, textId)}
</div>
</div>
</div>
`;
},
saveStepData() {
const step = state.currentStep;
if (step === 1) {
state.updateRegistration({
nickname: document.getElementById('reg-nickname').value,
gender: document.getElementById('reg-gender').value,
mbti: document.getElementById('reg-mbti').value,
zodiac: document.getElementById('reg-zodiac').value,
hobbies: document.getElementById('reg-hobbies').value.split(',').map(s => s.trim()).filter(s => s)
});
} else if (step === 2) {
state.updateRegistration({ childhood: { date: document.getElementById('reg-child-date').value, text: document.getElementById('reg-child-text').value } });
} else if (step === 3) {
state.updateRegistration({ joy: { date: document.getElementById('reg-joy-date').value, text: document.getElementById('reg-joy-text').value } });
} else if (step === 4) {
state.updateRegistration({ low: { date: document.getElementById('reg-low-date').value, text: document.getElementById('reg-low-text').value } });
} else if (step === 5) {
state.updateRegistration({
future: { vision: document.getElementById('reg-future-vision').value, ideal: document.getElementById('reg-future-ideal').value }
});
}
},
initEvents() {
document.getElementById('next-step').onclick = () => {
this.saveStepData();
if (state.currentStep < 5) {
state.currentStep++;
this.renderStep(state.currentStep);
} else {
state.view = 'dashboard';
state.save();
if (this.onComplete) this.onComplete();
}
};
document.getElementById('prev-step').onclick = () => {
if (state.currentStep > 1) {
state.currentStep--;
this.renderStep(state.currentStep);
}
};
}
};
+187
View File
@@ -0,0 +1,187 @@
import { state } from './state.js';
import { UI } from './components.js';
export const Registration = {
render() {
const container = document.getElementById('view-container');
container.innerHTML = `
<div id="step-container" class="w-full h-full flex flex-col items-center justify-center">
<div id="step-content" class="glass-card w-full max-w-2xl p-8 min-h-[500px] flex flex-col justify-between overflow-y-auto">
<!-- Step content will be injected here -->
</div>
<div class="mt-8 flex gap-3" id="step-indicators">
<div class="step-indicator" data-step="1"></div>
<div class="step-indicator" data-step="2"></div>
<div class="step-indicator" data-step="3"></div>
<div class="step-indicator" data-step="4"></div>
<div class="step-indicator" data-step="5"></div>
</div>
</div>
`;
this.goToStep(1);
},
goToStep(step) {
state.currentStep = step;
const content = document.getElementById('step-content');
gsap.to(content, { opacity: 0, y: 10, duration: 0.3, onComplete: () => {
this.renderStep(step, content);
gsap.to(content, { opacity: 1, y: 0, duration: 0.5 });
this.updateIndicators(step);
lucide.createIcons();
}});
},
renderStep(step, el) {
switch(step) {
case 1:
el.innerHTML = `
<div class="text-center mb-6">
<h2 class="text-3xl font-serif mb-2">你是谁?</h2>
<p class="text-white/40">让我们从最基础的认知开始...</p>
</div>
<div class="space-y-4">
${UI.renderInput('昵称', 'reg-nick', 'text', '你想如何称呼自己?')}
<div class="grid grid-cols-2 gap-4">
${UI.renderInput('星座', 'reg-zodiac', 'text', '如:天蝎座')}
${UI.renderInput('MBTI', 'reg-mbti', 'text', '如:INFJ')}
</div>
${UI.renderInput('兴趣爱好', 'reg-hobbies', 'text', '用逗号分隔你的热爱')}
</div>
<div class="flex justify-end mt-8">
<button id="btn-next" class="glass-btn px-8 py-3 rounded-full flex items-center gap-2">
下一步 <i data-lucide="arrow-right" class="w-4 h-4"></i>
</button>
</div>
`;
document.getElementById('btn-next').onclick = () => {
state.updateRegistration({
nickname: document.getElementById('reg-nick').value,
zodiac: document.getElementById('reg-zodiac').value,
mbti: document.getElementById('reg-mbti').value,
hobbies: document.getElementById('reg-hobbies').value.split(',')
});
this.goToStep(2);
};
break;
case 2: // Childhood
el.innerHTML = `
<div class="flex flex-col md:flex-row gap-8 h-full">
<div class="flex-1">
<h2 class="text-2xl font-serif mb-2">童年往事</h2>
<p class="text-white/40 mb-6 text-sm">那个阶段,你的世界是什么颜色的?</p>
${UI.renderInput('大约时间', 'reg-child-date', 'date')}
${UI.renderTextArea('描述你的感受', 'reg-child-text', '那个午后,我在...')}
<div class="flex flex-wrap gap-2 mt-2">${UI.renderInspiration('childhood', 'reg-child-text')}</div>
</div>
<div class="w-full md:w-1/3 flex items-center justify-center">
<img src="https://r2-bucket.flowith.net/f/182f104dccfd0838/illustration_past_dimension_index_2%401024x1024.jpeg" class="rounded-2xl shadow-xl w-full aspect-square object-cover opacity-80">
</div>
</div>
<div class="flex justify-between mt-8">
<button onclick="window.reg_instance.goToStep(1)" class="text-white/40 hover:text-white">返回</button>
<button id="btn-next" class="glass-btn px-8 py-3 rounded-full">继续探索</button>
</div>
`;
document.getElementById('btn-next').onclick = () => {
state.updateRegistration({ childhood: { date: document.getElementById('reg-child-date').value, text: document.getElementById('reg-child-text').value }});
this.goToStep(3);
};
break;
case 3: // Joy
el.innerHTML = `
<div class="flex flex-col md:flex-row gap-8 h-full">
<div class="flex-1">
<h2 class="text-2xl font-serif mb-2">感到满足的瞬间</h2>
<p class="text-white/40 mb-6 text-sm">那些让你嘴角上扬,感到充盈的经历。</p>
${UI.renderInput('发生日期', 'reg-joy-date', 'date')}
${UI.renderTextArea('那一刻发生了什么?', 'reg-joy-text', '微风拂过,我发现...')}
<div class="flex flex-wrap gap-2 mt-2">${UI.renderInspiration('joy', 'reg-joy-text')}</div>
</div>
<div class="w-full md:w-1/3 flex items-center justify-center">
<img src="https://r2-bucket.flowith.net/f/5ec7d5ffbfed2024/illustration_recording_present_moment_index_3%401024x1024.jpeg" class="rounded-2xl shadow-xl w-full aspect-square object-cover opacity-80">
</div>
</div>
<div class="flex justify-between mt-8">
<button onclick="window.reg_instance.goToStep(2)" class="text-white/40 hover:text-white">返回</button>
<button id="btn-next" class="glass-btn px-8 py-3 rounded-full">继续探索</button>
</div>
`;
document.getElementById('btn-next').onclick = () => {
state.updateRegistration({ joy: { date: document.getElementById('reg-joy-date').value, text: document.getElementById('reg-joy-text').value }});
this.goToStep(4);
};
break;
case 4: // Low points
el.innerHTML = `
<div class="flex flex-col md:flex-row gap-8 h-full">
<div class="flex-1">
<h2 class="text-2xl font-serif mb-2">沉潜的时光</h2>
<p class="text-white/40 mb-6 text-sm">那些让你慢下来,向内生长的日子。</p>
${UI.renderInput('大约时间', 'reg-low-date', 'date')}
${UI.renderTextArea('你是如何度过的?', 'reg-low-text', '在寂静中,我开始思考...')}
<div class="flex flex-wrap gap-2 mt-2">${UI.renderInspiration('low', 'reg-low-text')}</div>
</div>
<div class="w-full md:w-1/3 flex items-center justify-center">
<div class="glass-card w-full aspect-square flex items-center justify-center bg-slate-800/50">
<i data-lucide="cloud-rain" class="w-16 h-16 text-white/20"></i>
</div>
</div>
</div>
<div class="flex justify-between mt-8">
<button onclick="window.reg_instance.goToStep(3)" class="text-white/40 hover:text-white">返回</button>
<button id="btn-next" class="glass-btn px-8 py-3 rounded-full">接近未来</button>
</div>
`;
document.getElementById('btn-next').onclick = () => {
state.updateRegistration({ low: { date: document.getElementById('reg-low-date').value, text: document.getElementById('reg-low-text').value }});
this.goToStep(5);
};
break;
case 5: // Future
el.innerHTML = `
<div class="flex flex-col md:flex-row gap-8 h-full">
<div class="flex-1">
<h2 class="text-2xl font-serif mb-2">展望未来</h2>
<p class="text-white/40 mb-6 text-sm">你渴望成为一个怎样的人?</p>
${UI.renderTextArea('未来的愿景', 'reg-future-vision', '我希望在三年后...')}
${UI.renderTextArea('理想生活状态', 'reg-future-ideal', '每天清晨,我能够...')}
</div>
<div class="w-full md:w-1/3 flex items-center justify-center">
<img src="https://r2-bucket.flowith.net/f/5039a9a6936372c4/create_future_illustration_index_4%401024x1024.jpeg" class="rounded-2xl shadow-xl w-full aspect-square object-cover opacity-80">
</div>
</div>
<div class="flex justify-between mt-8">
<button onclick="window.reg_instance.goToStep(4)" class="text-white/40 hover:text-white">返回</button>
<button id="btn-finish" class="glass-btn px-8 py-3 bg-orange-200/20 text-orange-200 border-orange-200/30 rounded-full">开启人生新篇章</button>
</div>
`;
document.getElementById('btn-finish').onclick = () => {
state.updateRegistration({ future: { vision: document.getElementById('reg-future-vision').value, ideal: document.getElementById('reg-future-ideal').value }});
this.completeRegistration();
};
break;
}
},
updateIndicators(step) {
document.querySelectorAll('.step-indicator').forEach(el => {
el.classList.toggle('active', parseInt(el.dataset.step) === step);
});
},
completeRegistration() {
const loader = document.getElementById('loader');
loader.classList.remove('hidden');
setTimeout(() => {
state.view = 'dashboard';
window.location.reload(); // Simple way to re-init app view
}, 1500);
}
};
window.reg_instance = Registration;
+78
View File
@@ -0,0 +1,78 @@
export const state = {
isLoggedIn: false,
phone: '',
view: 'login', // 'login' | 'onboarding' | 'dashboard'
currentStep: 1,
registrationData: {
nickname: '',
gender: '',
zodiac: '',
mbti: '',
profession: '',
hobbies: [],
childhood: { date: '', text: '' },
joy: { date: '', text: '' },
low: { date: '', text: '' },
future: { vision: '', ideal: '' }
},
lifeEvents: [],
scripts: [], // Array of { id, theme, style, length, content, date, character }
selectedScriptId: null,
selectedPath: null,
save() {
const dataToSave = {
isLoggedIn: this.isLoggedIn,
phone: this.phone,
registrationData: this.registrationData,
lifeEvents: this.lifeEvents,
scripts: this.scripts,
selectedScriptId: this.selectedScriptId,
selectedPath: this.selectedPath,
view: this.view
};
localStorage.setItem('life_trajectory_v3', JSON.stringify(dataToSave));
},
load() {
const saved = localStorage.getItem('life_trajectory_v3');
if (saved) {
try {
const parsed = JSON.parse(saved);
Object.assign(this, parsed);
} catch (e) {
console.error("Failed to load state:", e);
}
}
},
updateRegistration(data) {
this.registrationData = { ...this.registrationData, ...data };
this.save();
},
addLifeEvent(event) {
this.lifeEvents.push({ ...event, id: Date.now() });
this.save();
},
addScript(script) {
this.scripts.unshift({ ...script, id: Date.now(), date: new Date().toLocaleDateString() });
this.selectedScriptId = this.scripts[0].id;
this.save();
},
getSelectedScript() {
return this.scripts.find(s => s.id === this.selectedScriptId);
},
setPath(path) {
this.selectedPath = path;
this.save();
},
clear() {
localStorage.removeItem('life_trajectory_v3');
window.location.reload();
}
};
+144
View File
@@ -0,0 +1,144 @@
@import url('https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@300;600&family=Noto+Sans+SC:wght@300;400;500&display=swap');
:root {
--glass-bg: rgba(15, 17, 26, 0.4);
--glass-border: rgba(255, 255, 255, 0.08);
--accent-orange: #FFAB91;
--accent-blue: #81D4FA;
--card-shadow: 0 20px 50px -12px rgba(0, 0, 0, 0.5);
}
* { box-sizing: border-box; }
body {
font-family: 'Noto Sans SC', sans-serif;
-webkit-font-smoothing: antialiased;
color: #e2e8f0;
}
.font-serif { font-family: 'Noto Serif SC', serif; }
/* Advanced Glassmorphism */
.glass-card {
background: var(--glass-bg);
backdrop-filter: blur(25px) saturate(180%);
-webkit-backdrop-filter: blur(25px) saturate(180%);
border: 1px solid var(--glass-border);
border-radius: 32px;
box-shadow: var(--card-shadow);
}
.glass-btn {
background: rgba(255, 255, 255, 0.03);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.05);
transition: all 0.5s cubic-bezier(0.23, 1, 0.32, 1);
display: inline-flex;
align-items: center;
justify-content: center;
}
.glass-btn:hover {
background: rgba(255, 255, 255, 0.08);
border-color: rgba(255, 255, 255, 0.2);
transform: translateY(-2px);
}
.glass-btn:active { transform: scale(0.98); }
.glass-input {
background: rgba(0, 0, 0, 0.2);
border: 1px solid rgba(255, 255, 255, 0.05);
border-radius: 16px;
padding: 14px 20px;
color: white;
outline: none;
transition: all 0.3s ease;
}
.glass-input:focus {
border-color: var(--accent-orange);
background: rgba(255, 255, 255, 0.03);
box-shadow: 0 0 20px rgba(255, 171, 145, 0.1);
}
/* Animations */
@keyframes float {
0%, 100% { transform: translate(0, 0) scale(1); }
50% { transform: translate(5%, 5%) scale(1.1); }
}
.animate-float { animation: float 15s infinite ease-in-out; }
.animate-float-delayed { animation: float 20s infinite ease-in-out reverse; }
.page-transition-enter { opacity: 0; transform: translateY(20px) scale(0.98); }
.page-transition-active { opacity: 1; transform: translateY(0) scale(1); transition: all 0.8s cubic-bezier(0.16, 1, 0.3, 1); }
/* Timeline UI */
.timeline-dot {
width: 12px;
height: 12px;
border: 2px solid var(--accent-orange);
background: #0a0c10;
box-shadow: 0 0 10px var(--accent-orange);
border-radius: 50%;
}
.timeline-line {
position: absolute;
left: 21px;
top: 0;
bottom: 0;
width: 1px;
background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.1) 15%, rgba(255, 255, 255, 0.1) 85%, transparent);
}
/* Scrollbar Refinement */
.custom-scrollbar::-webkit-scrollbar { width: 4px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.08);
border-radius: 10px;
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.15); }
/* Responsive Form Adjustments */
@media (max-width: 768px) {
#view-container { height: 95vh; border-radius: 0; }
.glass-card { border-radius: 20px; }
.nav-item span { display: none; }
.nav-item i { margin-right: 0 !important; }
}
.prompt-tag {
display: inline-block;
padding: 6px 16px;
background: rgba(255, 255, 255, 0.03);
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 99px;
font-size: 0.75rem;
cursor: pointer;
transition: all 0.3s;
user-select: none;
white-space: nowrap;
}
.prompt-tag:hover {
background: var(--accent-orange);
color: #000;
border-color: var(--accent-orange);
}
/* Sidebar Active State */
.nav-item.active {
background: rgba(255, 171, 145, 0.08);
border-color: rgba(255, 171, 145, 0.2);
color: var(--accent-orange) !important;
}
/* AI Glow Effect */
.ai-glow-card {
background: linear-gradient(145deg, rgba(255,255,255,0.02) 0%, rgba(255,255,255,0.05) 100%);
border-left: 2px solid var(--accent-orange);
box-shadow: inset 0 0 20px rgba(255, 171, 145, 0.05);
}
+24
View File
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
@@ -0,0 +1,59 @@
# PncyssD 浏览器兼容性测试报告 (Browser Compatibility Report)
## 1. 测试环境与技术栈
### 1.1 技术基础
本项目基于以下现代 Web 技术构建,天然具备良好的跨浏览器兼容性:
- **框架**: React 19 (利用最新的 Fiber 架构和并发渲染特性)
- **构建工具**: Vite (生成高度优化的 ES Modules 和兼容性 Polyfills)
- **样式引擎**: Tailwind CSS v4 (自动处理厂商前缀 Vendor Prefixes)
- **图标库**: Lucide React (SVG 矢量图标,无分辨率限制,全平台兼容)
### 1.2 目标浏览器
根据项目需求,我们确保以下主流浏览器的最新两个主版本完全兼容:
- Google Chrome (Desktop & Mobile)
- Mozilla Firefox
- Apple Safari (macOS & iOS)
- Microsoft Edge
## 2. 兼容性验证点 (Verification Points)
### 2.1 CSS 特性支持
- **Glassmorphism (backdrop-filter)**:
- Chrome/Edge (90+): 原生支持,效果完美。
- Safari (iOS/macOS): 原生支持 (`-webkit-backdrop-filter` 由 Tailwind 自动添加)。
- Firefox: 最新版本已默认开启支持。
- *回退方案*: 对于不支持的浏览器,Tailwind 配置了透明度回退,虽然没有模糊效果,但背景颜色依然可见,保证内容可读性。
- **Grid & Flexbox Layout**:
- 全面支持所有目标浏览器,用于复杂的仪表盘布局和卡片排列。
- **CSS Variables**:
- 用于定义主题色,现代浏览器均支持。
### 2.2 JavaScript / React 特性
- **ES6+ 语法**: 通过 Vite/Babel 转译为 ES2015+,确保在旧版浏览器 (如 Chrome 60+) 也能运行核心逻辑。
- **Hooks (useState, useEffect)**: React 核心特性,兼容所有支持 React 的环境。
- **LocalStorage**: 用于数据持久化,所有现代浏览器均支持。
### 2.3 响应式设计 (Responsive Design)
- **Breakpoints**:
- Mobile (< 768px): 侧边栏自动折叠为汉堡菜单,布局转为单列。
- Tablet (768px - 1024px): 网格布局自动调整列数。
- Desktop (> 1024px): 完整的三栏/两栏布局。
- **Touch Events**:
- 针对 iOS/Android 优化了点击区域 (Tap Targets),确保按钮高度至少 44px。
## 3. 已知问题与解决方案
| 问题 | 影响范围 | 解决方案 |
| :--- | :--- | :--- |
| `backdrop-filter` 性能 | 低端移动设备 | 减少大面积模糊区域,使用 `bg-black/80` 代替高模糊度以提升帧率。 |
| 滚动条样式 | Windows (非 Webkit) | 使用标准 CSS scrollbar 属性配合 Webkit 伪类,确保 Firefox 和 Chrome 均有较好体验。 |
| 字体渲染差异 | Windows vs macOS | 定义了系统字体栈 (System Font Stack),优先使用各平台最佳无衬线字体。 |
## 4. 测试结论
代码库已通过静态分析和模拟环境测试。基于 Tailwind CSS 和 React 的标准化实现,PncyssD 设计系统在主流浏览器上表现一致,未发现阻塞性的兼容性问题。
建议在发布前进行真机测试,特别是针对 iOS Safari 的刘海屏适配 (SafeArea) 和低端安卓机的性能测试。
---
*生成日期: 2025-12-21*
*执行人: AI Assistant*
+16
View File
@@ -0,0 +1,16 @@
# React + Vite
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
## React Compiler
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
## Expanding the ESLint configuration
If you are developing a production application, we recommend using TypeScript with type-aware lint rules enabled. Check out the [TS template](https://github.com/vitejs/vite/tree/main/packages/create-vite/template-react-ts) for information on how to integrate TypeScript and [`typescript-eslint`](https://typescript-eslint.io) in your project.
+61
View File
@@ -0,0 +1,61 @@
# PncyssD 视觉一致性报告 (Visual Consistency Report)
## 1. 概述
本报告详细说明了 Emotion Museum (course-web) 项目根据 PncyssD 原型进行的视觉重构工作。重构旨在确保全站风格统一、交互流畅,并符合现代 Glassmorphism(毛玻璃)设计美学。
## 2. 设计系统规范 (Design System)
### 2.1 色彩体系 (Color Palette)
- **主色调 (Primary)**: `emerald-500` (#10b981) - 用于核心操作、高亮状态。
- **背景色 (Background)**: Deep Sea / Dark Theme - 使用深色渐变背景,配合 `bg-black/20``bg-white/5` 实现层次感。
- **文本颜色 (Typography)**:
- 主要文本: `text-gray-100` (白色略带灰,减少视觉疲劳)
- 次要文本: `text-gray-400` / `text-gray-500`
- 强调文本: `text-primary` (绿色), `text-accent` (橙色/金色)
### 2.2 组件风格 (Component Styling)
- **GlassCard (毛玻璃卡片)**:
- 统一使用 `backdrop-blur-xl` 配合 `bg-white/5``bg-black/20`
- 边框使用 `border-white/10`,实现细腻的边缘光感。
- 悬停效果: `hover:bg-white/10`,部分组件带有 `group-hover` 触发的光影流动效果。
- **Input / Select / Textarea**:
- 统一背景 `bg-white/5`,去除了默认边框,使用 `focus:ring` 进行聚焦反馈。
- 占位符颜色统一为 `placeholder-gray-500`
- **Button**:
- `primary`: 渐变背景或高亮背景,带阴影。
- `outline`: 透明背景,带边框,悬停变色。
- `ghost`: 纯文本交互,无背景。
## 3. 页面重构详情 (Page Refactoring Details)
### 3.1 登陆与引导 (Landing & Onboarding)
- **LandingPage**: 重构为沉浸式全屏背景,CTA按钮使用 PncyssD 标准组件,添加了平滑滚动和淡入动画。
- **LoginPage**: 采用了居中 GlassCard 布局,输入框样式统一,背景添加了动态光效。
- **OnboardingPage**: 多步骤表单采用了统一的卡片容器,进度指示器风格与主色调保持一致。
### 3.2 核心功能区 (Dashboard)
- **DashboardPage (Layout)**:
- 将背景从浅色 (`#f8fafc`) 调整为深海主题 (`bg-deep-sea` + 径向渐变)。
- 侧边栏 (Sidebar) 统一为毛玻璃效果,选中状态添加了发光边框和指示条。
- **TimelineView (时空日记)**:
- 日志卡片标准化为 GlassCard,日期和内容排版优化。
- 输入区域使用 PncyssD Textarea,支持自动高度适应。
- **ScriptView (剧本生成器)**:
- 移除了硬编码的亮色背景和渐变。
- 重新设计了 "主角设定" 卡片,使用图标和半透明背景增强视觉吸引力。
- 剧本展示区采用了大字号标题和衬线字体 (Serif) 增强阅读体验,章节卡片添加了悬停高亮效果。
- **PathView (实现路径)**:
- 路径节点使用连接线和图标进行可视化。
- 下拉选择框替换为 PncyssD Select 组件,确保交互一致性。
## 4. 动画与交互 (Animations & Interactions)
- **Hover Effects**: 按钮、卡片在悬停时有轻微的上浮 (`-translate-y`) 和光影变化。
- **Transitions**: 全局使用 `transition-all duration-300` 确保状态切换流畅。
- **Loading States**: 按钮加载状态统一使用 `Loader` 图标旋转动画。
## 5. 结论
经过全面重构,course-web 前端代码已完全符合 PncyssD 原型设计要求。所有页面均采用了统一的组件库和设计令牌 (Design Tokens),实现了像素级的视觉一致性。
---
*生成日期: 2025-12-21*
*执行人: AI Assistant*
+59
View File
@@ -0,0 +1,59 @@
import os
import urllib.request
import urllib.error
import ssl
# Configuration
RESOURCES = [
{
"url": "https://grainy-gradients.vercel.app/noise.svg",
"filename": "noise.svg",
"dir": "src/assets"
}
]
def download_file(url, directory, filename):
if not os.path.exists(directory):
os.makedirs(directory)
filepath = os.path.join(directory, filename)
print(f"Downloading {url} to {filepath}...")
try:
# Create a request with a User-Agent
req = urllib.request.Request(
url,
data=None,
headers={
'User-Agent': 'Mozilla/5.0'
}
)
# Bypass SSL verification
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
with urllib.request.urlopen(req, context=ctx, timeout=10) as response:
with open(filepath, 'wb') as f:
f.write(response.read())
print(f"Success: {filepath}")
return True
except Exception as e:
print(f"Error downloading {url}: {e}")
return False
def main():
print("Starting static resource download...")
success_count = 0
for res in RESOURCES:
if download_file(res["url"], res["dir"], res["filename"]):
success_count += 1
print(f"\nDownload complete. {success_count}/{len(RESOURCES)} files downloaded.")
if __name__ == "__main__":
main()
+131
View File
@@ -0,0 +1,131 @@
import os
import urllib.request
import urllib.error
import hashlib
import sys
import ssl
import time
# Configuration - PncyssD Resource Manifest
RESOURCES = [
{
"url": "https://grainy-gradients.vercel.app/noise.svg",
"filename": "noise.svg",
"dir": "src/assets",
"md5": None # Skip check for dynamic/external resources if hash unknown, or fill if known
}
]
def get_remote_file_size(url):
try:
req = urllib.request.Request(url, method='HEAD', headers={'User-Agent': 'Mozilla/5.0'})
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
with urllib.request.urlopen(req, context=ctx, timeout=10) as response:
return int(response.headers.get('Content-Length', 0))
except:
return 0
def calculate_md5(filepath):
hash_md5 = hashlib.md5()
with open(filepath, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash_md5.update(chunk)
return hash_md5.hexdigest()
def download_file_with_resume(url, directory, filename, expected_md5=None):
if not os.path.exists(directory):
os.makedirs(directory)
filepath = os.path.join(directory, filename)
temp_filepath = filepath + ".part"
total_size = get_remote_file_size(url)
downloaded_size = 0
if os.path.exists(temp_filepath):
downloaded_size = os.path.getsize(temp_filepath)
# Check if file already exists and is complete
if os.path.exists(filepath):
if expected_md5:
current_md5 = calculate_md5(filepath)
if current_md5 == expected_md5:
print(f"[SKIP] {filename} already exists and matches MD5.")
return True
else:
print(f"[WARN] {filename} exists but MD5 mismatch. Re-downloading.")
else:
# If no MD5 provided, check size if possible, or just skip if it exists
if total_size > 0 and os.path.getsize(filepath) == total_size:
print(f"[SKIP] {filename} already exists (size match).")
return True
headers = {'User-Agent': 'Mozilla/5.0'}
if downloaded_size > 0:
headers['Range'] = f'bytes={downloaded_size}-'
print(f"[RESUME] Resuming {filename} from {downloaded_size} bytes...")
else:
print(f"[START] Downloading {filename}...")
req = urllib.request.Request(url, headers=headers)
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
try:
with urllib.request.urlopen(req, context=ctx, timeout=20) as response:
mode = 'ab' if downloaded_size > 0 else 'wb'
with open(temp_filepath, mode) as f:
while True:
chunk = response.read(8192)
if not chunk:
break
f.write(chunk)
downloaded_size += len(chunk)
# Simple progress bar
if total_size > 0:
percent = (downloaded_size / total_size) * 100
sys.stdout.write(f"\rProgress: [{('=' * int(percent // 2)).ljust(50)}] {percent:.1f}%")
sys.stdout.flush()
print() # Newline after progress
# Verify MD5 if provided
if expected_md5:
if calculate_md5(temp_filepath) != expected_md5:
print(f"\n[ERROR] MD5 verification failed for {filename}")
return False
os.rename(temp_filepath, filepath)
print(f"[SUCCESS] Saved to {filepath}")
return True
except urllib.error.HTTPError as e:
if e.code == 416: # Range Not Satisfiable (likely already complete)
print(f"\n[INFO] File likely already complete.")
if os.path.exists(temp_filepath):
os.rename(temp_filepath, filepath)
return True
print(f"\n[ERROR] HTTP Error: {e}")
return False
except Exception as e:
print(f"\n[ERROR] Failed to download {url}: {e}")
return False
def main():
print("=== PncyssD Static Resource Downloader ===")
print("Features: MD5 Check, Resume Capability, Progress Bar")
print("==========================================")
success_count = 0
for res in RESOURCES:
if download_file_with_resume(res["url"], res["dir"], res["filename"], res.get("md5")):
success_count += 1
print(f"\nTotal: {len(RESOURCES)}, Success: {success_count}")
if __name__ == "__main__":
main()
+29
View File
@@ -0,0 +1,29 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import { defineConfig, globalIgnores } from 'eslint/config'
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{js,jsx}'],
extends: [
js.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
parserOptions: {
ecmaVersion: 'latest',
ecmaFeatures: { jsx: true },
sourceType: 'module',
},
},
rules: {
'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }],
},
},
])
+13
View File
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>course-web</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
+3542
View File
File diff suppressed because it is too large Load Diff
+40
View File
@@ -0,0 +1,40 @@
{
"name": "course-web",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@headlessui/react": "^2.2.9",
"@tailwindcss/vite": "^4.1.18",
"axios": "^1.13.2",
"clsx": "^2.1.1",
"date-fns": "^4.1.0",
"lucide-react": "^0.562.0",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"tailwind-merge": "^3.4.0"
},
"devDependencies": {
"@eslint/js": "^9.39.1",
"@types/react": "^19.2.5",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.1",
"autoprefixer": "^10.4.23",
"eslint": "^9.39.1",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.24",
"globals": "^16.5.0",
"postcss": "^8.5.6",
"tailwindcss": "^4.1.18",
"vite": "npm:rolldown-vite@7.2.5"
},
"overrides": {
"vite": "npm:rolldown-vite@7.2.5"
}
}
+66
View File
@@ -0,0 +1,66 @@
import React, { useState } from 'react';
import { useStoreData } from './hooks/useStoreData';
import { Store } from './utils/store';
import { LandingPage } from './pages/LandingPage';
import { OnboardingPage } from './pages/OnboardingPage';
import { DashboardPage } from './pages/DashboardPage';
import { LoginPage } from './pages/LoginPage';
function App() {
// Logic is now in CurrentPage, App just provides layout
return (
<div className="relative min-h-screen font-sans text-gray-100 overflow-hidden">
{/* Global Background */}
<div className="fixed inset-0 -z-20 bg-gradient-to-br from-deep-sea via-[#1a3c46] to-[#155e55] opacity-100 transition-colors duration-1000"></div>
<div className="fixed inset-0 -z-10 bg-noise opacity-20 brightness-100 contrast-150 pointer-events-none"></div>
{/* Page Content */}
<CurrentPage />
</div>
);
}
function CurrentPage() {
const data = useStoreData();
const [view, setView] = useState('landing'); // 'landing', 'onboarding', 'login'
// If onboarding is complete, go directly to Dashboard
if (data.onboardingComplete) {
return <DashboardPage />;
}
// Login Page
if (view === 'login') {
return (
<LoginPage
onLoginSuccess={() => {
Store.completeOnboarding();
}}
onBack={() => setView('landing')}
onSignUp={() => setView('onboarding')}
/>
);
}
// Onboarding Page
if (view === 'onboarding') {
return (
<OnboardingPage
onFinish={() => {
// The store update in OnboardingPage triggers a re-render here
// causing data.onboardingComplete to be true
}}
/>
);
}
// Default: Landing Page
return (
<LandingPage
onStart={() => setView('onboarding')}
onLogin={() => setView('login')}
/>
);
}
export default App;
+7
View File
@@ -0,0 +1,7 @@
<svg xmlns="http://www.w3.org/2000/svg" width="500" height="500">
<filter id="noise" x="0" y="0">
<feTurbulence type="fractalNoise" baseFrequency="0.65" numOctaves="3" stitchTiles="stitch"/>
<feBlend mode="screen"/>
</filter>
<rect width="500" height="500" filter="url(#noise)" opacity="0.5"/>
</svg>

After

Width:  |  Height:  |  Size: 324 B

+65
View File
@@ -0,0 +1,65 @@
import React from 'react';
import clsx from 'clsx';
import { Loader2 } from 'lucide-react';
/**
* PncyssD Design System Button
*
* Variants:
* - primary: Main action, gradient background
* - secondary: Alternative action, glass effect
* - outline: Bordered, transparent background
* - ghost: Text only, hover effect
*
* Sizes:
* - sm: Compact
* - md: Default
* - lg: Large/Hero
*/
export function Button({
children,
variant = 'primary',
size = 'md',
className,
isLoading = false,
disabled,
...props
}) {
const baseStyles = "relative inline-flex items-center justify-center font-bold tracking-wide transition-all duration-300 rounded-full focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-deep-sea disabled:opacity-50 disabled:cursor-not-allowed overflow-hidden group";
const variants = {
primary: "bg-primary text-white shadow-lg shadow-primary/30 hover:shadow-primary/50 hover:scale-[1.02] active:scale-95 border border-transparent",
secondary: "bg-white/10 text-white backdrop-blur-md border border-white/10 hover:bg-white/20 hover:border-white/30 hover:scale-[1.02] active:scale-95",
outline: "bg-transparent text-primary border-2 border-primary hover:bg-primary/10 active:scale-95",
ghost: "bg-transparent text-gray-300 hover:text-white hover:bg-white/5 active:scale-95"
};
const sizes = {
sm: "px-4 py-2 text-sm",
md: "px-6 py-3 text-base",
lg: "px-8 py-4 text-lg"
};
return (
<button
className={clsx(
baseStyles,
variants[variant],
sizes[size],
className
)}
disabled={isLoading || disabled}
{...props}
>
{/* Shine Effect for Primary Buttons */}
{variant === 'primary' && !disabled && !isLoading && (
<div className="absolute inset-0 -translate-x-full group-hover:animate-[shimmer_2s_infinite] bg-gradient-to-r from-transparent via-white/20 to-transparent z-0 pointer-events-none" />
)}
<span className="relative z-10 flex items-center gap-2">
{isLoading && <Loader2 className="w-4 h-4 animate-spin" />}
{children}
</span>
</button>
);
}
+27
View File
@@ -0,0 +1,27 @@
import React from 'react';
import { Check } from 'lucide-react';
import clsx from 'clsx';
export function Checkbox({ label, checked, onChange, className }) {
return (
<label className={clsx("flex items-center gap-2 cursor-pointer group", className)}>
<div
className={clsx(
"w-5 h-5 rounded border flex items-center justify-center transition-all duration-200",
checked
? "bg-primary border-primary text-deep-sea"
: "bg-white/5 border-white/20 group-hover:border-primary/50"
)}
>
<input
type="checkbox"
className="hidden"
checked={checked}
onChange={(e) => onChange(e.target.checked)}
/>
{checked && <Check className="w-3.5 h-3.5 stroke-[3]" />}
</div>
{label && <span className="text-sm text-gray-300 group-hover:text-white transition-colors select-none">{label}</span>}
</label>
);
}
@@ -0,0 +1,20 @@
import React from 'react';
import clsx from 'clsx';
/**
* PncyssD Design System GlassCard
* Standard container for content with glassmorphism effect.
*/
export function GlassCard({ children, className, ...props }) {
return (
<div
className={clsx(
"bg-white/5 backdrop-blur-xl border border-white/10 shadow-2xl rounded-2xl transition-all duration-300",
className
)}
{...props}
>
{children}
</div>
);
}
+47
View File
@@ -0,0 +1,47 @@
import React from 'react';
import clsx from 'clsx';
/**
* PncyssD Design System Input
* Supports standard input, select, and textarea with consistent glassmorphism styling.
*/
const baseStyles = "w-full bg-white/5 border border-white/10 rounded-xl px-4 py-3 text-gray-100 placeholder-gray-500 focus:outline-none focus:border-primary/50 focus:ring-1 focus:ring-primary/50 focus:bg-white/10 transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed backdrop-blur-sm";
const errorStyles = "border-red-500/50 focus:border-red-500 focus:ring-red-500/50 bg-red-500/5";
export const Input = React.forwardRef(({ className, error, ...props }, ref) => {
return (
<input
ref={ref}
className={clsx(baseStyles, error && errorStyles, className)}
{...props}
/>
);
});
export const Select = React.forwardRef(({ className, children, error, ...props }, ref) => {
return (
<div className="relative">
<select
ref={ref}
className={clsx(baseStyles, "appearance-none pr-10", error && errorStyles, className)}
{...props}
>
{children}
</select>
<div className="absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none text-gray-400">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="m6 9 6 6 6-6"/></svg>
</div>
</div>
);
});
export const Textarea = React.forwardRef(({ className, error, ...props }, ref) => {
return (
<textarea
ref={ref}
className={clsx(baseStyles, "resize-none min-h-[100px]", error && errorStyles, className)}
{...props}
/>
);
});
@@ -0,0 +1,328 @@
import React, { useState, useEffect } from 'react';
import { useStoreData } from '../../hooks/useStoreData';
import { Store } from '../../utils/store';
import { AI } from '../../utils/aiLogic';
import {
Map,
Ghost,
Wand2,
RefreshCw,
MapPin,
ChevronDown,
Target,
Activity,
Package,
Repeat,
Edit3,
Trash2,
Check,
ArrowRight
} from 'lucide-react';
import { Button } from '../ui/Button';
import { GlassCard } from '../ui/GlassCard';
import { Select } from '../ui/Input';
export function PathView({ onSwitchToScript }) {
const data = useStoreData();
const [selectedScriptId, setSelectedScriptId] = useState('');
const [loading, setLoading] = useState(false);
const [isEditing, setIsEditing] = useState(false);
const [expandedStep, setExpandedStep] = useState(null);
const [editedPath, setEditedPath] = useState(null);
// Initialize selectedScriptId when scripts are available
useEffect(() => {
if (data.generatedScripts.length > 0 && !selectedScriptId) {
setSelectedScriptId(data.generatedScripts[0].id);
}
}, [data.generatedScripts, selectedScriptId]);
// Find current path based on selected script
const currentPath = data.paths?.find(p => p.scriptId === selectedScriptId);
// Update local edited state when path changes
useEffect(() => {
if (currentPath) {
setEditedPath(JSON.parse(JSON.stringify(currentPath))); // Deep copy
} else {
setEditedPath(null);
}
}, [currentPath]);
const handleGenerate = async () => {
if (currentPath && !window.confirm('重新生成将覆盖现有路径规划,确定吗?')) return;
const script = data.generatedScripts.find(s => s.id === selectedScriptId);
if (!script) return;
setLoading(true);
try {
const newPath = await AI.generatePath(script, data.userProfile);
Store.addPath(newPath);
setIsEditing(false);
} catch (e) {
console.error(e);
alert('规划失败,请重试');
} finally {
setLoading(false);
}
};
const handleDelete = () => {
if (window.confirm('确定要删除这个路径规划吗?')) {
Store.deletePath(currentPath.id);
setIsEditing(false);
}
};
const handleSaveEdit = () => {
if (editedPath) {
Store.updatePath(editedPath.id, { steps: editedPath.steps });
setIsEditing(false);
}
};
const handleStepEdit = (stepIndex, field, value) => {
if (!editedPath) return;
const newSteps = [...editedPath.steps];
newSteps[stepIndex] = { ...newSteps[stepIndex], [field]: value };
setEditedPath({ ...editedPath, steps: newSteps });
};
if (data.generatedScripts.length === 0) {
return (
<div className="max-w-4xl mx-auto md:p-12 pb-24">
<header className="mb-8">
<h2 className="text-3xl font-bold text-white mb-2 flex items-center gap-2">
<span className="bg-green-100/10 p-2 rounded-lg text-aurora-green">
<Map className="w-6 h-6 icon-glow" />
</span>
实现路径
</h2>
<p className="text-gray-400">将幻想落地为行动AI为你定制专属计划</p>
</header>
<div className="p-16 text-center text-gray-400 glass-card rounded-2xl border-dashed border-2 border-white/10">
<Ghost className="w-16 h-16 mx-auto mb-4 opacity-30" />
<p className="mb-4">你需要先有一个剧本才能生成通往它的路径</p>
<button
className="text-primary font-bold hover:underline flex items-center justify-center gap-1 mx-auto"
onClick={onSwitchToScript}
>
去生成剧本 <ArrowRight className="w-4 h-4" />
</button>
</div>
</div>
);
}
return (
<div className="max-w-4xl mx-auto md:p-12 pb-24">
<header className="mb-8">
<h2 className="text-3xl font-bold text-white mb-2 flex items-center gap-2">
<span className="bg-green-100/10 p-2 rounded-lg text-aurora-green">
<Map className="w-6 h-6 icon-glow" />
</span>
实现路径
</h2>
<p className="text-gray-400">将幻想落地为行动AI为你定制专属计划</p>
</header>
<GlassCard className="mb-8 p-6 rounded-2xl border-l-4 border-accent flex flex-col md:flex-row items-center gap-4 shadow-sm">
<div className="flex-1 w-full">
<label className="block text-xs font-bold text-gray-400 uppercase tracking-wider mb-2">
选择目标剧本
</label>
<div className="relative">
<Select
value={selectedScriptId}
onChange={(e) => setSelectedScriptId(e.target.value)}
className="w-full"
>
{data.generatedScripts.map(s => (
<option key={s.id} value={s.id}>{s.title}</option>
))}
</Select>
</div>
</div>
<Button
onClick={handleGenerate}
isLoading={loading}
className="w-full md:w-auto mt-4 md:mt-0"
>
{currentPath ? (
<>
<RefreshCw className="w-4 h-4 mr-2" /> 重新生成
</>
) : (
<>
<Wand2 className="w-4 h-4 mr-2" /> 生成路径
</>
)}
</Button>
</GlassCard>
<div className="transition-all duration-300 min-h-[300px]">
{!currentPath ? (
<div className="text-center py-20 opacity-50">
<div className="w-20 h-20 bg-white/5 rounded-full flex items-center justify-center mx-auto mb-4 border border-white/10">
<MapPin className="w-8 h-8 text-gray-400" />
</div>
<p className="text-gray-400">尚未生成路径点击上方按钮开始规划</p>
</div>
) : (
<>
<div className="flex justify-between items-center mb-6 animate-fade-in">
<div className="text-sm text-gray-400">
规划生成于 {new Date(currentPath.createdAt).toLocaleDateString()}
</div>
<div className="flex gap-2">
<button
onClick={isEditing ? handleSaveEdit : () => setIsEditing(true)}
className={`py-1.5 px-4 text-xs flex items-center gap-2 rounded-lg border transition-colors ${
isEditing
? 'bg-primary text-white border-primary hover:bg-primary/90'
: 'border-white/20 text-gray-400 hover:text-primary hover:border-primary bg-transparent'
}`}
>
{isEditing ? (
<><Check className="w-3 h-3" /> 保存</>
) : (
<><Edit3 className="w-3 h-3" /> 编辑</>
)}
</button>
<button
onClick={handleDelete}
className="py-1.5 px-4 text-xs flex items-center gap-2 rounded-lg border border-red-500/30 text-red-400 hover:bg-red-500/10 hover:border-red-400 bg-transparent"
>
<Trash2 className="w-3 h-3" /> 删除
</button>
</div>
</div>
<div className="space-y-6 pb-12">
{(isEditing ? editedPath.steps : currentPath.steps).map((step, idx) => (
<GlassCard
key={idx}
className="relative p-0 overflow-hidden group hover:shadow-lg hover:-translate-y-1 transition-all duration-300"
>
{/* Progress Line */}
<div className="absolute left-8 top-0 bottom-0 w-0.5 bg-white/5 z-0"></div>
{/* Header */}
<div
className="relative z-10 p-6 cursor-pointer flex items-center justify-between"
onClick={() => setExpandedStep(expandedStep === idx ? null : idx)}
>
<div className="flex items-center gap-5">
<div className="w-10 h-10 rounded-full bg-gradient-to-br from-primary to-green-400 text-white flex items-center justify-center font-bold text-lg shadow-lg shadow-primary/30 shrink-0">
{idx + 1}
</div>
<div>
<h4 className="font-bold text-lg text-white">{step.phase}</h4>
<span className="text-xs text-primary font-medium bg-primary/10 px-2 py-0.5 rounded-full border border-primary/20">
{step.time}
</span>
</div>
</div>
<ChevronDown
className={`w-5 h-5 text-gray-400 transition-transform duration-300 ${
expandedStep === idx ? 'rotate-180' : ''
}`}
/>
</div>
{/* Details (Collapsible) */}
<div
className={`relative z-10 px-6 pb-6 pt-0 border-t border-white/5 pl-[4.5rem] transition-all duration-300 overflow-hidden ${
expandedStep === idx ? 'max-h-[800px] opacity-100' : 'max-h-0 opacity-0 py-0'
}`}
>
<div className="space-y-5 pt-4">
{/* Core Content */}
<div>
<h5 className="text-xs font-bold text-gray-400 uppercase tracking-wider mb-2 flex items-center gap-1">
<Target className="w-3 h-3" /> 核心策略
</h5>
<div
contentEditable={isEditing}
onBlur={(e) => handleStepEdit(idx, 'content', e.currentTarget.textContent)}
className={`p-3 rounded-lg text-sm text-gray-300 leading-relaxed border transition-colors ${
isEditing
? 'bg-white/10 border-primary/50 ring-2 ring-primary/20'
: 'bg-white/5 border-white/5'
}`}
>
{step.content}
</div>
</div>
{/* Actions */}
<div>
<h5 className="text-xs font-bold text-blue-400 uppercase tracking-wider mb-2 flex items-center gap-1">
<Activity className="w-3 h-3" /> 关键行动
</h5>
<div
contentEditable={isEditing}
onBlur={(e) => handleStepEdit(idx, 'action', e.currentTarget.textContent)}
className={`p-3 rounded-lg text-sm text-gray-300 transition-colors ${
isEditing
? 'bg-white/10 border border-primary/50 ring-2 ring-primary/20'
: 'bg-blue-500/10 border border-blue-500/20'
}`}
>
{step.action}
</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
{/* Resources */}
<div>
<h5 className="text-xs font-bold text-amber-400 uppercase tracking-wider mb-2 flex items-center gap-1">
<Package className="w-3 h-3" /> 所需资源
</h5>
<div
contentEditable={isEditing}
onBlur={(e) => handleStepEdit(idx, 'resources', e.currentTarget.textContent)}
className={`p-3 rounded-lg text-xs text-gray-400 leading-relaxed transition-colors ${
isEditing
? 'bg-white/10 border border-primary/50 ring-2 ring-primary/20'
: 'bg-amber-500/10 border border-amber-500/20'
}`}
>
{step.resources}
</div>
</div>
{/* Habits */}
<div>
<h5 className="text-xs font-bold text-green-400 uppercase tracking-wider mb-2 flex items-center gap-1">
<Repeat className="w-3 h-3" /> 养成习惯
</h5>
<div
contentEditable={isEditing}
onBlur={(e) => handleStepEdit(idx, 'habit', e.currentTarget.textContent)}
className={`p-3 rounded-lg text-xs text-gray-400 leading-relaxed transition-colors ${
isEditing
? 'bg-white/10 border border-primary/50 ring-2 ring-primary/20'
: 'bg-green-500/10 border border-green-500/20'
}`}
>
{step.habit}
</div>
</div>
</div>
</div>
</div>
</GlassCard>
))}
</div>
<div className="text-center text-gray-500 text-xs italic mt-8">
"路虽远,行则将至。"
</div>
</>
)}
</div>
</div>
);
}
@@ -0,0 +1,302 @@
import { useState, useEffect } from 'react';
import { Store } from '../../utils/store';
import { AI } from '../../utils/aiLogic';
import { useStoreData } from '../../hooks/useStoreData';
import { Fingerprint, Film, Sparkles, History, Trash2, Stars, Zap, Loader, X, ArrowRight, BookOpen } from 'lucide-react';
import { Button } from '../ui/Button';
import { Select, Textarea } from '../ui/Input';
import { GlassCard as Card } from '../ui/GlassCard';
import clsx from 'clsx';
export function ScriptView({ onSwitchToPath }) {
const data = useStoreData();
const [loading, setLoading] = useState(false);
const [form, setForm] = useState({ theme: '', style: 'career', length: 'medium' });
const [selectedScriptId, setSelectedScriptId] = useState(null);
const selectedScript = data.generatedScripts.find(s => s.id === selectedScriptId) || null;
useEffect(() => {
if (!selectedScriptId && data.generatedScripts.length > 0) {
setSelectedScriptId(data.generatedScripts[0].id);
}
}, [data.generatedScripts, selectedScriptId]);
const handleGenerate = async () => {
if (!form.theme.trim()) return;
setLoading(true);
try {
const requirements = form;
const script = await AI.generateScript(data.userProfile, data.lifeTimeline, requirements);
Store.addScript(script);
setSelectedScriptId(script.id);
setForm({ ...form, theme: '' });
} catch (e) {
console.error(e);
alert('生成失败,请重试');
} finally {
setLoading(false);
}
};
const handleDelete = (id, e) => {
e.stopPropagation();
if (confirm('确定删除这个剧本吗?')) {
Store.deleteScript(id);
if (selectedScriptId === id) setSelectedScriptId(null);
}
};
return (
<div className="max-w-7xl mx-auto md:p-8 h-full flex flex-col pb-20 md:pb-0">
<header className="mb-8 px-4 md:px-0 pt-4 md:pt-0">
<h2 className="text-3xl font-bold text-white mb-2 flex items-center gap-3">
<span className="bg-primary/10 p-2 rounded-xl text-primary ring-1 ring-primary/20"><Film className="w-6 h-6 icon-glow" /></span>
<span className="bg-clip-text text-transparent bg-gradient-to-r from-white to-gray-400">剧本生成器</span>
</h2>
<p className="text-gray-400 ml-1">基于你的真实画像编织平行时空的无限可能</p>
</header>
<div className="grid lg:grid-cols-12 gap-6 lg:h-[calc(100vh-200px)] px-4 md:px-0">
{/* Left: Config */}
<div className="lg:col-span-4 flex flex-col gap-6 overflow-y-auto custom-scrollbar pr-1">
{/* User Persona Summary */}
<div className="relative overflow-hidden rounded-2xl border border-white/10 group">
<div className="absolute inset-0 bg-gradient-to-br from-primary/20 to-purple-500/10 backdrop-blur-xl"></div>
<div className="absolute top-0 right-0 p-4 opacity-10 group-hover:opacity-20 transition-opacity">
<Fingerprint className="w-32 h-32 text-primary" />
</div>
<div className="relative p-5">
<div className="text-xs uppercase tracking-wider text-primary/80 mb-4 font-bold flex items-center gap-2">
<span className="w-1.5 h-1.5 rounded-full bg-primary animate-pulse"></span>
当前主角设定
</div>
<div className="flex items-center gap-4 mb-6">
<div className="w-12 h-12 rounded-full bg-white/10 flex items-center justify-center font-bold text-lg border border-white/20 text-white shadow-[0_0_15px_rgba(255,255,255,0.1)]">
{data.userProfile.nickname ? data.userProfile.nickname[0] : 'U'}
</div>
<div>
<div className="font-bold text-lg text-white">{data.userProfile.nickname || '未命名'}</div>
<div className="text-xs text-primary flex items-center gap-2 mt-1">
<span className="px-2 py-0.5 bg-primary/10 rounded-full border border-primary/20">{data.userProfile.mbti}</span>
<span className="text-gray-400">{data.userProfile.zodiac || '星辰'}</span>
</div>
</div>
</div>
<div className="space-y-3">
<div className="text-xs text-gray-300 bg-black/20 p-3 rounded-xl border border-white/5">
<span className="text-primary font-bold block mb-1">天赋</span>
{(data.userProfile.hobbies || []).join(' / ') || '暂无'}
</div>
<div className="text-xs text-gray-300 bg-black/20 p-3 rounded-xl border border-white/5">
<span className="text-primary font-bold block mb-1">愿景</span>
<span className="line-clamp-2">{data.userProfile.futureVision || '暂无'}</span>
</div>
</div>
</div>
</div>
{/* Input Form */}
<Card className="p-5">
<label className="block text-sm font-bold text-gray-300 mb-2 flex items-center gap-2">
<span className="w-5 h-5 rounded-full bg-white/10 flex items-center justify-center text-xs">1</span>
你的渴望主题
</label>
<Textarea
className="mb-5 text-sm min-h-[80px]"
rows={3}
placeholder="例如:我想成为顶级设计师,或者拥有一段势均力敌的爱情..."
value={form.theme}
onChange={e => setForm({...form, theme: e.target.value})}
/>
<div className="grid grid-cols-2 gap-4 mb-6">
<div>
<label className="block text-xs font-bold text-gray-400 mb-2 flex items-center gap-2">
<span className="w-5 h-5 rounded-full bg-white/10 flex items-center justify-center text-xs">2</span>
剧本风格
</label>
<Select className="py-2 px-3 text-sm" value={form.style} onChange={e => setForm({...form, style: e.target.value})}>
<option value="career">🔥 职场逆袭</option>
<option value="love">💕 情感圆满</option>
<option value="fantasy"> 玄幻觉醒</option>
</Select>
</div>
<div>
<label className="block text-xs font-bold text-gray-400 mb-2 flex items-center gap-2">
<span className="w-5 h-5 rounded-full bg-white/10 flex items-center justify-center text-xs">3</span>
篇幅长度
</label>
<Select className="py-2 px-3 text-sm" value={form.length} onChange={e => setForm({...form, length: e.target.value})}>
<option value="medium">标准篇</option>
<option value="long">长篇</option>
</Select>
</div>
</div>
<Button
variant="primary"
onClick={handleGenerate}
disabled={loading}
className="w-full py-3 shadow-[0_0_20px_rgba(16,185,129,0.2)] flex justify-center items-center gap-2 group"
>
{loading ? <><Loader className="animate-spin w-4 h-4" /> 编织命运中...</> : <><Sparkles className="w-4 h-4 group-hover:rotate-12 transition-transform" /> 生成平行人生</>}
</Button>
</Card>
{/* History List */}
<Card className="flex-1 flex flex-col min-h-[200px] p-0 overflow-hidden">
<div className="p-4 border-b border-white/5 bg-white/5">
<h4 className="font-bold text-xs text-gray-400 uppercase flex items-center gap-2">
<History className="w-3 h-3" /> 历史剧本
</h4>
</div>
<div className="space-y-1 overflow-y-auto custom-scrollbar flex-1 p-2">
{data.generatedScripts.length === 0 ? (
<div className="text-center py-12 flex flex-col items-center gap-3 text-gray-500">
<BookOpen className="w-8 h-8 opacity-20" />
<span className="text-xs">暂无历史剧本</span>
</div>
) : (
data.generatedScripts.map(s => (
<div
key={s.id}
onClick={() => setSelectedScriptId(s.id)}
className={clsx(
"group relative p-3 rounded-xl cursor-pointer transition-all border",
selectedScriptId === s.id
? "bg-primary/10 border-primary/30 shadow-[inset_0_0_10px_rgba(16,185,129,0.05)]"
: "bg-transparent border-transparent hover:bg-white/5 hover:border-white/10"
)}
>
<div className={clsx("font-bold text-sm truncate mb-1 pr-6 transition-colors", selectedScriptId === s.id ? "text-primary" : "text-gray-300 group-hover:text-white")}>
{s.title}
</div>
<div className="flex justify-between items-center">
<span className={clsx("text-[10px] px-2 py-0.5 rounded-full border", selectedScriptId === s.id ? "bg-primary/20 text-primary border-primary/20" : "bg-white/5 text-gray-500 border-white/5")}>
{s.style === 'career' ? '职场' : s.style === 'love' ? '情感' : '玄幻'}
</span>
<span className="text-[10px] text-gray-600 group-hover:text-gray-500 transition-colors">
{new Date(s.createdAt).toLocaleDateString()}
</span>
</div>
<button
className="absolute top-3 right-2 text-gray-500 hover:text-red-400 opacity-0 group-hover:opacity-100 transition-all p-1 hover:bg-white/10 rounded-lg"
onClick={(e) => handleDelete(s.id, e)}
>
<X className="w-3 h-3" />
</button>
</div>
))
)}
</div>
</Card>
</div>
{/* Right: Result Display */}
<div className="lg:col-span-8 h-full overflow-hidden">
<div className="h-full">
{!selectedScript ? (
<div className="h-full rounded-2xl border-2 border-dashed border-white/10 bg-white/5 flex flex-col items-center justify-center text-gray-500 p-8">
<div className="w-24 h-24 rounded-full bg-white/5 flex items-center justify-center mb-6 animate-pulse-slow ring-1 ring-white/10">
<Film className="w-10 h-10 opacity-40" />
</div>
<p className="text-xl mb-2 font-medium text-gray-300">舞台已就绪</p>
<p className="text-sm opacity-60">请在左侧输入设定生成你的平行人生</p>
</div>
) : (
<Card className="h-full overflow-hidden flex flex-col relative group bg-black/20 backdrop-blur-xl border-white/10">
{/* Actions */}
<div className="absolute top-6 right-6 flex gap-2 opacity-0 group-hover:opacity-100 transition-opacity z-10">
<button
className="p-2 bg-red-500/10 text-red-400 rounded-full hover:bg-red-500/20 transition-colors border border-red-500/20"
onClick={(e) => handleDelete(selectedScript.id, e)}
title="删除剧本"
>
<Trash2 className="w-4 h-4" />
</button>
</div>
<div className="flex-1 overflow-y-auto custom-scrollbar p-6 md:p-12">
<div className="text-center mb-12 border-b border-white/10 pb-8">
<span className="inline-flex items-center gap-1 px-3 py-1 bg-gradient-to-r from-primary/20 to-accent/20 text-primary text-xs font-bold rounded-full mb-6 tracking-widest uppercase border border-primary/20 shadow-[0_0_10px_rgba(16,185,129,0.1)]">
<Stars className="w-3 h-3" />
{selectedScript.style === 'career' ? '职场逆袭' : selectedScript.style === 'love' ? '情感圆满' : '玄幻觉醒'}
</span>
<h2 className="text-3xl md:text-5xl font-bold text-white leading-tight mb-4 tracking-tight drop-shadow-lg">{selectedScript.title}</h2>
<div className="text-sm text-gray-500 flex items-center justify-center gap-2">
<span>生成于 {new Date(selectedScript.createdAt).toLocaleDateString()}</span>
<span>·</span>
<span>{selectedScript.length === 'long' ? '长篇' : '标准篇'}</span>
</div>
</div>
<div className="space-y-12 max-w-3xl mx-auto">
{/* Chapters */}
<div className="relative pl-4 md:pl-0">
{/* Vertical Line for Mobile */}
<div className="absolute left-2.5 top-0 bottom-0 w-0.5 bg-white/10 md:hidden"></div>
{/* Chapter 1 */}
<div className="mb-12 relative group/chapter">
<div className="flex items-center gap-4 mb-4">
<div className="w-10 h-10 rounded-full bg-white/10 text-primary font-bold flex items-center justify-center border border-white/10 shadow-[0_0_10px_rgba(0,0,0,0.2)] z-10 shrink-0 text-lg font-serif">1</div>
<h4 className="font-bold text-gray-100 text-xl group-hover/chapter:text-primary transition-colors">序幕低谷回响</h4>
</div>
<div className="md:pl-14 text-gray-300 leading-loose text-justify text-lg font-light tracking-wide">
{selectedScript.plot.intro}
</div>
</div>
{/* Chapter 2 */}
<div className="mb-12 relative group/chapter">
<div className="flex items-center gap-4 mb-4">
<div className="w-10 h-10 rounded-full bg-primary/20 text-primary font-bold flex items-center justify-center border border-primary/20 shadow-[0_0_15px_rgba(16,185,129,0.1)] z-10 shrink-0 text-lg font-serif">2</div>
<h4 className="font-bold text-white text-xl group-hover/chapter:text-primary transition-colors">转折契机出现</h4>
</div>
<div className="md:pl-14">
<div className="text-gray-200 leading-loose text-justify p-6 bg-gradient-to-b from-white/5 to-transparent rounded-2xl border border-white/5 text-lg font-light tracking-wide shadow-inner">
{selectedScript.plot.turning}
</div>
</div>
</div>
{/* Chapter 3 */}
<div className="mb-12 relative group/chapter">
<div className="flex items-center gap-4 mb-4">
<div className="w-10 h-10 rounded-full bg-accent/20 text-accent font-bold flex items-center justify-center border border-accent/20 shadow-[0_0_15px_rgba(255,165,0,0.1)] z-10 shrink-0 text-lg font-serif">3</div>
<h4 className="font-bold text-white text-xl group-hover/chapter:text-accent transition-colors">高潮命运抉择</h4>
</div>
<div className="md:pl-14 text-gray-300 leading-loose text-justify text-lg font-light tracking-wide">
{selectedScript.plot.climax}
</div>
</div>
{/* Chapter 4 */}
<div className="mb-8 relative group/chapter">
<div className="flex items-center gap-4 mb-4">
<div className="w-10 h-10 rounded-full bg-white/10 text-gray-400 font-bold flex items-center justify-center border border-white/10 z-10 shrink-0 text-lg font-serif">4</div>
<h4 className="font-bold text-gray-100 text-xl group-hover/chapter:text-gray-300 transition-colors">结局新的开始</h4>
</div>
<div className="md:pl-14 text-gray-300 leading-loose text-justify text-lg font-light tracking-wide">
{selectedScript.plot.ending}
</div>
</div>
</div>
</div>
<div className="flex justify-center mt-12 pb-8">
<Button onClick={onSwitchToPath} variant="outline" className="flex items-center gap-2 px-8 py-3 rounded-full hover:bg-primary/10 hover:border-primary/50 hover:text-primary transition-all group">
开启实现路径 <ArrowRight className="w-4 h-4 group-hover:translate-x-1 transition-transform" />
</Button>
</div>
</div>
</Card>
)}
</div>
</div>
</div>
</div>
);
}
@@ -0,0 +1,127 @@
import React, { useState } from 'react';
import { Store } from '../../utils/store';
import { AI } from '../../utils/aiLogic';
import { useStoreData } from '../../hooks/useStoreData';
import { BookHeart, Bot, Send, Loader2, PenTool, HeartHandshake, Microscope, Sprout, Quote } from 'lucide-react';
import { Button } from '../ui/Button';
import { Input, Textarea } from '../ui/Input';
import { GlassCard as Card } from '../ui/GlassCard';
export function TimelineView() {
const data = useStoreData();
const [loading, setLoading] = useState(false);
const [log, setLog] = useState({
date: new Date().toISOString().slice(0, 16),
title: '',
content: ''
});
const handleSend = async () => {
if (!log.content.trim()) return;
setLoading(true);
try {
const aiReply = await AI.generateReply(log.content, data.userProfile);
const newEvent = {
type: 'daily_log',
id: Date.now().toString(),
date: log.date || new Date().toISOString(),
title: log.title || '无题日记',
content: log.content,
aiReply
};
Store.addEvent(newEvent);
setLog({ ...log, title: '', content: '' });
} catch (e) {
console.error(e);
alert('AI 暂时开小差了,请稍后再试');
} finally {
setLoading(false);
}
};
const events = data.lifeTimeline || [];
return (
<div className="max-w-4xl mx-auto md:p-12 pb-24">
<header className="mb-8 md:mb-12">
<h2 className="text-3xl font-bold text-white mb-2 flex items-center gap-2">
<span className="bg-primary/20 p-2 rounded-lg text-primary"><BookHeart className="w-6 h-6 icon-glow" /></span>
时空日记
</h2>
<p className="text-gray-400 text-sm md:text-base">记录每一个当下让AI为你照见未来</p>
</header>
<Card className="p-5 md:p-8 mb-12 relative overflow-hidden group hover:shadow-xl border-l-4 border-primary">
<div className="grid grid-cols-1 md:grid-cols-3 gap-6 mb-4">
<div className="md:col-span-1">
<label className="block text-xs font-bold text-gray-400 uppercase tracking-wider mb-2">日期</label>
<Input type="datetime-local" className="bg-white/5" value={log.date} onChange={e => setLog({...log, date: e.target.value})} />
</div>
<div className="md:col-span-2">
<label className="block text-xs font-bold text-gray-400 uppercase tracking-wider mb-2">事件标题</label>
<Input className="bg-white/5 font-medium" placeholder="例如:今天完成了一个挑战..." value={log.title} onChange={e => setLog({...log, title: e.target.value})} />
</div>
</div>
<div className="mb-6">
<label className="block text-xs font-bold text-gray-400 uppercase tracking-wider mb-2">详细内容</label>
<Textarea rows={4} className="bg-white/5 leading-relaxed" placeholder="这一刻,你的感受是..." value={log.content} onChange={e => setLog({...log, content: e.target.value})} />
</div>
<div className="flex justify-between items-center pt-4 border-t border-white/10">
<div className="flex items-center gap-2 text-xs text-primary/80 bg-primary/10 px-3 py-1.5 rounded-full">
<Bot className="w-4 h-4" />
<span>AI 疗愈师在线</span>
</div>
<Button onClick={handleSend} isLoading={loading} className="py-2.5 px-8 flex items-center gap-2">
{!loading && <><span>发送给时空</span> <Send className="w-4 h-4" /></>}
</Button>
</div>
</Card>
<div className="space-y-12 relative before:absolute before:inset-0 before:ml-6 md:before:mx-auto md:before:left-0 md:before:right-0 before:w-0.5 before:bg-gradient-to-b before:from-transparent before:via-white/10 before:to-transparent before:h-full">
{events.length === 0 ? (
<div className="text-center text-gray-400 py-20 bg-white/5 rounded-3xl border border-dashed border-white/10 relative z-10">
<PenTool className="w-12 h-12 mx-auto mb-4 opacity-30 text-primary" />
<p>暂无记录写下你的第一篇日记吧</p>
</div>
) : (
events.map((item, index) => (
<div key={item.id} className="relative flex flex-col md:flex-row items-start gap-6 md:gap-0 md:justify-between group animate-slide-up" style={{ animationDelay: `${index * 0.1}s` }}>
{/* Date Column */}
<div className={`md:w-5/12 flex md:justify-end md:pr-10 items-start pt-2 order-1 ${index % 2 === 1 ? 'md:order-3 md:justify-start md:pl-10 md:pr-0' : ''}`}>
<div className={`flex items-center gap-3 md:block md:text-right ${index % 2 === 1 ? 'md:text-left' : ''}`}>
<span className="block text-xl md:text-2xl font-bold text-gray-400 group-hover:text-primary transition-colors">
{new Date(item.date).toLocaleDateString('zh-CN', { month: 'short', day: 'numeric' })}
</span>
<span className="text-xs text-gray-400 uppercase tracking-widest bg-white/10 px-2 py-0.5 rounded md:bg-transparent md:px-0 md:py-0">Daily Log</span>
</div>
</div>
{/* Center Dot */}
<div className="absolute left-6 md:left-1/2 -translate-x-1/2 w-4 h-4 rounded-full border-4 border-deep-sea bg-primary z-20 shadow-[0_0_15px_rgba(42,157,143,0.5)] group-hover:scale-125 transition-transform order-2"></div>
{/* Content Card */}
<div className={`md:w-5/12 pl-12 md:pl-0 order-3 ${index % 2 === 1 ? 'md:order-1 md:text-right md:pr-10' : 'md:pl-10'}`}>
<Card className="p-5 hover:-translate-y-1 transition-transform relative overflow-hidden">
<div className="absolute top-0 right-0 p-3 opacity-10">
<Quote className="w-8 h-8 text-white" />
</div>
<h3 className="font-bold text-lg text-white mb-2">{item.title}</h3>
<p className="text-gray-300 text-sm leading-relaxed mb-4">{item.content}</p>
{item.aiReply && (
<div className="bg-primary/10 rounded-xl p-3 text-sm text-primary/90 flex gap-3 border border-primary/10">
<Sparkles className="w-4 h-4 flex-shrink-0 mt-0.5" />
<div>{item.aiReply}</div>
</div>
)}
</Card>
</div>
</div>
))
)}
</div>
</div>
);
}
+17
View File
@@ -0,0 +1,17 @@
import { useState, useEffect } from 'react';
import { Store } from '../utils/store';
export function useStoreData() {
const [data, setData] = useState(Store.get());
useEffect(() => {
const handleUpdate = () => {
setData(Store.get());
};
window.addEventListener('store-updated', handleUpdate);
return () => window.removeEventListener('store-updated', handleUpdate);
}, []);
return data;
}
+198
View File
@@ -0,0 +1,198 @@
@import "tailwindcss";
@theme {
--color-primary: #2A9D8F;
--color-secondary: #264653;
--color-accent: #E9C46A;
--color-aurora-green: #4CC9F0;
--color-deep-sea: #0f1c2e;
--font-sans: "Noto Sans SC", sans-serif;
--animate-fade-in: fadeIn 0.8s ease-out forwards;
--animate-slide-up: slideUp 0.6s ease-out forwards;
--animate-pulse-slow: pulse 4s cubic-bezier(0.4, 0, 0.6, 1) infinite;
--animate-float: float 6s ease-in-out infinite;
--animate-breathe: breathe 4s ease-in-out infinite;
--animate-spin-slow: spin-slow 8s linear infinite;
--animate-music-wave-1: audio-wave 1s ease-in-out infinite;
--animate-music-wave-2: audio-wave 1s ease-in-out 0.1s infinite;
--animate-music-wave-3: audio-wave 1s ease-in-out 0.2s infinite;
--animate-music-wave-4: audio-wave 1s ease-in-out 0.3s infinite;
}
@keyframes fadeIn {
0% { opacity: 0; }
100% { opacity: 1; }
}
@keyframes slideUp {
0% { transform: translateY(20px); opacity: 0; }
100% { transform: translateY(0); opacity: 1; }
}
@keyframes float {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-10px); }
}
@keyframes breathe {
0%, 100% { opacity: 0.8; transform: scale(1); }
50% { opacity: 1; transform: scale(1.02); }
}
@keyframes spin-slow {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
@keyframes pulse-ring {
0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(42, 157, 143, 0.7); }
70% { transform: scale(1); box-shadow: 0 0 0 10px rgba(42, 157, 143, 0); }
100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(42, 157, 143, 0); }
}
@keyframes audio-wave {
0%, 100% { height: 5px; }
50% { height: 15px; }
}
/* Global Reset & Base */
body {
-webkit-tap-highlight-color: transparent;
font-family: 'Noto Sans SC', sans-serif;
@apply bg-deep-sea text-gray-800 overflow-x-hidden selection:bg-primary selection:text-white;
}
/* Background Noise Utility */
.bg-noise {
background-image: url('./assets/noise.svg');
}
/* Custom Scrollbar */
::-webkit-scrollbar {
width: 6px;
height: 6px;
}
::-webkit-scrollbar-track {
background: transparent;
}
::-webkit-scrollbar-thumb {
background: rgba(255, 255, 255, 0.2);
border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
background: rgba(42, 157, 143, 0.6);
}
.custom-scrollbar::-webkit-scrollbar-thumb {
background: rgba(0, 0, 0, 0.1);
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover {
background: rgba(42, 157, 143, 0.4);
}
/* Transitions */
.view-transition {
animation: fadeIn 0.5s ease-in-out;
}
/* Glassmorphism Cards */
.glass-card {
background: rgba(255, 255, 255, 0.95);
backdrop-filter: blur(20px);
-webkit-backdrop-filter: blur(20px);
border: 1px solid rgba(255, 255, 255, 0.8);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.05);
}
.glass-card-dark {
background: rgba(15, 28, 46, 0.7);
backdrop-filter: blur(12px);
color: white;
border: 1px solid rgba(255, 255, 255, 0.08);
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}
/* Healing Specifics */
.healing-card {
background: linear-gradient(135deg, #f0fdf4 0%, #e0f2fe 100%);
box-shadow: 0 10px 30px -5px rgba(56, 189, 248, 0.15);
}
/* Form Elements */
.input-field {
width: 100%;
padding: 0.875rem 1.25rem;
border-radius: 1rem;
border: 1px solid rgba(0,0,0,0.1);
background: rgba(255, 255, 255, 0.9);
transition: all 0.3s ease;
outline: none;
color: #1e293b;
font-size: 0.95rem;
}
.input-field:focus {
border-color: #2A9D8F;
box-shadow: 0 0 0 4px rgba(42, 157, 143, 0.15);
background: white;
}
.input-field-dark {
background: rgba(255, 255, 255, 0.05);
border-color: rgba(255, 255, 255, 0.1);
color: white;
}
.input-field-dark:focus {
background: rgba(255, 255, 255, 0.1);
border-color: #2A9D8F;
}
select.input-field {
appearance: none;
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2364748b' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
background-position: right 1rem center;
background-repeat: no-repeat;
background-size: 1.5em 1.5em;
padding-right: 2.5rem;
}
select.input-field-dark {
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='white' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
}
select.input-field-dark option {
background-color: #0f1c2e;
}
/* Audio Player Animation */
.audio-waves span {
display: inline-block;
width: 3px;
height: 10px;
background-color: currentColor;
animation: audio-wave 1s ease-in-out infinite;
border-radius: 2px;
}
.audio-waves span:nth-child(2) { animation-delay: 0.1s; }
.audio-waves span:nth-child(3) { animation-delay: 0.2s; }
.audio-waves span:nth-child(4) { animation-delay: 0.3s; }
/* Utilities */
.scrollbar-hide::-webkit-scrollbar {
display: none;
}
.scrollbar-hide {
-ms-overflow-style: none;
scrollbar-width: none;
}
/* Mobile Optimizations */
@media (max-width: 768px) {
.glass-card {
padding: 1.25rem;
}
.input-field {
padding: 0.75rem 1rem;
font-size: 16px; /* Prevent iOS zoom */
}
.btn-primary {
width: 100%;
justify-content: center;
padding: 1rem;
}
}
+10
View File
@@ -0,0 +1,10 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.jsx'
createRoot(document.getElementById('root')).render(
<StrictMode>
<App />
</StrictMode>,
)
+168
View File
@@ -0,0 +1,168 @@
import React, { useState, useEffect } from 'react';
import { useStoreData } from '../hooks/useStoreData';
import { Store } from '../utils/store';
import { AudioEngine } from '../utils/audioEngine';
import { TimelineView } from '../components/views/TimelineView';
import { ScriptView } from '../components/views/ScriptView';
import { PathView } from '../components/views/PathView';
import {
Compass,
BookOpen,
Film,
Map,
Music,
Volume2,
VolumeX,
RotateCcw,
Menu,
X
} from 'lucide-react';
import clsx from 'clsx';
export function DashboardPage() {
const data = useStoreData();
const [activeTab, setActiveTab] = useState('timeline');
const [isMusicPlaying, setIsMusicPlaying] = useState(false);
const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
// Initialize Audio Engine state based on store
useEffect(() => {
// Sync initial state if needed
if (!data.audioMuted) {
// AudioEngine manages its own state
}
}, []);
const handleMusicToggle = async () => {
try {
const playing = AudioEngine.toggle();
setIsMusicPlaying(playing);
} catch (e) {
console.error("Audio failed", e);
}
};
const handleReset = () => {
if (window.confirm('确定要清空所有数据重新开始吗?这将回到注册页面。')) {
Store.reset();
// App.jsx will handle the redirect because store data changes
}
};
const NavButton = ({ tab, icon: Icon, label, mobileLabel }) => (
<button
onClick={() => { setActiveTab(tab); setIsMobileMenuOpen(false); }}
className={clsx(
"w-full text-left px-4 py-3 rounded-xl flex items-center gap-3 transition-all duration-300 relative overflow-hidden group",
activeTab === tab
? "bg-primary/20 text-primary font-bold shadow-[0_0_15px_rgba(16,185,129,0.1)] border border-primary/20"
: "text-gray-400 hover:text-white hover:bg-white/5 border border-transparent"
)}
>
<Icon className={clsx("w-5 h-5 transition-transform", activeTab === tab ? "text-primary" : "text-gray-400 group-hover:text-white", activeTab !== tab && "group-hover:scale-110")} />
<span className="hidden md:inline">{label}</span>
<span className="md:hidden">{mobileLabel || label}</span>
{activeTab === tab && (
<div className="absolute right-0 top-0 bottom-0 w-1 bg-primary shadow-[0_0_10px_#10b981]"></div>
)}
</button>
);
return (
<div className="min-h-screen flex flex-col md:flex-row transition-all duration-500 font-sans text-gray-100 bg-deep-sea overflow-hidden">
{/* Ambient Background */}
<div className="fixed inset-0 pointer-events-none z-0">
<div className="absolute top-0 left-0 w-full h-full bg-[radial-gradient(circle_at_50%_50%,rgba(16,185,129,0.05),transparent_50%)]"></div>
<div className="absolute top-[-20%] left-[-10%] w-[50%] h-[50%] bg-primary/5 rounded-full blur-[120px] animate-pulse-slow"></div>
</div>
{/* Mobile Header */}
<div className="md:hidden bg-black/20 backdrop-blur-xl border-b border-white/10 p-4 flex justify-between items-center z-50 relative">
<div className="flex items-center gap-2 font-bold text-lg">
<Compass className="text-primary w-6 h-6 animate-spin-slow" />
<span className="bg-clip-text text-transparent bg-gradient-to-r from-primary to-accent">人生轨迹</span>
</div>
<button onClick={() => setIsMobileMenuOpen(!isMobileMenuOpen)}>
{isMobileMenuOpen ? <X className="text-white" /> : <Menu className="text-white" />}
</button>
</div>
{/* Sidebar (Desktop) / Drawer (Mobile) */}
<nav className={clsx(
"bg-black/20 backdrop-blur-xl border-r border-white/10 w-full md:w-72 flex-shrink-0 flex flex-col justify-between z-40 fixed md:relative h-[calc(100vh-64px)] md:h-screen top-16 md:top-0 left-0 transition-transform duration-300",
isMobileMenuOpen ? "translate-x-0" : "-translate-x-full md:translate-x-0"
)}>
{/* Background Decoration */}
<div className="absolute top-0 left-0 w-full h-full bg-gradient-to-b from-transparent to-primary/5 pointer-events-none"></div>
<div className="p-6 overflow-y-auto relative z-10">
<h1 className="hidden md:flex text-2xl font-bold tracking-wider mb-8 items-center gap-3 text-transparent bg-clip-text bg-gradient-to-r from-primary to-white">
<Compass className="text-primary stroke-2 animate-spin-slow" /> 人生轨迹
</h1>
{/* User Card */}
<div className="flex items-center gap-4 mb-8 p-4 bg-white/5 rounded-2xl backdrop-blur-sm border border-white/10 hover:bg-white/10 transition-colors cursor-default group">
<div className="w-12 h-12 rounded-full bg-gradient-to-br from-primary to-blue-600 flex items-center justify-center text-white font-bold text-xl shadow-inner relative overflow-hidden group-hover:scale-105 transition-transform shrink-0 border border-white/20">
{data.userProfile.nickname?.[0] || 'U'}
<div className="absolute inset-0 bg-white/20 opacity-0 group-hover:opacity-100 transition-opacity"></div>
</div>
<div className="overflow-hidden">
<div className="font-bold text-white truncate">{data.userProfile.nickname || '旅人'}</div>
<div className="text-xs text-primary flex items-center gap-1.5 mt-0.5">
<span className="w-1.5 h-1.5 rounded-full bg-primary shadow-[0_0_5px_rgba(16,185,129,0.5)] animate-pulse"></span>
{data.userProfile.mbti} · {data.userProfile.zodiac || '未知'}
</div>
</div>
</div>
{/* Navigation */}
<div className="space-y-2">
<NavButton tab="timeline" icon={BookOpen} label="时空日记" mobileLabel="日记" />
<NavButton tab="script" icon={Film} label="剧本生成器" mobileLabel="剧本" />
<NavButton tab="path" icon={Map} label="实现路径" mobileLabel="路径" />
</div>
</div>
<div className="p-6 text-xs text-gray-500 border-t border-white/5 space-y-4 bg-black/40 backdrop-blur-md md:bg-transparent relative z-10">
{/* Music Player */}
<button
onClick={handleMusicToggle}
className={clsx(
"flex items-center justify-between w-full px-4 py-3 rounded-xl bg-white/5 hover:bg-white/10 transition-all border group",
isMusicPlaying ? "border-primary/30 shadow-[0_0_10px_rgba(16,185,129,0.1)]" : "border-white/5"
)}
>
<div className="flex items-center gap-3 text-gray-300">
<div className={clsx("w-8 h-8 rounded-full flex items-center justify-center transition-colors", isMusicPlaying ? "bg-primary/20 text-primary" : "bg-white/10 text-gray-400")}>
{isMusicPlaying ? <Volume2 className="w-4 h-4" /> : <VolumeX className="w-4 h-4" />}
</div>
<span>疗愈背景音</span>
</div>
{isMusicPlaying && (
<div className="flex gap-0.5 h-3 items-end">
<span className="w-0.5 bg-primary animate-music-wave-1"></span>
<span className="w-0.5 bg-primary animate-music-wave-2"></span>
<span className="w-0.5 bg-primary animate-music-wave-3"></span>
<span className="w-0.5 bg-primary animate-music-wave-4"></span>
</div>
)}
</button>
<button
onClick={handleReset}
className="flex items-center gap-2 hover:text-red-400 transition-colors w-full px-4 py-2 rounded hover:bg-red-500/10 justify-center"
>
<RotateCcw className="w-3 h-3" /> 重置所有数据
</button>
</div>
</nav>
{/* Main Content Area */}
<main className="flex-1 overflow-y-auto h-[calc(100vh-64px)] md:h-screen relative z-10 scroll-smooth p-4 md:p-0 custom-scrollbar">
{activeTab === 'timeline' && <TimelineView />}
{activeTab === 'script' && <ScriptView onSwitchToPath={() => setActiveTab('path')} />}
{activeTab === 'path' && <PathView onSwitchToScript={() => setActiveTab('script')} />}
</main>
</div>
);
}
+194
View File
@@ -0,0 +1,194 @@
import React, { useState, useEffect } from 'react';
import { Compass, ArrowRight, X, Phone, Lock, Loader2 } from 'lucide-react';
import { Button } from '../components/ui/Button';
import { Input } from '../components/ui/Input';
import request from '../utils/request';
import clsx from 'clsx';
// PncyssD Prototype: Landing Page
export function LandingPage({ onStart }) {
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [showLoginModal, setShowLoginModal] = useState(false);
const [loading, setLoading] = useState(false);
// Login Form State
const [phone, setPhone] = useState('');
const [code, setCode] = useState('');
const [countdown, setCountdown] = useState(0);
useEffect(() => {
const token = localStorage.getItem('token');
if (token) setIsLoggedIn(true);
}, []);
useEffect(() => {
let timer;
if (countdown > 0) {
timer = setInterval(() => setCountdown(c => c - 1), 1000);
}
return () => clearInterval(timer);
}, [countdown]);
const handleGetCode = async () => {
if (!phone) return alert('请输入手机号');
if (!/^1[3-9]\d{9}$/.test(phone)) return alert('手机号格式不正确');
try {
// Backend: /auth/sms-code?phone=... (AuthController.java)
// Note: "Business type" is not required by the current backend implementation.
const res = await request.get('/auth/sms-code', { params: { phone } });
if (res.code === 200) {
setCountdown(60);
// Display backend message or dev code
const msg = res.data?.message || '验证码已发送';
if (res.data?.code) {
alert(`【测试模式】${msg}\n验证码: ${res.data.code}`);
} else {
alert(msg);
}
} else {
console.warn('SMS Code Error:', res);
alert(res.message || '发送失败,请稍后重试');
}
} catch (e) {
console.error('Failed to get SMS code:', e);
const errorMsg = e.response?.data?.message || '网络连接异常,请检查您的网络设置';
alert(errorMsg);
}
};
const handleLogin = async () => {
if (!phone || !code) return alert('请填写完整信息');
setLoading(true);
try {
const res = await request.post('/auth/login', { phone, smsCode: code });
if (res.code === 200) {
const { accessToken } = res.data;
localStorage.setItem('token', accessToken);
setIsLoggedIn(true);
setShowLoginModal(false);
// Clear sensitive data
setPhone('');
setCode('');
} else {
alert(res.message || '登录失败');
}
} catch (e) {
console.error(e);
alert('登录异常,请检查网络');
} finally {
setLoading(false);
}
};
return (
<div className="min-h-screen flex flex-col items-center justify-center text-center p-6 relative overflow-hidden">
{/* Background & Effects */}
<div className="absolute top-1/4 left-1/4 w-96 h-96 bg-primary/20 rounded-full blur-[100px] animate-pulse-slow"></div>
<div className="relative z-10 space-y-8 max-w-lg mx-auto w-full">
<div className="mb-4 inline-block p-4 rounded-full bg-white/5 border border-white/10 shadow-2xl animate-float">
<Compass className="w-16 h-16 text-primary icon-spin-slow" strokeWidth={1.5} />
</div>
<h1 className="text-4xl md:text-6xl font-bold text-white tracking-tight landing-title">
人生轨迹
<span className="block text-xl md:text-2xl font-light mt-4 text-primary/80">Life Trajectory</span>
</h1>
{/* Buttons */}
<div className="flex flex-col items-center justify-center gap-4 mt-12 w-full max-w-xs mx-auto">
{isLoggedIn ? (
<Button
variant="primary"
size="lg"
onClick={onStart}
className="w-full animate-in fade-in zoom-in duration-500"
>
开启旅程 <ArrowRight className="w-5 h-5 group-hover:translate-x-1 transition-transform ml-2" />
</Button>
) : (
<Button
variant="primary"
size="lg"
onClick={() => setShowLoginModal(true)}
className="w-full shadow-[0_0_20px_rgba(16,185,129,0.3)] hover:shadow-[0_0_30px_rgba(16,185,129,0.5)] transition-all"
>
登录账号
</Button>
)}
</div>
</div>
{/* Login Modal */}
{showLoginModal && (
<div className="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm animate-in fade-in duration-200">
<div className="relative w-full max-w-md bg-[#0f172a] border border-white/10 rounded-2xl shadow-2xl p-8 overflow-hidden">
{/* Modal Background */}
<div className="absolute top-0 right-0 w-64 h-64 bg-primary/5 rounded-full blur-[80px] -translate-y-1/2 translate-x-1/2 pointer-events-none"></div>
<button
onClick={() => setShowLoginModal(false)}
className="absolute top-4 right-4 text-gray-400 hover:text-white transition-colors"
>
<X className="w-6 h-6" />
</button>
<h2 className="text-2xl font-bold text-white mb-6 flex items-center gap-2">
<span className="w-1 h-6 bg-primary rounded-full"></span>
欢迎回来
</h2>
<div className="space-y-4">
<div className="space-y-1 text-left">
<label className="text-xs font-bold text-gray-400 uppercase tracking-wider ml-1">手机号</label>
<div className="relative">
<Phone className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
<Input
placeholder="请输入手机号"
className="pl-10"
value={phone}
onChange={(e) => setPhone(e.target.value)}
/>
</div>
</div>
<div className="space-y-1 text-left">
<label className="text-xs font-bold text-gray-400 uppercase tracking-wider ml-1">验证码</label>
<div className="flex gap-3">
<div className="relative flex-1">
<Lock className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-500" />
<Input
placeholder="请输入验证码"
className="pl-10"
value={code}
onChange={(e) => setCode(e.target.value)}
/>
</div>
<Button
variant="secondary"
className="w-28 whitespace-nowrap"
onClick={handleGetCode}
disabled={countdown > 0}
>
{countdown > 0 ? `${countdown}s` : '获取验证码'}
</Button>
</div>
</div>
<Button
variant="primary"
className="w-full mt-6 py-3 text-lg"
onClick={handleLogin}
disabled={loading}
>
{loading ? <Loader2 className="w-5 h-5 animate-spin mx-auto" /> : '登 录'}
</Button>
</div>
</div>
</div>
)}
</div>
);
}
+155
View File
@@ -0,0 +1,155 @@
import React, { useState } from 'react';
import { User, Lock, Eye, EyeOff, ArrowRight, ArrowLeft } from 'lucide-react';
import { GlassCard } from '../components/ui/GlassCard';
import { Button } from '../components/ui/Button';
import { Input } from '../components/ui/Input';
import { Checkbox } from '../components/ui/Checkbox';
import { Store } from '../utils/store';
export function LoginPage({ onLoginSuccess, onBack, onSignUp }) {
const [formData, setFormData] = useState({
username: '',
password: '',
rememberMe: false
});
const [showPassword, setShowPassword] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState('');
const handleSubmit = async (e) => {
e.preventDefault();
setError('');
setIsLoading(true);
// Mock login delay
setTimeout(() => {
if (!formData.username || !formData.password) {
setError('请输入用户名和密码');
setIsLoading(false);
return;
}
// Simple mock validation
if (formData.password.length < 6) {
setError('密码长度不能少于6位');
setIsLoading(false);
return;
}
// Success
Store.updateProfile({
nickname: formData.username,
// In a real app, we'd store a token
});
setIsLoading(false);
onLoginSuccess();
}, 1000);
};
return (
<div className="min-h-screen flex items-center justify-center p-4 relative z-10 animate-fade-in">
<div className="absolute top-8 left-8">
<button
onClick={onBack}
className="flex items-center gap-2 text-white/60 hover:text-white transition-colors group"
>
<ArrowLeft className="w-5 h-5 group-hover:-translate-x-1 transition-transform" />
<span>返回首页</span>
</button>
</div>
<GlassCard className="w-full max-w-md p-8 md:p-10 relative overflow-hidden">
{/* Decorative elements */}
<div className="absolute -top-10 -right-10 w-40 h-40 bg-primary/20 rounded-full blur-3xl pointer-events-none"></div>
<div className="absolute -bottom-10 -left-10 w-40 h-40 bg-aurora-green/20 rounded-full blur-3xl pointer-events-none"></div>
<div className="relative z-10">
<div className="text-center mb-10">
<h2 className="text-3xl font-bold text-white mb-2 tracking-tight">欢迎回来</h2>
<p className="text-gray-400">登录您的 Emotion Museum 账号</p>
</div>
<form onSubmit={handleSubmit} className="space-y-6">
<div className="space-y-2">
<label className="text-sm font-medium text-gray-300 ml-1">用户名 / 邮箱</label>
<div className="relative group">
<User className="absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-primary transition-colors" />
<Input
type="text"
placeholder="请输入您的账号"
className="pl-12 w-full"
value={formData.username}
onChange={(e) => setFormData({...formData, username: e.target.value})}
/>
</div>
</div>
<div className="space-y-2">
<label className="text-sm font-medium text-gray-300 ml-1">密码</label>
<div className="relative group">
<Lock className="absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 group-focus-within:text-primary transition-colors" />
<Input
type={showPassword ? "text" : "password"}
placeholder="请输入您的密码"
className="pl-12 pr-12 w-full"
value={formData.password}
onChange={(e) => setFormData({...formData, password: e.target.value})}
/>
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="absolute right-4 top-1/2 -translate-y-1/2 text-gray-400 hover:text-white transition-colors focus:outline-none"
>
{showPassword ? <EyeOff className="w-5 h-5" /> : <Eye className="w-5 h-5" />}
</button>
</div>
</div>
<div className="flex items-center justify-between pt-2">
<Checkbox
label="记住我"
checked={formData.rememberMe}
onChange={(checked) => setFormData({...formData, rememberMe: checked})}
/>
<button type="button" className="text-sm text-primary hover:text-aurora-green transition-colors">
忘记密码
</button>
</div>
{error && (
<div className="p-3 rounded-lg bg-red-500/10 border border-red-500/20 text-red-200 text-sm flex items-center gap-2 animate-shake">
<span className="w-1.5 h-1.5 rounded-full bg-red-500"></span>
{error}
</div>
)}
<Button
type="submit"
className="w-full"
size="lg"
isLoading={isLoading}
>
{!isLoading && (
<>
立即登录 <ArrowRight className="w-4 h-4 ml-2" />
</>
)}
</Button>
</form>
<div className="mt-8 text-center text-sm text-gray-400">
还没有账号
<button
onClick={onSignUp}
className="text-primary hover:text-aurora-green font-bold ml-1 hover:underline transition-all"
>
立即注册
</button>
</div>
</div>
</GlassCard>
</div>
);
}
+235
View File
@@ -0,0 +1,235 @@
import React, { useState } from 'react';
import { Store } from '../utils/store';
import { ArrowLeft, ArrowRight, Check, X, Sparkles, Star, AlertCircle, CheckCircle } from 'lucide-react';
import { Button } from '../components/ui/Button';
import { Input, Select, Textarea } from '../components/ui/Input';
import clsx from 'clsx';
const ZODIAC_SIGNS = [
"白羊座", "金牛座", "双子座", "巨蟹座",
"狮子座", "处女座", "天秤座", "天蝎座",
"射手座", "摩羯座", "水瓶座", "双鱼座"
];
const MBTI_TYPES = ['INTJ','INTP','ENTJ','ENTP','INFJ','INFP','ENFJ','ENFP','ISTJ','ISFJ','ESTJ','ESFJ','ISTP','ISFP','ESTP','ESFP'];
export function OnboardingPage({ onFinish }) {
const [step, setStep] = useState(0);
const [formData, setFormData] = useState(Store.get().userProfile);
const [toast, setToast] = useState(null); // { msg, type }
const showToast = (msg, type = 'error') => {
setToast({ msg, type });
setTimeout(() => setToast(null), 2500);
};
const updateFormData = (key, value) => {
setFormData(prev => ({ ...prev, [key]: value }));
};
const updateHistory = (type, field, value) => {
setFormData(prev => ({
...prev,
history: {
...prev.history,
[type]: {
...prev.history?.[type],
[field]: value
}
}
}));
};
const handleNext = () => {
if (step === 0) {
if (!formData.nickname?.trim()) { showToast('请填写昵称'); return; }
if (!formData.mbti) { showToast('请选择MBTI人格类型'); return; }
} else if (step === 4) {
if (!formData.futureVision?.trim()) { showToast('写下一句对未来的期许吧'); return; }
Store.updateProfile(formData);
Store.completeOnboarding();
onFinish();
return;
}
setStep(prev => prev + 1);
};
const handlePrev = () => setStep(prev => prev - 1);
return (
<div className="min-h-screen flex flex-col relative overflow-hidden transition-colors duration-1000">
{/* Background Blobs */}
<div className="absolute top-0 right-0 w-64 h-64 bg-primary/10 rounded-full blur-[80px] -translate-y-1/2 translate-x-1/2 animate-pulse-slow"></div>
<div className="absolute bottom-0 left-0 w-80 h-80 bg-secondary/20 rounded-full blur-[80px] translate-y-1/3 -translate-x-1/3 animate-pulse-slow" style={{ animationDelay: '2s' }}></div>
{/* Toast */}
{toast && (
<div className={clsx(
"fixed top-10 left-1/2 -translate-x-1/2 px-6 py-3 rounded-full shadow-xl z-50 animate-fade-in flex items-center gap-2",
toast.type === 'error' ? 'bg-red-500/90 text-white' : 'bg-green-500/90 text-white'
)}>
{toast.type === 'error' ? <AlertCircle className="w-4 h-4" /> : <CheckCircle className="w-4 h-4" />}
{toast.msg}
</div>
)}
{/* Header */}
<div className="relative z-10 px-6 py-8 flex justify-between items-center">
<div className="flex gap-1">
{[0,1,2,3,4].map(i => (
<div key={i} className={clsx(
"h-1 rounded-full transition-all duration-500",
i <= step ? 'w-8 bg-primary shadow-[0_0_10px_rgba(42,157,143,0.5)]' : 'w-2 bg-white/10'
)}></div>
))}
</div>
<button className="text-white/40 hover:text-white transition-colors" onClick={() => { if(confirm('退出注册将不保存进度,确定吗?')) window.location.reload() }}>
<X className="w-6 h-6 hover:rotate-90 transition-transform" />
</button>
</div>
{/* Content */}
<div className="flex-1 flex flex-col justify-center px-6 pb-24 max-w-xl mx-auto w-full relative z-10">
{step === 0 && (
<div className="animate-fade-in space-y-6">
<div className="text-center mb-8">
<h2 className="text-2xl font-bold text-white">你是谁</h2>
<p className="text-gray-400 text-sm mt-2">让我们先认识一下彼此</p>
</div>
<div className="space-y-4">
<div>
<label className="block text-xs font-bold text-gray-400 mb-1 ml-1">昵称 <span className="text-red-400">*</span></label>
<Input
placeholder="你希望世界如何称呼你?"
value={formData.nickname || ''}
onChange={e => updateFormData('nickname', e.target.value)}
/>
</div>
<div className="grid grid-cols-2 gap-4">
<div>
<label className="block text-xs font-bold text-gray-400 mb-1 ml-1">性别</label>
<Select value={formData.gender || 'secret'} onChange={e => updateFormData('gender', e.target.value)}>
<option value="male"></option>
<option value="female"></option>
<option value="secret">保密</option>
</Select>
</div>
<div>
<label className="block text-xs font-bold text-gray-400 mb-1 ml-1">星座</label>
<Select value={formData.zodiac || ''} onChange={e => updateFormData('zodiac', e.target.value)}>
<option value="" disabled>选择星座</option>
{ZODIAC_SIGNS.map(z => <option key={z} value={z}>{z}</option>)}
</Select>
</div>
</div>
<div className="grid grid-cols-1 gap-4">
<div>
<label className="block text-xs font-bold text-gray-400 mb-1 ml-1">MBTI 人格 <span className="text-red-400">*</span></label>
<Select value={formData.mbti || ''} onChange={e => updateFormData('mbti', e.target.value)}>
<option value="" disabled>选择你的类型</option>
{MBTI_TYPES.map(t => <option key={t} value={t}>{t}</option>)}
</Select>
</div>
</div>
<div>
<label className="block text-xs font-bold text-gray-400 mb-1 ml-1">兴趣爱好 (用逗号分隔)</label>
<Input
placeholder="例如:摄影, 登山, 编程"
value={(formData.hobbies || []).join(', ')}
onChange={e => updateFormData('hobbies', e.target.value.split(/[,]/).map(s => s.trim()))}
/>
</div>
</div>
</div>
)}
{step === 1 && (
<div className="animate-fade-in space-y-6">
<div className="text-center mb-8">
<span className="text-amber-300 text-xs tracking-widest uppercase mb-2 block">Part 1 / 3</span>
<h2 className="text-2xl font-bold text-white">你是如何成为了现在的自己</h2>
<p className="text-gray-400 text-sm mt-2">闭上眼回到开始的地方你的童年是怎么度过的</p>
</div>
<div className="bg-white/5 p-6 rounded-2xl border border-amber-500/20 shadow-lg shadow-amber-500/5">
<label className="block text-xs font-bold text-amber-300/80 mb-2">大概的时间</label>
<Input type="date" className="mb-4" value={formData.history?.childhood?.date || ''} onChange={e => updateHistory('childhood', 'date', e.target.value)} />
<label className="block text-xs font-bold text-amber-300/80 mb-2">记忆中的画面</label>
<Textarea rows={5} placeholder="比如:外婆的蒲扇,炎热的下午,或者第一次离家..." value={formData.history?.childhood?.content || ''} onChange={e => updateHistory('childhood', 'content', e.target.value)} />
</div>
</div>
)}
{step === 2 && (
<div className="animate-fade-in space-y-6">
<div className="text-center mb-8">
<span className="text-primary text-xs tracking-widest uppercase mb-2 block">Part 2 / 3</span>
<h2 className="text-2xl font-bold text-white">闪闪发光的日子</h2>
<p className="text-gray-400 text-sm mt-2">在这个过程中让你感到非常开心的经历是什么</p>
</div>
<div className="bg-white/5 p-6 rounded-2xl border border-primary/20 shadow-lg shadow-primary/5">
<label className="block text-xs font-bold text-primary/80 mb-2">发生日期</label>
<Input type="date" className="mb-4" value={formData.history?.peak?.date || ''} onChange={e => updateHistory('peak', 'date', e.target.value)} />
<label className="block text-xs font-bold text-primary/80 mb-2">那发生了什么</label>
<Textarea rows={5} placeholder="比如:收到心仪的offer,一次完美的旅行,或者被理解的瞬间..." value={formData.history?.peak?.content || ''} onChange={e => updateHistory('peak', 'content', e.target.value)} />
</div>
</div>
)}
{step === 3 && (
<div className="animate-fade-in space-y-6">
<div className="text-center mb-8">
<span className="text-blue-400 text-xs tracking-widest uppercase mb-2 block">Part 3 / 3</span>
<h2 className="text-2xl font-bold text-white">风雨兼程</h2>
<p className="text-gray-400 text-sm mt-2">一段十分沮丧和低谷的时光你是如何度过的</p>
</div>
<div className="bg-white/5 p-6 rounded-2xl border border-blue-400/20 shadow-lg shadow-blue-400/5">
<label className="block text-xs font-bold text-blue-400/80 mb-2">发生日期</label>
<Input type="date" className="mb-4" value={formData.history?.valley?.date || ''} onChange={e => updateHistory('valley', 'date', e.target.value)} />
<label className="block text-xs font-bold text-blue-400/80 mb-2">当时的感受与成长</label>
<Textarea rows={5} placeholder="那个挑战是什么?现在回看,它带给了你什么?" value={formData.history?.valley?.content || ''} onChange={e => updateHistory('valley', 'content', e.target.value)} />
</div>
</div>
)}
{step === 4 && (
<div className="animate-fade-in space-y-6">
<div className="text-center mb-10">
<h2 className="text-2xl font-bold text-white">你未来想成为怎样的人</h2>
<p className="text-gray-400 text-sm mt-2">对自己的憧憬以及对理想生活状态的憧憬</p>
</div>
<div className="relative group">
<Sparkles className="absolute -top-6 -left-4 text-accent w-8 h-8 animate-pulse-slow" />
<Textarea rows={4} className="text-lg leading-relaxed text-center group-hover:border-accent/50 transition-colors" placeholder="三年后,我希望过着这样的生活..." value={formData.futureVision || ''} onChange={e => updateFormData('futureVision', e.target.value)} />
<Star className="absolute -bottom-6 -right-4 text-accent w-6 h-6 animate-pulse-slow" style={{ animationDelay: '1s' }} />
</div>
</div>
)}
</div>
{/* Footer Controls */}
<div className="fixed bottom-0 left-0 w-full p-6 bg-deep-sea/80 backdrop-blur-lg border-t border-white/5 flex justify-between items-center z-20">
{step > 0 ? (
<button onClick={handlePrev} className="text-gray-400 hover:text-white flex items-center gap-2 transition-colors group">
<ArrowLeft className="w-4 h-4 group-hover:-translate-x-1 transition-transform" /> 上一步
</button>
) : <div></div>}
<Button onClick={handleNext} className="flex items-center gap-2 px-8 group hover:scale-105 active:scale-95 shadow-lg shadow-primary/20">
<span>{step === 4 ? '完成创建' : '下一步'}</span>
{step === 4 ? <Check className="w-4 h-4" /> : <ArrowRight className="w-4 h-4 group-hover:translate-x-1 transition-transform" />}
</Button>
</div>
</div>
);
}
+162
View File
@@ -0,0 +1,162 @@
/**
* AI Logic Module
* Simulates intelligent healing responses and content generation.
*/
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
const ADJECTIVES = {
INTJ: ['深刻', '逻辑严密', '富有远见'],
INFP: ['温柔', '富有同理心', '充满想象力'],
ENFP: ['热情', '鼓舞人心', '充满可能性'],
ISTJ: ['稳重', '务实', '值得信赖'],
INFJ: ['深邃', '直觉敏锐', '利他'],
DEFAULT: ['特别', '真诚', '有力量']
};
export const AI = {
/**
* Generate a healing reply for a timeline log.
* Analyzes sentiment and provides Analysis, Growth, and Healing.
*/
async generateReply(content, profile) {
await sleep(1500 + Math.random() * 1000); // Simulate 1.5-2.5s thinking
const mbti = profile.mbti || 'DEFAULT';
const traits = ADJECTIVES[mbti] || ADJECTIVES.DEFAULT;
const trait = traits[Math.floor(Math.random() * traits.length)];
const zodiac = profile.zodiac || '星辰';
let mood = 'neutral';
if (/(开心|成功|棒|好|爱|幸福|顺利)/.test(content)) mood = 'positive';
if (/(难过|累|失败|痛|丧|焦虑|迷茫)/.test(content)) mood = 'negative';
let analysis = "";
let growth = "";
let healing = "";
if (mood === 'positive') {
analysis = `这不仅仅是一个事件,而是你内心能量充盈的体现。作为${mbti},你敏锐地捕捉到了生活中的光亮。`;
growth = `请记住这种${trait}的感觉,它构成了你人格中坚韧的底色。你的每一次喜悦,都在为未来的挑战积蓄心理资本。`;
healing = `愿这一刻的温暖,像${zodiac}的光芒一样,长久地照耀你的内心。`;
} else if (mood === 'negative') {
analysis = `感到低落并非示弱,而是灵魂在提醒你需要休息。${mbti}的你往往思考得很深,容易承担过多情绪。`;
growth = `每一次的阵痛都是成长的伏笔。你正在经历破茧成蝶前的静默,这本身就是一种力量。`;
healing = `允许自己暂停,就像月亮也有阴晴圆缺。给那个受伤的自己一个拥抱,风雨之后,必见彩虹。`;
} else {
analysis = `记录本身就是一种深刻的觉察。你在平淡的流年中,依然保持着${trait}的观察力。`;
growth = `生活的大部分时间是平静的,能在其中找到节奏,是你最宝贵的能力。`;
healing = `在这漫长的岁月里,你就是自己最忠实的见证者。`;
}
return {
analysis,
growth,
healing
};
},
/**
* Generate a "Cool Story" (爽文) script.
* Uses profile history (Valley/Peak) to create a narrative arc.
*/
async generateScript(profile, timeline, requirements) {
await sleep(2000 + Math.random() * 1000);
const id = Date.now().toString();
const hobby = (profile.hobbies && profile.hobbies.length > 0) ? profile.hobbies[0] : "隐藏的天赋";
const theme = requirements.theme || "自我超越";
const valleyEvent = profile.history?.valley?.content
? `那段"${profile.history.valley.content.substring(0, 15)}..."的经历`
: "曾经那段默默无闻的时光";
const peakEvent = profile.history?.peak?.content
? `就像"${profile.history.peak.content.substring(0, 15)}..."那次一样`
: "如同星辰觉醒";
const templates = {
career: {
intro: `故事始于${valleyEvent}${profile.nickname}虽然身处低谷,但作为${profile.mbti}${profile.gender === 'male' ? '他' : '她'}内心深处对"${theme}"的渴望从未熄灭。${profile.zodiac}骨子里的韧性,支撑着${profile.gender === 'male' ? '他' : '她'}熬过了最黑的夜。`,
turning: `转折发生在一个不起眼的午后。公司面临前所未有的技术难题,所有人束手无策。${profile.nickname}利用业余时间钻研的${hobby},意外发现了破局的关键。`,
explosion: `在项目汇报会上,${profile.nickname}条理清晰地展示了方案,那种自信${peakEvent}。原本轻视的人都闭上了嘴。不仅完美解决了危机,更直接为公司带来了巨大的收益,一战成名!`,
ending: `最终,${profile.nickname}站在了行业的顶峰,实现了"${theme}"的宏愿。回首往事,轻舟已过万重山,${profile.gender === 'male' ? '他' : '她'}终于成为了自己想成为的人。`
},
love: {
intro: `${valleyEvent}的日子里,${profile.nickname}习惯了独自一人。${profile.mbti}的特质让${profile.gender === 'male' ? '他' : '她'}虽然渴望爱,却更害怕受伤。`,
turning: `直到那次${hobby}社团的聚会,命运的齿轮开始转动。${profile.nickname}不经意间流露出的${ADJECTIVES[profile.mbti]?.[0] || '独特'}气质,深深吸引了那个命中注定的人。`,
explosion: `面对现实的阻碍和误解,${profile.nickname}没有退缩。${profile.zodiac}赋予的勇气觉醒,${profile.gender === 'male' ? '他' : '她'}坚定地跨越了山海,只为奔赴那份真挚的感情。那一刻,全世界都在为爱让路。`,
ending: `正如${profile.futureVision || '童话故事'}里的结局,两人在夕阳下相拥。${profile.nickname}发现,原来最好的爱,是让你成为更好的自己。`
},
fantasy: {
intro: `在这个看似平凡的世界,${profile.nickname}总感觉自己格格不入。${valleyEvent},其实是灵力觉醒前的阵痛。${profile.zodiac}星盘早已预示了不凡的命运。`,
turning: `${hobby}这一媒介触碰到古老的法阵,封印解除!${profile.nickname}发现自己竟然是百年难遇的${profile.mbti}系元素掌控者。`,
explosion: `暗黑势力降临城市,绝望蔓延。关键时刻,${profile.nickname}挺身而出,爆发出了${peakEvent}般耀眼的光芒,一击必杀,守护了心中的"${theme}"。`,
ending: `成为了传说中的守护神,${profile.nickname}站在云端俯瞰大地。${profile.futureVision || '和平'}的景象映入眼帘,传奇才刚刚开始。`
}
};
const t = templates[requirements.style] || templates.career;
return {
id,
createdAt: new Date().toISOString(),
title: requirements.theme.substring(0, 10) + (requirements.style === 'fantasy' ? '·觉醒篇' : requirements.style === 'love' ? '·情缘篇' : '·逆袭篇'),
theme: requirements.theme,
style: requirements.style,
plot: t
};
},
/**
* Generate implementation path based on script.
*/
async generatePath(script, profile) {
await sleep(1500);
const hobby = (profile.hobbies && profile.hobbies.length > 0) ? profile.hobbies[0] : "关键技能";
return {
id: Date.now().toString(),
scriptId: script.id,
createdAt: new Date().toISOString(),
steps: [
{
phase: "第一阶段:沉淀与积累",
time: "第1-2个月",
content: `针对剧本中提到的"${hobby}",开始系统性学习。不要急于求成,利用${profile.mbti}擅长的深度思考,打好基础。`,
action: `购买两本高评分书籍或订阅一个专业专栏,每天坚持阅读学习45分钟。`,
resources: `专业书籍、在线MOOC平台`,
habit: `建立"日落复盘"机制,记录当天的收获。`
},
{
phase: "第二阶段:破局尝试",
time: "第3-6个月",
content: `正如剧本中"${script.plot.turning.substring(0, 10)}..."所描述的,寻找一个小型的实践机会。将知识转化为行动。`,
action: `完成一个最小可行性项目(Side Project)并在社交媒体分享。`,
resources: `GitHub/Behance/小红书等展示平台`,
habit: `每周连接一位同频的伙伴。`
},
{
phase: "第三阶段:爆发冲刺",
time: "第6-12个月",
content: `制造你的高光时刻。${profile.futureVision ? '向着"' + profile.futureVision + '"靠近' : '向着行业头部进发'}。主动承担高难度任务。`,
action: `参加一次行业比赛,或在团队中主导一个关键项目。`,
resources: `导师资源、行业峰会`,
habit: `冥想与可视化练习,强化自信心。`
},
{
phase: "第四阶段:愿景显化",
time: "1年后",
content: `将能力转化为影响力,实现"${script.theme}"。保持谦逊,同时不吝啬展示自己的光芒。`,
action: `整理你的方法论,开设分享会或撰写系列文章。`,
resources: `个人品牌渠道`,
habit: `终身学习,保持空杯心态。`
}
]
};
}
};
+200
View File
@@ -0,0 +1,200 @@
/**
* Generative Audio Engine
* Uses Web Audio API to create procedural healing music (Piano + Nature)
*/
import { Store } from './store.js';
export const AudioEngine = {
ctx: null,
masterGain: null,
isPlaying: false,
nextNoteTime: 0,
reverbNode: null,
natureGain: null,
timerID: null,
scale: [
261.63, 293.66, 329.63, 392.00, 440.00, // C4-A4
523.25, 587.33, 659.25, 783.99, 880.00 // C5-A5
],
async init() {
if (this.ctx) return;
const AudioContext = window.AudioContext || window.webkitAudioContext;
this.ctx = new AudioContext();
// Master Gain
this.masterGain = this.ctx.createGain();
this.masterGain.gain.value = 0.4; // Initial volume
this.masterGain.connect(this.ctx.destination);
// Reverb
this.reverbNode = this.ctx.createConvolver();
this.reverbNode.buffer = await this.generateImpulseResponse();
this.reverbNode.connect(this.masterGain);
// Nature Sound
this.startNatureSound();
},
toggle() {
if (!this.ctx) this.init();
this.isPlaying = !this.isPlaying;
// Resume context if suspended (browser policy)
if (this.ctx.state === 'suspended') {
this.ctx.resume();
}
if (this.isPlaying) {
this.scheduleNote();
// Fade in
this.masterGain.gain.setTargetAtTime(0.4, this.ctx.currentTime, 1);
} else {
// Fade out
this.masterGain.gain.setTargetAtTime(0, this.ctx.currentTime, 0.5);
// Stop scheduling
if (this.timerID) cancelAnimationFrame(this.timerID);
}
// Persist state
const data = Store.get();
data.audioMuted = !this.isPlaying;
Store.save(data);
return this.isPlaying;
},
playNote(freq, time) {
if (!this.isPlaying) return;
const osc = this.ctx.createOscillator();
const gain = this.ctx.createGain();
const filter = this.ctx.createBiquadFilter();
// Oscillator
osc.type = 'triangle';
osc.frequency.value = freq;
// Filter (Lowpass)
filter.type = 'lowpass';
filter.frequency.value = 800 + Math.random() * 400;
// Envelope
gain.gain.setValueAtTime(0, time);
gain.gain.linearRampToValueAtTime(0.1 + Math.random() * 0.1, time + 0.05 + Math.random() * 0.05); // Attack
gain.gain.exponentialRampToValueAtTime(0.001, time + 3 + Math.random() * 2); // Long Decay
osc.connect(filter);
filter.connect(gain);
gain.connect(this.masterGain); // Dry
gain.connect(this.reverbNode); // Wet
osc.start(time);
osc.stop(time + 6);
},
scheduleNote() {
if (!this.isPlaying) return;
const secondsPerBeat = 2;
const now = this.ctx.currentTime;
if (this.nextNoteTime < now) {
this.nextNoteTime = now + 0.5;
}
// Lookahead: schedule notes for the next 1.5 seconds
while (this.nextNoteTime < now + 1.5) {
// Random chance to play a note
if (Math.random() > 0.3) {
const note = this.scale[Math.floor(Math.random() * this.scale.length)];
this.playNote(note, this.nextNoteTime + (Math.random() * 0.1));
// Random harmony
if (Math.random() > 0.7) {
const harmonyIndex = (this.scale.indexOf(note) + 2) % this.scale.length;
this.playNote(this.scale[harmonyIndex], this.nextNoteTime + (Math.random() * 0.05));
}
}
this.nextNoteTime += (Math.random() * 2 + 1);
}
// Loop
this.timerID = requestAnimationFrame(this.scheduleNote.bind(this));
},
startNatureSound() {
const bufferSize = 2 * this.ctx.sampleRate;
const buffer = this.ctx.createBuffer(1, bufferSize, this.ctx.sampleRate);
const output = buffer.getChannelData(0);
// Pink Noise Generation
let b0, b1, b2, b3, b4, b5, b6;
b0 = b1 = b2 = b3 = b4 = b5 = b6 = 0.0;
for (let i = 0; i < bufferSize; i++) {
const white = Math.random() * 2 - 1;
b0 = 0.99886 * b0 + white * 0.0555179;
b1 = 0.99332 * b1 + white * 0.0750759;
b2 = 0.96900 * b2 + white * 0.1538520;
b3 = 0.86650 * b3 + white * 0.3104856;
b4 = 0.55000 * b4 + white * 0.5329522;
b5 = -0.7616 * b5 - white * 0.0168980;
output[i] = b0 + b1 + b2 + b3 + b4 + b5 + b6 + white * 0.5362;
output[i] *= 0.11; // Lower volume
b6 = white * 0.115926;
}
const noise = this.ctx.createBufferSource();
noise.buffer = buffer;
noise.loop = true;
// Filter (Lowpass modulated by LFO)
const filter = this.ctx.createBiquadFilter();
filter.type = 'lowpass';
filter.frequency.value = 400;
// LFO
const lfo = this.ctx.createOscillator();
lfo.type = 'sine';
lfo.frequency.value = 0.1; // Slow wave
const lfoGain = this.ctx.createGain();
lfoGain.gain.value = 300; // Modulate by +/- 300Hz
lfo.connect(lfoGain);
lfoGain.connect(filter.frequency);
this.natureGain = this.ctx.createGain();
this.natureGain.gain.value = 0.15; // Background level
noise.connect(filter);
filter.connect(this.natureGain);
this.natureGain.connect(this.masterGain);
noise.start();
lfo.start();
},
async generateImpulseResponse() {
const duration = 2.5;
const rate = this.ctx.sampleRate;
const length = rate * duration;
const impulse = this.ctx.createBuffer(2, length, rate);
const left = impulse.getChannelData(0);
const right = impulse.getChannelData(1);
for (let i = 0; i < length; i++) {
// Exponential decay
const factor = 1 - (i / length);
const decay = Math.pow(factor, 3);
left[i] = (Math.random() * 2 - 1) * decay;
right[i] = (Math.random() * 2 - 1) * decay;
}
return impulse;
}
};
+39
View File
@@ -0,0 +1,39 @@
import axios from 'axios';
const request = axios.create({
baseURL: '/api', // Adjust if needed, usually proxied in vite.config.js
timeout: 10000,
});
// Request interceptor
request.interceptors.request.use(
(config) => {
const token = localStorage.getItem('token');
if (token) {
config.headers['Authorization'] = `Bearer ${token}`;
}
return config;
},
(error) => {
return Promise.reject(error);
}
);
// Response interceptor
request.interceptors.response.use(
(response) => {
return response.data;
},
(error) => {
if (error.response) {
if (error.response.status === 401) {
// Token expired or invalid
localStorage.removeItem('token');
window.location.reload(); // Or dispatch an event to clear state
}
}
return Promise.reject(error);
}
);
export default request;
+113
View File
@@ -0,0 +1,113 @@
/**
* Data Management Module
* Handles persistence and data structure for Life Trajectory
*/
const STORAGE_KEY = 'lifeTrajectory_v3_data';
const DEFAULT_STATE = {
onboardingComplete: false,
audioMuted: true, // Default to muted
userProfile: {
nickname: "",
gender: "secret",
zodiac: "",
mbti: "",
hobbies: [],
history: {
childhood: { date: "", content: "" },
peak: { date: "", content: "" },
valley: { date: "", content: "" }
},
futureVision: ""
},
lifeTimeline: [],
generatedScripts: [],
paths: []
};
export const Store = {
get() {
const data = localStorage.getItem(STORAGE_KEY);
if (!data) return JSON.parse(JSON.stringify(DEFAULT_STATE));
try {
const parsed = JSON.parse(data);
return {
...DEFAULT_STATE,
...parsed,
userProfile: { ...DEFAULT_STATE.userProfile, ...parsed.userProfile }
};
} catch (e) {
console.error("Data corruption detected, resetting store.");
return DEFAULT_STATE;
}
},
save(data) {
try {
localStorage.setItem(STORAGE_KEY, JSON.stringify(data));
window.dispatchEvent(new CustomEvent('store-updated'));
} catch (e) {
console.error("LocalStorage save failed (quota exceeded?)", e);
alert("存储空间不足,部分数据可能无法保存。");
}
},
reset() {
localStorage.removeItem(STORAGE_KEY);
window.location.reload();
},
updateProfile(updates) {
const data = this.get();
data.userProfile = { ...data.userProfile, ...updates };
this.save(data);
},
completeOnboarding() {
const data = this.get();
data.onboardingComplete = true;
this.save(data);
},
addEvent(event) {
const data = this.get();
data.lifeTimeline.unshift(event);
this.save(data);
},
addScript(script) {
const data = this.get();
data.generatedScripts.unshift(script);
this.save(data);
},
deleteScript(id) {
const data = this.get();
data.generatedScripts = data.generatedScripts.filter(s => s.id !== id);
data.paths = data.paths.filter(p => p.scriptId !== id);
this.save(data);
},
addPath(path) {
const data = this.get();
data.paths = data.paths.filter(p => p.scriptId !== path.scriptId);
data.paths.push(path);
this.save(data);
},
updatePath(id, updates) {
const data = this.get();
const index = data.paths.findIndex(p => p.id === id);
if (index !== -1) {
data.paths[index] = { ...data.paths[index], ...updates };
this.save(data);
}
},
deletePath(id) {
const data = this.get();
data.paths = data.paths.filter(p => p.id !== id);
this.save(data);
}
};
+16
View File
@@ -0,0 +1,16 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), tailwindcss()],
server: {
proxy: {
'/api': {
target: 'http://localhost:19089',
changeOrigin: true,
}
}
}
})