multipleimg.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. var Nova = getApp().Nova
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. options: null
  8. },
  9. ready: function() {
  10. // 在组件布局完成后执行,确保options参数中有data信息
  11. this.loadData()
  12. },
  13. /**
  14. * 组件的初始数据
  15. */
  16. data: {},
  17. /**
  18. * 组件的方法列表
  19. */
  20. methods: {
  21. async loadData() {
  22. let { options } = this.data
  23. console.log('多图组', this.data)
  24. let {
  25. data,
  26. style
  27. } = options
  28. console.log(style, className)
  29. let { className, src, filter, list } = data
  30. this.setData({
  31. list,
  32. src,
  33. style,
  34. className,
  35. filter
  36. })
  37. },
  38. goNovaURL: function(ev) {
  39. let item = ev.currentTarget.dataset.item
  40. let url = ''
  41. if (item.className == 'ShopGoods' && item.objectId) {
  42. url =
  43. '/nova-shop/pages/shop-goods/goods-detail/index?id=' + item.objectId
  44. }
  45. if (item.className == 'Article' && item.objectId) {
  46. url = '/common-page/pages/cates/article-detail/index?id=' + item.objectId
  47. }
  48. if (item.className == 'Lesson' && item.objectId) {
  49. url = ''
  50. }
  51. if (item.url) {
  52. url = item.url
  53. }
  54. Nova.goNovaURL(url)
  55. }
  56. },
  57. attached: function() {
  58. // let { options } = this.data
  59. // console.log('多图组', options)
  60. // var that = this
  61. // var allData = that.data.noramalData
  62. // //定义两个临时的变量来记录左右两栏的高度,避免频繁调用setData方法
  63. // var leftH = that.data.leftHight
  64. // var rightH = that.data.rightHight
  65. // var leftData = []
  66. // var rightData = []
  67. // for (let i = 0; i < allData.length; i++) {
  68. // var currentItemHeight = parseInt(
  69. // Math.round((allData[i].CoverHeight * 345) / allData[i].CoverWidth)
  70. // )
  71. // allData[i].CoverHeight = currentItemHeight + 'rpx' //因为xml文件中直接引用的该值作为高度,所以添加对应单位
  72. // if (leftH == rightH || leftH < rightH) {
  73. // //判断左右两侧当前的累计高度,来确定item应该放置在左边还是右边
  74. // leftData.push(allData[i])
  75. // leftH += currentItemHeight
  76. // } else {
  77. // rightData.push(allData[i])
  78. // rightH += currentItemHeight
  79. // }
  80. // }
  81. // //更新左右两栏的数据以及累计高度
  82. // that.setData({
  83. // leftHight: leftH,
  84. // rightHight: rightH,
  85. // leftList: leftData,
  86. // rightList: rightData
  87. // })
  88. }
  89. })