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
This commit is contained in:
liyang
2018-08-09 22:48:22 +08:00
parent b1cba27e78
commit 5e6cbd1579
6 changed files with 34 additions and 17 deletions

View File

@@ -9,6 +9,7 @@ const db = low(adapter)
db.defaults({
// 新
sys: {},
db: {},
// 旧
pageOpenedList: [],
database: [],

View File

@@ -1 +1 @@
3d6b1e7aec946cdf2583d293307b3c9a38239c61
4fee0ebd82dca4d2b9cd0ff053df6807cfd880ac

View File

@@ -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 = ''
}) {

View File

@@ -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

View File

@@ -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

View File

@@ -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: '请重新登陆'