page
Former-commit-id: 1801c7a5909d5415b360a996d4ecab23280b1076 [formerly 1801c7a5909d5415b360a996d4ecab23280b1076 [formerly 1801c7a5909d5415b360a996d4ecab23280b1076 [formerly 1801c7a5909d5415b360a996d4ecab23280b1076 [formerly 209999b1c78ca63880406cb2b633c3560aae0eba [formerly 54edc3b4bd966e2496564198d59ff84fe9ba0b25]]]]] Former-commit-id: ad91a7092b963def0579ecc2011e578e87a8ecd5 Former-commit-id: fb96644ac016362df708618fafef872b7bc2567c Former-commit-id: 257c0b84b8069b3ccb8ddc53e965a974fca01189 [formerly 6954456a39b73136a14f80b0747aea90a694c9a5] Former-commit-id: 99c7481e576afeac70fff4effa7e57f6b17cb79d Former-commit-id: cfddcdd7f760c61e4abe02159a75d484ad6c6e63 Former-commit-id: 06d4e8cf94bd8c24fa167d77f843c93541afb5e6 Former-commit-id: ef6879d28d953c827184c4d5caa6c7fef6b2326f Former-commit-id: 1f1114b417621402ec7d9d3540b305563fb140ec
This commit is contained in:
99
src/store/modules/d2admin/index.js
Normal file
99
src/store/modules/d2admin/index.js
Normal file
@@ -0,0 +1,99 @@
|
||||
import get from 'lodash.get'
|
||||
import set from 'lodash.set'
|
||||
import utilLib from '@/libs/util.js'
|
||||
import dbLib from '@/libs/db.js'
|
||||
|
||||
// 模块
|
||||
|
||||
import db from './modules/db'
|
||||
import releases from './modules/releases'
|
||||
import user from './modules/user'
|
||||
import menu from './modules/menu'
|
||||
import theme from './modules/theme'
|
||||
import log from './modules/log'
|
||||
import account from './modules/account'
|
||||
import fullscreen from './modules/fullscreen'
|
||||
import ua from './modules/ua'
|
||||
import gray from './modules/gray'
|
||||
import page from './modules/page'
|
||||
|
||||
export default {
|
||||
namespaced: true,
|
||||
modules: {
|
||||
db,
|
||||
releases,
|
||||
user,
|
||||
menu,
|
||||
theme,
|
||||
log,
|
||||
account,
|
||||
fullscreen,
|
||||
ua,
|
||||
gray,
|
||||
page
|
||||
},
|
||||
mutations: {
|
||||
/**
|
||||
* @class 通用工具
|
||||
* @description 将 state 中某一项存储到数据库 如果已经有的话就更新数据 需要 uuid
|
||||
* @param {Object} state vuex state
|
||||
* @param {String} key key name
|
||||
*/
|
||||
utilVuex2DbByUuid (state, key) {
|
||||
const dbKey = key.split('.')[key.split('.').length - 1]
|
||||
const row = dbLib.get(dbKey).find({uuid: utilLib.cookies.get('uuid')})
|
||||
const value = get(state, key, '')
|
||||
if (row.value()) {
|
||||
row.assign({ value }).write()
|
||||
} else {
|
||||
dbLib.get(dbKey).push({
|
||||
uuid: utilLib.cookies.get('uuid'),
|
||||
value
|
||||
}).write()
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @class 通用工具
|
||||
* @description 从数据库取值到 vuex 需要 uuid
|
||||
* @param {Object} state vuex state
|
||||
* @param {Object} param key 键名, defaultValue 取值失败默认值, handleFunction 处理函数
|
||||
*/
|
||||
utilDb2VuexByUuid (state, { key, defaultValue, handleFunction }) {
|
||||
const dbKey = key.split('.')[key.split('.').length - 1]
|
||||
const row = dbLib.get(dbKey).find({uuid: utilLib.cookies.get('uuid')}).value()
|
||||
const handle = handleFunction || (res => res)
|
||||
set(state, key, row ? handle(row.value) : defaultValue)
|
||||
},
|
||||
/**
|
||||
* @class 通用工具
|
||||
* @description 将 state 中某一项存储到数据库 如果已经有的话就更新数据 不需要 uuid 所有用户共享
|
||||
* @param {Object} state vuex state
|
||||
* @param {String} key key name
|
||||
*/
|
||||
utilVuex2Db (state, key) {
|
||||
const dbKey = key.split('.')[key.split('.').length - 1]
|
||||
const row = dbLib.get(dbKey).find({pub: 'pub'})
|
||||
const value = get(state, key, '')
|
||||
if (row.value()) {
|
||||
row.assign({ value }).write()
|
||||
} else {
|
||||
dbLib.get(dbKey).push({
|
||||
pub: 'pub',
|
||||
value
|
||||
}).write()
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @class 通用工具
|
||||
* @description 从数据库取值到 vuex 不需要 uuid 所有用户共享
|
||||
* @param {Object} state vuex state
|
||||
* @param {Object} param key 键名, defaultValue 取值失败时的默认值, handleFunction 处理函数
|
||||
*/
|
||||
utilDb2Vuex (state, { key, defaultValue, handleFunction }) {
|
||||
const dbKey = key.split('.')[key.split('.').length - 1]
|
||||
const row = dbLib.get(dbKey).find({pub: 'pub'}).value()
|
||||
const handle = handleFunction || (res => res)
|
||||
set(state, key, row ? handle(row.value) : defaultValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user