Files
mes-ui-d2/src/store/modules/theme.js
liyang 870ec8b48a no message
Former-commit-id: 7bb5e62cb621d9a7e1d5d137ea1daf8e9bfbee74
Former-commit-id: 92e1ec9948b6bb6536eae3003b33b4fe9f1ff177
Former-commit-id: a30a575808b36631a6968d66afbeeaa8f183ce1c
2018-06-11 21:12:50 +08:00

48 lines
1.0 KiB
JavaScript

import Cookies from 'js-cookie'
export default {
state: {
list: [
{
name: 'd2admin 经典',
value: 'd2',
preview: '/static/image/theme-preview/d2@2x.png'
},
{
name: '流星',
value: 'star',
preview: '/static/image/theme-preview/star@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}`
}
}
}