Commit 61b5d082 authored by suntao's avatar suntao

ww

parent 2e8ad844
...@@ -28,6 +28,7 @@ router.beforeEach(({meta, path}, from, next) => { ...@@ -28,6 +28,7 @@ router.beforeEach(({meta, path}, from, next) => {
if (whiteList.indexOf(path) !== -1) { if (whiteList.indexOf(path) !== -1) {
next() next()
} else { } else {
store.dispatch('GenerateRoutes')
let {auth = true} = meta let {auth = true} = meta
let isLogin = Boolean(store.state.login.tokens != '') //true用户已登录, false用户未登录 let isLogin = Boolean(store.state.login.tokens != '') //true用户已登录, false用户未登录
......
<template> <template>
<div class="dashboard-container"> <div class="dashboard-container">
<div class="dashboard-text">name:{{ name }}</div> <div class="dashboard-text">name:{{ username }}</div>
<div class="dashboard-text">roles:<span v-for="role in roles" :key="role">{{ role }}</span></div> <!-- <div class="dashboard-text">roles:<span v-for="role in roles" :key="role">{{ role }}</span></div>-->
</div> </div>
</template> </template>
...@@ -10,12 +10,11 @@ import { mapGetters } from 'vuex' ...@@ -10,12 +10,11 @@ import { mapGetters } from 'vuex'
export default { export default {
name: 'Dashboard', name: 'Dashboard',
computed: { computed:
// ...mapGetters([ mapGetters([
// 'name', 'username'
// 'roles' ])
// ])
}
} }
</script> </script>
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<section class="app-main"> <section class="app-main">
<transition name="fade-transform" mode="out-in"> <transition name="fade-transform" mode="out-in">
<!-- or name="fade" --> <!-- or name="fade" -->
<!-- <router-view :key="key"></router-view> --> <router-view :key="key"></router-view>
<router-view/> <router-view/>
</transition> </transition>
</section> </section>
...@@ -12,9 +12,9 @@ ...@@ -12,9 +12,9 @@
export default { export default {
name: 'AppMain', name: 'AppMain',
computed: { computed: {
// key() { key() {
// return this.$route.name !== undefined ? this.$route.name + +new Date() : this.$route + +new Date() return this.$route.username !== undefined ? this.$route.username + +new Date() : this.$route + +new Date()
// } }
} }
} }
</script> </script>
......
...@@ -15,23 +15,28 @@ ...@@ -15,23 +15,28 @@
</template> </template>
<script> <script>
import { mapGetters } from 'vuex'
import SidebarItem from './SidebarItem' import SidebarItem from './SidebarItem'
import variables from '@/styles/variables.scss' import variables from '@/styles/variables.scss'
export default { export default {
components: { SidebarItem }, components: { SidebarItem },
computed: { computed: {
sidebar:mapGetters([ sidebar() {
'permission_routers', return this.$store.state.app.sidebar
'sidebar' },
]), permission_routers() {
return this.$store.state.permission.routers
},
variables() { variables() {
return variables return variables
}, },
isCollapse() { isCollapse() {
return !this.sidebar.opened return !this.sidebar.opened
} }
},
created() {
} }
} }
</script> </script>
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
]), ]),
watch: { watch: {
tokens: function (val) { tokens: function (val) {
this.$router.push('/home/channels'); this.$router.push('/channel');
} }
}, },
created() { created() {
......
const getters = { const getters = {
sidebar: state => state.app.sidebar,
device: state => state.app.device,
tokens: state => state.login.tokens, tokens: state => state.login.tokens,
username: state => state.login.username, username: state => state.login.username,
permission_routers: state => state.permission.routers,
addRouters: state => state.permission.addRouters,
} }
export default getters export default getters
...@@ -7,8 +7,10 @@ import createLogger from 'vuex/dist/logger' ...@@ -7,8 +7,10 @@ import createLogger from 'vuex/dist/logger'
import createPersistedState from 'vuex-persistedstate' //vuex持久化localstorage插件 import createPersistedState from 'vuex-persistedstate' //vuex持久化localstorage插件
import * as Cookies from 'js-cookie'; import * as Cookies from 'js-cookie';
import * as state from './state' import * as state from './state'
import * as mutations from './mutations' // import * as mutations from './mutations'
import * as actions from './actions' // import * as actions from './actions'
import permission from './modules/permission'
import app from './modules/app'
import getters from './getters' import getters from './getters'
import menu from './modules/menu' import menu from './modules/menu'
import login from './modules/login' import login from './modules/login'
...@@ -25,10 +27,10 @@ let persistedState = { ...@@ -25,10 +27,10 @@ let persistedState = {
const store = new Vuex.Store({ const store = new Vuex.Store({
state, state,
mutations,
actions,
getters, getters,
modules: { modules: {
app,
permission,
menu, menu,
login login
}, },
......
...@@ -11,14 +11,17 @@ const app = { ...@@ -11,14 +11,17 @@ const app = {
mutations: { mutations: {
TOGGLE_SIDEBAR: state => { TOGGLE_SIDEBAR: state => {
if (state.sidebar.opened) { if (state.sidebar.opened) {
console.log("sidebarStatus=1")
Cookies.set('sidebarStatus', 1) Cookies.set('sidebarStatus', 1)
} else { } else {
Cookies.set('sidebarStatus', 0) Cookies.set('sidebarStatus', 0)
} }
console.log("sidebarStatus=out")
state.sidebar.opened = !state.sidebar.opened state.sidebar.opened = !state.sidebar.opened
state.sidebar.withoutAnimation = false state.sidebar.withoutAnimation = false
}, },
CLOSE_SIDEBAR: (state, withoutAnimation) => { CLOSE_SIDEBAR: (state, withoutAnimation) => {
console.log("sidebarStatus=CLOSE_SIDEBAR")
Cookies.set('sidebarStatus', 1) Cookies.set('sidebarStatus', 1)
state.sidebar.opened = false state.sidebar.opened = false
state.sidebar.withoutAnimation = withoutAnimation state.sidebar.withoutAnimation = withoutAnimation
......
...@@ -22,13 +22,13 @@ function filterAsyncRouter(routes, roles) { ...@@ -22,13 +22,13 @@ function filterAsyncRouter(routes, roles) {
const res = [] const res = []
routes.forEach(route => { routes.forEach(route => {
const tmp = { ...route } const tmp = { route }
if (hasPermission(roles, tmp)) { // if (hasPermission(roles, tmp)) {
if (tmp.children) { if (tmp.children) {
tmp.children = filterAsyncRouter(tmp.children, roles) tmp.children = filterAsyncRouter(tmp.children, roles)
} }
res.push(tmp) res.push(tmp)
} // }
}) })
return res return res
...@@ -48,14 +48,14 @@ const permission = { ...@@ -48,14 +48,14 @@ const permission = {
actions: { actions: {
GenerateRoutes({ commit }, data) { GenerateRoutes({ commit }, data) {
return new Promise(resolve => { return new Promise(resolve => {
const { roles } = data // const { roles } = data
let accessedRouters let accessedRouters
if (roles.includes('admin')) { // if (roles.includes('admin')) {
accessedRouters = asyncRouterMap accessedRouters = asyncRouterMap
} else { // } else {
accessedRouters = filterAsyncRouter(asyncRouterMap, roles) // accessedRouters = filterAsyncRouter(asyncRouterMap, roles)
} // }
commit('SET_ROUTERS', accessedRouters) commit('SET_ROUTERS', accessedRouters)
resolve() resolve()
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment