mixin.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // import Vue from 'vue'
  2. import {mapState} from "vuex";
  3. // const mixinsComputed = Vue.config.optionMergeStrategies.computed
  4. // const mixinsMethods = Vue.config.optionMergeStrategies.methods
  5. const mixin = {
  6. computed: {
  7. ...mapState({
  8. layoutMode: state => state.app.layout,
  9. navTheme: state => state.app.theme,
  10. primaryColor: state => state.app.color,
  11. colorWeak: state => state.app.weak,
  12. multipage: state => state.app.multipage,//多页签设置
  13. fixedHeader: state => state.app.fixedHeader,
  14. fixSiderbar: state => state.app.fixSiderbar,
  15. contentWidth: state => state.app.contentWidth,
  16. autoHideHeader: state => state.app.autoHideHeader,
  17. sidebarOpened: state => state.app.sidebar.opened
  18. })
  19. }
  20. }
  21. const mixinDevice = {
  22. computed: {
  23. ...mapState({
  24. device: state => state.app.device,
  25. })
  26. },
  27. methods: {
  28. isMobile() {
  29. return this.device === 'mobile'
  30. },
  31. isDesktop() {
  32. return this.device === 'desktop'
  33. }
  34. }
  35. }
  36. export {mixin, mixinDevice}
  37. import { mapGetters, mapMutations, mapActions } from 'vuex'
  38. /**
  39. * 歌曲列表
  40. */
  41. export const listMixin = {
  42. computed: {
  43. ...mapGetters(['playing', 'currentMusic'])
  44. },
  45. methods: {
  46. selectItem(item, index) {
  47. if (item.id === this.currentMusic.id && this.playing) {
  48. this.setPlaying(false)
  49. } else {
  50. this.selectPlay({
  51. list: this.list,
  52. index
  53. })
  54. }
  55. },
  56. ...mapMutations({
  57. setPlaying: 'SET_PLAYING'
  58. }),
  59. ...mapActions(['selectPlay'])
  60. }
  61. }
  62. /**
  63. * loading状态
  64. * @type {{data(): *, methods: {_hideLoad(): void}}}
  65. */
  66. export const loadMixin = {
  67. data() {
  68. return {
  69. mmLoadShow: true // loading状态
  70. }
  71. },
  72. methods: {
  73. _hideLoad() {
  74. let timer
  75. clearTimeout(timer)
  76. timer = setTimeout(() => {
  77. this.mmLoadShow = false
  78. }, 200)
  79. }
  80. }
  81. }