Files
mes-ui-d2/src/store/modules/theme.js
liyang 870cfe780e no message
Former-commit-id: d2d43cefdcf6072cd508d8e64062510ed5e3e086 [formerly d2d43cefdcf6072cd508d8e64062510ed5e3e086 [formerly d2d43cefdcf6072cd508d8e64062510ed5e3e086 [formerly d2d43cefdcf6072cd508d8e64062510ed5e3e086 [formerly b3fdc1e73b3414f9dfade8f485b99adbf036b2e9 [formerly c3700b44829953aea923edbf3ab5b9db6382930b]]]]]
Former-commit-id: 471bdc0cbefdc936b366d35a158e964d74b26069
Former-commit-id: 25fc285a63059865e40dda86f5f5a13da4ab3671
Former-commit-id: 58b3261c8b573ceeaff5210cb0f7d8da615c2f90 [formerly 5235d2f5df43e0e0c9f1285ff565036dc296dc92]
Former-commit-id: d19894aca0094ad1ac8b1bed2ddb73fdd1a21337
Former-commit-id: ca6fc0d78bf115e8c98c2a1977061fe7f910f6f0
Former-commit-id: 3fa391d327ac35fb4f5088e51387bbe8cad22274
Former-commit-id: 1d0ede8f99db796986dee5faf1960dab9cd33dde
Former-commit-id: 24a84ded86b3b74efafb17442d9a1b0bf6533d4f
2018-06-27 01:34:01 +08:00

73 lines
1.8 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: 'violet',
preview: 'static/image/theme/violet/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}`
}
}
}