Files
JianSu-Naming/miniprogram/app.js
王鹏 2c47fb8f65 feat: 完善见素起名小程序功能
- 添加收藏锦囊功能,支持查看和删除收藏
- 实现积分系统,每日赠送5次灵感次数
- 添加静心阅读功能,阅读15秒可获得额外次数
- 实现灵感广场,展示用户分享的名字
- 添加字源溯源组件,长按汉字查看详情
- 优化空状态和结语卡片样式统一
- 添加音频控制(静音/风铃/雨落/古琴/白噪音/森林/溪流)
- 优化名字生成逻辑,确保每次返回5个不重复名字
- 修复卡片翻转样式问题
- 移除首页动态提醒气泡
2026-04-18 16:56:31 +08:00

80 lines
2.3 KiB
JavaScript
Raw 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.

App({
onLaunch() {
// 初始化音效上下文
this.globalData.audioContexts = {
flip: wx.createInnerAudioContext(), // 翻页声
success: wx.createInnerAudioContext(), // 收藏成功
inkDrop: wx.createInnerAudioContext(), // 水滴声
swipe: wx.createInnerAudioContext() // 滑动切换
};
// 预设音效资源(本地文件)
// 翻页声 - 纸张摩擦
this.globalData.audioContexts.flip.src = '/assets/audio/flip.mp3';
// 收藏成功 - 清脆铃声
this.globalData.audioContexts.success.src = '/assets/audio/success.mp3';
// 水滴声 - 水墨滴落
this.globalData.audioContexts.inkDrop.src = '/assets/audio/inkDrop.mp3';
// 滑动声
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;
},
playAudio(type) {
const ctx = this.globalData.audioContexts[type];
if (ctx) {
ctx.stop();
try {
ctx.play();
} catch (err) {
console.log('音效播放失败:', err);
}
}
},
globalData: {
audioContexts: {},
openid: null,
// API 基础地址 - 修改这里即可切换环境
apiBaseUrl: 'http://localhost:8080'
// apiBaseUrl: 'https://feast.yidaima.cn/jsu'
// 生产环境:'https://api.yourdomain.com'
}
});