Skip to content

Commit

Permalink
优化登陆和注销逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
FairyEver committed Jan 16, 2019
1 parent aba258f commit 6e381f2
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d2-admin",
"version": "1.6.11",
"version": "1.6.12",
"private": true,
"scripts": {
"serve": "vue-cli-service serve --open",
Expand Down
2 changes: 1 addition & 1 deletion src/layout/header-aside/components/header-user/index.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<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-item @click.native="logOff">
<d2-icon name="power-off" class="d2-mr-5"/>
Expand Down
6 changes: 3 additions & 3 deletions src/router/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import business from './modules/business'

import layoutHeaderAside from '@/layout/header-aside'

const meta = { auth: true }

/**
* 在主框架内显示
*/
Expand All @@ -25,7 +23,9 @@ const frameIn = [
{
path: 'index',
name: 'index',
meta,
meta: {
auth: true
},
component: () => import('@/pages/index')
},
// 刷新页面 必须保留
Expand Down
6 changes: 0 additions & 6 deletions src/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,5 @@ export default {
// 是否默认开启页面切换动画
transition: {
active: true
},
// 在读取持久化数据失败时默认用户信息
user: {
info: {
name: 'Ghost'
}
}
}
6 changes: 4 additions & 2 deletions src/store/modules/d2admin/modules/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ export default {
* @param {Object} param vm {Object} vue 实例
* @param {Object} param confirm {Boolean} 是否需要确认
*/
logout ({ commit }, { vm, confirm = false }) {
logout ({ commit, dispatch }, { vm, confirm = false }) {
/**
* @description 注销
*/
function logout () {
async function logout () {
// 删除cookie
util.cookies.remove('token')
util.cookies.remove('uuid')
// 清空 vuex 用户信息
await dispatch('d2admin/user/set', {}, { root: true })
// 跳转路由
vm.$router.push({
name: 'login'
Expand Down
7 changes: 2 additions & 5 deletions src/store/modules/d2admin/modules/user.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
// 设置文件
import setting from '@/setting.js'

export default {
namespaced: true,
state: {
// 用户信息
info: setting.user.info
info: {}
},
actions: {
/**
Expand Down Expand Up @@ -38,7 +35,7 @@ export default {
state.info = await dispatch('d2admin/db/get', {
dbName: 'sys',
path: 'user.info',
defaultValue: setting.user.info,
defaultValue: {},
user: true
}, { root: true })
// end
Expand Down

0 comments on commit 6e381f2

Please sign in to comment.