From 5e6cbd1579f263bbcc0970f7075601e1612363cb Mon Sep 17 00:00:00 2001 From: liyang <1711467488@qq.com> Date: Thu, 9 Aug 2018 22:48:22 +0800 Subject: [PATCH] util > db Former-commit-id: 3f25dc5b6b23f62385c841a76d5bb45131cc9193 [formerly 3f25dc5b6b23f62385c841a76d5bb45131cc9193 [formerly 3f25dc5b6b23f62385c841a76d5bb45131cc9193 [formerly 3f25dc5b6b23f62385c841a76d5bb45131cc9193 [formerly 74fcd8e90581bb7b626ab9fc2a9e65ac67d395de [formerly d9208f02fe63e650dc50171135c3b2c065ff64e5]]]]] Former-commit-id: a4698ed2b3b2e0028797f905fbe7b11e4a968e01 Former-commit-id: 59a9cd716ed5ce050c275a87a466eff9df2f40f1 Former-commit-id: 5f1f0bee97697af1da02228c5bc77551d2ac48d4 [formerly a98902cb278f1ece4cc2b5db7c0ec8b91ab6a4f0] Former-commit-id: 8e6039dc03de7a5558c5e093d74e087595b0c860 Former-commit-id: 0a3c3b74a5c8350508d60bd9fef43520cac1f6fe Former-commit-id: 8a5127adc877f792f7877fb1430dcdf8c85b1943 Former-commit-id: 70c79607216f3010475ce41f354ac5be4932e659 Former-commit-id: cbd3d49dde479cee9d7c3d66ca39a39d745c9d21 --- src/libs/db.js | 1 + .../modules/d2admin/index.js.REMOVED.git-id | 2 +- .../d2admin/modules/{util.js => db.js} | 34 ++++++++++++++----- src/store/modules/d2admin/modules/menu.js | 6 ++-- src/store/modules/d2admin/modules/theme.js | 4 +-- src/store/modules/d2admin/modules/user.js | 4 +-- 6 files changed, 34 insertions(+), 17 deletions(-) rename src/store/modules/d2admin/modules/{util.js => db.js} (78%) diff --git a/src/libs/db.js b/src/libs/db.js index e7951468..1161022d 100644 --- a/src/libs/db.js +++ b/src/libs/db.js @@ -9,6 +9,7 @@ const db = low(adapter) db.defaults({ // 新 sys: {}, + db: {}, // 旧 pageOpenedList: [], database: [], diff --git a/src/store/modules/d2admin/index.js.REMOVED.git-id b/src/store/modules/d2admin/index.js.REMOVED.git-id index 585686ad..3ce6d6d8 100644 --- a/src/store/modules/d2admin/index.js.REMOVED.git-id +++ b/src/store/modules/d2admin/index.js.REMOVED.git-id @@ -1 +1 @@ -3d6b1e7aec946cdf2583d293307b3c9a38239c61 \ No newline at end of file +4fee0ebd82dca4d2b9cd0ff053df6807cfd880ac \ No newline at end of file diff --git a/src/store/modules/d2admin/modules/util.js b/src/store/modules/d2admin/modules/db.js similarity index 78% rename from src/store/modules/d2admin/modules/util.js rename to src/store/modules/d2admin/modules/db.js index e6e1ce3d..15700566 100644 --- a/src/store/modules/d2admin/modules/util.js +++ b/src/store/modules/d2admin/modules/db.js @@ -8,9 +8,9 @@ import util from '@/libs/util.js' * @param {Object} param defaultValue {*} 初始化默认值 */ function pathInit ({ - dbName = 'sys', + dbName = 'db', path = '', - defaultValue = [] + defaultValue = '' }) { const sys = db.get(dbName) if (!sys.get(path).value()) { @@ -49,15 +49,31 @@ export default { namespaced: true, mutations: { /** - * @description 将数据存储到指定位置 [用户存储区域] + * @description 将数据存储到指定位置 [不区分用户] * @param {Object} state vuex state * @param {Object} param dbName {String} 数据库名称 * @param {Object} param path {String} 存储路径 * @param {Object} param value {*} 需要存储的值 */ - // TODO: 抽象 - dbValueSetByUser (state, { - dbName = 'sys', + set (state, { + dbName = 'db', + path = '', + value = '' + }) { + db + .get(dbName) + .set(path, value) + .write() + }, + /** + * @description 将数据存储到指定位置 [区分用户] + * @param {Object} state vuex state + * @param {Object} param dbName {String} 数据库名称 + * @param {Object} param path {String} 存储路径 + * @param {Object} param value {*} 需要存储的值 + */ + setByUser (state, { + dbName = 'db', path = '', value = '' }) { @@ -80,14 +96,14 @@ export default { }, actions: { /** - * @description 从系统存储中获取数据 [用户存储区域] + * @description 获取数据 [区分用户] * @param {Object} state vuex state * @param {Object} param dbName {String} 数据库名称 * @param {Object} param path {String} 存储路径 * @param {Object} param defaultValue {*} 取值失败的默认值 */ - dbValueGetByUser (context, { - dbName = 'sys', + getByUser (context, { + dbName = 'db', path = '', defaultValue = '' }) { diff --git a/src/store/modules/d2admin/modules/menu.js b/src/store/modules/d2admin/modules/menu.js index 0284695f..cc7c1b8f 100644 --- a/src/store/modules/d2admin/modules/menu.js +++ b/src/store/modules/d2admin/modules/menu.js @@ -34,7 +34,7 @@ export default { // store 赋值 state.asideCollapse = collapse // 持久化 - this.commit('d2admin/util/dbValueSetByUser', { + this.commit('d2admin/db/setByUser', { dbName: 'sys', path: 'menu.asideCollapse', value: state.asideCollapse @@ -48,7 +48,7 @@ export default { // store 赋值 state.asideCollapse = !state.asideCollapse // 持久化 - this.commit('d2admin/util/dbValueSetByUser', { + this.commit('d2admin/db/setByUser', { dbName: 'sys', path: 'menu.asideCollapse', value: state.asideCollapse @@ -60,7 +60,7 @@ export default { */ async asideCollapseLoad (state) { // store 赋值 - state.asideCollapse = await this.dispatch('d2admin/util/dbValueGetByUser', { + state.asideCollapse = await this.dispatch('d2admin/db/getByUser', { dbName: 'sys', path: 'menu.asideCollapse', defaultValue: false diff --git a/src/store/modules/d2admin/modules/theme.js b/src/store/modules/d2admin/modules/theme.js index b3fc5600..e887d2ff 100644 --- a/src/store/modules/d2admin/modules/theme.js +++ b/src/store/modules/d2admin/modules/theme.js @@ -29,7 +29,7 @@ export default { // 将 vuex 中的主题应用到 dom this.commit('d2admin/theme/dom') // 持久化 - this.commit('d2admin/util/dbValueSetByUser', { + this.commit('d2admin/db/setByUser', { dbName: 'sys', path: 'theme.activeName', value: state.activeName @@ -41,7 +41,7 @@ export default { */ async load (state) { // store 赋值 - state.activeName = await this.dispatch('d2admin/util/dbValueGetByUser', { + state.activeName = await this.dispatch('d2admin/db/getByUser', { dbName: 'sys', path: 'theme.activeName', defaultValue: state.list[0].name diff --git a/src/store/modules/d2admin/modules/user.js b/src/store/modules/d2admin/modules/user.js index 1381eb34..6a5d139e 100644 --- a/src/store/modules/d2admin/modules/user.js +++ b/src/store/modules/d2admin/modules/user.js @@ -16,7 +16,7 @@ export default { // store 赋值 state.info = info // 持久化 - this.commit('d2admin/util/dbValueSetByUser', { + this.commit('d2admin/db/setByUser', { dbName: 'sys', path: 'user.info', value: info @@ -28,7 +28,7 @@ export default { */ async load (state) { // store 赋值 - state.info = await this.dispatch('d2admin/util/dbValueGetByUser', { + state.info = await this.dispatch('d2admin/db/getByUser', { dbName: 'sys', path: 'user.info', defaultValue: '请重新登陆'