mpwxs.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. let mpMixins = {}
  2. let is_pc = null
  3. // #ifdef H5
  4. import {isPC} from "./isPC"
  5. is_pc = isPC()
  6. // #endif
  7. // #ifdef APP-VUE|| MP-WEIXIN || H5
  8. mpMixins = {
  9. data() {
  10. return {
  11. is_show: 'none'
  12. }
  13. },
  14. watch: {
  15. show(newVal) {
  16. this.is_show = this.show
  17. }
  18. },
  19. created() {
  20. this.swipeaction = this.getSwipeAction()
  21. if (this.swipeaction.children !== undefined) {
  22. this.swipeaction.children.push(this)
  23. }
  24. },
  25. mounted() {
  26. this.is_show = this.show
  27. },
  28. methods: {
  29. // wxs 中调用
  30. closeSwipe(e) {
  31. if (!this.autoClose) return
  32. this.swipeaction.closeOther(this)
  33. },
  34. change(e) {
  35. this.$emit('change', e.open)
  36. if (this.is_show !== e.open) {
  37. this.is_show = e.open
  38. }
  39. },
  40. appTouchStart(e) {
  41. if (is_pc) return
  42. const {
  43. clientX
  44. } = e.changedTouches[0]
  45. this.clientX = clientX
  46. this.timestamp = new Date().getTime()
  47. },
  48. appTouchEnd(e, index, item, position) {
  49. if (is_pc) return
  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. if (!is_pc) return
  66. // #ifdef H5
  67. this.$emit('click', {
  68. content: item,
  69. index,
  70. position
  71. })
  72. // #endif
  73. }
  74. }
  75. }
  76. // #endif
  77. export default mpMixins