Skip to content

Commit

Permalink
[*] 修改 auth 的路由,修复 sidebar 展示的逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Sep 18, 2024
1 parent 2ac181f commit 47c8704
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ setInterval(async () => {
if (rs.status === 401) {
sendWarningMessage('登录过期或未登录,请重新登录后台!')
logout()
router.push('/login')
router.push('/auth/login')
}
}
}, 10000)
Expand Down
6 changes: 3 additions & 3 deletions src/components/GuestSideBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,19 @@ const menuOptions = [
icon: renderIcon(LogInOutline)
},
{
path: '/login',
path: '/auth/login',
label: '登录',
key: 'Login',
icon: renderIcon(LogInOutline)
},
{
path: '/register',
path: '/auth/register',
label: '注册',
key: 'Register',
icon: renderIcon(MailOpenOutline)
},
{
path: '/reset_password',
path: '/auth/resetPassword',
label: '重置密码',
key: 'ResetPassword',
icon: renderIcon(PlanetOutline)
Expand Down
33 changes: 25 additions & 8 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,41 @@ const routes = [
component: () => import('@views/SignView.vue')
},
{
path: '/login',
path: '/auth/login',
name: 'Login',
meta: {
title: '登录',
keepAlive: true,
autoRedirectLogined: true
autoRedirectLogined: true,
sidebar: {
guest: true
}
},
component: () => import('@views/auth/LoginView.vue')
},
{
path: '/register',
path: '/auth/register',
name: 'Register',
meta: {
title: '注册',
keepAlive: true,
autoRedirectLogined: true
autoRedirectLogined: true,
sidebar: {
guest: true
}
},
component: () => import('@views/auth/RegisterView.vue')
},
{
path: '/reset_password',
path: '/auth/resetPassword',
name: 'ResetPassword',
meta: {
title: '重置密码',
keepAlive: true,
autoRedirectLogined: true
autoRedirectLogined: true,
sidebar: {
guest: true
}
},
component: () => import('@views/auth/ResetPasswordView.vue')
},
Expand Down Expand Up @@ -214,8 +223,16 @@ router.afterEach((to) => {
changeMainSideBarShow(true)
changeShowGuestSideBar(false)
} else {
changeMainSideBarShow(false)
changeShowGuestSideBar(false)
if (to.meta.sidebar?.guest) {
changeShowGuestSideBar(true)
changeMainSideBarShow(false)
} else if (to.meta.sidebar?.main) {
changeShowGuestSideBar(false)
changeMainSideBarShow(true)
} else {
changeShowGuestSideBar(false)
changeMainSideBarShow(false)
}
}

if (userData.getters.get_token) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,5 @@ export function getProxies(username, token) {

export function logout() {
userData.commit('delete_user_info')
router.push('/login')
router.push('/auth/login')
}
2 changes: 1 addition & 1 deletion src/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ instance.interceptors.response.use(
// 在登录成功后返回当前页面,这一步需要在登录页操作。
case 401:
router.replace({
path: '/login',
path: '/auth/login',
query: {
redirect: router.currentRoute.fullPath
}
Expand Down
8 changes: 4 additions & 4 deletions src/views/auth/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ if (code !== null) {
rs = await api.v2.oauth.qq.loginByCode(code)
} catch (e) {
sendErrorMessage('登录失败: ' + e)
router.push('/login')
router.push('/auth/login')
}
if (!rs) return
if (rs.status === 200) {
Expand All @@ -117,7 +117,7 @@ if (token !== null) {
rs = await api.v2.oauth.loginByToken(token)
} catch (e) {
sendErrorMessage('登录失败: ' + e)
router.push('/login')
router.push('/auth/login')
}
if (!rs) return
if (rs.status === 200) {
Expand All @@ -130,7 +130,7 @@ if (token !== null) {
}
function goRegister() {
router.push('/register')
router.push('/auth/register')
}
// LoCyan OAuth 2.0
Expand All @@ -139,7 +139,7 @@ function oauthLogin() {
window.location.href =
'https://api-v2.locyanfrp.cn/api/v2/oauth/authorize?redirectUrl=http://' +
window.location.host +
'/login'
'/auth/login'
}
// 登录
Expand Down
4 changes: 2 additions & 2 deletions src/views/auth/RegisterView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const verify = ref({
})
function goLogin() {
router.push('/login')
router.push('/auth/login')
}
async function sendCode() {
Expand Down Expand Up @@ -121,7 +121,7 @@ async function register() {
// const rs = post('https://api.locyanfrp.cn/User/DoReg', model.value)
if (rs.status === 200) {
message.success(rs.message)
router.push('/login')
router.push('/auth/login')
} else {
message.error(rs.message)
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/auth/ResetPasswordView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ if (code !== null) {
}
function goLogin() {
router.push('/login')
router.push('/auth/login')
}
async function doResetRequest() {
Expand Down

0 comments on commit 47c8704

Please sign in to comment.