index.js 5.7 KB

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