banner.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <template>
  2. <view class="diy-banner-box pr" :class="itemData.style.imgShape"
  3. :style="'background-color:'+itemData.style.background+';'">
  4. <swiper class="swiper" :autoplay="autoplay" :interval="interval" :duration="duration" @change="changeSwiper" :style="itemData.style.imgShape=='square'?'height:'+itemData.style.height+'rpx;':'height:'+(itemData.style.height*0.92)+'rpx;'">
  5. <swiper-item v-for="(item,index) in itemData.data" :key="index" @click="gotoPages(item,itemData)">
  6. <image :style="itemData.style.imgShape=='square'?'height:'+itemData.style.height+'rpx;':'height:'+(itemData.style.height*0.92)+'rpx;'" :src="item.imgUrl"></image>
  7. </swiper-item>
  8. </swiper>
  9. <view class="swiper-dots ww100 d-c-c" :class="itemData.style.btnShape">
  10. <view :class="current==index?'swiper-dot active':'swiper-dot'" v-for="(item,index) in itemData.data"
  11. :style="current==index?'background-color:'+indicatorActiveColor+';':''" :key="index">
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. data() {
  19. return {
  20. indicatorDots: true,
  21. autoplay: true,
  22. interval: 2000,
  23. duration: 500,
  24. indicatorActiveColor: '#ffffff',
  25. current: 0
  26. }
  27. },
  28. props: ['itemData'],
  29. created() {
  30. this.interval = this.itemData.params.interval;
  31. this.indicatorActiveColor = this.itemData.style.btnColor;
  32. },
  33. methods: {
  34. changeSwiper(e) {
  35. this.current = e.detail.current;
  36. },
  37. /*跳转页面*/
  38. gotoPages(e,data) {
  39. let urlStr = e.linkUrl.split('?')[1]
  40. // 创建空对象存储参数
  41. let obj = {};
  42. // 再通过 & 将每一个参数单独分割出来
  43. let paramsArr = urlStr.split('&')
  44. for(let i = 0,len = paramsArr.length;i < len;i++){
  45. // 再通过 = 将每一个参数分割为 key:value 的形式
  46. let arr = paramsArr[i].split('=')
  47. obj[arr[0]] = arr[1];
  48. }
  49. let AppId = obj.naviAppId;
  50. if(AppId!=""&&AppId!=null&&AppId!=undefined){
  51. uni.navigateToMiniProgram({
  52. appId:AppId,// appid
  53. path:e.linkUrl,// 首页路径
  54. envVersion:"release",
  55. success: res => {
  56. console.log("打开成功", res);
  57. },
  58. fail: err => {
  59. console.log(err);
  60. }
  61. });
  62. return;
  63. }
  64. // #ifdef MP-WEIXIN
  65. this.gotoPage(e.linkUrl);
  66. // #endif
  67. // #ifndef MP-WEIXIN
  68. console.log('不在微信',e,data.data)
  69. let a = e.linkUrl
  70. a = a.split('/')[0]
  71. if(a == 'pages'){
  72. this.gotoPage(e.linkUrl);
  73. }else{
  74. window.location.href = e.linkUrl
  75. }
  76. console.log(a)
  77. // #endif
  78. }
  79. }
  80. }
  81. </script>
  82. <style>
  83. .diy-banner-box,
  84. .diy-banner-box .swiper {
  85. overflow-x: hidden;
  86. width: 750rpx;
  87. /* background-color: #FFFFFF; */
  88. }
  89. .diy-banner-box.round,
  90. .diy-banner-box.round .swiper {
  91. width: 750rpx;
  92. /* background-color: #FFFFFF; */
  93. }
  94. .diy-banner-box image {
  95. width: 750rpx;
  96. }
  97. .diy-banner-box.round{
  98. padding: 30rpx;
  99. box-sizing: border-box;
  100. }
  101. .diy-banner-box.round image {
  102. width: 690rpx;
  103. border-radius: 12rpx;
  104. }
  105. .diy-banner-box.round .swiper-dots {
  106. position: absolute;
  107. bottom: 40rpx;
  108. left: 0;
  109. right: 0;
  110. margin: auto;
  111. }
  112. .diy-banner-box.square .swiper-dots {
  113. position: absolute;
  114. bottom: 20rpx;
  115. left: 0;
  116. right: 0;
  117. margin: auto;
  118. }
  119. .swiper-dots.square .swiper-dot {
  120. width: 14rpx;
  121. height: 14rpx;
  122. margin: 0 4rpx;
  123. background: #ebedf0;
  124. opacity: 0.3;
  125. }
  126. .swiper-dots.round .swiper-dot {
  127. width: 22rpx;
  128. height: 22rpx;
  129. margin: 0 4rpx;
  130. background: #ebedf0;
  131. opacity: 0.3;
  132. border-radius: 50%;
  133. }
  134. .swiper-dots.rectangle .swiper-dot {
  135. width: 40rpx;
  136. height: 6rpx;
  137. margin: 0 4rpx;
  138. background: #ebedf0;
  139. opacity: 0.3;
  140. border-radius: 4rpx;
  141. }
  142. .swiper-dots.round .swiper-dot.active,
  143. .swiper-dots.square .swiper-dot.active,
  144. .swiper-dots.rectangle .swiper-dot.active {
  145. opacity: 1;
  146. }
  147. </style>