登录注册完成
This commit is contained in:
parent
4671a6d390
commit
26712f144d
|
@ -6,7 +6,7 @@
|
|||
<Fold v-else />
|
||||
</el-icon>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="right">
|
||||
<el-dropdown trigger="click" @command="handleCommand">
|
||||
<div class="user-info">
|
||||
|
@ -32,7 +32,7 @@
|
|||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, inject } from 'vue'
|
||||
import { ref, inject, onMounted } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import { ElMessageBox } from 'element-plus'
|
||||
import { User, Setting, SwitchButton, Expand, Fold } from '@element-plus/icons-vue'
|
||||
|
@ -46,6 +46,9 @@ const userInfo = ref({
|
|||
avatar: 'https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png'
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
const toggleSidebar = () => {
|
||||
isCollapsed.value = !isCollapsed.value
|
||||
}
|
||||
|
@ -71,11 +74,11 @@ const handleLogout = async () => {
|
|||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
|
||||
|
||||
// 清除本地存储的用户信息和token
|
||||
localStorage.removeItem('token')
|
||||
localStorage.removeItem('userInfo')
|
||||
|
||||
|
||||
// 跳转到登录页
|
||||
router.push('/login')
|
||||
} catch {
|
||||
|
@ -123,4 +126,4 @@ const handleLogout = async () => {
|
|||
align-items: center;
|
||||
gap: 20px;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
|
|
@ -19,7 +19,7 @@ service.interceptors.request.use(
|
|||
if (token) {
|
||||
config.headers = {
|
||||
...config.headers,
|
||||
Authorization: token
|
||||
Authorization: `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
return config
|
||||
|
@ -55,6 +55,7 @@ service.interceptors.response.use(
|
|||
|
||||
// 处理 HTTP 错误
|
||||
if (error.response) {
|
||||
console.log(error.response)
|
||||
const { status } = error.response
|
||||
switch (status) {
|
||||
case 400:
|
||||
|
|
|
@ -316,9 +316,9 @@ const handleLogin = async () => {
|
|||
console.log(token)
|
||||
userStore.setToken(token)
|
||||
const res = await userApi.getCurrentUser()
|
||||
//console.log(res)
|
||||
console.log(res)
|
||||
ElMessage.success('登录成功')
|
||||
//router.push('/')
|
||||
router.push('/')
|
||||
} catch (error) {
|
||||
console.error('登录失败:', error)
|
||||
} finally {
|
||||
|
|
Loading…
Reference in New Issue