index.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <template>
  2. <view class="U000002-template1" :style="wrapper_style">
  3. <image v-if="list.length == 0" @load="init" mode="widthFix" :src="defaultUrl" :style="img_style"
  4. :id="'content-wrap0'">
  5. </image>
  6. <swiper v-if="list.length > 0" :indicator-dots="true" :autoplay="false" :interval="3000" @change="changeSwiper"
  7. :current="currentIndex" :style="{height:swiperHeight+'px'}">
  8. <swiper-item v-for="(item, index) in list" :key="item.id" :style="img_style">
  9. <view v-if="item.is_minApp==1" @click="$until.u_gopage('U_slideshow',item)">
  10. <image mode="widthFix" @load="init" :src="item.image" :style="img_style" :id="'content-wrap'+index">
  11. </image>
  12. </view>
  13. <!-- #ifdef MP-WEIXIN -->
  14. <view v-else @click="$until.u_gopage('U_slideshow',item)">
  15. <image mode="widthFix" @load="init" :src="item.image" :style="img_style" :id="'content-wrap'+index">
  16. </image>
  17. </view>
  18. <!-- #endif -->
  19. <!-- #ifdef H5 -->
  20. <view v-else>
  21. <wx-open-launch-weapp :username="item.gh_id" :path="item.minApp_link">
  22. <image mode="widthFix" @load="init" :src="item.image" :style="img_style"
  23. :id="'content-wrap'+index"></image>
  24. </wx-open-launch-weapp>
  25. </view>
  26. <!-- #endif -->
  27. </swiper-item>
  28. </swiper>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. props: ['datas', 'styles'],
  34. data() {
  35. const self = this;
  36. let siteinfo = getApp().globalData.siteinfo;
  37. let data = {
  38. settingFile: siteinfo,
  39. defaultUrl: siteinfo.root_img + '/static/app/banner.png',
  40. //滑块的高度(单位px)
  41. swiperHeight: '180',
  42. //当前索引
  43. currentIndex: 0,
  44. //列表数据
  45. dataList: [],
  46. };
  47. return data;
  48. },
  49. computed: {
  50. /** 样式 */
  51. wrapper_style() {
  52. const {
  53. padding_top,
  54. padding_bottom,
  55. padding_left,
  56. padding_right,
  57. bg_color
  58. } = this.datas;
  59. if (this.list.length == 1) {
  60. return `
  61. background-color: ${bg_color};
  62. padding-top: ${padding_top*2}rpx;
  63. padding-bottom: ${padding_bottom*2}rpx;
  64. padding-left: ${padding_left*2}rpx;
  65. padding-right: ${padding_right*2}rpx;
  66. `;
  67. } else {
  68. return `
  69. background-color: ${bg_color};
  70. padding-top: ${padding_top*2}rpx;
  71. padding-bottom: ${padding_bottom*2}rpx;
  72. padding-left: ${padding_left*2}rpx;
  73. padding-right: ${padding_right*2}rpx;
  74. `;
  75. }
  76. },
  77. img_style() {
  78. const {
  79. picture_border,
  80. } = this.datas;
  81. return `
  82. width: 100%;
  83. border-radius: ${picture_border}px;
  84. `;
  85. },
  86. // 广告轮播列表
  87. list() {
  88. try {
  89. let list = [...this.datas.list] || [];
  90. list = list.filter(item => item.image != '');
  91. return list;
  92. } catch (err) {
  93. return [];
  94. }
  95. }
  96. },
  97. methods: {
  98. //手动切换题目
  99. changeSwiper(e) {
  100. this.currentIndex = e.detail.current;
  101. //动态设置swiper的高度,使用nextTick延时设置
  102. this.$nextTick(() => {
  103. this.setSwiperHeight();
  104. });
  105. },
  106. init() {
  107. this.$nextTick(() => {
  108. this.setSwiperHeight();
  109. });
  110. },
  111. //动态设置swiper的高度
  112. setSwiperHeight() {
  113. let that = this;
  114. let element = "#content-wrap" + this.currentIndex;
  115. let query = uni.createSelectorQuery().in(that);
  116. query.select(element).boundingClientRect();
  117. query.exec((res) => {
  118. if (res && res[0]) {
  119. if (that.swiperHeight != res[0].height) {
  120. that.swiperHeight = res[0].height;
  121. }
  122. }
  123. });
  124. },
  125. }
  126. };
  127. </script>
  128. <style lang="less" scoped>
  129. .U000002-template1 {
  130. display: block;
  131. margin-left: auto;
  132. margin-right: auto;
  133. text-align: center;
  134. overflow: hidden;
  135. img {
  136. width: 100%;
  137. }
  138. }
  139. </style>