Files
inchstep/miniapp/pages/profile/index/index.js
T
zeronline b01a5f91c3
CI / Server (Go) (push) Has been cancelled
CI / Web (Next.js) (push) Has been cancelled
CI / Mobile (React Native) (push) Has been cancelled
CI / Admin (React) (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
提交修改
2026-06-29 16:49:54 +08:00

34 lines
1.0 KiB
JavaScript

const api = require('../../../services/api')
const app = getApp()
Page({
data: { user: null, themeMode: 'light' },
onShow() {
if (!app.globalData.token) { wx.reLaunch({ url: '/pages/login/index' }); return }
this.setData({ themeMode: app.globalData.themeMode })
this.loadProfile()
},
async loadProfile() {
try {
const user = await api.get('/api/users/profile')
app.globalData.user = user
this.setData({ user })
} catch(e) {}
},
goEdit() { wx.navigateTo({ url: '/pages/profile/edit/index' }) },
goAchievements() { wx.navigateTo({ url: '/pages/achievements/index' }) },
onThemeToggle(e) {
app.toggleTheme()
this.setData({ themeMode: app.globalData.themeMode })
},
onLogout() {
wx.showModal({ title: '确认退出', content: '确定要退出登录吗?', success: (res) => {
if (res.confirm) {
app.globalData.token = ''; app.globalData.user = null
wx.removeStorageSync('token'); wx.removeStorageSync('user')
wx.reLaunch({ url: '/pages/login/index' })
}
}})
},
})