Files
mes-ui-d2/src/store/modules/theme.js
liyang 9b1fe4cae8 build image and file path compatibility repair
Former-commit-id: 69e5e4092b151379d27aa2eccde1255672277fb8 [formerly 69e5e4092b151379d27aa2eccde1255672277fb8 [formerly 69e5e4092b151379d27aa2eccde1255672277fb8 [formerly 69e5e4092b151379d27aa2eccde1255672277fb8 [formerly b70254441d8a42159229d3a1ffb6337a4904ce87 [formerly 218fe905d457ba3c6d7f48ceda77fbd38a6341ce]]]]]
Former-commit-id: 185cbeff13a282fadbf959c1227927501f39a728
Former-commit-id: 5740a528b4627568a348f2d3b59528a16c7a6f34
Former-commit-id: 771cc66a523221c6ee2b0279a0819caab64b2f53 [formerly c7def5344c50d8edf8a3b41a2dbc1305445282f2]
Former-commit-id: 3a9c6a8dd6b4399b04be05749d21692bff9ddc33
Former-commit-id: 6a4677e1001a6ec39cd7e5e051eaee1b1bf85ae1
Former-commit-id: 553208b3aaf49b39a63f495eec7097f9efcb2bd5
Former-commit-id: 1887cc7586fb947dd9f8815e61e6abd349bbdb4b
Former-commit-id: 0ba5ab3302ce4540b3706a32178e515ba9053536
2018-06-22 01:15:28 +08:00

68 lines
1.7 KiB
JavaScript

import Cookies from 'js-cookie'
export default {
state: {
list: [
{
name: 'd2admin 经典',
value: 'd2',
preview: 'static/image/theme/d2/preview@2x.png'
},
{
name: '简约线条',
value: 'line',
backgroundImage: 'static/image/bg/line-squashed.jpg',
preview: 'static/image/theme/line/preview@2x.png'
},
{
name: '流星',
value: 'star',
backgroundImage: 'static/image/bg/star-squashed.jpg',
preview: 'static/image/theme/star/preview@2x.png'
},
{
name: 'Tomorrow Night Blue (vsCode)',
value: 'tomorrow-night-blue',
preview: 'static/image/theme/tomorrow-night-blue/preview@2x.png'
}
],
name: '',
backGroundImage: ''
},
mutations: {
// 从 cookie 加载主题
loadTheme (state) {
const name = Cookies.get('themeName')
if (name) {
// 设置 store
state.name = name
// 激活主题
this.commit('activeTheme')
} else {
// 设置新的主题为列表第一项
this.commit('setTheme', state.list[0].value)
}
},
// 设置新的主题
setTheme (state, name) {
// 设置 store
state.name = name
// 设置 Cookie
Cookies.set('themeName', name, {
expires: 365
})
// 激活主题
this.commit('activeTheme')
},
// 激活当前主题
activeTheme (state) {
// 设置背景图片
const themeSetting = state.list.find(e => e.value === state.name)
if (themeSetting) {
state.backGroundImage = themeSetting.backgroundImage || ''
}
document.body.className = `theme-${state.name}`
}
}
}