s-popup-image.vue 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <view>
  3. <view v-for="(item, index) in popupList" :key="index">
  4. <su-popup
  5. v-if="index === currentIndex"
  6. :show="item.isShow"
  7. type="center"
  8. backgroundColor="none"
  9. round="0"
  10. :showClose="true"
  11. :isMaskClick="false"
  12. @close="onClose(index)"
  13. >
  14. <view class="img-box">
  15. <image
  16. class="modal-img"
  17. :src="sheep.$url.cdn(item.imgUrl)"
  18. mode="widthFix"
  19. @tap.stop="onPopup(item.url)"
  20. />
  21. </view>
  22. </su-popup>
  23. </view>
  24. </view>
  25. </template>
  26. <script setup>
  27. import sheep from '@/sheep';
  28. import { computed, ref } from 'vue';
  29. import { saveAdvHistory } from '@/sheep/hooks/useModal';
  30. // 定义属性
  31. const props = defineProps({
  32. data: {
  33. type: Object,
  34. default() {},
  35. }
  36. })
  37. // const modalStore = sheep.$store('modal');
  38. const modalStore = JSON.parse(uni.getStorageSync('modal-store') || '{}');
  39. console.log(modalStore)
  40. const advHistory = modalStore.advHistory || [];
  41. const currentIndex = ref(0);
  42. const popupList = computed(() => {
  43. const list = props.data.list || [];
  44. const newList = [];
  45. if (list.length > 0) {
  46. list.forEach((adv) => {
  47. if (adv.showType === 'once' && advHistory.includes(adv.imgUrl)) {
  48. adv.isShow = false;
  49. } else {
  50. adv.isShow = true;
  51. newList.push(adv);
  52. }
  53. // 记录弹窗已显示过
  54. saveAdvHistory(adv);
  55. });
  56. }
  57. return newList;
  58. });
  59. // 跳转链接
  60. function onPopup(path) {
  61. sheep.$router.go(path);
  62. }
  63. // 关闭
  64. function onClose(index) {
  65. currentIndex.value = index + 1;
  66. popupList.value[index].isShow = false;
  67. }
  68. </script>
  69. <style lang="scss" scoped>
  70. .img-box {
  71. width: 610rpx;
  72. // height: 800rpx;
  73. }
  74. .modal-img {
  75. width: 100%;
  76. height: 100%;
  77. }
  78. </style>