You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.6 KiB
72 lines
1.6 KiB
|
6 years ago
|
/**
|
||
|
|
* 侧边栏的响应式数据
|
||
|
|
*/
|
||
|
|
import Vue from 'vue'
|
||
|
|
import {bindThis} from "@/util"
|
||
|
|
import {createGetters, createMutations} from "@/util/observable"
|
||
|
|
import {getters as appGetters} from "./app"
|
||
|
|
|
||
|
|
const state = {
|
||
|
|
//抽屉模式时的显隐
|
||
|
|
show: false,
|
||
|
|
|
||
|
6 years ago
|
//主题,light 或 dark
|
||
|
|
theme: 'light',
|
||
|
|
|
||
|
6 years ago
|
//手风琴效果
|
||
|
|
uniqueOpen: true,
|
||
|
|
|
||
|
|
//是否折叠
|
||
|
|
collapse: false,
|
||
|
|
|
||
|
|
//折叠时显示上级
|
||
|
|
showParentOnCollapse: false,
|
||
|
|
|
||
|
|
//自动隐藏
|
||
|
6 years ago
|
autoHide: false,
|
||
|
|
|
||
|
|
//汉堡包的位置,aside 或 head
|
||
|
6 years ago
|
hamburgerPosition: 'aside',
|
||
|
|
|
||
|
|
//是否显示搜索框
|
||
|
|
search: true
|
||
|
6 years ago
|
}
|
||
|
|
|
||
|
|
const store = Vue.observable(state)
|
||
|
|
|
||
|
|
export const getters = createGetters(store)
|
||
|
|
|
||
|
|
export const mutations = bindThis({
|
||
|
|
...createMutations(store),
|
||
|
|
|
||
|
6 years ago
|
/*移动端或设置了侧边栏自动隐藏时打开关闭抽屉,否则展开折叠*/
|
||
|
6 years ago
|
open() {
|
||
|
6 years ago
|
if (appGetters.isMobile || store.autoHide) {
|
||
|
6 years ago
|
store.show = true
|
||
|
|
}
|
||
|
|
else store.collapse = false
|
||
|
|
},
|
||
|
|
close() {
|
||
|
6 years ago
|
if (appGetters.isMobile || store.autoHide) {
|
||
|
6 years ago
|
store.show = false
|
||
|
|
}
|
||
|
|
else store.collapse = true
|
||
|
|
},
|
||
|
|
//切换侧边栏的状态
|
||
|
|
switch(action) {
|
||
|
|
switch (action) {
|
||
|
|
case 'open':
|
||
|
|
return this.open()
|
||
|
|
case 'close':
|
||
|
|
return this.close()
|
||
|
|
default :
|
||
|
|
let open = true
|
||
|
6 years ago
|
if (appGetters.isMobile) {
|
||
|
6 years ago
|
open = !store.show
|
||
|
|
}
|
||
|
|
else open = store.collapse
|
||
|
|
return open ? this.open() : this.close()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
})
|