Initial Commit

This commit is contained in:
chenglijuan
2026-04-18 22:15:11 +08:00
commit 9de2bdee2e
25 changed files with 1465 additions and 0 deletions
+45
View File
@@ -0,0 +1,45 @@
// app.js
App({
onLaunch() {
if (!wx.cloud) {
console.error('请使用 2.2.3 或以上的基础库以使用云能力')
} else {
wx.cloud.init({
traceUser: true
})
}
// 自动静默登录:调用云函数获取 openid
this.silentLogin()
},
silentLogin() {
wx.cloud.callFunction({
name: 'login',
data: {},
success: (res) => {
const openid = res.result.openid
const userInfo = res.result.userInfo || {}
userInfo.openid = openid
this.globalData.userInfo = userInfo
this.globalData.isLoggedIn = true
wx.setStorageSync('userInfo', userInfo)
// 通知当前页面刷新
if (this.loginReadyCallback) {
this.loginReadyCallback(userInfo)
}
},
fail: (err) => {
console.error('静默登录失败', err)
this.globalData.isLoggedIn = false
}
})
},
globalData: {
userInfo: null,
isLoggedIn: false
}
})