2026-04-16 11:25:29 +08:00
|
|
|
|
App({
|
|
|
|
|
|
onLaunch() {
|
|
|
|
|
|
// 初始化音效上下文
|
|
|
|
|
|
this.globalData.audioContexts = {
|
2026-04-17 15:34:51 +08:00
|
|
|
|
flip: wx.createInnerAudioContext(), // 翻页声
|
|
|
|
|
|
success: wx.createInnerAudioContext(), // 收藏成功
|
|
|
|
|
|
inkDrop: wx.createInnerAudioContext(), // 水滴声
|
|
|
|
|
|
swipe: wx.createInnerAudioContext() // 滑动切换
|
2026-04-16 11:25:29 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2026-04-18 16:56:31 +08:00
|
|
|
|
// 预设音效资源(本地文件)
|
2026-04-17 15:34:51 +08:00
|
|
|
|
// 翻页声 - 纸张摩擦
|
2026-04-18 16:56:31 +08:00
|
|
|
|
this.globalData.audioContexts.flip.src = '/assets/audio/flip.mp3';
|
2026-04-17 15:34:51 +08:00
|
|
|
|
// 收藏成功 - 清脆铃声
|
2026-04-18 16:56:31 +08:00
|
|
|
|
this.globalData.audioContexts.success.src = '/assets/audio/success.mp3';
|
2026-04-17 15:34:51 +08:00
|
|
|
|
// 水滴声 - 水墨滴落
|
2026-04-18 16:56:31 +08:00
|
|
|
|
this.globalData.audioContexts.inkDrop.src = '/assets/audio/inkDrop.mp3';
|
2026-04-17 15:34:51 +08:00
|
|
|
|
// 滑动声
|
2026-04-18 16:56:31 +08:00
|
|
|
|
this.globalData.audioContexts.swipe.src = '/assets/audio/swipe.mp3';
|
|
|
|
|
|
|
|
|
|
|
|
// 微信登录获取 openid
|
|
|
|
|
|
this.wxLogin();
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 微信登录
|
|
|
|
|
|
wxLogin() {
|
|
|
|
|
|
wx.login({
|
|
|
|
|
|
success: (res) => {
|
|
|
|
|
|
if (res.code) {
|
|
|
|
|
|
// 发送 code 到后端换取 openid
|
|
|
|
|
|
wx.request({
|
|
|
|
|
|
url: `${this.globalData.apiBaseUrl}/api/auth/login`,
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
data: { code: res.code },
|
|
|
|
|
|
success: (response) => {
|
|
|
|
|
|
if (response.data && response.data.success) {
|
|
|
|
|
|
this.globalData.openid = response.data.openid;
|
|
|
|
|
|
console.log('登录成功,openid:', response.data.openid);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.error('登录失败:', response.data);
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
fail: (err) => {
|
|
|
|
|
|
console.error('登录请求失败:', err);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.error('登录失败:', res.errMsg);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
// 获取 openid(如果还未获取到则返回 null)
|
|
|
|
|
|
getOpenid() {
|
|
|
|
|
|
return this.globalData.openid;
|
2026-04-16 11:25:29 +08:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
playAudio(type) {
|
|
|
|
|
|
const ctx = this.globalData.audioContexts[type];
|
|
|
|
|
|
if (ctx) {
|
|
|
|
|
|
ctx.stop();
|
2026-04-18 16:56:31 +08:00
|
|
|
|
try {
|
|
|
|
|
|
ctx.play();
|
|
|
|
|
|
} catch (err) {
|
2026-04-17 15:34:51 +08:00
|
|
|
|
console.log('音效播放失败:', err);
|
2026-04-18 16:56:31 +08:00
|
|
|
|
}
|
2026-04-16 11:25:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
globalData: {
|
2026-04-17 15:34:51 +08:00
|
|
|
|
audioContexts: {},
|
2026-04-18 16:56:31 +08:00
|
|
|
|
openid: null,
|
2026-04-17 15:34:51 +08:00
|
|
|
|
// API 基础地址 - 修改这里即可切换环境
|
2026-04-18 16:56:31 +08:00
|
|
|
|
apiBaseUrl: 'http://localhost:8080'
|
|
|
|
|
|
// apiBaseUrl: 'https://feast.yidaima.cn/jsu'
|
2026-04-17 15:34:51 +08:00
|
|
|
|
// 生产环境:'https://api.yourdomain.com'
|
2026-04-16 11:25:29 +08:00
|
|
|
|
}
|
2026-04-17 15:34:51 +08:00
|
|
|
|
});
|