Skip to content

Commit

Permalink
[*] 登录后自动重定向首页到仪表板,使用 routeName 而不是路径重定向
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Oct 7, 2024
1 parent 2f6e27d commit d2796a3
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ setInterval(async () => {
if (userData.getters.get_token !== '') {
const valid = await fetchUserInfo()
if (!valid) {
router.push('/auth/login')
router.push({ name: 'Login' })
}
}
}, 10000)
Expand Down
2 changes: 1 addition & 1 deletion src/components/UserInfo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ function doLogOut() {
changeUserInfoShow(false)
logout()
sendSuccessMessage('您已登出,感谢您的使用!')
router.push('/auth/login')
router.push({ name: 'Login' })
}
async function changePassword() {
Expand Down
4 changes: 2 additions & 2 deletions src/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const routes = [
path: '/',
name: 'MainPage',
meta: {
title: '首页'
title: '首页',
},
component: () => import('@views/MainView.vue')
},
Expand Down Expand Up @@ -288,7 +288,7 @@ const router = createRouter({
scrollBehavior(to, from, savedPosition) {
return {
top: 0,
behavior: 'smooth',
behavior: 'smooth'
}
},
})
Expand Down
3 changes: 3 additions & 0 deletions src/views/MainView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@
</template>

<script setup>
import userData from '@/utils/stores/userData'
import router from '@router'
if (userData.getters.get_token) router.push({ name: 'Dashboard' })
const GoToDocs = () => {
window.open('https://docs.locyanfrp.cn')
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/NotFoundView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import userData from '@/utils/stores/userData/store'
style="margin-top: 10px"
@click="
() => {
if (userData.getters.get_token !== '') router.push('/dashboard')
if (userData.getters.get_token !== '') router.push({ name: 'Dashboard' })
else router.push('/')
}
"
Expand Down
6 changes: 1 addition & 5 deletions src/views/auth/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
</n-space>
<n-space justify="end">
<n-button type="primary" @click="login"> 登录</n-button>
<n-button ghost style="--n-border: none" type="primary" @click="goRegister">
<n-button ghost style="--n-border: none" type="primary" @click="() => router.push({ name: 'Register' })">
没有账户?去注册
</n-button>
</n-space>
Expand Down Expand Up @@ -96,10 +96,6 @@ if (redirect !== null) {
// })
// }
function goRegister() {
router.push('/auth/register')
}
// LoCyan OAuth 2.0
// There is no need
// function oauthLogin() {
Expand Down
8 changes: 2 additions & 6 deletions src/views/auth/RegisterView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<div style="display: flex; margin-bottom: 20px; justify-content: flex-end">
<n-space>
<n-button type="primary" @click="register" style="margin-right: 10px"> 注册 </n-button>
<n-button ghost type="primary" style="--n-border: none" @click="goLogin">
<n-button ghost type="primary" style="--n-border: none" @click="() => router.push({ name: 'Login' })">
已有账户?去登录
</n-button>
</n-space>
Expand Down Expand Up @@ -84,10 +84,6 @@ const verify = ref({
msg: `发送验证码`
})
function goLogin() {
router.push('/auth/login')
}
async function sendCode() {
// logger.info('发送邮件验证代码')
verify.value.isClick = true
Expand Down Expand Up @@ -130,7 +126,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('/auth/login')
router.push({ name: 'Login' })
} else {
message.error(rs.message)
}
Expand Down
6 changes: 1 addition & 5 deletions src/views/auth/ResetPasswordView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<n-button type="primary" @click="sendResetMail" style="margin-right: 10px">
发送邮件
</n-button>
<n-button ghost type="primary" @click="goLogin"> 登录</n-button>
<n-button ghost type="primary" @click="() => router.push({ name: 'Login' })"> 登录</n-button>
</n-space>
</div>
</n-form>
Expand Down Expand Up @@ -90,10 +90,6 @@ if (code !== null) {
sendResetEmail.value = false
}
function goLogin() {
router.push('/auth/login')
}
async function doResetRequest() {
if (code === '' || code === undefined) {
message.error('非法请求!')
Expand Down
2 changes: 1 addition & 1 deletion src/views/callback/auth/oauth/qq/LoginView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="flex-center outbox" v-else>
<n-h2>发生错误</n-h2>
<p>{{ errorMessage }}</p>
<n-button style="margin-top: 10px" @click="() => router.push('/auth/login')">
<n-button style="margin-top: 10px" @click="() => router.push({ name: 'Login' })">
返回登录
</n-button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/views/proxies/ProxiesView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ async function launchProxyThroughApplication(id) {
window.open(url)
},
onNegativeClick: () => {
router.push('/other/software')
router.push({ name: 'Software' })
},
onMaskClick: () => {
sendSuccessMessage('你取消了操作!')
Expand Down

0 comments on commit d2796a3

Please sign in to comment.