commit | author | age
|
9bcb19
|
1 |
// import Vue from 'vue' |
I |
2 |
import { deviceEnquire, DEVICE_TYPE } from '@/utils/device' |
|
3 |
import { mapState } from 'vuex' |
|
4 |
|
|
5 |
// const mixinsComputed = Vue.config.optionMergeStrategies.computed |
|
6 |
// const mixinsMethods = Vue.config.optionMergeStrategies.methods |
|
7 |
|
|
8 |
const mixin = { |
|
9 |
computed: { |
|
10 |
...mapState({ |
|
11 |
layoutMode: state => state.app.layout, |
|
12 |
navTheme: state => state.app.theme, |
|
13 |
primaryColor: state => state.app.color, |
|
14 |
colorWeak: state => state.app.weak, |
|
15 |
fixedHeader: state => state.app.fixedHeader, |
|
16 |
fixSiderbar: state => state.app.fixSiderbar, |
|
17 |
fixSidebar: state => state.app.fixSiderbar, |
|
18 |
contentWidth: state => state.app.contentWidth, |
|
19 |
autoHideHeader: state => state.app.autoHideHeader, |
|
20 |
sidebarOpened: state => state.app.sidebar, |
|
21 |
multiTab: state => state.app.multiTab |
|
22 |
}) |
|
23 |
}, |
|
24 |
methods: { |
|
25 |
isTopMenu () { |
|
26 |
return this.layoutMode === 'topmenu' |
|
27 |
}, |
|
28 |
isSideMenu () { |
|
29 |
return !this.isTopMenu() |
|
30 |
} |
|
31 |
} |
|
32 |
} |
|
33 |
|
|
34 |
const mixinDevice = { |
|
35 |
computed: { |
|
36 |
...mapState({ |
|
37 |
device: state => state.app.device |
|
38 |
}) |
|
39 |
}, |
|
40 |
methods: { |
|
41 |
isMobile () { |
|
42 |
return this.device === DEVICE_TYPE.MOBILE |
|
43 |
}, |
|
44 |
isDesktop () { |
|
45 |
return this.device === DEVICE_TYPE.DESKTOP |
|
46 |
}, |
|
47 |
isTablet () { |
|
48 |
return this.device === DEVICE_TYPE.TABLET |
|
49 |
} |
|
50 |
} |
|
51 |
} |
|
52 |
|
|
53 |
const AppDeviceEnquire = { |
|
54 |
mounted () { |
|
55 |
const { $store } = this |
|
56 |
deviceEnquire(deviceType => { |
|
57 |
switch (deviceType) { |
|
58 |
case DEVICE_TYPE.DESKTOP: |
|
59 |
$store.commit('TOGGLE_DEVICE', 'desktop') |
|
60 |
$store.dispatch('setSidebar', true) |
|
61 |
break |
|
62 |
case DEVICE_TYPE.TABLET: |
|
63 |
$store.commit('TOGGLE_DEVICE', 'tablet') |
|
64 |
$store.dispatch('setSidebar', false) |
|
65 |
break |
|
66 |
case DEVICE_TYPE.MOBILE: |
|
67 |
default: |
|
68 |
$store.commit('TOGGLE_DEVICE', 'mobile') |
|
69 |
$store.dispatch('setSidebar', true) |
|
70 |
break |
|
71 |
} |
|
72 |
}) |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
export { mixin, AppDeviceEnquire, mixinDevice } |