Files
mzltMpfqGS e4a087e67e init
2026-04-15 19:45:16 +08:00

107 lines
2.7 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.

// pages/user/user.js
// 用户中心逻辑处理
const app = getApp()
Page({
data: {
userInfo: null,
hasLogin: false,
menuList: [
{ id: 1, name: '我的文章', icon: 'icon-article', url: '/pages/my-article/my-article' },
{ id: 2, name: '我的收藏', icon: 'icon-favorite', url: '/pages/my-favorite/my-favorite' },
{ id: 3, name: '我的评论', icon: 'icon-comment', url: '/pages/my-comment/my-comment' },
{ id: 4, name: '浏览历史', icon: 'icon-history', url: '/pages/history/history' },
{ id: 5, name: '消息通知', icon: 'icon-notification', url: '/pages/notification/notification' },
{ id: 6, name: '意见反馈', icon: 'icon-feedback', url: '/pages/feedback/feedback' },
{ id: 7, name: '系统设置', icon: 'icon-settings', url: '/pages/settings/settings' }
],
stats: {
articleCount: 12,
favoriteCount: 45,
commentCount: 128
}
},
onLoad() {
this.checkLoginStatus()
},
onShow() {
this.checkLoginStatus()
},
// 检查登录状态
checkLoginStatus() {
const userInfo = wx.getStorageSync('userInfo')
this.setData({
userInfo: userInfo,
hasLogin: !!userInfo
})
},
// 跳转到登录页面
goToLogin() {
wx.navigateTo({
url: '/pages/login/login'
})
},
// 跳转到用户信息编辑页面
goToProfile() {
if (!this.data.hasLogin) {
this.goToLogin()
return
}
wx.navigateTo({
url: '/pages/profile/profile'
})
},
// 跳转到菜单页面
goToMenu(e) {
const url = e.currentTarget.dataset.url
if (!this.data.hasLogin && url !== '/pages/settings/settings') {
this.goToLogin()
return
}
wx.navigateTo({ url })
},
// 退出登录
handleLogout() {
wx.showModal({
title: '提示',
content: '确定要退出登录吗?',
success: (res) => {
if (res.confirm) {
wx.removeStorageSync('userInfo')
wx.removeStorageSync('token')
this.setData({
userInfo: null,
hasLogin: false
})
wx.showToast({
title: '已退出登录',
icon: 'success'
})
}
}
})
},
// 预览图片
previewAvatar() {
if (!this.data.userInfo || !this.data.userInfo.avatar) return
wx.previewImage({
urls: [this.data.userInfo.avatar]
})
}
})
/**
* @联系作者16768118056
* @描述:(此项目非免费分享)源码百分百可用,搞定毕设不发愁,支持远程调试安装、二次开发、定制、讲解、文档类。
* @访问https://www.notmaker.com/detail/8326a897119d4542896c863a69d7bbe7/gtt20260415查看完整运行演示。
*/