detail-swiper.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import { Cell, CellGroup, Skeleton, SkeletonParagraph, Image } from 'vant';
  2. import { defineComponent, onMounted, reactive, watch, ref } from 'vue';
  3. import styles from './detail.module.less';
  4. import SwiperClass, { Navigation, Thumbs, Pagination } from 'swiper';
  5. import { Swiper, SwiperSlide } from 'swiper/vue';
  6. import 'swiper/css';
  7. import 'swiper/css/navigation';
  8. import 'swiper/css/thumbs';
  9. import 'swiper/css/pagination';
  10. import iconVideoDefault from '@common/images/icon-video-r.png';
  11. import { checkFile } from '@/helpers/toolsValidate';
  12. import palyBtn from './images/palyBtn.png';
  13. import arrayIcon from './images/array-icon.png';
  14. export default defineComponent({
  15. name: 'detail-swiper',
  16. emits: ['showImageToas'],
  17. props: {
  18. item: {
  19. type: Object,
  20. default: {}
  21. }
  22. },
  23. setup(props, { slots, emit }) {
  24. const forms = reactive({
  25. loading: false
  26. });
  27. const thumbsSwiper = ref<SwiperClass>();
  28. const setThumbsSwiper = (swiper: SwiperClass) => {
  29. thumbsSwiper.value = swiper;
  30. console.log(thumbsSwiper.value, 'setThumbsSwiper');
  31. };
  32. const modules = [Navigation, Thumbs, Pagination];
  33. onMounted(() => {});
  34. return () => (
  35. <>
  36. {props.item.attachmentUrl.length > 0 ? (
  37. <div class={styles.progItemList}>
  38. <Swiper
  39. class="topSwiper"
  40. style={{
  41. '--swiper-navigation-color': '#fff',
  42. '--swiper-pagination-color': '#fff'
  43. }}
  44. modules={modules}
  45. space-between={10}
  46. pagination={true}
  47. thumbs={{ swiper: thumbsSwiper.value }}>
  48. {props.item.attachmentUrl.map((i: any, index: number) => (
  49. <SwiperSlide class="slide">
  50. <div
  51. class={styles.photo}
  52. onClick={() => {
  53. emit('showImageToas', {
  54. imagePreview: props.item.attachmentUrl,
  55. imageShow: true,
  56. startPosition: index
  57. });
  58. // forms.imagePreview = item.attachmentUrl;
  59. // forms.imageShow = true;
  60. // forms.startPosition = index;
  61. }}>
  62. {checkFile(i, 'image') ? (
  63. <Image src={i + '@base@tag=imgScale'} fit="cover" />
  64. ) : (
  65. <div class={styles.videoWErap}>
  66. <Image src={palyBtn} class={styles.palyBtn}></Image>
  67. <video
  68. style={{ backgroundColor: '#F8F8F8' }}
  69. poster={iconVideoDefault}
  70. src={i + '#t=1,4'}
  71. />
  72. </div>
  73. )}
  74. {props.item.attachmentUrl.length > 4 && index === 3 ? (
  75. <div class={styles.photoMore}>
  76. +{props.item.attachmentUrl.length - 4}
  77. </div>
  78. ) : (
  79. ''
  80. )}
  81. </div>
  82. </SwiperSlide>
  83. ))}
  84. </Swiper>
  85. <div class={styles.thumbsWrap}>
  86. <div
  87. class={styles.thumbsMore}
  88. onClick={() => {
  89. emit('showImageToas', {
  90. imagePreview: props.item.attachmentUrl,
  91. imageShow: true,
  92. startPosition: 0
  93. });
  94. }}>
  95. <p>全</p>
  96. <p>部</p>
  97. <Image class={styles.arrayIcon} src={arrayIcon}></Image>
  98. </div>
  99. <Swiper
  100. class="thumbs-swiper"
  101. modules={modules}
  102. space-between={10}
  103. slides-per-view={4}
  104. watch-slides-progress={true}
  105. freeMode={true}
  106. onSwiper={setThumbsSwiper}>
  107. {props.item.attachmentUrl.map((i: any, index: number) => (
  108. <SwiperSlide class="slide">
  109. <div class={styles.photo}>
  110. {checkFile(i, 'image') ? (
  111. <Image
  112. src={i + '@base@tag=imgScale&w=120'}
  113. fit="cover"
  114. />
  115. ) : (
  116. <div class={styles.videoSmallWErap}>
  117. <Image src={palyBtn} class={styles.playBtn}></Image>
  118. <video
  119. style={{ backgroundColor: '#F8F8F8' }}
  120. poster={iconVideoDefault}
  121. src={i + '#t=1,4'}
  122. />
  123. </div>
  124. )}
  125. {props.item.attachmentUrl.length > 4 && index === 3 ? (
  126. <div class={styles.photoMore}>
  127. +{props.item.attachmentUrl.length - 4}
  128. </div>
  129. ) : (
  130. ''
  131. )}
  132. </div>
  133. </SwiperSlide>
  134. ))}
  135. </Swiper>
  136. </div>
  137. </div>
  138. ) : null}
  139. </>
  140. );
  141. }
  142. });