Files
mes-ui-d2/src/store/modules/theme.js
liyang e6de24eec9 no message
Former-commit-id: e2c026af338324e8b73c81c0eb1111aca4a59331
Former-commit-id: 17b4c62eb9d6969b2280d2be90c950135d6c97b1
Former-commit-id: d80fb50bd9af7a37f9f19a9c03814fe8caa75f72
Former-commit-id: 585047923edece36922102390b2df05079f25a40
2018-06-12 15:30:26 +08:00

58 lines
1.3 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',
preview: '/static/image/theme/line/preview@2x.png'
},
{
name: '流星',
value: 'star',
preview: '/static/image/theme/star/preview@2x.png'
},
{
name: 'tomorrow-night-blue',
value: 'tomorrow-night-blue',
preview: '/static/image/theme/tomorrow-night-blue/preview@2x.png'
}
],
name: ''
},
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)
// 激活主题
this.commit('activeTheme')
},
// 激活当前主题
activeTheme (state) {
document.body.className = `theme-${state.name}`
}
}
}