swiper.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <template>
  2. <swiper
  3. :current="current"
  4. @change="swiperChange"
  5. :indicator-dots="indicatorDots"
  6. :indicator-color="indicatorColor"
  7. :indicator-active-color="indicatorActiveColor"
  8. :autoplay="autoplay"
  9. :interval="interval"
  10. :duration="duration"
  11. :circular="circular"
  12. :vertical="vertical"
  13. class="swiper_list"
  14. :style="{ width: width, height: height, '--borderRadius': borderRadius }"
  15. >
  16. <template v-if="listArr.length">
  17. <swiper-item
  18. v-for="(item, index) in listArr"
  19. :key="index"
  20. style="overflow-y: scroll"
  21. >
  22. <slot :name="'item_' + index">
  23. <image
  24. class="img"
  25. lazy-load
  26. :src="urlName ? item[urlName] : item"
  27. alt=""
  28. :style="{ width: width, height: height }"
  29. >
  30. </image>
  31. </slot>
  32. </swiper-item>
  33. </template>
  34. <template v-else-if="swiperList.length">
  35. <swiper-item
  36. v-for="(item, index) in swiperList"
  37. :key="index"
  38. @click="itemClick(item)"
  39. >
  40. <slot name="swiper">
  41. <image
  42. class="img"
  43. lazy-load
  44. :src="urlName ? item[urlName] : item"
  45. alt=""
  46. :style="{ width: width, height: height }"
  47. >
  48. </image>
  49. </slot>
  50. </swiper-item>
  51. </template>
  52. <slot name="cont"></slot>
  53. </swiper>
  54. </template>
  55. <script setup>
  56. import { computed, onMounted } from "vue";
  57. import { useSystemStore } from "@/store";
  58. const useSystem = useSystemStore();
  59. const props = defineProps({
  60. indicatorDots: Boolean,
  61. indicatorColor: {
  62. type: String,
  63. default: "rgba(0, 0, 0, .3)",
  64. },
  65. indicatorActiveColor: {
  66. type: String,
  67. default: "#000000",
  68. },
  69. autoplay: Boolean,
  70. interval: {
  71. type: Number,
  72. default: 3000,
  73. },
  74. duration: {
  75. type: Number,
  76. default: 500,
  77. },
  78. circular: Boolean,
  79. vertical: Boolean,
  80. urlName: {
  81. type: String,
  82. default: "picture",
  83. },
  84. listArr: {
  85. type: Array,
  86. default: () => [],
  87. },
  88. current: {
  89. type: Number,
  90. default: 0,
  91. },
  92. width: {
  93. type: String,
  94. default: "100%",
  95. },
  96. height: {
  97. type: String,
  98. default: "175px",
  99. },
  100. borderRadius: {
  101. type: String,
  102. default: "8px",
  103. },
  104. });
  105. const emit = defineEmits(["change", "itemClick"]);
  106. const swiperList = computed(() => !props.listArr.length && useSystem.getBanner);
  107. const swiperChange = (e) => {
  108. emit("change", e.detail);
  109. };
  110. const itemClick = (e) => {
  111. emit("itemClick", e);
  112. };
  113. onMounted(() => {
  114. useSystem.setBanner();
  115. });
  116. </script>
  117. <style lang="less" scoped>
  118. @import url("@/style.less");
  119. .swiper_list {
  120. border-radius: var(--borderRadius);
  121. overflow: hidden;
  122. .img {
  123. width: 100%;
  124. height: 100%;
  125. display: block;
  126. border-radius: var(--borderRadius);
  127. }
  128. }
  129. </style>