diff --git a/JY-Salon-WeChat/pages/profile/index.js b/JY-Salon-WeChat/pages/profile/index.js index bb0799ab..a4e60c24 100644 --- a/JY-Salon-WeChat/pages/profile/index.js +++ b/JY-Salon-WeChat/pages/profile/index.js @@ -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() diff --git a/JY-Salon-WeChat/pages/profile/index.wxml b/JY-Salon-WeChat/pages/profile/index.wxml index dca10981..bd6a718f 100644 --- a/JY-Salon-WeChat/pages/profile/index.wxml +++ b/JY-Salon-WeChat/pages/profile/index.wxml @@ -11,9 +11,9 @@ - - {{item.title}} - › + + {{item.action === 'logout' && loggingOut ? '退出中...' : item.title}} + › diff --git a/JY-Salon-WeChat/pages/profile/index.wxss b/JY-Salon-WeChat/pages/profile/index.wxss index cef72e14..0919286f 100644 --- a/JY-Salon-WeChat/pages/profile/index.wxss +++ b/JY-Salon-WeChat/pages/profile/index.wxss @@ -81,6 +81,11 @@ border-bottom: 0; } +.danger-row { + justify-content: center; + color: #c96868; +} + .arrow { color: #b0a79e; font-size: 44rpx;