style: update store
This commit is contained in:
+4
-8
@@ -77,14 +77,12 @@ export function dbGet ({
|
||||
defaultValue = '',
|
||||
user = false
|
||||
}) {
|
||||
return new Promise(resolve => {
|
||||
resolve(cloneDeep(db.get(pathInit({
|
||||
return cloneDeep(db.get(pathInit({
|
||||
dbName,
|
||||
path,
|
||||
user,
|
||||
defaultValue
|
||||
})).value()))
|
||||
})
|
||||
})).value())
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,9 +96,7 @@ export function database ({
|
||||
validator = () => true,
|
||||
defaultValue = ''
|
||||
} = {}) {
|
||||
return new Promise(resolve => {
|
||||
resolve(db.get(pathInit({
|
||||
return db.get(pathInit({
|
||||
dbName, path, user, validator, defaultValue
|
||||
})))
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -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,8 +14,7 @@ export default {
|
||||
* @param {Object} context
|
||||
* @param {String} color 尺寸
|
||||
*/
|
||||
set ({ state, dispatch, commit }, color) {
|
||||
return new Promise(async resolve => {
|
||||
async set ({ state, dispatch, commit }, color) {
|
||||
// 记录上个值
|
||||
const old = state.value
|
||||
// store 赋值
|
||||
@@ -31,16 +31,12 @@ export default {
|
||||
oldColor: old,
|
||||
newColor: state.value
|
||||
})
|
||||
// end
|
||||
resolve()
|
||||
})
|
||||
},
|
||||
/**
|
||||
* @description 从持久化数据读取颜色设置
|
||||
* @param {Object} context
|
||||
*/
|
||||
load ({ state, dispatch, commit }) {
|
||||
return new Promise(async resolve => {
|
||||
async load ({ state, dispatch, commit }) {
|
||||
// 记录上个值
|
||||
const old = state.value
|
||||
// store 赋值
|
||||
@@ -55,9 +51,6 @@ export default {
|
||||
oldColor: old,
|
||||
newColor: state.value
|
||||
})
|
||||
// end
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ export default {
|
||||
* @param {Object} context
|
||||
*/
|
||||
toggle ({ commit }) {
|
||||
return new Promise(resolve => {
|
||||
if (screenfull.isFullscreen) {
|
||||
screenfull.exit()
|
||||
commit('set', false)
|
||||
@@ -31,9 +30,6 @@ export default {
|
||||
screenfull.request()
|
||||
commit('set', true)
|
||||
}
|
||||
// end
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
|
||||
@@ -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,8 +37,7 @@ export default {
|
||||
* @param {Object} context
|
||||
* @param {String} size 尺寸
|
||||
*/
|
||||
set ({ state, dispatch }, size) {
|
||||
return new Promise(async resolve => {
|
||||
async set ({ state, dispatch }, size) {
|
||||
// store 赋值
|
||||
state.value = size
|
||||
// 应用
|
||||
@@ -52,16 +49,12 @@ export default {
|
||||
value: state.value,
|
||||
user: true
|
||||
}, { root: true })
|
||||
// end
|
||||
resolve()
|
||||
})
|
||||
},
|
||||
/**
|
||||
* @description 从持久化数据读取尺寸设置
|
||||
* @param {Object} context
|
||||
*/
|
||||
load ({ state, dispatch }) {
|
||||
return new Promise(async resolve => {
|
||||
async load ({ state, dispatch }) {
|
||||
// store 赋值
|
||||
state.value = await dispatch('d2admin/db/get', {
|
||||
dbName: 'sys',
|
||||
@@ -71,9 +64,6 @@ export default {
|
||||
}, { root: true })
|
||||
// 应用
|
||||
dispatch('apply')
|
||||
// end
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,8 +23,7 @@ export default {
|
||||
* @description 激活一个主题
|
||||
* @param {String} themeValue 需要激活的主题名称
|
||||
*/
|
||||
set ({ state, commit, dispatch }, themeName) {
|
||||
return new Promise(async resolve => {
|
||||
async set ({ state, commit, dispatch }, themeName) {
|
||||
// 检查这个主题在主题列表里是否存在
|
||||
state.activeName = state.list.find(e => e.name === themeName) ? themeName : state.list[0].name
|
||||
// 将 vuex 中的主题应用到 dom
|
||||
@@ -36,15 +35,11 @@ export default {
|
||||
value: state.activeName,
|
||||
user: true
|
||||
}, { root: true })
|
||||
// end
|
||||
resolve()
|
||||
})
|
||||
},
|
||||
/**
|
||||
* @description 从持久化数据加载主题设置 * @param {Object} context
|
||||
*/
|
||||
load ({ state, commit, dispatch }) {
|
||||
return new Promise(async resolve => {
|
||||
async load ({ state, commit, dispatch }) {
|
||||
// store 赋值
|
||||
let activeName = await dispatch('d2admin/db/get', {
|
||||
dbName: 'sys',
|
||||
@@ -67,9 +62,6 @@ export default {
|
||||
}
|
||||
// 将 vuex 中的主题应用到 dom
|
||||
commit('dom')
|
||||
// end
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
|
||||
@@ -13,8 +13,7 @@ export default {
|
||||
* @param {Object} context
|
||||
* @param {Boolean} active 新的状态
|
||||
*/
|
||||
set ({ state, dispatch }, active) {
|
||||
return new Promise(async resolve => {
|
||||
async set ({ state, dispatch }, active) {
|
||||
// store 赋值
|
||||
state.active = active
|
||||
// 持久化
|
||||
@@ -24,16 +23,12 @@ export default {
|
||||
value: state.active,
|
||||
user: true
|
||||
}, { root: true })
|
||||
// end
|
||||
resolve()
|
||||
})
|
||||
},
|
||||
/**
|
||||
* 从数据库读取页面过渡动画设置
|
||||
* @param {Object} context
|
||||
*/
|
||||
load ({ state, dispatch }) {
|
||||
return new Promise(async resolve => {
|
||||
async load ({ state, dispatch }) {
|
||||
// store 赋值
|
||||
state.active = await dispatch('d2admin/db/get', {
|
||||
dbName: 'sys',
|
||||
@@ -41,9 +36,6 @@ export default {
|
||||
defaultValue: setting.transition.active,
|
||||
user: true
|
||||
}, { root: true })
|
||||
// end
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,8 +10,7 @@ export default {
|
||||
* @param {Object} context
|
||||
* @param {*} info info
|
||||
*/
|
||||
set ({ state, dispatch }, info) {
|
||||
return new Promise(async resolve => {
|
||||
async set ({ state, dispatch }, info) {
|
||||
// store 赋值
|
||||
state.info = info
|
||||
// 持久化
|
||||
@@ -21,16 +20,12 @@ export default {
|
||||
value: info,
|
||||
user: true
|
||||
}, { root: true })
|
||||
// end
|
||||
resolve()
|
||||
})
|
||||
},
|
||||
/**
|
||||
* @description 从数据库取用户数据
|
||||
* @param {Object} context
|
||||
*/
|
||||
load ({ state, dispatch }) {
|
||||
return new Promise(async resolve => {
|
||||
async load ({ state, dispatch }) {
|
||||
// store 赋值
|
||||
state.info = await dispatch('d2admin/db/get', {
|
||||
dbName: 'sys',
|
||||
@@ -38,9 +33,6 @@ export default {
|
||||
defaultValue: {},
|
||||
user: true
|
||||
}, { root: true })
|
||||
// end
|
||||
resolve()
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user