diff --git a/src/layout/header-aside/components/header-color/index.vue b/src/layout/header-aside/components/header-color/index.vue index fc956dc2..e350add3 100644 --- a/src/layout/header-aside/components/header-color/index.vue +++ b/src/layout/header-aside/components/header-color/index.vue @@ -1,11 +1,13 @@ diff --git a/src/store/modules/d2admin/modules/account.js b/src/store/modules/d2admin/modules/account.js index fb089607..6d6615e0 100644 --- a/src/store/modules/d2admin/modules/account.js +++ b/src/store/modules/d2admin/modules/account.js @@ -107,6 +107,7 @@ export default { await dispatch('d2admin/menu/asideCollapseLoad', null, { root: true }) // DB -> store 持久化数据加载全局尺寸 await dispatch('d2admin/size/load', null, { root: true }) + // DB -> store 持久化数据加载颜色设置 await dispatch('d2admin/color/load', null, { root: true }) // end resolve() diff --git a/src/store/modules/d2admin/modules/color.js b/src/store/modules/d2admin/modules/color.js index 85c35175..7f308834 100644 --- a/src/store/modules/d2admin/modules/color.js +++ b/src/store/modules/d2admin/modules/color.js @@ -1,3 +1,6 @@ +import client from 'webpack-theme-color-replacer/client' +import forElementUI from 'webpack-theme-color-replacer/forElementUI' + export default { namespaced: true, state: { @@ -10,8 +13,10 @@ export default { * @param {Object} state vuex state * @param {String} color 尺寸 */ - set ({ state, dispatch }, color) { + set ({ state, dispatch, commit }, color) { return new Promise(async resolve => { + // 记录上个值 + const old = state.value // store 赋值 state.value = color // 持久化 @@ -21,6 +26,11 @@ export default { value: state.value, user: true }, { root: true }) + // 应用 + commit('apply', { + oldColor: old, + newColor: state.value + }) // end resolve() }) @@ -29,8 +39,10 @@ export default { * @description 从持久化数据读取颜色设置 * @param {Object} state vuex state */ - load ({ state, dispatch }) { + load ({ state, dispatch, commit }) { return new Promise(async resolve => { + // 记录上个值 + const old = state.value // store 赋值 state.value = await dispatch('d2admin/db/get', { dbName: 'sys', @@ -38,9 +50,28 @@ export default { defaultValue: process.env.VUE_APP_ELEMENT_COLOR, user: true }, { root: true }) + // 应用 + commit('apply', { + oldColor: old, + newColor: state.value + }) // end resolve() }) } + }, + mutations: { + /** + * @description 将 vuex 中的主题颜色设置应用到系统中 + * @param {Object} state vuex state + * @param {Object} payload 设置 + */ + apply (state, { oldColor, newColor }) { + var options = { + oldColors: [...forElementUI.getElementUISeries(oldColor)], + newColors: [...forElementUI.getElementUISeries(newColor)] + } + client.changer.changeColor(options) + } } }