Commit 3af7c5fd by 胡悦

还原db

1 parent f3d136d2
...@@ -2,20 +2,20 @@ import low from 'lowdb' ...@@ -2,20 +2,20 @@ import low from 'lowdb'
import LocalStorage from 'lowdb/adapters/LocalStorage' import LocalStorage from 'lowdb/adapters/LocalStorage'
import util from '@/libs/util' import util from '@/libs/util'
const isDev = process.env.NODE_ENV === 'development' const isDev = process.env.NODE_ENV === 'development'
// const adapter = new LocalStorage(`${process.env.VUE_APP_STORAGE_PREFIX}-${process.env.VUE_APP_VERSION}`, { 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)), serialize: (data) => isDev ? JSON.stringify(data) : escape(JSON.stringify(data)),
// deserialize: (data) => isDev ? JSON.parse(data) : JSON.parse(unescape(data)) deserialize: (data) => isDev ? JSON.parse(data) : JSON.parse(unescape(data))
// }) })
// const db = low(adapter) const db = low(adapter)
// db db
// .defaults({ .defaults({
// sys: {}, sys: {},
// database: {} database: {}
// }) })
// .write() .write()
// export default db export default db
/** /**
* @description 检查路径是否存在 不存在的话初始化 * @description 检查路径是否存在 不存在的话初始化
...@@ -31,16 +31,16 @@ export function pathInit({ ...@@ -31,16 +31,16 @@ export function pathInit({
path = '', path = '',
user = true, user = true,
validator = () => true, validator = () => true,
defaultValue = '.' defaultValue = ''
}) { }) {
const uuid = util.cookies.get('uuid') || 'ghost-uuid' const uuid = util.cookies.get('uuid') || 'ghost-uuid'
const currentPath = `${dbName}.${user ? `user.${uuid}` : 'public'}${path ? `.${path}` : ''}` const currentPath = `${dbName}.${user ? `user.${uuid}` : 'public'}${path ? `.${path}` : ''}`
// const value = db.get(currentPath).value() const value = db.get(currentPath).value()
// if (!(value !== undefined && validator(value))) { if (!(value !== undefined && validator(value))) {
// db db
// .set(currentPath, defaultValue) .set(currentPath, defaultValue)
// .write() .write()
// } }
return currentPath return currentPath
} }
...@@ -58,16 +58,11 @@ export function dbSet({ ...@@ -58,16 +58,11 @@ export function dbSet({
value = '', value = '',
user = false user = false
}) { }) {
// db.set(pathInit({ db.set(pathInit({
// dbName, dbName,
// path, path,
// user user
// }), value).write() }), value).write()
localStorage.setItem(pathInit({
dbName,
path,
user
}),JSON.stringify(value))
} }
/** /**
...@@ -84,22 +79,13 @@ export function dbGet({ ...@@ -84,22 +79,13 @@ export function dbGet({
defaultValue = '', defaultValue = '',
user = false user = false
}) { }) {
console.log(dbName,
path,
user,
defaultValue)
return new Promise(resolve => { return new Promise(resolve => {
// resolve(_.cloneDeep(db.get(pathInit({ resolve(_.cloneDeep(db.get(pathInit({
// dbName,
// path,
// user,
// defaultValue
// })).value()))
resolve(JSON.parse(localStorage.getItem(pathInit({
dbName, dbName,
path, path,
user user,
})))) defaultValue
})).value()))
}) })
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!