mpwxs.js 1.6 KB

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