优化登陆和注销逻辑

Former-commit-id: 342bebf978c2a53193e7d89e7a538c4b72867a55
This commit is contained in:
liyang
2019-01-16 10:45:16 +08:00
parent 20bc963eab
commit 9876365d82
6 changed files with 11 additions and 18 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "d2-admin", "name": "d2-admin",
"version": "1.6.11", "version": "1.6.12",
"private": true, "private": true,
"scripts": { "scripts": {
"serve": "vue-cli-service serve --open", "serve": "vue-cli-service serve --open",
@@ -1,6 +1,6 @@
<template> <template>
<el-dropdown size="small" class="d2-mr"> <el-dropdown size="small" class="d2-mr">
<span class="btn-text">你好 {{info.name}}</span> <span class="btn-text">{{info.name ? `你好 ${info.name}` : '未登录'}}</span>
<el-dropdown-menu slot="dropdown"> <el-dropdown-menu slot="dropdown">
<el-dropdown-item @click.native="logOff"> <el-dropdown-item @click.native="logOff">
<d2-icon name="power-off" class="d2-mr-5"/> <d2-icon name="power-off" class="d2-mr-5"/>
+3 -3
View File
@@ -2,8 +2,6 @@ import demo from './modules/demo'
import layoutHeaderAside from '@/layout/header-aside' import layoutHeaderAside from '@/layout/header-aside'
const meta = { auth: true }
/** /**
* 在主框架内显示 * 在主框架内显示
*/ */
@@ -17,7 +15,9 @@ const frameIn = [
{ {
path: 'index', path: 'index',
name: 'index', name: 'index',
meta, meta: {
auth: true
},
component: () => import('@/pages/index') component: () => import('@/pages/index')
}, },
// 刷新页面 必须保留 // 刷新页面 必须保留
-6
View File
@@ -63,11 +63,5 @@ export default {
// 是否默认开启页面切换动画 // 是否默认开启页面切换动画
transition: { transition: {
active: true active: true
},
// 在读取持久化数据失败时默认用户信息
user: {
info: {
name: 'Ghost'
}
} }
} }
+4 -2
View File
@@ -52,14 +52,16 @@ export default {
* @param {Object} param vm {Object} vue 实例 * @param {Object} param vm {Object} vue 实例
* @param {Object} param confirm {Boolean} 是否需要确认 * @param {Object} param confirm {Boolean} 是否需要确认
*/ */
logout ({ commit }, { vm, confirm = false }) { logout ({ commit, dispatch }, { vm, confirm = false }) {
/** /**
* @description 注销 * @description 注销
*/ */
function logout () { async function logout () {
// 删除cookie // 删除cookie
util.cookies.remove('token') util.cookies.remove('token')
util.cookies.remove('uuid') util.cookies.remove('uuid')
// 清空 vuex 用户信息
await dispatch('d2admin/user/set', {}, { root: true })
// 跳转路由 // 跳转路由
vm.$router.push({ vm.$router.push({
name: 'login' name: 'login'
+2 -5
View File
@@ -1,11 +1,8 @@
// 设置文件
import setting from '@/setting.js'
export default { export default {
namespaced: true, namespaced: true,
state: { state: {
// 用户信息 // 用户信息
info: setting.user.info info: {}
}, },
actions: { actions: {
/** /**
@@ -38,7 +35,7 @@ export default {
state.info = await dispatch('d2admin/db/get', { state.info = await dispatch('d2admin/db/get', {
dbName: 'sys', dbName: 'sys',
path: 'user.info', path: 'user.info',
defaultValue: setting.user.info, defaultValue: {},
user: true user: true
}, { root: true }) }, { root: true })
// end // end