mpwxs.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. let mpMixins = {}
  2. // #ifdef APP-VUE|| MP-WEIXIN || H5
  3. import {isPC} from "./isPC"
  4. mpMixins = {
  5. data() {
  6. return {
  7. is_show: 'none'
  8. }
  9. },
  10. watch: {
  11. show(newVal) {
  12. this.is_show = this.show
  13. }
  14. },
  15. created() {
  16. this.swipeaction = this.getSwipeAction()
  17. if (this.swipeaction.children !== undefined) {
  18. this.swipeaction.children.push(this)
  19. }
  20. },
  21. mounted() {
  22. this.is_show = this.show
  23. },
  24. methods: {
  25. // wxs 中调用
  26. closeSwipe(e) {
  27. if (!this.autoClose) return
  28. this.swipeaction.closeOther(this)
  29. },
  30. change(e) {
  31. this.$emit('change', e.open)
  32. if (this.is_show !== e.open) {
  33. this.is_show = e.open
  34. }
  35. },
  36. appTouchStart(e) {
  37. // #ifdef H5
  38. if (isPC()) return
  39. // #endif
  40. const {
  41. clientX
  42. } = e.changedTouches[0]
  43. this.clientX = clientX
  44. this.timestamp = new Date().getTime()
  45. },
  46. appTouchEnd(e, index, item, position) {
  47. // #ifdef H5
  48. if (isPC()) return
  49. // #endif
  50. const {
  51. clientX
  52. } = e.changedTouches[0]
  53. // fixed by xxxx 模拟点击事件,解决 ios 13 点击区域错位的问题
  54. let diff = Math.abs(this.clientX - clientX)
  55. let time = (new Date().getTime()) - this.timestamp
  56. if (diff < 40 && time < 300) {
  57. this.$emit('click', {
  58. content: item,
  59. index,
  60. position
  61. })
  62. }
  63. },
  64. onClickForPC(index, item, position) {
  65. // #ifdef H5
  66. if (!isPC()) return
  67. this.$emit('click', {
  68. content: item,
  69. index,
  70. position
  71. })
  72. // #endif
  73. }
  74. }
  75. }
  76. // #endif
  77. export default mpMixins