diff --git a/src/libs/util.db.js b/src/libs/util.db.js index eca7d82..e51eec4 100644 --- a/src/libs/util.db.js +++ b/src/libs/util.db.js @@ -77,14 +77,12 @@ export function dbGet ({ defaultValue = '', user = false }) { - return new Promise(resolve => { - resolve(cloneDeep(db.get(pathInit({ - dbName, - path, - user, - defaultValue - })).value())) - }) + return cloneDeep(db.get(pathInit({ + dbName, + path, + user, + defaultValue + })).value()) } /** @@ -98,9 +96,7 @@ export function database ({ validator = () => true, defaultValue = '' } = {}) { - return new Promise(resolve => { - resolve(db.get(pathInit({ - dbName, path, user, validator, defaultValue - }))) - }) + return db.get(pathInit({ + dbName, path, user, validator, defaultValue + })) } diff --git a/src/store/modules/d2admin/modules/color.js b/src/store/modules/d2admin/modules/color.js index 0b22cba..a217e81 100644 --- a/src/store/modules/d2admin/modules/color.js +++ b/src/store/modules/d2admin/modules/color.js @@ -1,3 +1,4 @@ +import { cloneDeep } from 'lodash' import client from 'webpack-theme-color-replacer/client' import forElementUI from 'webpack-theme-color-replacer/forElementUI' @@ -13,50 +14,42 @@ export default { * @param {Object} context * @param {String} color 尺寸 */ - set ({ state, dispatch, commit }, color) { - return new Promise(async resolve => { - // 记录上个值 - const old = state.value - // store 赋值 - state.value = color || process.env.VUE_APP_ELEMENT_COLOR - // 持久化 - await dispatch('d2admin/db/set', { - dbName: 'sys', - path: 'color.value', - value: state.value, - user: true - }, { root: true }) - // 应用 - commit('apply', { - oldColor: old, - newColor: state.value - }) - // end - resolve() + async set ({ state, dispatch, commit }, color) { + // 记录上个值 + const old = state.value + // store 赋值 + state.value = color || process.env.VUE_APP_ELEMENT_COLOR + // 持久化 + await dispatch('d2admin/db/set', { + dbName: 'sys', + path: 'color.value', + value: state.value, + user: true + }, { root: true }) + // 应用 + commit('apply', { + oldColor: old, + newColor: state.value }) }, /** * @description 从持久化数据读取颜色设置 * @param {Object} context */ - load ({ state, dispatch, commit }) { - return new Promise(async resolve => { - // 记录上个值 - const old = state.value - // store 赋值 - state.value = await dispatch('d2admin/db/get', { - dbName: 'sys', - path: 'color.value', - defaultValue: process.env.VUE_APP_ELEMENT_COLOR, - user: true - }, { root: true }) - // 应用 - commit('apply', { - oldColor: old, - newColor: state.value - }) - // end - resolve() + async load ({ state, dispatch, commit }) { + // 记录上个值 + const old = state.value + // store 赋值 + state.value = await dispatch('d2admin/db/get', { + dbName: 'sys', + path: 'color.value', + defaultValue: process.env.VUE_APP_ELEMENT_COLOR, + user: true + }, { root: true }) + // 应用 + commit('apply', { + oldColor: old, + newColor: state.value }) } }, @@ -69,8 +62,8 @@ export default { */ apply (state, { oldColor, newColor }) { var options = { - oldColors: [...forElementUI.getElementUISeries(oldColor)], - newColors: [...forElementUI.getElementUISeries(newColor)] + oldColors: cloneDeep(forElementUI.getElementUISeries(oldColor)), + newColors: cloneDeep(forElementUI.getElementUISeries(newColor)) } client.changer.changeColor(options) } diff --git a/src/store/modules/d2admin/modules/fullscreen.js b/src/store/modules/d2admin/modules/fullscreen.js index bfa8ceb..da3391b 100644 --- a/src/store/modules/d2admin/modules/fullscreen.js +++ b/src/store/modules/d2admin/modules/fullscreen.js @@ -23,17 +23,13 @@ export default { * @param {Object} context */ toggle ({ commit }) { - return new Promise(resolve => { - if (screenfull.isFullscreen) { - screenfull.exit() - commit('set', false) - } else { - screenfull.request() - commit('set', true) - } - // end - resolve() - }) + if (screenfull.isFullscreen) { + screenfull.exit() + commit('set', false) + } else { + screenfull.request() + commit('set', true) + } } }, mutations: { diff --git a/src/store/modules/d2admin/modules/size.js b/src/store/modules/d2admin/modules/size.js index 539e6d4..265ea70 100644 --- a/src/store/modules/d2admin/modules/size.js +++ b/src/store/modules/d2admin/modules/size.js @@ -28,9 +28,7 @@ export default { if (state.value) return Promise.resolve() return new Promise(resolve => { const timer = setInterval(() => { - if (state.value) { - resolve(clearInterval(timer)) - } + if (state.value) resolve(clearInterval(timer)) }, 10) }) }, @@ -39,41 +37,33 @@ export default { * @param {Object} context * @param {String} size 尺寸 */ - set ({ state, dispatch }, size) { - return new Promise(async resolve => { - // store 赋值 - state.value = size - // 应用 - dispatch('apply', true) - // 持久化 - await dispatch('d2admin/db/set', { - dbName: 'sys', - path: 'size.value', - value: state.value, - user: true - }, { root: true }) - // end - resolve() - }) + async set ({ state, dispatch }, size) { + // store 赋值 + state.value = size + // 应用 + dispatch('apply', true) + // 持久化 + await dispatch('d2admin/db/set', { + dbName: 'sys', + path: 'size.value', + value: state.value, + user: true + }, { root: true }) }, /** * @description 从持久化数据读取尺寸设置 * @param {Object} context */ - load ({ state, dispatch }) { - return new Promise(async resolve => { - // store 赋值 - state.value = await dispatch('d2admin/db/get', { - dbName: 'sys', - path: 'size.value', - defaultValue: 'default', - user: true - }, { root: true }) - // 应用 - dispatch('apply') - // end - resolve() - }) + async load ({ state, dispatch }) { + // store 赋值 + state.value = await dispatch('d2admin/db/get', { + dbName: 'sys', + path: 'size.value', + defaultValue: 'default', + user: true + }, { root: true }) + // 应用 + dispatch('apply') } } } diff --git a/src/store/modules/d2admin/modules/theme.js b/src/store/modules/d2admin/modules/theme.js index 93f1c23..df2d9a2 100644 --- a/src/store/modules/d2admin/modules/theme.js +++ b/src/store/modules/d2admin/modules/theme.js @@ -1,13 +1,13 @@ -// 设置文件 +import { get } from 'lodash' import setting from '@/setting.js' export default { namespaced: true, 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: { /** @@ -23,12 +23,35 @@ export default { * @description 激活一个主题 * @param {String} themeValue 需要激活的主题名称 */ - set ({ state, commit, dispatch }, themeName) { - return new Promise(async resolve => { - // 检查这个主题在主题列表里是否存在 - state.activeName = state.list.find(e => e.name === themeName) ? themeName : state.list[0].name - // 将 vuex 中的主题应用到 dom - commit('dom') + async set ({ state, commit, dispatch }, themeName) { + // 检查这个主题在主题列表里是否存在 + state.activeName = state.list.find(e => e.name === themeName) ? themeName : state.list[0].name + // 将 vuex 中的主题应用到 dom + commit('dom') + // 持久化 + await dispatch('d2admin/db/set', { + dbName: 'sys', + path: 'theme.activeName', + value: state.activeName, + user: true + }, { root: true }) + }, + /** + * @description 从持久化数据加载主题设置 * @param {Object} context + */ + async load ({ state, commit, dispatch }) { + // store 赋值 + let activeName = await dispatch('d2admin/db/get', { + dbName: 'sys', + path: 'theme.activeName', + defaultValue: state.list[0].name, + user: true + }, { root: true }) + // 检查这个主题在主题列表里是否存在 + if (state.list.find(e => e.name === activeName)) { + state.activeName = activeName + } else { + state.activeName = state.list[0].name // 持久化 await dispatch('d2admin/db/set', { dbName: 'sys', @@ -36,40 +59,9 @@ export default { value: state.activeName, user: true }, { root: true }) - // end - resolve() - }) - }, - /** - * @description 从持久化数据加载主题设置 * @param {Object} context - */ - load ({ state, commit, dispatch }) { - return new Promise(async resolve => { - // store 赋值 - let activeName = await dispatch('d2admin/db/get', { - dbName: 'sys', - path: 'theme.activeName', - defaultValue: state.list[0].name, - user: true - }, { root: true }) - // 检查这个主题在主题列表里是否存在 - if (state.list.find(e => e.name === activeName)) { - state.activeName = activeName - } else { - state.activeName = state.list[0].name - // 持久化 - await dispatch('d2admin/db/set', { - dbName: 'sys', - path: 'theme.activeName', - value: state.activeName, - user: true - }, { root: true }) - } - // 将 vuex 中的主题应用到 dom - commit('dom') - // end - resolve() - }) + } + // 将 vuex 中的主题应用到 dom + commit('dom') } }, mutations: { diff --git a/src/store/modules/d2admin/modules/transition.js b/src/store/modules/d2admin/modules/transition.js index 3849464..edb7c12 100644 --- a/src/store/modules/d2admin/modules/transition.js +++ b/src/store/modules/d2admin/modules/transition.js @@ -13,37 +13,29 @@ export default { * @param {Object} context * @param {Boolean} active 新的状态 */ - set ({ state, dispatch }, active) { - return new Promise(async resolve => { - // store 赋值 - state.active = active - // 持久化 - await dispatch('d2admin/db/set', { - dbName: 'sys', - path: 'transition.active', - value: state.active, - user: true - }, { root: true }) - // end - resolve() - }) + async set ({ state, dispatch }, active) { + // store 赋值 + state.active = active + // 持久化 + await dispatch('d2admin/db/set', { + dbName: 'sys', + path: 'transition.active', + value: state.active, + user: true + }, { root: true }) }, /** * 从数据库读取页面过渡动画设置 * @param {Object} context */ - load ({ state, dispatch }) { - return new Promise(async resolve => { - // store 赋值 - state.active = await dispatch('d2admin/db/get', { - dbName: 'sys', - path: 'transition.active', - defaultValue: setting.transition.active, - user: true - }, { root: true }) - // end - resolve() - }) + async load ({ state, dispatch }) { + // store 赋值 + state.active = await dispatch('d2admin/db/get', { + dbName: 'sys', + path: 'transition.active', + defaultValue: setting.transition.active, + user: true + }, { root: true }) } } } diff --git a/src/store/modules/d2admin/modules/user.js b/src/store/modules/d2admin/modules/user.js index 1a55246..13c9fc3 100644 --- a/src/store/modules/d2admin/modules/user.js +++ b/src/store/modules/d2admin/modules/user.js @@ -10,37 +10,29 @@ export default { * @param {Object} context * @param {*} info info */ - set ({ state, dispatch }, info) { - return new Promise(async resolve => { - // store 赋值 - state.info = info - // 持久化 - await dispatch('d2admin/db/set', { - dbName: 'sys', - path: 'user.info', - value: info, - user: true - }, { root: true }) - // end - resolve() - }) + async set ({ state, dispatch }, info) { + // store 赋值 + state.info = info + // 持久化 + await dispatch('d2admin/db/set', { + dbName: 'sys', + path: 'user.info', + value: info, + user: true + }, { root: true }) }, /** * @description 从数据库取用户数据 * @param {Object} context */ - load ({ state, dispatch }) { - return new Promise(async resolve => { - // store 赋值 - state.info = await dispatch('d2admin/db/get', { - dbName: 'sys', - path: 'user.info', - defaultValue: {}, - user: true - }, { root: true }) - // end - resolve() - }) + async load ({ state, dispatch }) { + // store 赋值 + state.info = await dispatch('d2admin/db/get', { + dbName: 'sys', + path: 'user.info', + defaultValue: {}, + user: true + }, { root: true }) } } }