管理和服务分离

This commit is contained in:
simple321vip
2022-04-20 22:48:23 +08:00
parent 952587cd2c
commit e3be0674d8
12 changed files with 54 additions and 334 deletions
+24 -13
View File
@@ -3,20 +3,18 @@ import App from './App.vue'
import ElementPlus from "element-plus";
import 'element-plus/dist/index.css'
import router from './router'
// vue store
import { createPinia } from 'pinia'
const store = createPinia()
let app = createApp(App)
app.use(router)
app.use(ElementPlus)
app.use(store)
import { getToken } from './utils/auth'
const whiteList = ['/', '/blog']
import { getToken, getUser } from './utils/auth'
import { User } from './entity/index'
const whiteList = ['/login']
let url = window.location.href
console.log(url)
if (url != 'http://localhost:3000/') {
@@ -44,21 +42,34 @@ router.beforeEach((to, from, next) => {
console.log(from.path, to.path)
const token = getToken()
if (to.path === '/login') {
if (token) {
next('/home')
if (typeof token === 'string') {
if (to.path === '/login') {
if (token) {
next('/')
}
} else if (to.path === '/') {
const user = <User>(JSON.parse(getUser() as string))
console.log(user)
if (user) {
router.push({
path: '/home',
query: user
})
}
} else {
next()
}
}
if (whiteList.includes(to.path)) {
next()
} else {
next()
if (whiteList.includes(to.path)) {
next()
} else {
next('/login')
}
}
})