LandscapePopup.vue 2.8 KB
Newer Older
zhangsan's avatar
1  
zhangsan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
<template>
  <transition name="fade">
    <div v-if="visible" class="landscape-popup">
      <div class="popup-mask" @click="handleMaskClick"></div>
      <transition name="zoom">
        <div v-if="visible" class="popup-content">
          <div class="close-btn" @click="handleClose">
            <van-icon name="close" size="30px" color="#fff"/>
          </div>
          <img 
            :src="popupImage" 
            class="popup-image" 
            @click="handleImageClick"
          />
        </div>
      </transition>
    </div>
  </transition>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRouter } from 'vue-router'
import { showToast } from 'vant'
// 导入所有需要的图片
import AppDownloadImg from '@/static/other/app.png'
import ShimingImg from '@/static/other/shiming.png'
import MyteamImg from '@/static/other/myteam.png'
const props = defineProps({
  type: {
    type: String,
    required: true,
    validator: (value) => ['app', 'shiming'].includes(value)
  }
})

const router = useRouter()
const visible = ref(false)

// 根据type返回对应的图片
const popupImage = computed(() => {
  const imageMap = {
    app: AppDownloadImg,
    shiming: ShimingImg,
    team: MyteamImg
  }
  return imageMap[props.type]
})

const handleClose = () => {
  visible.value = false
}

const handleMaskClick = () => {
  handleClose()
}

const handleImageClick = () => {
  if (props.type === 'shiming') {
    router.push('/user/shiming')
  } else if (props.type === 'app') {
    const appDownload = sessionStorage.getItem('appdownload')
    if (appDownload && appDownload != 'undefined') {
      window.location.href = appDownload
    } else {
      showToast('暂无下载链接')
    }
  }
  handleClose()
}

// 暴露打开方法
const open = () => {
  visible.value = true
}

defineExpose({ open })
</script>

<style scoped>
.landscape-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
}

.popup-mask {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
}

.popup-content {
  position: relative;
  width: 80%;
  max-width: 500px;
  z-index: 1000;
}

.popup-image {
  width: 100%;
  display: block;
}

.close-btn {
  position: absolute;
  top: -35px;
  right: -30px;
  width: 30px;
  height: 30px;
  cursor: pointer;
}

/* 遮罩层淡入淡出动画 */
.fade-enter-active,
.fade-leave-active {
zhangsan's avatar
1  
zhangsan committed
126
  transition: opacity .5s ease;
zhangsan's avatar
1  
zhangsan committed
127 128 129 130 131 132 133 134 135 136
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}

/* 弹窗内容缩放动画 */
.zoom-enter-active,
.zoom-leave-active {
zhangsan's avatar
1  
zhangsan committed
137
  transition: all .5s ease;
zhangsan's avatar
1  
zhangsan committed
138 139 140 141 142 143 144 145 146 147 148 149 150 151
}

.zoom-enter-from,
.zoom-leave-to {
  opacity: 0;
  transform: scale(0.5);
}

.zoom-enter-to,
.zoom-leave-from {
  opacity: 1;
  transform: scale(1);
}
</style>