提交登录限制
This commit is contained in:
parent
5d762b82a5
commit
4bdb545c0c
@ -51,12 +51,12 @@ const state = reactive({
|
|||||||
const login = reactive({ username: 'admin', password: 'admin', captcha: '', uuid: '',role: 0,})
|
const login = reactive({ username: 'admin', password: 'admin', captcha: '', uuid: '',role: 0,})
|
||||||
const onLogin = () => {
|
const onLogin = () => {
|
||||||
state.loading = true
|
state.loading = true
|
||||||
if (login.role) {
|
if (login.role == 1) {
|
||||||
console.log("管理员")
|
console.log("管理员")
|
||||||
loginAdmin(login).then(response => {
|
loginAdmin(login).then(response => {
|
||||||
state.loading = false
|
state.loading = false
|
||||||
ElMessage.success('登录成功')
|
ElMessage.success('登录成功')
|
||||||
userStore().isLogin = true
|
userStore().adminIsLogin = true
|
||||||
userStore().adminToken = response.data.token
|
userStore().adminToken = response.data.token
|
||||||
router.push('/admin')
|
router.push('/admin')
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
@ -66,10 +66,9 @@ const onLogin = () => {
|
|||||||
} else {
|
} else {
|
||||||
loginFront(login)
|
loginFront(login)
|
||||||
ElMessage.success("登录成功~")
|
ElMessage.success("登录成功~")
|
||||||
router.push('/front')
|
router.push('/')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取验证码
|
* 获取验证码
|
||||||
*/
|
*/
|
||||||
@ -92,7 +91,6 @@ onMounted(() => {
|
|||||||
height: 100vh;
|
height: 100vh;
|
||||||
background: #FFFFFF;
|
background: #FFFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
.module {
|
.module {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -100,12 +98,10 @@ onMounted(() => {
|
|||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
}
|
}
|
||||||
|
|
||||||
.module_img {
|
.module_img {
|
||||||
width: 60%;
|
width: 60%;
|
||||||
height: auto;
|
height: auto;
|
||||||
}
|
}
|
||||||
|
|
||||||
.module_r {
|
.module_r {
|
||||||
width: 40%;
|
width: 40%;
|
||||||
background: #e5efee;
|
background: #e5efee;
|
||||||
@ -113,7 +109,6 @@ onMounted(() => {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|
||||||
.module_mian {
|
.module_mian {
|
||||||
width: 65%;
|
width: 65%;
|
||||||
background: #FFFFFF;
|
background: #FFFFFF;
|
||||||
@ -122,21 +117,18 @@ onMounted(() => {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
padding-top: 40px;
|
padding-top: 40px;
|
||||||
padding-bottom: 40px;
|
padding-bottom: 40px;
|
||||||
|
|
||||||
.module_title {
|
.module_title {
|
||||||
font-size: 18px;
|
font-size: 18px;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #333333;
|
color: #333333;
|
||||||
}
|
}
|
||||||
|
|
||||||
.module_desc {
|
.module_desc {
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #a7a7a7;
|
color: #a7a7a7;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.module_m {
|
.module_m {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
width: 80%;
|
width: 80%;
|
||||||
@ -148,7 +140,6 @@ onMounted(() => {
|
|||||||
color: #333333;
|
color: #333333;
|
||||||
margin-bottom: 5px;
|
margin-bottom: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.module_input {
|
.module_input {
|
||||||
width: 96%;
|
width: 96%;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
@ -158,12 +149,10 @@ onMounted(() => {
|
|||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
font-size: 12px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.module_code {
|
.module_code {
|
||||||
width: 96%;
|
width: 96%;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
.module_code_input {
|
.module_code_input {
|
||||||
width: 60%;
|
width: 60%;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
@ -173,7 +162,6 @@ onMounted(() => {
|
|||||||
padding-left: 2%;
|
padding-left: 2%;
|
||||||
padding-right: 2%;
|
padding-right: 2%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.module_code_img {
|
.module_code_img {
|
||||||
width: 130px;
|
width: 130px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
@ -183,11 +171,9 @@ onMounted(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.module_radio input {
|
.module_radio input {
|
||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.forgetpwd {
|
.forgetpwd {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
width: 80%;
|
width: 80%;
|
||||||
@ -196,7 +182,6 @@ onMounted(() => {
|
|||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.module_button {
|
.module_button {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
display: block;
|
display: block;
|
||||||
@ -209,7 +194,6 @@ onMounted(() => {
|
|||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.module_button:active {
|
.module_button:active {
|
||||||
opacity: 0.4;
|
opacity: 0.4;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import { setupLayouts } from 'virtual:meta-layouts'
|
import { setupLayouts } from 'virtual:meta-layouts'
|
||||||
import { createRouter, createWebHistory } from 'vue-router'
|
import { createRouter, createWebHistory } from 'vue-router'
|
||||||
import { routes as fileRoutes } from 'vue-router/auto-routes'
|
import { routes as fileRoutes } from 'vue-router/auto-routes'
|
||||||
import { userInfoAdmin } from '~/api/user/adminUserApi'
|
|
||||||
declare module 'vue-router' {}
|
declare module 'vue-router' {}
|
||||||
|
|
||||||
// 重定向 BASE_URL
|
// 重定向 BASE_URL
|
||||||
@ -14,36 +13,21 @@ export const router = createRouter({
|
|||||||
})
|
})
|
||||||
// 路由拦截
|
// 路由拦截
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
|
|
||||||
if (to.fullPath.includes("/front")){
|
if (to.fullPath.includes("/front")){
|
||||||
console.log(to.fullPath)
|
console.log(to.fullPath)
|
||||||
console.log(to)
|
console.log(to.fullPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 管理员全部限制
|
// 管理员全部限制
|
||||||
else if (to.fullPath.includes("/admin")){
|
else if (to.fullPath.includes("/admin")){
|
||||||
console.log("管理员认证~")
|
console.log("管理员认证~")
|
||||||
// 判断有没有登录
|
//判断有没有登录
|
||||||
if (userStore().adminToken === null || userStore().adminToken === undefined ||userStore().adminToken == ""){
|
if (!userStore().adminIsLogin){
|
||||||
|
ElMessage.warning("认证失败~")
|
||||||
next('/login');
|
next('/login');
|
||||||
}else {
|
|
||||||
// 获取用户信息
|
|
||||||
userInfoAdmin().then(response => {
|
|
||||||
userStore().adminUserInfo = response.data
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 在这里编写拦截逻辑
|
|
||||||
// 例如,检查用户是否认证
|
|
||||||
const isLogin = userStore().isLogin
|
|
||||||
const authList=["/"]
|
|
||||||
if (authList.includes(to.fullPath) && !isLogin) {
|
|
||||||
// 如果用户未认证,则跳转到登录页面
|
|
||||||
next('/login');
|
|
||||||
} else {
|
|
||||||
// 如果用户已认证,或者不需要认证,则继续
|
|
||||||
next();
|
next();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router
|
export default router
|
||||||
|
@ -3,7 +3,8 @@ import { defineStore } from 'pinia'
|
|||||||
export default defineStore('userStore', {
|
export default defineStore('userStore', {
|
||||||
state() {
|
state() {
|
||||||
return {
|
return {
|
||||||
isLogin: true,
|
adminIsLogin: false,
|
||||||
|
isLogin: false,
|
||||||
adminToken: "",
|
adminToken: "",
|
||||||
frontToken: "",
|
frontToken: "",
|
||||||
adminUserInfo:{},
|
adminUserInfo:{},
|
||||||
|
Loading…
Reference in New Issue
Block a user