index.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. var that;
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. previewImgList: {
  8. type: Array,
  9. value: false
  10. },
  11. previewImg: {
  12. type: null,
  13. value: false
  14. },
  15. },
  16. attached: function () {
  17. that = this;
  18. },
  19. /**
  20. * 组件的初始数据
  21. */
  22. data: {
  23. preview_box_top: 0,
  24. left: '0px;',
  25. touchS: [0, 0],
  26. touchE: [0, 0],
  27. index: 0,
  28. imgindex:0,
  29. previewHideStatus:false,
  30. scale: 1,
  31. scaleObj:{
  32. scale:1,
  33. x:0,
  34. y:0,
  35. yes:true
  36. },
  37. touchStartTime: 0, // 触摸开始时间
  38. touchEndTime: 0, // 触摸结束时间
  39. lastTapTime: 0, // 最后一次单击事件点击发生时间
  40. lastTapTimeoutFunc: null, // 单击事件点击后要触发的函数
  41. },
  42. /**
  43. * 组件的方法列表
  44. */
  45. methods: {
  46. jingzhi(e) {
  47. let diffTouch = this.data.touchEndTime - this.data.touchStartTime;
  48. let curTime = e.timeStamp;
  49. let lastTime = this.data.lastTapDiffTime;
  50. this.data.lastTapDiffTime = curTime;
  51. this.setData({previewHideStatus: false,preview_box_top: '100%' })
  52. //两次点击间隔小于300ms, 认为是双击
  53. // let diff = curTime - lastTime;
  54. // if (diff < 300) {
  55. // console.log("double tap")
  56. // clearTimeout(this.data.lastTapTimeoutFunc); // 成功触发双击事件时,取消单击事件的执行
  57. // if(this.data.scale == 1){
  58. // this.setData({
  59. // scale:2
  60. // })
  61. // }else{
  62. // this.setData({
  63. // scale:1
  64. // })
  65. // }
  66. // } else {
  67. // this.data.lastTapTimeoutFunc = setTimeout(function () {
  68. // console.log("single tap")
  69. // if(that.data.scaleObj.yes){
  70. // that.setData({previewHideStatus: false })
  71. // console.log('运行了');
  72. // }
  73. // }, 300);
  74. // }
  75. },
  76. configqxClick(e) { this.setData({ scopeWritePhotosAlbum: e.detail }) },
  77. touchStart: function (e) {
  78. this.data.touchStartTime = e.timeStamp //时间点
  79. let sx = e.touches[0].pageX
  80. let sy = e.touches[0].pageY
  81. this.data.touchS = [sx, sy];
  82. },
  83. touchMove: function (e) {
  84. let start = this.data.touchS;
  85. let sx = e.touches[0].pageX;
  86. let sy = e.touches[0].pageY;
  87. this.data.touchE = [sx, sy];
  88. },
  89. touchEnd: function (e) {
  90. this.data.touchEndTime = e.timeStamp //时间点
  91. let start = this.data.touchS
  92. let end = this.data.touchE
  93. let scaleObj = this.data.scaleObj
  94. //如果((start[0] < end[0] - 50) && (scaleObj.scale==1&&scaleObj.x==0&&scaleObj.y==0)) //左滑动
  95. //如果((start[0] > end[0] + 50) && (scaleObj.scale==1&&scaleObj.x==0&&scaleObj.y==0)) //右滑动
  96. if(scaleObj.yes){
  97. if(end[0] == 0){
  98. console.log('点击')
  99. }else if((start[0] < end[0] - 50) && (scaleObj.scale==1&&scaleObj.x==0&&scaleObj.y==0)){
  100. if (this.data.index !== 0) {
  101. this.data.index -= 1;
  102. this.data.imgindex -=1;
  103. this.setData({ index: this.data.index, left: '-' + this.data.index + '00%;transition: all .5s;', imgindex: this.data.imgindex });
  104. }
  105. }else if((start[0] > end[0] + 50) && (scaleObj.scale==1&&scaleObj.x==0&&scaleObj.y==0)){
  106. if (this.data.index !== this.data.previewImgList.length - 1) {
  107. this.data.index += 1;
  108. this.data.imgindex += 1;
  109. this.setData({ index: this.data.index, left: '-' + this.data.index + '00%;transition: all .5s;', imgindex: this.data.imgindex });
  110. }
  111. }else{
  112. console.log('下滑/上滑');
  113. this.setData({ preview_box_top: '100%' })
  114. }
  115. this.data.touchE = [0, 0];
  116. }
  117. setTimeout(()=>{
  118. if(this.data.scaleObj.x == 0 && this.data.scaleObj.y == 0 && this.data.scaleObj.scale == 1){
  119. console.log('yes is true');
  120. this.data.scaleObj.yes = true;
  121. }
  122. },500)
  123. },
  124. showPreview() {
  125. this.setData({ previewHideStatus: true, preview_box_top: 0 })
  126. },
  127. hidePreview() {
  128. this.setData({ previewHideStatus: false, preview_box_top: 0 })
  129. },
  130. onScale(e) {
  131. this.data.scaleObj = {
  132. scale:e.detail.scale,
  133. x:e.detail.x,
  134. y:e.detail.y,
  135. yes:false
  136. }
  137. },
  138. stopPageScroll() { return },
  139. },
  140. observers: {
  141. 'previewImgList': function (arr) {
  142. console.log(arr)
  143. },
  144. 'previewImg':function(img){
  145. this.data.previewImgList.map((item,index)=>{
  146. if(item == img){
  147. let imgindex = index;
  148. imgindex+=1;
  149. this.setData({ index: index, imgindex: imgindex, left: '-'+index+'00%;' })
  150. }
  151. })
  152. }
  153. },
  154. })