Files
ChowBox/miniapp/components/box-animation/box-animation.js
王鹏 802b4ba229 fix: 修复 VoiceController Map.of 兼容性 + ExploreController 参数不匹配
- VoiceController: Map.of() -> Collections.singletonMap() 兼容 Java 8
- ExploreController: 补齐 takeoutService.roll() 缺失的 taste/priceRange/allergies 参数

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-08 20:02:27 +08:00

106 lines
2.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Component({
properties: {
show: { type: Boolean, value: false },
boxType: { type: String, value: 'takeout' },
dataReady: { type: Boolean, value: false }
},
data: {
act: 0,
boxEmoji: '🎁',
sparkEmoji: '✨',
confettiColors: [],
_pendingAct3: false
},
observers: {
'show': function(val) {
if (val) {
this.setData({ act: 0, _pendingAct3: false });
this.startAct1();
} else {
this.reset();
}
},
'dataReady': function(val) {
if (val && this.data._pendingAct3) {
this.playAct3();
}
},
'boxType': function(val) {
const config = this.getTypeConfig(val);
this.setData({
boxEmoji: config.boxEmoji,
sparkEmoji: config.sparkEmoji,
confettiColors: config.confettiColors
});
}
},
methods: {
getTypeConfig(type) {
const map = {
takeout: {
boxEmoji: '🛵',
sparkEmoji: '🛵',
confettiColors: ['#E8693B', '#FF8A5C', '#FFD54F', '#FFAB40',
'#FFCC80', '#E8693B', '#FF8A5C', '#FFD54F', '#FFAB40']
},
fridge: {
boxEmoji: '🥬',
sparkEmoji: '🥬',
confettiColors: ['#4CAF50', '#66BB6A', '#A5D6A7', '#81C784',
'#C8E6C9', '#4CAF50', '#66BB6A', '#A5D6A7', '#81C784']
},
explore: {
boxEmoji: '🍜',
sparkEmoji: '📍',
confettiColors: ['#7C3AED', '#9C27B0', '#CE93D8', '#BA68C8',
'#E1BEE7', '#7C3AED', '#9C27B0', '#CE93D8', '#BA68C8']
}
};
return map[type] || map.takeout;
},
/* ── Act 1: 光晕扩散 + 盒子震动 (0400ms) ── */
startAct1() {
wx.vibrateShort({ type: 'light' });
setTimeout(() => {
this.setData({ act: 1 });
}, 50);
// Act 2: 盒盖飞起 + 金光 + 白屏 (400ms)
setTimeout(() => {
wx.vibrateShort({ type: 'medium' });
this.setData({ act: 2 });
// 标记等待数据
this.setData({ _pendingAct3: true });
// 如果数据已就绪,立即进入 Act 3
if (this.data.dataReady) {
this.playAct3();
}
}, 400);
},
/* ── Act 3: 内容弹出 + 纸屑(数据就绪后触发) ── */
playAct3() {
this.setData({ _pendingAct3: false });
wx.vibrateLong();
setTimeout(() => {
this.setData({ act: 3 });
}, 150);
// 通知父页面动画完成
setTimeout(() => {
this.triggerEvent('done');
}, 2200);
},
reset() {
this.setData({ act: 0, _pendingAct3: false });
}
}
});