style: update store
This commit is contained in:
+9
-13
@@ -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
|
}))
|
||||||
})))
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,50 +14,42 @@ 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 赋值
|
state.value = color || process.env.VUE_APP_ELEMENT_COLOR
|
||||||
state.value = color || process.env.VUE_APP_ELEMENT_COLOR
|
// 持久化
|
||||||
// 持久化
|
await dispatch('d2admin/db/set', {
|
||||||
await dispatch('d2admin/db/set', {
|
dbName: 'sys',
|
||||||
dbName: 'sys',
|
path: 'color.value',
|
||||||
path: 'color.value',
|
value: state.value,
|
||||||
value: state.value,
|
user: true
|
||||||
user: true
|
}, { root: true })
|
||||||
}, { root: true })
|
// 应用
|
||||||
// 应用
|
commit('apply', {
|
||||||
commit('apply', {
|
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 赋值
|
state.value = await dispatch('d2admin/db/get', {
|
||||||
state.value = await dispatch('d2admin/db/get', {
|
dbName: 'sys',
|
||||||
dbName: 'sys',
|
path: 'color.value',
|
||||||
path: 'color.value',
|
defaultValue: process.env.VUE_APP_ELEMENT_COLOR,
|
||||||
defaultValue: process.env.VUE_APP_ELEMENT_COLOR,
|
user: true
|
||||||
user: true
|
}, { root: true })
|
||||||
}, { root: true })
|
// 应用
|
||||||
// 应用
|
commit('apply', {
|
||||||
commit('apply', {
|
oldColor: old,
|
||||||
oldColor: old,
|
newColor: state.value
|
||||||
newColor: state.value
|
|
||||||
})
|
|
||||||
// end
|
|
||||||
resolve()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -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,17 +23,13 @@ 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)
|
} else {
|
||||||
} else {
|
screenfull.request()
|
||||||
screenfull.request()
|
commit('set', true)
|
||||||
commit('set', true)
|
}
|
||||||
}
|
|
||||||
// end
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
|
|||||||
@@ -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,41 +37,33 @@ 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
|
// 应用
|
||||||
// 应用
|
dispatch('apply', true)
|
||||||
dispatch('apply', true)
|
// 持久化
|
||||||
// 持久化
|
await dispatch('d2admin/db/set', {
|
||||||
await dispatch('d2admin/db/set', {
|
dbName: 'sys',
|
||||||
dbName: 'sys',
|
path: 'size.value',
|
||||||
path: 'size.value',
|
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',
|
path: 'size.value',
|
||||||
path: 'size.value',
|
defaultValue: 'default',
|
||||||
defaultValue: 'default',
|
user: true
|
||||||
user: true
|
}, { root: true })
|
||||||
}, { root: true })
|
// 应用
|
||||||
// 应用
|
dispatch('apply')
|
||||||
dispatch('apply')
|
|
||||||
// end
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,12 +23,35 @@ 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
|
commit('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', {
|
await dispatch('d2admin/db/set', {
|
||||||
dbName: 'sys',
|
dbName: 'sys',
|
||||||
@@ -36,40 +59,9 @@ export default {
|
|||||||
value: state.activeName,
|
value: state.activeName,
|
||||||
user: true
|
user: true
|
||||||
}, { root: true })
|
}, { root: true })
|
||||||
// end
|
}
|
||||||
resolve()
|
// 将 vuex 中的主题应用到 dom
|
||||||
})
|
commit('dom')
|
||||||
},
|
|
||||||
/**
|
|
||||||
* @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()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mutations: {
|
mutations: {
|
||||||
|
|||||||
@@ -13,37 +13,29 @@ 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
|
// 持久化
|
||||||
// 持久化
|
await dispatch('d2admin/db/set', {
|
||||||
await dispatch('d2admin/db/set', {
|
dbName: 'sys',
|
||||||
dbName: 'sys',
|
path: 'transition.active',
|
||||||
path: 'transition.active',
|
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',
|
path: 'transition.active',
|
||||||
path: 'transition.active',
|
defaultValue: setting.transition.active,
|
||||||
defaultValue: setting.transition.active,
|
user: true
|
||||||
user: true
|
}, { root: true })
|
||||||
}, { root: true })
|
|
||||||
// end
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,37 +10,29 @@ 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
|
// 持久化
|
||||||
// 持久化
|
await dispatch('d2admin/db/set', {
|
||||||
await dispatch('d2admin/db/set', {
|
dbName: 'sys',
|
||||||
dbName: 'sys',
|
path: 'user.info',
|
||||||
path: 'user.info',
|
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',
|
path: 'user.info',
|
||||||
path: 'user.info',
|
defaultValue: {},
|
||||||
defaultValue: {},
|
user: true
|
||||||
user: true
|
}, { root: true })
|
||||||
}, { root: true })
|
|
||||||
// end
|
|
||||||
resolve()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user