设置页面退出登录实现
This commit is contained in:
parent
84dc8e3399
commit
37fb325872
|
|
@ -33,7 +33,7 @@ export function userLogin(data) {
|
||||||
* @returns {Promise} 返回登出结果
|
* @returns {Promise} 返回登出结果
|
||||||
*/
|
*/
|
||||||
export function userLogout() {
|
export function userLogout() {
|
||||||
return post('/user/logout')
|
return post('/logout')
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,17 @@
|
||||||
<view class="info">
|
<view class="info">
|
||||||
<view v-for="(item, index) in userInfoSettings" :key="index" class="info-row">
|
<view v-for="(item, index) in userInfoSettings" :key="index" class="info-row">
|
||||||
<view class="label">{{ item.label }}</view>
|
<view class="label">{{ item.label }}</view>
|
||||||
<view class="value" @click="goChangePhone">{{ item.value }} ></view>
|
<view class="value">{{ item.value }} ></view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="log-out">退出登录</view>
|
<view class="log-out" @click="handleLogout">退出登录</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { userLogout } from '@/api/auth/auth.js'
|
||||||
|
import { clearToken } from '@/utils/request.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
|
@ -26,20 +29,64 @@ export default {
|
||||||
value: '昵称', // 默认占位文字,实际应为用户昵称
|
value: '昵称', // 默认占位文字,实际应为用户昵称
|
||||||
type: 'nickname',
|
type: 'nickname',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
label: '手机号',
|
|
||||||
value: '158****5964', // 脱敏后的手机号
|
|
||||||
type: 'phone',
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
goChangePhone() {
|
// 退出登录处理
|
||||||
uni.navigateTo({
|
async handleLogout() {
|
||||||
url: '/pages/securityVerification/securityVerification',
|
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>
|
</script>
|
||||||
|
|
@ -98,6 +145,13 @@ export default {
|
||||||
height: 98rpx;
|
height: 98rpx;
|
||||||
background: #ffffff;
|
background: #ffffff;
|
||||||
border-radius: 24.5px;
|
border-radius: 24.5px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.3s ease;
|
||||||
|
|
||||||
|
&:active {
|
||||||
|
background: #f5f5f5;
|
||||||
|
transform: scale(0.98);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user