From 1166e0d98f21642454a3adc66adbd1f64dec31e9 Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Thu, 13 Sep 2018 23:14:40 +0800 Subject: [PATCH] account user Former-commit-id: 18e8f9b184a466dd3afdcca8b77ccd9922d408a4 [formerly 18e8f9b184a466dd3afdcca8b77ccd9922d408a4 [formerly 18e8f9b184a466dd3afdcca8b77ccd9922d408a4 [formerly 18e8f9b184a466dd3afdcca8b77ccd9922d408a4 [formerly 26eec1dacb860262e4e7a81946d6d44739441da3 [formerly 8b6ff706f6abb1771924571087264230424f32d2]]]]] Former-commit-id: a9006cb1d0b08630344ae3148efc45bda1fae8f3 Former-commit-id: 209b2c0fe35119ed4319dac1a1b9c553e15c4522 Former-commit-id: 493b0705c65043774efc00cdcfbf3ad97ed54a52 [formerly acb407878497fbc86b0bbfa7470d43455a7944f2] Former-commit-id: 39e40e3c3e4313c35eac57b87caea57fbf0c245d Former-commit-id: 8873735485e0c6836cf2d8e1717f9e94a5de814e Former-commit-id: 78d64eb4d6132adec46158bccf3c7d06576bce6d Former-commit-id: 39429a1692c5c34c87bdff344622a752c06619f4 Former-commit-id: 6726ad62ee8fdb8e952920f8f5ffad86a7d4fa04 --- package-lock.json.REMOVED.git-id | 2 +- src/main.js | 2 +- src/store/modules/d2admin/modules/account.js | 46 ++++++++++---------- src/store/modules/d2admin/modules/user.js | 42 ++++++++++-------- 4 files changed, 49 insertions(+), 43 deletions(-) diff --git a/package-lock.json.REMOVED.git-id b/package-lock.json.REMOVED.git-id index 298e7b3f..f90e2089 100644 --- a/package-lock.json.REMOVED.git-id +++ b/package-lock.json.REMOVED.git-id @@ -1 +1 @@ -4d463a54f93007210c2e07a05d8f012c386a0023 \ No newline at end of file +b322c0027c15926f73f03ec142269e3512c5cc14 \ No newline at end of file diff --git a/src/main.js b/src/main.js index 2ac579e2..f9c5628b 100644 --- a/src/main.js +++ b/src/main.js @@ -62,7 +62,7 @@ new Vue({ // 检查最新版本 this.$store.dispatch('d2admin/releases/checkUpdate') // 用户登录后从数据库加载一系列的设置 - this.$store.commit('d2admin/account/load') + this.$store.dispatch('d2admin/account/load') // 获取并记录用户 UA this.$store.commit('d2admin/ua/get') // 初始化全屏监听 diff --git a/src/store/modules/d2admin/modules/account.js b/src/store/modules/d2admin/modules/account.js index 78569bd9..133cba32 100644 --- a/src/store/modules/d2admin/modules/account.js +++ b/src/store/modules/d2admin/modules/account.js @@ -12,9 +12,7 @@ export default { * @param {Object} param password {String} 密码 * @param {Object} param route {Object} 登录成功后定向的路由对象 */ - login ({ - commit - }, { + login ({ dispatch }, { vm, username, password, @@ -27,7 +25,7 @@ export default { username, password }) - .then(res => { + .then(async res => { // 设置 cookie 一定要存 uuid 和 token 两个 cookie // 整个系统依赖这两个数据进行校验和存储 // uuid 是用户身份唯一标识 用户注册的时候确定 并且不可改变 不可重复 @@ -36,11 +34,11 @@ export default { util.cookies.set('uuid', res.uuid) util.cookies.set('token', res.token) // 设置 vuex 用户信息 - commit('d2admin/user/set', { + await dispatch('d2admin/user/set', { name: res.name }, { root: true }) // 用户登录后从持久化数据加载一系列的设置 - commit('load') + await dispatch('load') // 更新路由 尝试去获取 cookie 里保存的需要重定向的页面完整地址 const path = util.cookies.get('redirect') // 根据是否存有重定向页面判断如何重定向 @@ -49,9 +47,7 @@ export default { util.cookies.remove('redirect') }) .catch(err => { - console.group('登录结果') console.log('err: ', err) - console.groupEnd() }) }, /** @@ -92,26 +88,28 @@ export default { } else { logout() } - } - }, - mutations: { + }, /** * @description 用户登录后从持久化数据加载一系列的设置 * @param {Object} state vuex state */ - load (state) { - // DB -> store 加载用户名 - this.commit('d2admin/user/load') - // DB -> store 加载主题 - this.commit('d2admin/theme/load') - // DB -> store 加载页面过渡效果设置 - this.commit('d2admin/transition/load') - // DB -> store 持久化数据加载上次退出时的多页列表 - this.commit('d2admin/page/openedLoad') - // DB -> store 持久化数据加载侧边栏折叠状态 - this.commit('d2admin/menu/asideCollapseLoad') - // DB -> store 持久化数据加载全局尺寸 - this.commit('d2admin/size/load') + load ({ commit, dispatch }) { + return new Promise(async resolve => { + // DB -> store 加载用户名 + await dispatch('d2admin/user/load', null, { root: true }) + // DB -> store 加载主题 + commit('d2admin/theme/load', null, { root: true }) + // DB -> store 加载页面过渡效果设置 + commit('d2admin/transition/load', null, { root: true }) + // DB -> store 持久化数据加载上次退出时的多页列表 + commit('d2admin/page/openedLoad', null, { root: true }) + // DB -> store 持久化数据加载侧边栏折叠状态 + commit('d2admin/menu/asideCollapseLoad', null, { root: true }) + // DB -> store 持久化数据加载全局尺寸 + commit('d2admin/size/load', null, { root: true }) + // end + resolve() + }) } } } diff --git a/src/store/modules/d2admin/modules/user.js b/src/store/modules/d2admin/modules/user.js index add8a466..ff19e64b 100644 --- a/src/store/modules/d2admin/modules/user.js +++ b/src/store/modules/d2admin/modules/user.js @@ -7,34 +7,42 @@ export default { // 用户信息 info: setting.user.info }, - mutations: { + actions: { /** * @description 设置用户数据 * @param {Object} state vuex state * @param {*} info info */ - set (state, info) { - // store 赋值 - state.info = info - // 持久化 - this.dispatch('d2admin/db/set', { - dbName: 'sys', - path: 'user.info', - value: info, - user: true + set ({ state, dispatch }, info) { + return new Promise(async resolve => { + // store 赋值 + state.info = info + // 持久化 + await dispatch('d2admin/db/set', { + dbName: 'sys', + path: 'user.info', + value: info, + user: true + }, { root: true }) + // end + resolve() }) }, /** * @description 从数据库取用户数据 * @param {Object} state vuex state */ - async load (state) { - // store 赋值 - state.info = await this.dispatch('d2admin/db/get', { - dbName: 'sys', - path: 'user.info', - defaultValue: setting.user.info, - user: true + load ({ state, dispatch }) { + return new Promise(async resolve => { + // store 赋值 + state.info = await dispatch('d2admin/db/get', { + dbName: 'sys', + path: 'user.info', + defaultValue: setting.user.info, + user: true + }, { root: true }) + // end + resolve() }) } }