mixin.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* 目前nuxt 版本如果不高于 1.0.0 并不支持vuex的方法,因此获取相对于的东西只能通过this.$store.state来获取
  2. 如果nuxt框架为 1.0.0以上,vuex属性状态这里可以优化
  3. */
  4. import BScroll from 'better-scroll'
  5. import Vue from 'vue'
  6. // import { mapState } from 'vuex'
  7. Vue.mixin({
  8. computed: {
  9. user() {
  10. return this.$store.state.option.user
  11. },
  12. sortEnterprises () {
  13. if (this.user.data.enterprises) {
  14. let ens = this.user.data.enterprises.slice()
  15. if (ens && ens.length) {
  16. ens.sort(function (a, b) {
  17. return b.lastLoginTime - a.lastLoginTime
  18. })
  19. }
  20. return ens
  21. } else {
  22. return ''
  23. }
  24. },
  25. // 判断是否erp嵌入
  26. isInFrame () {
  27. if (this.$route.query.type === 'erp') {
  28. this.$store.commit('option/ADD_COOKIES', 'type=erp;')
  29. return true
  30. } else {
  31. let cookies = this.$store.state.option.cookies
  32. let cookieArr = cookies.split(';')
  33. let cookieObj = {}
  34. for (let i = 0; i < cookieArr.length; i++) {
  35. if (cookieArr[i].indexOf('=') > -1) {
  36. let tmpArr = cookieArr[i].split('=')
  37. cookieObj[tmpArr[0].trim()] = tmpArr[1].trim()
  38. }
  39. }
  40. return cookieObj.type === 'erp'
  41. }
  42. }
  43. },
  44. methods: {
  45. goLastPage: function () {
  46. window.history.back(-1)
  47. },
  48. preventTouchMove (e) {
  49. e.preventDefault()
  50. },
  51. stopPropagation: function (e) {
  52. if (e) {
  53. e.stopPropagation()
  54. }
  55. },
  56. _initscroll() {
  57. if (!this.initSctoll) {
  58. this.initSctoll = new BScroll(this.$refs.mobileModalBox, {
  59. click: true
  60. })
  61. } else {
  62. this.initSctoll.refresh()
  63. }
  64. }
  65. }
  66. })