完成数据持久化方式缓存示例

Former-commit-id: ad9918157b0f25f353e218870a1486fd111c76b3 [formerly ad9918157b0f25f353e218870a1486fd111c76b3 [formerly ad9918157b0f25f353e218870a1486fd111c76b3 [formerly ad9918157b0f25f353e218870a1486fd111c76b3 [formerly 5ab32ee88ba0cbb71499514202fa88131944b6cf [formerly 8b6298bcec0cf00eda1342846fa3f8ff3fea5192]]]]]
Former-commit-id: fca6f35a71568c622756ce2341ca4c8d6a043fa9
Former-commit-id: ec6ab591de18bd6c57c3e4e93f708686a2d75386
Former-commit-id: d3153bca1972183e08a4e709c98cbb525914a8cd [formerly 051d39ec9aa2aa953143b2bb6f10fcb74f53d8b3]
Former-commit-id: 76b941703caef91041247018a11b1cf10999d440
Former-commit-id: f39e54960b15eb225abb0019219895f1d3864bb8
Former-commit-id: 0c790b19d0b4040413cdb16dacb11ce3db465694
Former-commit-id: 929843b780f1309638bdd31aa00965806820b41d
Former-commit-id: e5609aee97279c71ed2963f67f9521aef2fb86b1
This commit is contained in:
liyang
2018-11-29 10:14:44 +08:00
parent c40ffd28eb
commit 13a13e3335
6 changed files with 199 additions and 64 deletions

View File

@@ -1,5 +1,6 @@
import db from '@/libs/db.js'
import util from '@/libs/util.js'
import { cloneDeep } from 'lodash'
/**
* @description 检查路径是否存在 不存在的话初始化
@@ -20,6 +21,13 @@ function pathInit ({
const uuid = util.cookies.get('uuid') || 'ghost-uuid'
const currentPath = `${dbName}.${user ? `user.${uuid}` : 'public'}${path ? `.${path}` : ''}`
const value = db.get(currentPath).value()
console.group('pathInit')
console.log('dbName', dbName)
console.log('path', path)
console.log('user', user)
console.log('defaultValue', defaultValue)
console.log('value', value)
console.groupEnd()
if (!(value !== undefined && validator(value))) {
db
.set(currentPath, defaultValue)
@@ -66,12 +74,12 @@ export default {
user = false
}) {
return new Promise(resolve => {
resolve(db.get(pathInit({
resolve(cloneDeep(db.get(pathInit({
dbName,
path,
user,
defaultValue
})).value())
})).value()))
})
},
/**
@@ -118,7 +126,7 @@ export default {
*/
databasePage (context, {
vm,
basis = 'name',
basis = 'fullPath',
user = false
} = {}) {
return new Promise(resolve => {
@@ -139,7 +147,7 @@ export default {
*/
databasePageClear (context, {
vm,
basis = 'name',
basis = 'fullPath',
user = false
} = {}) {
return new Promise(resolve => {
@@ -161,7 +169,7 @@ export default {
*/
pageSet (context, {
vm,
basis = 'name',
basis = 'fullPath',
user = false
}) {
return new Promise(resolve => {
@@ -170,7 +178,7 @@ export default {
path: `$page.${vm.$route[basis]}.$data`,
user,
validator: () => false,
defaultValue: vm.$data
defaultValue: cloneDeep(vm.$data)
})))
})
},
@@ -183,16 +191,16 @@ export default {
*/
pageGet (context, {
vm,
basis = 'name',
basis = 'fullPath',
user = false
}) {
return new Promise(resolve => {
resolve(db.get(pathInit({
resolve(cloneDeep(db.get(pathInit({
dbName: 'database',
path: `$page.${vm.$route[basis]}.$data`,
user,
defaultValue: vm.$data
})).value())
defaultValue: cloneDeep(vm.$data)
})).value()))
})
},
/**
@@ -204,7 +212,7 @@ export default {
*/
pageClear (context, {
vm,
basis = 'name',
basis = 'fullPath',
user = false
}) {
return new Promise(resolve => {