Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
glsx-business
/
supply-web
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 3af7c5fd
authored
Sep 14, 2020
by
胡悦
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
还原db
1 parent
f3d136d2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
42 deletions
src/libs/util.db.js
src/libs/util.db.js
View file @
3af7c5f
...
...
@@ -2,20 +2,20 @@ import low from 'lowdb'
import
LocalStorage
from
'lowdb/adapters/LocalStorage'
import
util
from
'@/libs/util'
const
isDev
=
process
.
env
.
NODE_ENV
===
'development'
//
const adapter = new LocalStorage(`${process.env.VUE_APP_STORAGE_PREFIX}-${process.env.VUE_APP_VERSION}`, {
//
serialize: (data) => isDev ? JSON.stringify(data) : escape(JSON.stringify(data)),
//
deserialize: (data) => isDev ? JSON.parse(data) : JSON.parse(unescape(data))
//
})
//
const db = low(adapter)
const
adapter
=
new
LocalStorage
(
`
${
process
.
env
.
VUE_APP_STORAGE_PREFIX
}
-
${
process
.
env
.
VUE_APP_VERSION
}
`
,
{
serialize
:
(
data
)
=>
isDev
?
JSON
.
stringify
(
data
)
:
escape
(
JSON
.
stringify
(
data
)),
deserialize
:
(
data
)
=>
isDev
?
JSON
.
parse
(
data
)
:
JSON
.
parse
(
unescape
(
data
))
})
const
db
=
low
(
adapter
)
//
db
//
.defaults({
//
sys: {},
//
database: {}
//
})
//
.write()
db
.
defaults
({
sys
:
{},
database
:
{}
})
.
write
()
//
export default db
export
default
db
/**
* @description 检查路径是否存在 不存在的话初始化
...
...
@@ -31,16 +31,16 @@ export function pathInit({
path
=
''
,
user
=
true
,
validator
=
()
=>
true
,
defaultValue
=
'
.
'
defaultValue
=
''
})
{
const
uuid
=
util
.
cookies
.
get
(
'uuid'
)
||
'ghost-uuid'
const
currentPath
=
`
${
dbName
}
.
${
user
?
`user.
${
uuid
}
`
:
'public'
}${
path
?
`.
${
path
}
`
:
''
}
`
//
const value = db.get(currentPath).value()
//
if (!(value !== undefined && validator(value))) {
//
db
//
.set(currentPath, defaultValue)
//
.write()
//
}
const
value
=
db
.
get
(
currentPath
).
value
()
if
(
!
(
value
!==
undefined
&&
validator
(
value
)))
{
db
.
set
(
currentPath
,
defaultValue
)
.
write
()
}
return
currentPath
}
...
...
@@ -58,16 +58,11 @@ export function dbSet({
value
=
''
,
user
=
false
})
{
// db.set(pathInit({
// dbName,
// path,
// user
// }), value).write()
localStorage
.
setItem
(
pathInit
({
dbName
,
path
,
user
}),
JSON
.
stringify
(
value
))
db
.
set
(
pathInit
({
dbName
,
path
,
user
}),
value
).
write
()
}
/**
...
...
@@ -84,22 +79,13 @@ export function dbGet({
defaultValue
=
''
,
user
=
false
})
{
console
.
log
(
dbName
,
path
,
user
,
defaultValue
)
return
new
Promise
(
resolve
=>
{
// resolve(_.cloneDeep(db.get(pathInit({
// dbName,
// path,
// user,
// defaultValue
// })).value()))
resolve
(
JSON
.
parse
(
localStorage
.
getItem
(
pathInit
({
resolve
(
_
.
cloneDeep
(
db
.
get
(
pathInit
({
dbName
,
path
,
user
}))))
user
,
defaultValue
})).
value
()))
})
}
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment