mpwxs.js 1.5 KB

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