no message
Former-commit-id: d07fe1d63fb90fabf61f1f8a18e58516ac2b745b [formerly d07fe1d63fb90fabf61f1f8a18e58516ac2b745b [formerly d07fe1d63fb90fabf61f1f8a18e58516ac2b745b [formerly d07fe1d63fb90fabf61f1f8a18e58516ac2b745b [formerly 6b59f360c22f390b3ec6f6948505e24378c0cecb [formerly 0472907a3f838efd21220b56a1c8c1176a1d51f6]]]]] Former-commit-id: 702c07649d30237673343180b4d020fc476f19e4 Former-commit-id: 97af6bd0619e0e88a2feb2c55b1aba996a7ad384 Former-commit-id: 1e73e419aa444484dff3f7261ea7db0787a15a59 [formerly 29ec469cfdd5c2c65c4c358c07b8957fdf87f364] Former-commit-id: 4735c6cfa1131c8dc048a770d8be08df715eeb5e Former-commit-id: 2ec0dbbd3fed3a07244066140a40dd7d4339ddf2 Former-commit-id: 09af0a4454198b6f1e700db0dacf2dcec688295a Former-commit-id: 68c3bda43ff8083da9e852b4c2cd046d296cfecb Former-commit-id: 2d81467c4fa25d64468f979ea5b33fcea323f251
This commit is contained in:
@@ -77,11 +77,11 @@ export default {
|
|||||||
},
|
},
|
||||||
mounted () {
|
mounted () {
|
||||||
// 加载主题
|
// 加载主题
|
||||||
this.d2adminThemeLoadFromLo()
|
this.d2adminThemeLoad()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapMutations([
|
...mapMutations([
|
||||||
'd2adminThemeLoadFromLo'
|
'd2adminThemeLoad'
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,14 @@
|
|||||||
|
import Cookies from 'js-cookie'
|
||||||
|
|
||||||
let util = {}
|
let util = {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 得到现在的用户
|
||||||
|
*/
|
||||||
|
util.uuid = function () {
|
||||||
|
return Cookies.get('uuid')
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打开全屏
|
* 打开全屏
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -3,13 +3,10 @@ import Vuex from 'vuex'
|
|||||||
|
|
||||||
import d2admin from './modules/d2admin'
|
import d2admin from './modules/d2admin'
|
||||||
|
|
||||||
import theme from './modules/theme'
|
|
||||||
|
|
||||||
Vue.use(Vuex)
|
Vue.use(Vuex)
|
||||||
|
|
||||||
export default new Vuex.Store({
|
export default new Vuex.Store({
|
||||||
modules: {
|
modules: {
|
||||||
d2admin,
|
d2admin
|
||||||
theme
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,15 +1,11 @@
|
|||||||
import util from '@/libs/util.js'
|
import util from '@/libs/util.js'
|
||||||
|
|
||||||
import themeList from '@/assets/style/theme/list.js'
|
|
||||||
|
|
||||||
import db from '@/libs/db.js'
|
import db from '@/libs/db.js'
|
||||||
|
import themeList from '@/assets/style/theme/list.js'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
state: {
|
state: {
|
||||||
// 系统
|
// 系统
|
||||||
appName: 'D2Admin',
|
appName: 'D2Admin',
|
||||||
// 用户
|
|
||||||
userId: '',
|
|
||||||
// 全屏
|
// 全屏
|
||||||
isFullScreen: false,
|
isFullScreen: false,
|
||||||
// 主题
|
// 主题
|
||||||
@@ -31,19 +27,43 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 激活新的主题
|
* 激活一个主题(应用到dom上)
|
||||||
* @param {state} state vuex state
|
* @param {state} state vuex state
|
||||||
|
* @param {string} themeActiveValue 需要激活的主题名称
|
||||||
*/
|
*/
|
||||||
d2adminThemeSet (state, themeActiveValue) {
|
d2adminThemeSet (state, themeActiveValue) {
|
||||||
console.log('d2adminThemeSet', themeActiveValue)
|
// 从列表里找到需要激活的主题的数据
|
||||||
|
const theme = state.themeList.find(e => e.value === themeActiveValue)
|
||||||
|
// 设置 state
|
||||||
|
state.themeActive = theme
|
||||||
|
// 设置 dom
|
||||||
|
document.body.className = `theme-${state.themeActive.value}`
|
||||||
|
// 保存到数据库
|
||||||
|
this.commit('d2adminThemeSave', themeActiveValue)
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* 从本地加载主题设置
|
* 从数据库加载主题设置
|
||||||
* @param {state} state vuex state
|
* @param {state} state vuex state
|
||||||
*/
|
*/
|
||||||
d2adminThemeLoadFromLo (state) {
|
d2adminThemeLoad (state) {
|
||||||
console.log(db.get('themeActive').find({name: 'hhh'}).value())
|
const themeActive = db.get('themeActive').find({uuid: util.uuid()}).value()
|
||||||
// db.get('themeActive').push({name: 'hhh'}).write()
|
this.commit('d2adminThemeSet', themeActive ? themeActive.value : state.themeList[0].value)
|
||||||
|
},
|
||||||
|
/**
|
||||||
|
* 向数据保存一个主题
|
||||||
|
* @param {state} state vuex state
|
||||||
|
* @param {string} themeActiveValue 需要保存的主题名称
|
||||||
|
*/
|
||||||
|
d2adminThemeSave (state, themeActiveValue) {
|
||||||
|
const setting = db.get('themeActive').find({uuid: util.uuid()})
|
||||||
|
if (setting.value()) {
|
||||||
|
setting.assign({value: themeActiveValue}).write()
|
||||||
|
} else {
|
||||||
|
db.get('themeActive').push({
|
||||||
|
uuid: util.uuid(),
|
||||||
|
value: themeActiveValue
|
||||||
|
}).write()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
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}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user