mixin.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 {deepCopy} from '~utils/baseUtils'
  7. // import { mapState } from 'vuex'
  8. Vue.mixin({
  9. computed: {
  10. user() {
  11. return this.$store.state.option.user
  12. },
  13. sortEnterprises () {
  14. if (this.user.data.enterprises) {
  15. let ens = this.user.data.enterprises.slice()
  16. if (ens && ens.length) {
  17. ens.sort(function (a, b) {
  18. return b.lastLoginTime - a.lastLoginTime
  19. })
  20. }
  21. return ens
  22. } else {
  23. return ''
  24. }
  25. },
  26. // 判断是否erp嵌入
  27. isInFrame () {
  28. if (this.$route.query.type === 'erp') {
  29. this.$store.commit('option/ADD_COOKIES', 'type=erp;')
  30. return true
  31. } else {
  32. let cookies = this.$store.state.option.cookies
  33. let cookieArr = cookies.split(';')
  34. let cookieObj = {}
  35. for (let i = 0; i < cookieArr.length; i++) {
  36. if (cookieArr[i].indexOf('=') > -1) {
  37. let tmpArr = cookieArr[i].split('=')
  38. cookieObj[tmpArr[0].trim()] = tmpArr[1].trim()
  39. }
  40. }
  41. return cookieObj.type === 'erp'
  42. }
  43. },
  44. currentEnName () {
  45. if (this.user.data.enterprise) {
  46. return this.user.data.enterprise.uu ? this.user.data.enterprise.enName : this.user.data.userName + '(个人账户)'
  47. } else {
  48. return {}
  49. }
  50. },
  51. baseUtils () {
  52. return {deepCopy: deepCopy}
  53. }
  54. },
  55. methods: {
  56. goLastPage: function () {
  57. window.history.back(-1)
  58. },
  59. preventTouchMove (e) {
  60. e.preventDefault()
  61. },
  62. stopPropagation: function (e) {
  63. if (e) {
  64. e.stopPropagation()
  65. }
  66. },
  67. _initscroll() {
  68. if (!this.initSctoll) {
  69. this.initSctoll = new BScroll(this.$refs.mobileModalBox, {
  70. click: true
  71. })
  72. } else {
  73. this.initSctoll.refresh()
  74. }
  75. }
  76. }
  77. })