mpwxs.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.children !== undefined) {
  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) return
  34. this.swipeaction.closeOther(this)
  35. },
  36. change(e) {
  37. this.$emit('change', e.open)
  38. if (this.is_show !== e.open) {
  39. this.is_show = e.open
  40. }
  41. },
  42. appTouchStart(e) {
  43. if (is_pc) return
  44. const {
  45. clientX
  46. } = e.changedTouches[0]
  47. this.clientX = clientX
  48. this.timestamp = new Date().getTime()
  49. },
  50. appTouchEnd(e, index, item, position) {
  51. if (is_pc) return
  52. const {
  53. clientX
  54. } = e.changedTouches[0]
  55. // fixed by xxxx 模拟点击事件,解决 ios 13 点击区域错位的问题
  56. let diff = Math.abs(this.clientX - clientX)
  57. let time = (new Date().getTime()) - this.timestamp
  58. if (diff < 40 && time < 300) {
  59. this.$emit('click', {
  60. content: item,
  61. index,
  62. position
  63. })
  64. }
  65. },
  66. onClickForPC(index, item, position) {
  67. if (!is_pc) return
  68. // #ifdef H5
  69. this.$emit('click', {
  70. content: item,
  71. index,
  72. position
  73. })
  74. // #endif
  75. }
  76. }
  77. }
  78. // #endif
  79. export default mpMixins