index.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // nova-tourism/components/home/index.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. },
  8. /**
  9. * 组件的初始数据
  10. */
  11. data: {
  12. //屏幕高度
  13. statusBarHeight: 0, // 状态栏高度
  14. screenHeight: 0, // 屏幕高度
  15. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  16. bottomNavHeight: 0, // 底部导航栏高度
  17. contentHeight: 0, // 可用内容高度
  18. //
  19. showNav: false, // 控制导航栏的显示与隐藏
  20. scrollTop: 0, // 当前滚动位置
  21. // 轮播图数组
  22. imageUrls: ['https://tse4-mm.cn.bing.net/th/id/OIP-C.3r1vguZyWFUJ80A2Nf2k3AHaEK?rs=1&pid=ImgDetMain', 'https://ts1.cn.mm.bing.net/th/id/R-C.9881613a29f26488b40938427aa585e4?rik=fim4XvDejjHE%2fQ&riu=http%3a%2f%2fn.sinaimg.cn%2fsinakd20220516ac%2f797%2fw2048h1149%2f20220516%2fb0aa-5aca29fe2dfa69c385118bbc74d039de.jpg&ehk=tzq%2bJP6uMipI0aIHY3bMSVO7lS7ZQM6TKMlwZ5CFP4s%3d&risl=&pid=ImgRaw&r=0', 'https://pic3.zhimg.com/v2-5fb13110e1de13d4c11e6e7f5b8026da_r.jpg', 'https://desk-fd.zol-img.com.cn/t_s960x600c5/g5/M00/02/04/ChMkJ1bKyEyIMaKUAAhskHwWGqUAALIAAM2KsIACGyo249.jpg'],
  23. index: 1,
  24. //卡片数组
  25. cardarr: [1, 2, 3, 4, 5, 6, 7],
  26. //日历
  27. date_start: '',
  28. date_end:'',
  29. week_start:'',
  30. week_end:'',
  31. show: false,
  32. },
  33. lifetimes: {
  34. detached: function () {
  35. // 在组件实例被从页面节点树移除时执行
  36. },
  37. attached: async function () {
  38. // 在组件实例进入页面节点树时执行
  39. // 计算
  40. const systemInfo = wx.getSystemInfoSync();
  41. const statusBarHeight = systemInfo.statusBarHeight || 0;
  42. const screenHeight = systemInfo.screenHeight || 0;
  43. const custom = wx.getMenuButtonBoundingClientRect();
  44. const customHeight = custom.height + 10 + 2 || 0;
  45. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  46. const contentHeight = (statusBarHeight +customHeight) * 750 / systemInfo.windowWidth;
  47. this.setData({
  48. statusBarHeight,
  49. screenHeight,
  50. customHeight,
  51. bottomNavHeight,
  52. contentHeight
  53. });
  54. console.log(this.data.bottomNavHeight);
  55. },
  56. },
  57. /**
  58. * 组件的方法列表
  59. */
  60. methods: {
  61. //滑动显示导航栏
  62. onScroll: function (event) {
  63. const scrollTop = event.detail.scrollTop; // 获取当前滚动位置
  64. this.setData({
  65. scrollTop: scrollTop,
  66. showNav: scrollTop > 295 // 当滚动超过 时显示导航栏
  67. });
  68. },
  69. //随轮播图变化而变化
  70. onSwiperChange: function (event) {
  71. const currentIndex = event.detail.current; // 获取当前索引
  72. this.setData({
  73. index: currentIndex + 1
  74. })
  75. },
  76. //选择日期
  77. //打开日历
  78. onDisplay() {
  79. this.setData({ show: true });
  80. },
  81. //关闭日历
  82. onClose() {
  83. this.setData({ show: false });
  84. },
  85. formatDate(date) {
  86. date = new Date(date);
  87. console.log(date);
  88. return `${date.getMonth() + 1}月${date.getDate()}日`;
  89. },
  90. onConfirm(event) {
  91. const [start, end] = event.detail;
  92. this.setData({
  93. show: false,
  94. date_start: `${this.formatDate(start)} `,
  95. date_end:`${this.formatDate(end)}`
  96. });
  97. console.log(this.data.date_start,this.data.date_end);
  98. },
  99. }
  100. })