158 lines
3.4 KiB
Vue
158 lines
3.4 KiB
Vue
<template>
|
|
<view class="page">
|
|
<view class="info">
|
|
<view v-for="(item, index) in userInfoSettings" :key="index" class="info-row">
|
|
<view class="label">{{ item.label }}</view>
|
|
<view class="value">{{ item.value }} ></view>
|
|
</view>
|
|
</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 {
|
|
userInfoSettings: [
|
|
{
|
|
label: '头像',
|
|
value: '', // 实际项目中这里可能是图片URL
|
|
icon: '灰色圆形图标', // 描述性文字,实际可用图片路径替换
|
|
type: 'avatar',
|
|
},
|
|
{
|
|
label: '昵称',
|
|
value: '昵称', // 默认占位文字,实际应为用户昵称
|
|
type: 'nickname',
|
|
},
|
|
],
|
|
}
|
|
},
|
|
methods: {
|
|
// 退出登录处理
|
|
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>
|
|
|
|
<style lang="scss" scoped>
|
|
.page {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
min-height: 100vh;
|
|
background: #f3f5f6;
|
|
|
|
.info {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
width: 710rpx;
|
|
background: #ffffff;
|
|
|
|
border-radius: 10px;
|
|
opacity: 1;
|
|
margin: 30rpx auto;
|
|
|
|
//border: solid 1rpx red;
|
|
|
|
.info-row {
|
|
display: flex;
|
|
border-bottom: solid 1rpx #d8d8d8;
|
|
width: 646rpx;
|
|
padding: 40rpx 0;
|
|
margin: 0 34rpx;
|
|
|
|
.label {
|
|
flex: 1;
|
|
color: #3d3d3d;
|
|
font-size: 16px;
|
|
}
|
|
|
|
.value {
|
|
flex: 1;
|
|
text-align: right;
|
|
color: #bbbbbb;
|
|
font-size: 16px;
|
|
}
|
|
}
|
|
}
|
|
|
|
.log-out {
|
|
margin-top: 866rpx;
|
|
text-align: center;
|
|
line-height: 98rpx;
|
|
color: #f15a04;
|
|
font-size: 16px;
|
|
font-weight: 500;
|
|
width: 710rpx;
|
|
height: 98rpx;
|
|
background: #ffffff;
|
|
border-radius: 24.5px;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
|
|
&:active {
|
|
background: #f5f5f5;
|
|
transform: scale(0.98);
|
|
}
|
|
}
|
|
}
|
|
</style>
|