slideshow.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <template>
  2. <view>
  3. <view v-if="list.length">
  4. <swiper
  5. :style="{
  6. width: tovw(width),
  7. height: tovw(height),
  8. marginBottom: tovw(marginBottom),
  9. }"
  10. :autoplay="autoplay"
  11. :interval="interval"
  12. circular
  13. >
  14. <swiper-item
  15. class="swiper-item"
  16. v-for="(item, index) in list"
  17. :key="item.list"
  18. >
  19. <u--image
  20. @click="onClick(index)"
  21. :src="item.cover"
  22. :width="tovw(width)"
  23. :height="tovw(height)"
  24. mode="aspectFill"
  25. :lazy-load="true"
  26. >
  27. <template v-slot:loading>
  28. <u-loading-icon color="red"></u-loading-icon>
  29. </template>
  30. </u--image>
  31. </swiper-item>
  32. </swiper>
  33. </view>
  34. <view style="height: 10px" v-else-if="empty" />
  35. </view>
  36. </template>
  37. <script>
  38. import { viewImage } from "../utils/settleFiles";
  39. export default {
  40. name: "slideshow",
  41. props: {
  42. autoplay: {
  43. type: Boolean,
  44. default: true,
  45. },
  46. interval: {
  47. type: [Number, String],
  48. default: 5000,
  49. },
  50. empty: {
  51. type: Boolean,
  52. default: false,
  53. },
  54. marginBottom:{
  55. type: [Number, String],
  56. default: 0,
  57. }
  58. },
  59. data() {
  60. return {
  61. width: 375,
  62. height: 500,
  63. list: [],
  64. };
  65. },
  66. methods: {
  67. getBanners(locations, systemclient = "marketingtool") {
  68. return new Promise((resolve, reject) => {
  69. this.$Http
  70. .basic({
  71. id: "20240426154302",
  72. content: {
  73. systemclient,
  74. locations,
  75. date: Date.now(),
  76. },
  77. })
  78. .then((res) => {
  79. console.log("获取广告位" + locations, res);
  80. resolve(res.msg);
  81. if (this.cutoff(res.msg)) return;
  82. try {
  83. let list = res.data[locations[0]];
  84. if (list.length) {
  85. if (list[0].dimensional) {
  86. let dimensional = list[0].dimensional.split("*");
  87. this.width = dimensional[0] - 0;
  88. this.height = dimensional[1] - 0;
  89. }
  90. this.list = list.map((v) => {
  91. v.cover = this.getSpecifiedImage(v.attinfos[0], "compressed");
  92. return v;
  93. });
  94. }
  95. } catch (error) {}
  96. });
  97. });
  98. },
  99. onClick(index) {
  100. let item = this.list[index];
  101. console.log("点击广告图", index, item);
  102. if (item.hyperlink) {
  103. uni.navigateTo({
  104. url: item.hyperlink,
  105. fail: (fail) => {
  106. console.log("跳转失败原因", fail);
  107. viewImage(item.attinfos[0].url);
  108. },
  109. });
  110. } else {
  111. viewImage(item.attinfos[0].url);
  112. }
  113. },
  114. },
  115. };
  116. </script>
  117. <style lang="scss" scoped></style>