Page({ data: { keyword: '', surname: '', activeMode: 'baby', isGenerating: false, modes: [ { key: 'baby', label: '宝宝' }, { key: 'persona', label: '人设' }, { key: 'classic', label: '拾遗' } ] }, onLoad() { // 页面加载时检查是否需要重置状态 }, onShow() { // 每次显示页面时重置生成状态 this.setData({ isGenerating: false }); }, // 选择模式 selectMode(e) { const mode = e.currentTarget.dataset.mode; this.setData({ activeMode: mode }); }, // 姓氏输入 onSurnameInput(e) { this.setData({ surname: e.detail.value }); }, // 关键词输入 onInput(e) { this.setData({ keyword: e.detail.value }); }, // 开始生成(带水墨动画) startGenerate() { const { keyword, surname, activeMode } = this.data; // 非空校验 if (!keyword.trim()) { const placeholderMap = { 'baby': '请输入期待', 'persona': '请输入人设', 'classic': '请输入关键词' }; wx.showToast({ title: placeholderMap[activeMode] || '请输入内容', icon: 'none' }); return; } // 宝宝模式需要姓氏 if (activeMode === 'baby' && !surname.trim()) { wx.showToast({ title: '请输入姓氏', icon: 'none' }); return; } // 触发水墨动画 this.setData({ isGenerating: true }); // 播放水滴声 getApp().playAudio('inkDrop'); // 触觉反馈 wx.vibrateShort({ type: 'light' }); // 延迟 1000ms 后跳转,确保仪式感完整 setTimeout(() => { // 构建跳转 URL let url = `/pages/index/index?keyword=${encodeURIComponent(keyword)}&mode=${activeMode}`; if (activeMode === 'baby' && surname) { url += `&surname=${encodeURIComponent(surname)}`; } wx.navigateTo({ url: url }); }, 1000); } });