slideshow.vue 3.2 KB

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