From f198228bee91f2c52dc80b2377f165a3294dcd1a Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Mon, 20 Aug 2018 23:29:53 +0800 Subject: [PATCH] db Former-commit-id: b89fbea2ff27c6ded9accac4abfb48dca53a4c6a [formerly b89fbea2ff27c6ded9accac4abfb48dca53a4c6a [formerly b89fbea2ff27c6ded9accac4abfb48dca53a4c6a [formerly b89fbea2ff27c6ded9accac4abfb48dca53a4c6a [formerly ce523a7fcf737361f8af7caa6a37cd2908454d10 [formerly 3ecbc40150fefc40b6cc52d9853888a98bb45221]]]]] Former-commit-id: 5508f237a48bd72ad5196031dfee3658725395fa Former-commit-id: 57110a720dbad54a397139142c5cc6ebb4491cf9 Former-commit-id: d787a9bd2b9915cbde1c7b8a1cc0c989bb4c4caa [formerly 112b721b50eb13f961d1ad589cf80165e46d53f6] Former-commit-id: 428c78e47cdd6cdad33eacfa0e296cd6caa9e610 Former-commit-id: 671bc93046a8be2a379b121b4cd71faf6c6773de Former-commit-id: 2c4006138822cd94b26d4ba670fbfd36a7c36c8f Former-commit-id: f91b68d365453002c3eee90523e18fbe9ed4ba7c Former-commit-id: d212444f15115ae63c20306037be9e17dc99f326 --- docs/zh/sys-vuex/README.md.REMOVED.git-id | 2 +- .../db/page-snapshot-public/index.vue | 4 +- .../db/page-snapshot-user/index.vue | 4 +- src/store/modules/d2admin/modules/db.js | 52 ++++--------------- src/store/modules/d2admin/modules/menu.js | 15 +++--- src/store/modules/d2admin/modules/page.js | 10 ++-- src/store/modules/d2admin/modules/theme.js | 10 ++-- .../modules/d2admin/modules/transition.js | 10 ++-- src/store/modules/d2admin/modules/user.js | 10 ++-- 9 files changed, 47 insertions(+), 70 deletions(-) diff --git a/docs/zh/sys-vuex/README.md.REMOVED.git-id b/docs/zh/sys-vuex/README.md.REMOVED.git-id index 7e5ba358..aa90a54c 100644 --- a/docs/zh/sys-vuex/README.md.REMOVED.git-id +++ b/docs/zh/sys-vuex/README.md.REMOVED.git-id @@ -1 +1 @@ -78fa73fc382c9d9c7950f10e3a5b7b7064f647b6 \ No newline at end of file +d991a147e53c59451408d5106031d926cb69a35f \ No newline at end of file diff --git a/src/pages/demo/playground/db/page-snapshot-public/index.vue b/src/pages/demo/playground/db/page-snapshot-public/index.vue index 3b86d04c..89305695 100644 --- a/src/pages/demo/playground/db/page-snapshot-public/index.vue +++ b/src/pages/demo/playground/db/page-snapshot-public/index.vue @@ -86,7 +86,7 @@ export default { } }, async created () { - const data = await this.pageLoad({ vm: this }) + const data = await this.pageGet({ vm: this }) for (const key in data) { if (data.hasOwnProperty(key)) this[key] = data[key] } @@ -102,7 +102,7 @@ export default { methods: { ...mapActions('d2admin/db', [ 'pageSet', - 'pageLoad', + 'pageGet', 'pageClear' ]), async handleClear () { diff --git a/src/pages/demo/playground/db/page-snapshot-user/index.vue b/src/pages/demo/playground/db/page-snapshot-user/index.vue index 4e17b74a..15dbc60e 100644 --- a/src/pages/demo/playground/db/page-snapshot-user/index.vue +++ b/src/pages/demo/playground/db/page-snapshot-user/index.vue @@ -86,7 +86,7 @@ export default { } }, async created () { - const data = await this.pageLoad({ vm: this, user: true }) + const data = await this.pageGet({ vm: this, user: true }) for (const key in data) { if (data.hasOwnProperty(key)) this[key] = data[key] } @@ -102,7 +102,7 @@ export default { methods: { ...mapActions('d2admin/db', [ 'pageSet', - 'pageLoad', + 'pageGet', 'pageClear' ]), async handleClear () { diff --git a/src/store/modules/d2admin/modules/db.js b/src/store/modules/d2admin/modules/db.js index bbaa9dfe..b8045c71 100644 --- a/src/store/modules/d2admin/modules/db.js +++ b/src/store/modules/d2admin/modules/db.js @@ -37,33 +37,18 @@ export default { * @param {Object} param dbName {String} 数据库名称 * @param {Object} param path {String} 存储路径 * @param {Object} param value {*} 需要存储的值 + * @param {Object} param user {Boolean} 是否区分用户 */ set (context, { dbName = 'database', path = '', - value = '' + value = '', + user = false }) { db.set(pathInit({ dbName, path, - user: false - }), value).write() - }, - /** - * @description 将数据存储到指定位置 | 路径不存在会自动初始化 [ 区分用户 ] - * @description 效果类似于取值 dbName.path[user] = value - * @param {Object} param dbName {String} 数据库名称 - * @param {Object} param path {String} 存储路径 - * @param {Object} param value {*} 需要存储的值 - */ - setByUser (context, { - dbName = 'database', - path = '', - value = '' - }) { - db.set(pathInit({ - dbName, - path + user }), value).write() }, /** @@ -72,38 +57,19 @@ export default { * @param {Object} param dbName {String} 数据库名称 * @param {Object} param path {String} 存储路径 * @param {Object} param defaultValue {*} 取值失败的默认值 + * @param {Object} param user {Boolean} 是否区分用户 */ get (context, { dbName = 'database', path = '', - defaultValue = '' + defaultValue = '', + user = false }) { return new Promise(resolve => { resolve(db.get(pathInit({ dbName, path, - user: false, - defaultValue - })).value()) - }) - }, - /** - * @description 获取数据 [ 区分用户 ] - * @description 效果类似于取值 dbName.path[user] || defaultValue - * @param {Object} param dbName {String} 数据库名称 - * @param {Object} param path {String} 存储路径 - * @param {Object} param defaultValue {*} 取值失败的默认值 - */ - getByUser (context, { - dbName = 'database', - path = '', - defaultValue = '' - }) { - return new Promise((resolve, reject) => { - resolve(db.get(pathInit({ - dbName, - path, - user: true, + user, defaultValue })).value()) }) @@ -215,7 +181,7 @@ export default { * @param {Object} param basis {String} 页面区分依据 [ name | path | fullPath ] * @param {Object} param user {Boolean} 是否区分用户 */ - pageLoad (context, { + pageGet (context, { vm, basis = 'name', user = false diff --git a/src/store/modules/d2admin/modules/menu.js b/src/store/modules/d2admin/modules/menu.js index ee3c85d7..99db6e8e 100644 --- a/src/store/modules/d2admin/modules/menu.js +++ b/src/store/modules/d2admin/modules/menu.js @@ -39,10 +39,11 @@ export default { // store 赋值 state.asideCollapse = collapse // 持久化 - this.dispatch('d2admin/db/setByUser', { + this.dispatch('d2admin/db/set', { dbName: 'sys', path: 'menu.asideCollapse', - value: state.asideCollapse + value: state.asideCollapse, + user: true }) }, /** @@ -53,10 +54,11 @@ export default { // store 赋值 state.asideCollapse = !state.asideCollapse // 持久化 - this.dispatch('d2admin/db/setByUser', { + this.dispatch('d2admin/db/set', { dbName: 'sys', path: 'menu.asideCollapse', - value: state.asideCollapse + value: state.asideCollapse, + user: true }) }, /** @@ -65,10 +67,11 @@ export default { */ async asideCollapseLoad (state) { // store 赋值 - state.asideCollapse = await this.dispatch('d2admin/db/getByUser', { + state.asideCollapse = await this.dispatch('d2admin/db/get', { dbName: 'sys', path: 'menu.asideCollapse', - defaultValue: setting.menu.asideCollapse + defaultValue: setting.menu.asideCollapse, + user: true }) } } diff --git a/src/store/modules/d2admin/modules/page.js b/src/store/modules/d2admin/modules/page.js index 63e8d844..7ac2c47b 100644 --- a/src/store/modules/d2admin/modules/page.js +++ b/src/store/modules/d2admin/modules/page.js @@ -93,10 +93,11 @@ export default { * @param {Object} state vuex state */ opend2db (state) { - this.dispatch('d2admin/db/setByUser', { + this.dispatch('d2admin/db/set', { dbName: 'sys', path: 'page.opened', - value: state.opened + value: state.opened, + user: true }) }, /** @@ -106,10 +107,11 @@ export default { */ async openedLoad (state) { // store 赋值 - const value = await this.dispatch('d2admin/db/getByUser', { + const value = await this.dispatch('d2admin/db/get', { dbName: 'sys', path: 'page.opened', - defaultValue: setting.page.opened + defaultValue: setting.page.opened, + user: true }) // 在处理函数中进行数据优化 过滤掉现在已经失效的页签或者已经改变了信息的页签 // 以 name 字段为准 diff --git a/src/store/modules/d2admin/modules/theme.js b/src/store/modules/d2admin/modules/theme.js index f5920baf..e12b1439 100644 --- a/src/store/modules/d2admin/modules/theme.js +++ b/src/store/modules/d2admin/modules/theme.js @@ -30,10 +30,11 @@ export default { // 将 vuex 中的主题应用到 dom this.commit('d2admin/theme/dom') // 持久化 - this.dispatch('d2admin/db/setByUser', { + this.dispatch('d2admin/db/set', { dbName: 'sys', path: 'theme.activeName', - value: state.activeName + value: state.activeName, + user: true }) }, /** @@ -42,10 +43,11 @@ export default { */ async load (state) { // store 赋值 - state.activeName = await this.dispatch('d2admin/db/getByUser', { + state.activeName = await this.dispatch('d2admin/db/get', { dbName: 'sys', path: 'theme.activeName', - defaultValue: state.list[0].name + defaultValue: state.list[0].name, + user: true }) // 更新到页面 this.commit('d2admin/theme/dom') diff --git a/src/store/modules/d2admin/modules/transition.js b/src/store/modules/d2admin/modules/transition.js index b08ce975..2f46a355 100644 --- a/src/store/modules/d2admin/modules/transition.js +++ b/src/store/modules/d2admin/modules/transition.js @@ -17,10 +17,11 @@ export default { // store 赋值 state.active = active // 持久化 - this.dispatch('d2admin/db/setByUser', { + this.dispatch('d2admin/db/set', { dbName: 'sys', path: 'transition.active', - value: state.active + value: state.active, + user: true }) }, /** @@ -29,10 +30,11 @@ export default { */ async load (state) { // store 赋值 - state.active = await this.dispatch('d2admin/db/getByUser', { + state.active = await this.dispatch('d2admin/db/get', { dbName: 'sys', path: 'transition.active', - defaultValue: setting.transition.active + defaultValue: setting.transition.active, + user: true }) } } diff --git a/src/store/modules/d2admin/modules/user.js b/src/store/modules/d2admin/modules/user.js index 51b1be25..add8a466 100644 --- a/src/store/modules/d2admin/modules/user.js +++ b/src/store/modules/d2admin/modules/user.js @@ -17,10 +17,11 @@ export default { // store 赋值 state.info = info // 持久化 - this.dispatch('d2admin/db/setByUser', { + this.dispatch('d2admin/db/set', { dbName: 'sys', path: 'user.info', - value: info + value: info, + user: true }) }, /** @@ -29,10 +30,11 @@ export default { */ async load (state) { // store 赋值 - state.info = await this.dispatch('d2admin/db/getByUser', { + state.info = await this.dispatch('d2admin/db/get', { dbName: 'sys', path: 'user.info', - defaultValue: setting.user.info + defaultValue: setting.user.info, + user: true }) } }