ImagePopup.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <template>
  2. <view class="popup-mask" v-if="visible" @click="handleClose">
  3. <view class="popup-content" @click.stop>
  4. <view class="close-btn" @click="handleClose">×</view>
  5. <image
  6. class="popup-image"
  7. :src="imageUrl"
  8. mode="widthFix"
  9. ></image>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. name: 'ImagePopup',
  16. props: {
  17. imageUrl: {
  18. type: String,
  19. default: ''
  20. },
  21. storageKey: {
  22. type: String,
  23. default: 'version_shown'
  24. }
  25. },
  26. data() {
  27. return {
  28. visible: false
  29. }
  30. },
  31. mounted() {
  32. this.checkAndShowPopup()
  33. },
  34. methods: {
  35. checkAndShowPopup() {
  36. const hasShown = uni.getStorageSync(this.storageKey)
  37. if (!hasShown) {
  38. this.visible = true
  39. }
  40. },
  41. handleClose() {
  42. this.visible = false
  43. uni.setStorage({
  44. key: this.storageKey,
  45. data: true
  46. })
  47. this.$emit('close')
  48. }
  49. }
  50. }
  51. </script>
  52. <style lang="less" scoped>
  53. .popup-mask {
  54. position: fixed;
  55. top: 0;
  56. left: 0;
  57. width: 100%;
  58. height: 100%;
  59. background-color: rgba(0, 0, 0, 0.7);
  60. z-index: 9999;
  61. display: flex;
  62. justify-content: center;
  63. align-items: center;
  64. .popup-content {
  65. position: relative;
  66. width: 85%;
  67. max-width: 600rpx;
  68. background-color: transparent;
  69. border-radius: 16rpx;
  70. box-sizing: border-box;
  71. .close-btn {
  72. position: absolute;
  73. bottom: -60rpx;
  74. left: 50%;
  75. transform: translateX(-50%);
  76. width: 56rpx;
  77. height: 56rpx;
  78. line-height: 48rpx;
  79. text-align: center;
  80. font-size: 40rpx;
  81. color: #999;
  82. background-color: rgba(255, 255, 255, 0.9);
  83. border-radius: 50%;
  84. border: 2rpx solid #ddd;
  85. z-index: 10;
  86. cursor: pointer;
  87. &:active {
  88. background-color: #f5f5f5;
  89. }
  90. }
  91. .popup-image {
  92. width: 100%;
  93. border-radius: 8rpx;
  94. }
  95. }
  96. }
  97. </style>