index.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { Image, Swiper } from "@queenjs/ui";
  2. import { defineComponent, reactive, ref } from "vue";
  3. import { array, string } from "vue-types";
  4. export default defineComponent({
  5. props: {
  6. data: array<string>().isRequired,
  7. current: string().isRequired,
  8. },
  9. setup(props) {
  10. const carouselRef = ref();
  11. const index = props.data.findIndex((d) => d == props.current);
  12. const state = reactive({
  13. index: index,
  14. });
  15. return () => {
  16. const { data } = props;
  17. return (
  18. <div class="relative">
  19. <div class="absolute w-1/1 top-15px let-0 text-center z-9 text-shadow">
  20. {state.index + 1}/{data.length}
  21. </div>
  22. <Swiper
  23. onInit={(e) => (carouselRef.value = e)}
  24. options={{
  25. slidesPerView: 1,
  26. initialSlide: state.index,
  27. on: {
  28. slideChange: (e: any) => {
  29. state.index = e.realIndex;
  30. },
  31. },
  32. }}
  33. >
  34. {data?.map((item, index) => (
  35. <Swiper.Slider
  36. key={index}
  37. class="!h-100vh flex felx-col items-center justify-center"
  38. >
  39. <div class="flex-1 max-h-1/1 overflow-y-auto">
  40. <Image
  41. src={item}
  42. class="w-1/1 !object-contain bg-light-50"
  43. size={800}
  44. />
  45. </div>
  46. </Swiper.Slider>
  47. ))}
  48. </Swiper>
  49. </div>
  50. );
  51. };
  52. },
  53. });