设置页面退出登录实现

This commit is contained in:
WindowBird 2025-08-19 16:01:22 +08:00
parent 84dc8e3399
commit 37fb325872
2 changed files with 67 additions and 13 deletions

View File

@ -33,7 +33,7 @@ export function userLogin(data) {
* @returns {Promise} 返回登出结果
*/
export function userLogout() {
return post('/user/logout')
return post('/logout')
}
/**

View File

@ -3,14 +3,17 @@
<view class="info">
<view v-for="(item, index) in userInfoSettings" :key="index" class="info-row">
<view class="label">{{ item.label }}</view>
<view class="value" @click="goChangePhone">{{ item.value }} ></view>
<view class="value">{{ item.value }} ></view>
</view>
</view>
<view class="log-out">退出登录</view>
<view class="log-out" @click="handleLogout">退出登录</view>
</view>
</template>
<script>
import { userLogout } from '@/api/auth/auth.js'
import { clearToken } from '@/utils/request.js'
export default {
data() {
return {
@ -26,20 +29,64 @@ export default {
value: '昵称', //
type: 'nickname',
},
{
label: '手机号',
value: '158****5964', //
type: 'phone',
},
],
}
},
methods: {
goChangePhone() {
uni.navigateTo({
url: '/pages/securityVerification/securityVerification',
})
},
// 退
async handleLogout() {
try {
//
const res = await new Promise((resolve, reject) => {
uni.showModal({
title: '确认退出',
content: '确定要退出登录吗?',
confirmText: '确定',
cancelText: '取消',
success: resolve,
fail: reject
})
})
if (!res.confirm) {
return
}
// 退API
const response = await userLogout()
if (response.code === 200) {
// token
clearToken()
//
uni.removeStorageSync('userInfo')
//
uni.showToast({
title: '退出成功',
icon: 'success',
duration: 1500
})
//
setTimeout(() => {
uni.reLaunch({
url: '/pages/login/login'
})
}, 1500)
} else {
throw new Error(response.msg || '退出失败')
}
} catch (error) {
console.error('退出登录失败:', error)
uni.showToast({
title: error.message || '退出失败',
icon: 'none',
duration: 2000
})
}
}
},
}
</script>
@ -98,6 +145,13 @@ export default {
height: 98rpx;
background: #ffffff;
border-radius: 24.5px;
cursor: pointer;
transition: all 0.3s ease;
&:active {
background: #f5f5f5;
transform: scale(0.98);
}
}
}
</style>