mixin.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. currentEnName () {
  44. if (this.user.data.enterprise) {
  45. return this.user.data.enterprise.uu ? this.user.data.enterprise.enName : this.user.data.userName + '(个人账户)'
  46. } else {
  47. return {}
  48. }
  49. }
  50. },
  51. methods: {
  52. goLastPage: function () {
  53. window.history.back(-1)
  54. },
  55. preventTouchMove (e) {
  56. e.preventDefault()
  57. },
  58. stopPropagation: function (e) {
  59. if (e) {
  60. e.stopPropagation()
  61. }
  62. },
  63. _initscroll() {
  64. if (!this.initSctoll) {
  65. this.initSctoll = new BScroll(this.$refs.mobileModalBox, {
  66. click: true
  67. })
  68. } else {
  69. this.initSctoll.refresh()
  70. }
  71. }
  72. },
  73. filters: {
  74. time: function (time) {
  75. if (typeof time === 'number') {
  76. if (!time) {
  77. return '无'
  78. } else {
  79. let d = new Date(time)
  80. let year = d.getFullYear()
  81. let month = d.getMonth() + 1
  82. let day = d.getDate() < 10 ? '0' + d.getDate() : '' + d.getDate()
  83. let hour = d.getHours() < 10 ? '0' + d.getHours() : '' + d.getHours()
  84. let minutes = d.getMinutes() < 10 ? '0' + d.getMinutes() : '' + d.getMinutes()
  85. let seconds = d.getSeconds() < 10 ? '0' + d.getSeconds() : '' + d.getSeconds()
  86. return year + '-' + month + '-' + day + ' ' + hour + ':' + minutes + ':' + seconds
  87. }
  88. }
  89. }
  90. }
  91. })