mixin.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. // 默认收起侧边栏
  58. $store.dispatch('setSidebar', false)
  59. break
  60. case DEVICE_TYPE.TABLET:
  61. $store.commit('TOGGLE_DEVICE', 'tablet')
  62. $store.dispatch('setSidebar', false)
  63. break
  64. case DEVICE_TYPE.MOBILE:
  65. default:
  66. $store.commit('TOGGLE_DEVICE', 'mobile')
  67. $store.dispatch('setSidebar', true)
  68. break
  69. }
  70. })
  71. }
  72. }
  73. export { mixin, AppDeviceEnquire, mixinDevice }