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