index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // nova-werun/pages/circle-detail/index.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. //屏幕高度
  8. statusBarHeight: 0, // 状态栏高度
  9. screenHeight: 0, // 屏幕高度
  10. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  11. bottomNavHeight: 0, // 底部导航栏高度
  12. contentHeight: 0, // 可用内容高度
  13. contentHeight2: 0,
  14. contentpadding: 0, //顶部padding高度
  15. //图片
  16. images: [
  17. 'http://img2.baidu.com/it/u=2324169262,1340424811&fm=253&app=138&f=JPEG?w=800&h=1422',
  18. 'https://img2.baidu.com/it/u=2814429148,2262424695&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1422',
  19. 'https://img2.baidu.com/it/u=2814429148,2262424695&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1422',
  20. 'https://inews.gtimg.com/om_bt/OE8piEBa-tbqn-wNvWZl8coi4AlzoUD43upEkoAnIkYL8AA/641',
  21. 'https://inews.gtimg.com/om_bt/OE8piEBa-tbqn-wNvWZl8coi4AlzoUD43upEkoAnIkYL8AA/641',
  22. 'https://inews.gtimg.com/om_bt/OE8piEBa-tbqn-wNvWZl8coi4AlzoUD43upEkoAnIkYL8AA/641',
  23. 'https://img2.baidu.com/it/u=2814429148,2262424695&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1422',
  24. 'https://img2.baidu.com/it/u=2814429148,2262424695&fm=253&fmt=auto&app=138&f=JPEG?w=800&h=1422',
  25. 'https://inews.gtimg.com/om_bt/OE8piEBa-tbqn-wNvWZl8coi4AlzoUD43upEkoAnIkYL8AA/641',
  26. 'https://inews.gtimg.com/om_bt/OE8piEBa-tbqn-wNvWZl8coi4AlzoUD43upEkoAnIkYL8AA/641',
  27. 'https://inews.gtimg.com/om_bt/OE8piEBa-tbqn-wNvWZl8coi4AlzoUD43upEkoAnIkYL8AA/641',
  28. 'https://inews.gtimg.com/om_bt/OE8piEBa-tbqn-wNvWZl8coi4AlzoUD43upEkoAnIkYL8AA/641',
  29. 'https://inews.gtimg.com/om_bt/OE8piEBa-tbqn-wNvWZl8coi4AlzoUD43upEkoAnIkYL8AA/641',
  30. 'https://inews.gtimg.com/om_bt/OE8piEBa-tbqn-wNvWZl8coi4AlzoUD43upEkoAnIkYL8AA/641',
  31. ],
  32. imageclass:''
  33. },
  34. /**
  35. * 生命周期函数--监听页面加载
  36. */
  37. onLoad: function (options) {
  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 contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  47. const contentHeight = (screenHeight - bottomNavHeight ) * 750 / systemInfo.windowWidth;
  48. const contentHeight2 = (screenHeight - bottomNavHeight - 50 - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  49. this.setData({
  50. statusBarHeight,
  51. screenHeight,
  52. customHeight,
  53. bottomNavHeight,
  54. contentHeight,
  55. contentpadding,
  56. contentHeight2
  57. });
  58. console.log('123', contentHeight, contentHeight2);
  59. },
  60. /**
  61. * 生命周期函数--监听页面初次渲染完成
  62. */
  63. onReady: function () {
  64. },
  65. /**
  66. * 生命周期函数--监听页面显示
  67. */
  68. onShow: function () {
  69. },
  70. /**
  71. * 生命周期函数--监听页面隐藏
  72. */
  73. onHide: function () {
  74. },
  75. /**
  76. * 生命周期函数--监听页面卸载
  77. */
  78. onUnload: function () {
  79. },
  80. /**
  81. * 页面相关事件处理函数--监听用户下拉动作
  82. */
  83. onPullDownRefresh: function () {
  84. },
  85. /**
  86. * 页面上拉触底事件的处理函数
  87. */
  88. onReachBottom: function () {
  89. },
  90. /**
  91. * 用户点击右上角分享
  92. */
  93. onShareAppMessage: function () {
  94. },
  95. onImageLoad: function (e) {
  96. const {
  97. width,
  98. height
  99. } = e.detail; // 获取图片的宽高
  100. console.log('11', e.detail);
  101. const imageClass = width > height ? 'image-landscape' : 'image-portrait'; // 判断横竖屏
  102. this.setData({
  103. imageclass: imageClass // 动态设置图片的类名
  104. });
  105. },
  106. previewImage: function(e) {
  107. const index = e.currentTarget.dataset.index; // 获取当前点击图片的索引
  108. const images = this.data.images; // 获取所有图片的链接
  109. wx.previewImage({
  110. current: images[index], // 当前显示图片的链接
  111. urls: images // 需要预览的图片链接列表
  112. });
  113. },
  114. goback(){
  115. wx.navigateBack({
  116. delta: 1 // 返回上一页
  117. });
  118. }
  119. })