Commit 61b5d082 authored by suntao's avatar suntao

ww

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