index.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  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. id: 0,
  18. txt: '廖家山一期',
  19. top: -12,
  20. left: 36,
  21. dropTop: 4,
  22. dropLeft: 4,
  23. zIndex: 10
  24. }, {
  25. id: 2,
  26. txt: '双峰山1号',
  27. top: -20,
  28. left: 18,
  29. dropTop: 5,
  30. dropLeft: 5,
  31. zIndex: 9
  32. }, {
  33. id: 1,
  34. txt: '四公里大片区',
  35. top: -30,
  36. left: 50,
  37. dropTop: 5,
  38. dropLeft: 5,
  39. zIndex: 11
  40. }, {
  41. id: 3,
  42. txt: '广阳湾产城融合三期',
  43. top: -35,
  44. left: 61,
  45. dropTop: 5,
  46. dropLeft: 9,
  47. zIndex: 9
  48. }, {
  49. id: 4,
  50. txt: '广阳湾产城融合二期',
  51. top: -38,
  52. left: 33,
  53. dropTop: 5,
  54. dropLeft: 9
  55. }, {
  56. id: 5,
  57. txt: '广阳湾产城融合一期',
  58. top: -50,
  59. left: 14,
  60. dropTop: 5,
  61. dropLeft: 9
  62. }],
  63. list: [{
  64. icon: 'icon-quyu.png',
  65. txt: '两江四岸、区域核心',
  66. top: 0,
  67. left: 12
  68. }, {
  69. icon: 'icon-house.png',
  70. txt: '山城花冠、主城肺叶',
  71. top: 1,
  72. left: 5
  73. }, {
  74. icon: 'icon-ai.png',
  75. txt: '南部增长极,金融“第三极”',
  76. top: 1,
  77. left: 0
  78. }, {
  79. icon: 'icon-car.png',
  80. txt: '毗邻机场、坐拥东站',
  81. top: 1,
  82. left: 12
  83. }, {
  84. icon: 'icon-bod.png',
  85. txt: '产业坚实、人才汇聚',
  86. top: 1,
  87. left: 20
  88. }],
  89. touchData: {
  90. flag: 0,
  91. lastX: 0,
  92. lastY: 0
  93. },
  94. animationData: {},
  95. currentIndex: 0,
  96. isAnimating: false
  97. },
  98. /**
  99. * 生命周期函数--监听页面加载
  100. */
  101. onLoad(options) {
  102. },
  103. /**
  104. * 生命周期函数--监听页面初次渲染完成
  105. */
  106. onReady() {
  107. this.initAnimations();
  108. setTimeout(() => {
  109. this.startAnimationLoop();
  110. }, 500);
  111. },
  112. /**
  113. * 生命周期函数--监听页面显示
  114. */
  115. onShow() {
  116. },
  117. /**
  118. * 生命周期函数--监听页面隐藏
  119. */
  120. onHide() {
  121. },
  122. /**
  123. * 生命周期函数--监听页面卸载
  124. */
  125. onUnload() {
  126. },
  127. /**
  128. * 页面相关事件处理函数--监听用户下拉动作
  129. */
  130. onPullDownRefresh() {
  131. },
  132. /**
  133. * 页面上拉触底事件的处理函数
  134. */
  135. onReachBottom() {
  136. },
  137. /**
  138. * 用户点击右上角分享
  139. */
  140. onShareAppMessage() {
  141. return {
  142. title: '2024年土地供应',
  143. imageUrl: imgUrl + '/tdcr/share.jpg'
  144. }
  145. },
  146. handleTouchend() {
  147. let touchData = this.data.touchData
  148. touchData.flag = 0
  149. //停止滑动
  150. this.setData({
  151. touchData
  152. })
  153. },
  154. handleTouchstart(event) {
  155. this.setData({
  156. touchData: {
  157. flag: 0,
  158. lastX: event.changedTouches[0].pageX,
  159. lastY: event.changedTouches[0].pageY
  160. }
  161. })
  162. },
  163. handleTouchmove(event) {
  164. let touchData = this.data.touchData
  165. if (touchData.flag !== 0) {
  166. return;
  167. }
  168. let currentX = event.changedTouches[0].pageX;
  169. let currentY = event.changedTouches[0].pageY;
  170. let tx = currentX - touchData.lastX;
  171. let ty = currentY - touchData.lastY;
  172. //左右方向偏移大于上下偏移认为是左右滑动
  173. if (Math.abs(tx) - Math.abs(ty) > 5) {
  174. // 向左滑动
  175. if (tx < 0) {
  176. // 如果到最右侧
  177. console.log('向左滑动');
  178. touchData.flag = 1;
  179. wx.navigateTo({
  180. url: './tdcr-list/index',
  181. })
  182. } else if (tx > 0) {
  183. // 如果到最左侧
  184. touchData.flag = 2;
  185. console.log('向右滑动');
  186. wx.navigateBack()
  187. }
  188. }
  189. //将当前坐标进行保存以进行下一次计算
  190. touchData.lastX = currentX;
  191. touchData.lastY = currentY;
  192. this.setData({
  193. touchData
  194. })
  195. },
  196. initAnimations: function() {
  197. const list = this.data.list;
  198. list.forEach((item, index) => {
  199. this.createAnimation(index);
  200. });
  201. },
  202. createAnimation: function(index) {
  203. const animation = wx.createAnimation({
  204. duration: 1000, // 动画持续时间
  205. timingFunction: 'ease', // 动画效果
  206. });
  207. this.setData({
  208. ['animationData[' + index + ']']: animation.export(),
  209. });
  210. },
  211. startAnimationLoop: function() {
  212. const list = this.data.list;
  213. const currentIndex = this.data.currentIndex;
  214. if (currentIndex < list.length) {
  215. if (this.data.isAnimating) return;
  216. this.setData({
  217. isAnimating: true
  218. })
  219. // 获取当前索引的动画对象
  220. const animation = wx.createAnimation({
  221. duration: 1000,
  222. timingFunction: 'linear',
  223. });
  224. // 放大动画
  225. animation.scale(1.2, 1.2).step();
  226. // 更新动画数据
  227. this.setData({
  228. ['animationData[' + currentIndex + ']']: animation.export(),
  229. isAnimating: this.data.isAnimating
  230. });
  231. // 设置动画结束后回调
  232. setTimeout(() => {
  233. // 恢复到原始大小
  234. const restoreAnimation = wx.createAnimation({
  235. duration: 1000,
  236. timingFunction: 'linear',
  237. });
  238. restoreAnimation.scale(1, 1).step();
  239. this.setData({
  240. ['animationData[' + currentIndex + ']']: restoreAnimation.export(),
  241. isAnimating: false
  242. });
  243. // 动画结束后,索引递增,如果到达列表末尾,则重置为0
  244. this.setData({
  245. currentIndex: (currentIndex + 1) % list.length,
  246. });
  247. if ((currentIndex + 1) % list.length == 0 && currentIndex != 0) {
  248. setTimeout(() => {
  249. this.startAnimationLoop();
  250. }, 2000);
  251. } else {
  252. this.startAnimationLoop();
  253. }
  254. }, 1500);
  255. }
  256. },
  257. toDetail(e) {
  258. wx.navigateTo({
  259. url: './details/detail?index=' + e.target.dataset.index,
  260. })
  261. }
  262. })