添加店务小程序退出登录
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
const { BRAND_CONFIG } = require('../../utils/config')
|
const { BRAND_CONFIG } = require('../../utils/config')
|
||||||
const userApi = require('../../api/user')
|
const userApi = require('../../api/user')
|
||||||
|
const authApi = require('../../api/auth')
|
||||||
const auth = require('../../utils/auth')
|
const auth = require('../../utils/auth')
|
||||||
const { chooseImageFilePath, uploadProfileImage } = require('../../utils/upload')
|
const { chooseImageFilePath, uploadProfileImage } = require('../../utils/upload')
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ Page({
|
|||||||
editModalVisible: false,
|
editModalVisible: false,
|
||||||
profileSaving: false,
|
profileSaving: false,
|
||||||
avatarUploading: false,
|
avatarUploading: false,
|
||||||
|
loggingOut: false,
|
||||||
profileForm: {
|
profileForm: {
|
||||||
nickname: '',
|
nickname: '',
|
||||||
avatar: '',
|
avatar: '',
|
||||||
@@ -32,7 +34,8 @@ Page({
|
|||||||
{ title: '店铺设置', url: '/pages/shop-settings/index' },
|
{ title: '店铺设置', url: '/pages/shop-settings/index' },
|
||||||
{ title: '数据导出', url: '/pages/export/index' },
|
{ title: '数据导出', url: '/pages/export/index' },
|
||||||
{ title: '修改密码', url: '/pages/password/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()
|
this.openEditProfile()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (action === 'logout') {
|
||||||
|
this.confirmLogout()
|
||||||
|
return
|
||||||
|
}
|
||||||
wx.navigateTo({ url: event.currentTarget.dataset.url })
|
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() {
|
async loadProfile() {
|
||||||
try {
|
try {
|
||||||
const profile = await userApi.info()
|
const profile = await userApi.info()
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="section menu-list card">
|
<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">
|
<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.title}}</text>
|
<text>{{item.action === 'logout' && loggingOut ? '退出中...' : item.title}}</text>
|
||||||
<text class="arrow">›</text>
|
<text wx:if="{{item.action !== 'logout'}}" class="arrow">›</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
|||||||
@@ -81,6 +81,11 @@
|
|||||||
border-bottom: 0;
|
border-bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.danger-row {
|
||||||
|
justify-content: center;
|
||||||
|
color: #c96868;
|
||||||
|
}
|
||||||
|
|
||||||
.arrow {
|
.arrow {
|
||||||
color: #b0a79e;
|
color: #b0a79e;
|
||||||
font-size: 44rpx;
|
font-size: 44rpx;
|
||||||
|
|||||||
Reference in New Issue
Block a user