index.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. // pagesPublic/pages/tdcr/index.js
  2. const {imgUrl} = require('../api/request')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. imgPath: imgUrl + 'tdcr/',
  9. cursorGuys: [{
  10. left: 48,
  11. top: 1.5
  12. }, {
  13. left: 20,
  14. top: 4
  15. }],
  16. cursors: [{
  17. txt: '弹子石组团\nB8-1、B8-3、B9',
  18. top: -12,
  19. left: 28,
  20. dropTop: 3.5,
  21. dropLeft: 12
  22. }, {
  23. txt: '四公里\n棚户区地块',
  24. top: -16,
  25. left: 20,
  26. dropTop: 5,
  27. dropLeft: 5
  28. }, {
  29. txt: '茶园组团\nC01-16/02、\nC01-17/02',
  30. top: -32,
  31. left: 61,
  32. dropTop: 4,
  33. dropLeft: 5
  34. }],
  35. list: [{
  36. icon: 'icon-quyu.png',
  37. txt: '区域中心 得天独厚',
  38. top: 0,
  39. left: 12
  40. }, {
  41. icon: 'icon-house.png',
  42. txt: '南岸新区 宜居宜业',
  43. top: 1,
  44. left: 5
  45. }, {
  46. icon: 'icon-ai.png',
  47. txt: '资源富集 优势明显',
  48. top: 1,
  49. left: 0
  50. }, {
  51. icon: 'icon-car.png',
  52. txt: '立体交通 四通八达',
  53. top: 1,
  54. left: 12
  55. }, {
  56. icon: 'icon-bod.png',
  57. txt: '产业坚实 人才汇聚',
  58. top: 1,
  59. left: 20
  60. }],
  61. touchData: {
  62. flag: 0,
  63. lastX: 0,
  64. lastY: 0
  65. },
  66. animationData: {},
  67. currentIndex: 0,
  68. isAnimating: false
  69. },
  70. /**
  71. * 生命周期函数--监听页面加载
  72. */
  73. onLoad(options) {
  74. wx.showTabBar({
  75. fail: (e) => {
  76. console.log(e);
  77. }
  78. })
  79. },
  80. /**
  81. * 生命周期函数--监听页面初次渲染完成
  82. */
  83. onReady() {
  84. this.initAnimations();
  85. setTimeout(() => {
  86. this.startAnimationLoop();
  87. }, 500);
  88. },
  89. /**
  90. * 生命周期函数--监听页面显示
  91. */
  92. onShow() {
  93. },
  94. /**
  95. * 生命周期函数--监听页面隐藏
  96. */
  97. onHide() {
  98. },
  99. /**
  100. * 生命周期函数--监听页面卸载
  101. */
  102. onUnload() {
  103. },
  104. /**
  105. * 页面相关事件处理函数--监听用户下拉动作
  106. */
  107. onPullDownRefresh() {
  108. },
  109. /**
  110. * 页面上拉触底事件的处理函数
  111. */
  112. onReachBottom() {
  113. },
  114. /**
  115. * 用户点击右上角分享
  116. */
  117. onShareAppMessage() {
  118. return {
  119. title: '2024年土地出让',
  120. imageUrl: imgUrl + '/tdcr/share.jpg'
  121. }
  122. },
  123. handleTouchend() {
  124. let touchData = this.data.touchData
  125. touchData.flag = 0
  126. //停止滑动
  127. this.setData({
  128. touchData
  129. })
  130. },
  131. handleTouchstart(event) {
  132. this.setData({
  133. touchData: {
  134. flag: 0,
  135. lastX: event.changedTouches[0].pageX,
  136. lastY: event.changedTouches[0].pageY
  137. }
  138. })
  139. },
  140. handleTouchmove(event) {
  141. let touchData = this.data.touchData
  142. if (touchData.flag !== 0) {
  143. return;
  144. }
  145. let currentX = event.changedTouches[0].pageX;
  146. let currentY = event.changedTouches[0].pageY;
  147. let tx = currentX - touchData.lastX;
  148. let ty = currentY - touchData.lastY;
  149. //左右方向偏移大于上下偏移认为是左右滑动
  150. if (Math.abs(tx) - Math.abs(ty) > 5) {
  151. // 向左滑动
  152. if (tx < 0) {
  153. // 如果到最右侧
  154. console.log('向左滑动');
  155. touchData.flag = 1;
  156. wx.navigateTo({
  157. url: './tdcr-list/index',
  158. })
  159. } else if (tx > 0) {
  160. // 如果到最左侧
  161. touchData.flag = 2;
  162. console.log('向右滑动');
  163. }
  164. }
  165. //将当前坐标进行保存以进行下一次计算
  166. touchData.lastX = currentX;
  167. touchData.lastY = currentY;
  168. this.setData({
  169. touchData
  170. })
  171. },
  172. initAnimations: function() {
  173. const list = this.data.list;
  174. list.forEach((item, index) => {
  175. this.createAnimation(index);
  176. });
  177. },
  178. createAnimation: function(index) {
  179. const animation = wx.createAnimation({
  180. duration: 1000, // 动画持续时间
  181. timingFunction: 'ease', // 动画效果
  182. });
  183. this.setData({
  184. ['animationData[' + index + ']']: animation.export(),
  185. });
  186. },
  187. startAnimationLoop: function() {
  188. const list = this.data.list;
  189. const currentIndex = this.data.currentIndex;
  190. if (currentIndex < list.length) {
  191. if (this.data.isAnimating) return;
  192. this.setData({
  193. isAnimating: true
  194. })
  195. // 获取当前索引的动画对象
  196. const animation = wx.createAnimation({
  197. duration: 1000,
  198. timingFunction: 'linear',
  199. });
  200. // 放大动画
  201. animation.scale(1.2, 1.2).step();
  202. // 更新动画数据
  203. this.setData({
  204. ['animationData[' + currentIndex + ']']: animation.export(),
  205. isAnimating: this.data.isAnimating
  206. });
  207. // 设置动画结束后回调
  208. setTimeout(() => {
  209. // 恢复到原始大小
  210. const restoreAnimation = wx.createAnimation({
  211. duration: 1000,
  212. timingFunction: 'linear',
  213. });
  214. restoreAnimation.scale(1, 1).step();
  215. this.setData({
  216. ['animationData[' + currentIndex + ']']: restoreAnimation.export(),
  217. isAnimating: false
  218. });
  219. // 动画结束后,索引递增,如果到达列表末尾,则重置为0
  220. this.setData({
  221. currentIndex: (currentIndex + 1) % list.length,
  222. });
  223. if ((currentIndex + 1) % list.length == 0 && currentIndex != 0) {
  224. setTimeout(() => {
  225. this.startAnimationLoop();
  226. }, 2000);
  227. } else {
  228. this.startAnimationLoop();
  229. }
  230. }, 1500);
  231. }
  232. },
  233. })