slideshow.vue 2.9 KB

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