style: update store

This commit is contained in:
FairyEver
2020-05-06 19:35:17 +08:00
parent 5313f368fa
commit 9e8e3345f1
7 changed files with 143 additions and 192 deletions
+4 -8
View File
@@ -77,14 +77,12 @@ export function dbGet ({
defaultValue = '', defaultValue = '',
user = false user = false
}) { }) {
return new Promise(resolve => { return cloneDeep(db.get(pathInit({
resolve(cloneDeep(db.get(pathInit({
dbName, dbName,
path, path,
user, user,
defaultValue defaultValue
})).value())) })).value())
})
} }
/** /**
@@ -98,9 +96,7 @@ export function database ({
validator = () => true, validator = () => true,
defaultValue = '' defaultValue = ''
} = {}) { } = {}) {
return new Promise(resolve => { return db.get(pathInit({
resolve(db.get(pathInit({
dbName, path, user, validator, defaultValue dbName, path, user, validator, defaultValue
}))) }))
})
} }
+5 -12
View File
@@ -1,3 +1,4 @@
import { cloneDeep } from 'lodash'
import client from 'webpack-theme-color-replacer/client' import client from 'webpack-theme-color-replacer/client'
import forElementUI from 'webpack-theme-color-replacer/forElementUI' import forElementUI from 'webpack-theme-color-replacer/forElementUI'
@@ -13,8 +14,7 @@ export default {
* @param {Object} context * @param {Object} context
* @param {String} color 尺寸 * @param {String} color 尺寸
*/ */
set ({ state, dispatch, commit }, color) { async set ({ state, dispatch, commit }, color) {
return new Promise(async resolve => {
// 记录上个值 // 记录上个值
const old = state.value const old = state.value
// store 赋值 // store 赋值
@@ -31,16 +31,12 @@ export default {
oldColor: old, oldColor: old,
newColor: state.value newColor: state.value
}) })
// end
resolve()
})
}, },
/** /**
* @description 从持久化数据读取颜色设置 * @description 从持久化数据读取颜色设置
* @param {Object} context * @param {Object} context
*/ */
load ({ state, dispatch, commit }) { async load ({ state, dispatch, commit }) {
return new Promise(async resolve => {
// 记录上个值 // 记录上个值
const old = state.value const old = state.value
// store 赋值 // store 赋值
@@ -55,9 +51,6 @@ export default {
oldColor: old, oldColor: old,
newColor: state.value newColor: state.value
}) })
// end
resolve()
})
} }
}, },
mutations: { mutations: {
@@ -69,8 +62,8 @@ export default {
*/ */
apply (state, { oldColor, newColor }) { apply (state, { oldColor, newColor }) {
var options = { var options = {
oldColors: [...forElementUI.getElementUISeries(oldColor)], oldColors: cloneDeep(forElementUI.getElementUISeries(oldColor)),
newColors: [...forElementUI.getElementUISeries(newColor)] newColors: cloneDeep(forElementUI.getElementUISeries(newColor))
} }
client.changer.changeColor(options) client.changer.changeColor(options)
} }
@@ -23,7 +23,6 @@ export default {
* @param {Object} context * @param {Object} context
*/ */
toggle ({ commit }) { toggle ({ commit }) {
return new Promise(resolve => {
if (screenfull.isFullscreen) { if (screenfull.isFullscreen) {
screenfull.exit() screenfull.exit()
commit('set', false) commit('set', false)
@@ -31,9 +30,6 @@ export default {
screenfull.request() screenfull.request()
commit('set', true) commit('set', true)
} }
// end
resolve()
})
} }
}, },
mutations: { mutations: {
+3 -13
View File
@@ -28,9 +28,7 @@ export default {
if (state.value) return Promise.resolve() if (state.value) return Promise.resolve()
return new Promise(resolve => { return new Promise(resolve => {
const timer = setInterval(() => { const timer = setInterval(() => {
if (state.value) { if (state.value) resolve(clearInterval(timer))
resolve(clearInterval(timer))
}
}, 10) }, 10)
}) })
}, },
@@ -39,8 +37,7 @@ export default {
* @param {Object} context * @param {Object} context
* @param {String} size 尺寸 * @param {String} size 尺寸
*/ */
set ({ state, dispatch }, size) { async set ({ state, dispatch }, size) {
return new Promise(async resolve => {
// store 赋值 // store 赋值
state.value = size state.value = size
// 应用 // 应用
@@ -52,16 +49,12 @@ export default {
value: state.value, value: state.value,
user: true user: true
}, { root: true }) }, { root: true })
// end
resolve()
})
}, },
/** /**
* @description 从持久化数据读取尺寸设置 * @description 从持久化数据读取尺寸设置
* @param {Object} context * @param {Object} context
*/ */
load ({ state, dispatch }) { async load ({ state, dispatch }) {
return new Promise(async resolve => {
// store 赋值 // store 赋值
state.value = await dispatch('d2admin/db/get', { state.value = await dispatch('d2admin/db/get', {
dbName: 'sys', dbName: 'sys',
@@ -71,9 +64,6 @@ export default {
}, { root: true }) }, { root: true })
// 应用 // 应用
dispatch('apply') dispatch('apply')
// end
resolve()
})
} }
} }
} }
+5 -13
View File
@@ -1,13 +1,13 @@
// 设置文件 import { get } from 'lodash'
import setting from '@/setting.js' import setting from '@/setting.js'
export default { export default {
namespaced: true, namespaced: true,
state: { state: {
// 主题 // 主题
list: setting.theme.list, list: get(setting, 'theme.list', []),
// 现在激活的主题 这应该是一个名字 不是对象 // 现在激活的主题 这应该是一个名字 不是对象
activeName: setting.theme.list[0].name activeName: get(setting, 'theme.list[0].name', 'd2')
}, },
getters: { getters: {
/** /**
@@ -23,8 +23,7 @@ export default {
* @description 激活一个主题 * @description 激活一个主题
* @param {String} themeValue 需要激活的主题名称 * @param {String} themeValue 需要激活的主题名称
*/ */
set ({ state, commit, dispatch }, themeName) { async set ({ state, commit, dispatch }, themeName) {
return new Promise(async resolve => {
// 检查这个主题在主题列表里是否存在 // 检查这个主题在主题列表里是否存在
state.activeName = state.list.find(e => e.name === themeName) ? themeName : state.list[0].name state.activeName = state.list.find(e => e.name === themeName) ? themeName : state.list[0].name
// 将 vuex 中的主题应用到 dom // 将 vuex 中的主题应用到 dom
@@ -36,15 +35,11 @@ export default {
value: state.activeName, value: state.activeName,
user: true user: true
}, { root: true }) }, { root: true })
// end
resolve()
})
}, },
/** /**
* @description 从持久化数据加载主题设置 * @param {Object} context * @description 从持久化数据加载主题设置 * @param {Object} context
*/ */
load ({ state, commit, dispatch }) { async load ({ state, commit, dispatch }) {
return new Promise(async resolve => {
// store 赋值 // store 赋值
let activeName = await dispatch('d2admin/db/get', { let activeName = await dispatch('d2admin/db/get', {
dbName: 'sys', dbName: 'sys',
@@ -67,9 +62,6 @@ export default {
} }
// 将 vuex 中的主题应用到 dom // 将 vuex 中的主题应用到 dom
commit('dom') commit('dom')
// end
resolve()
})
} }
}, },
mutations: { mutations: {
@@ -13,8 +13,7 @@ export default {
* @param {Object} context * @param {Object} context
* @param {Boolean} active 新的状态 * @param {Boolean} active 新的状态
*/ */
set ({ state, dispatch }, active) { async set ({ state, dispatch }, active) {
return new Promise(async resolve => {
// store 赋值 // store 赋值
state.active = active state.active = active
// 持久化 // 持久化
@@ -24,16 +23,12 @@ export default {
value: state.active, value: state.active,
user: true user: true
}, { root: true }) }, { root: true })
// end
resolve()
})
}, },
/** /**
* 从数据库读取页面过渡动画设置 * 从数据库读取页面过渡动画设置
* @param {Object} context * @param {Object} context
*/ */
load ({ state, dispatch }) { async load ({ state, dispatch }) {
return new Promise(async resolve => {
// store 赋值 // store 赋值
state.active = await dispatch('d2admin/db/get', { state.active = await dispatch('d2admin/db/get', {
dbName: 'sys', dbName: 'sys',
@@ -41,9 +36,6 @@ export default {
defaultValue: setting.transition.active, defaultValue: setting.transition.active,
user: true user: true
}, { root: true }) }, { root: true })
// end
resolve()
})
} }
} }
} }
+2 -10
View File
@@ -10,8 +10,7 @@ export default {
* @param {Object} context * @param {Object} context
* @param {*} info info * @param {*} info info
*/ */
set ({ state, dispatch }, info) { async set ({ state, dispatch }, info) {
return new Promise(async resolve => {
// store 赋值 // store 赋值
state.info = info state.info = info
// 持久化 // 持久化
@@ -21,16 +20,12 @@ export default {
value: info, value: info,
user: true user: true
}, { root: true }) }, { root: true })
// end
resolve()
})
}, },
/** /**
* @description 从数据库取用户数据 * @description 从数据库取用户数据
* @param {Object} context * @param {Object} context
*/ */
load ({ state, dispatch }) { async load ({ state, dispatch }) {
return new Promise(async resolve => {
// store 赋值 // store 赋值
state.info = await dispatch('d2admin/db/get', { state.info = await dispatch('d2admin/db/get', {
dbName: 'sys', dbName: 'sys',
@@ -38,9 +33,6 @@ export default {
defaultValue: {}, defaultValue: {},
user: true user: true
}, { root: true }) }, { root: true })
// end
resolve()
})
} }
} }
} }