添加店务小程序退出登录

This commit is contained in:
2026-07-16 14:55:48 +08:00
parent 62a7684e79
commit d020d8b933
3 changed files with 54 additions and 4 deletions
+46 -1
View File
@@ -1,5 +1,6 @@
const { BRAND_CONFIG } = require('../../utils/config')
const userApi = require('../../api/user')
const authApi = require('../../api/auth')
const auth = require('../../utils/auth')
const { chooseImageFilePath, uploadProfileImage } = require('../../utils/upload')
@@ -20,6 +21,7 @@ Page({
editModalVisible: false,
profileSaving: false,
avatarUploading: false,
loggingOut: false,
profileForm: {
nickname: '',
avatar: '',
@@ -32,7 +34,8 @@ Page({
{ title: '店铺设置', url: '/pages/shop-settings/index' },
{ title: '数据导出', url: '/pages/export/index' },
{ title: '修改密码', url: '/pages/password/index' },
{ title: '关于系统', url: '/pages/about/index' }
{ title: '关于系统', url: '/pages/about/index' },
{ title: '退出登录', action: 'logout', danger: true }
]
},
@@ -58,9 +61,51 @@ Page({
this.openEditProfile()
return
}
if (action === 'logout') {
this.confirmLogout()
return
}
wx.navigateTo({ url: event.currentTarget.dataset.url })
},
confirmLogout() {
if (this.data.loggingOut) {
return
}
wx.showModal({
title: '退出登录',
content: '确认退出当前账号吗?',
confirmText: '退出',
confirmColor: '#d98d8d',
success: res => {
if (res.confirm) {
this.logout()
}
}
})
},
async logout() {
if (this.data.loggingOut) {
return
}
this.setData({ loggingOut: true })
try {
await authApi.logout()
const app = getApp()
if (app && typeof app.clearSession === 'function') {
app.clearSession()
} else {
auth.clearSession()
}
wx.reLaunch({ url: '/pages/login/index' })
} catch (error) {
wx.showToast({ title: error.message || '退出登录失败', icon: 'none' })
} finally {
this.setData({ loggingOut: false })
}
},
async loadProfile() {
try {
const profile = await userApi.info()
+3 -3
View File
@@ -11,9 +11,9 @@
</view>
<view class="section menu-list card">
<view wx:for="{{menus}}" wx:key="title" class="menu-row" data-url="{{item.url}}" data-action="{{item.action}}" bindtap="go">
<text>{{item.title}}</text>
<text class="arrow">›</text>
<view wx:for="{{menus}}" wx:key="title" class="menu-row {{item.danger ? 'danger-row' : ''}}" data-url="{{item.url}}" data-action="{{item.action}}" bindtap="go">
<text>{{item.action === 'logout' && loggingOut ? '退出中...' : item.title}}</text>
<text wx:if="{{item.action !== 'logout'}}" class="arrow">›</text>
</view>
</view>
+5
View File
@@ -81,6 +81,11 @@
border-bottom: 0;
}
.danger-row {
justify-content: center;
color: #c96868;
}
.arrow {
color: #b0a79e;
font-size: 44rpx;