app.ts
1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { VuexModule, Module, Mutation, Action, getModule } from 'vuex-module-decorators'
import { getSidebarStatus, setSidebarStatus } from '@/utils/cookies'
import store from '@/store'
export enum DeviceType {
Mobile,
Desktop,
}
export interface IAppState {
device: DeviceType
sidebar: {
opened: boolean
withoutAnimation: boolean
}
}
@Module({ dynamic: true, store, name: 'app' })
class App extends VuexModule implements IAppState {
public sidebar = {
opened: getSidebarStatus() !== 'closed',
withoutAnimation: false
}
public device = DeviceType.Desktop
@Mutation
private TOGGLE_SIDEBAR(withoutAnimation: boolean) {
this.sidebar.opened = !this.sidebar.opened
this.sidebar.withoutAnimation = withoutAnimation
if (this.sidebar.opened) {
setSidebarStatus('opened')
} else {
setSidebarStatus('closed')
}
}
@Mutation
private CLOSE_SIDEBAR(withoutAnimation: boolean) {
this.sidebar.opened = false
this.sidebar.withoutAnimation = withoutAnimation
setSidebarStatus('closed')
}
@Mutation
private TOGGLE_DEVICE(device: DeviceType) {
this.device = device
}
@Action
public ToggleSideBar(withoutAnimation: boolean) {
this.TOGGLE_SIDEBAR(withoutAnimation)
}
@Action
public CloseSideBar(withoutAnimation: boolean) {
this.CLOSE_SIDEBAR(withoutAnimation)
}
@Action
public ToggleDevice(device: DeviceType) {
this.TOGGLE_DEVICE(device)
}
}
export const AppModule = getModule(App)