mixin.js 1.9 KB

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