global-push-ad.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view v-if="visible" class="gpa-mask" @click="onMask">
  3. <view class="gpa-box" @click.stop>
  4. <image
  5. class="gpa-img"
  6. :src="imageUrl"
  7. mode="widthFix"
  8. @click="onImageClick"
  9. />
  10. <view class="gpa-close" @click="close">×</view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. import { pushAdState, closePushAd } from '@/common/pushAdStore.js'
  16. export default {
  17. name: 'GlobalPushAd',
  18. computed: {
  19. visible() {
  20. return pushAdState.visible
  21. },
  22. imageUrl() {
  23. return pushAdState.imageUrl
  24. },
  25. linkUrl() {
  26. return pushAdState.linkUrl
  27. }
  28. },
  29. methods: {
  30. close() {
  31. closePushAd()
  32. },
  33. onMask() {
  34. this.close()
  35. },
  36. onImageClick() {
  37. const url = this.linkUrl
  38. if (!url) return
  39. // #ifdef APP-PLUS
  40. if (/^https?:\/\//i.test(url)) {
  41. plus.runtime.openURL(url)
  42. return
  43. }
  44. // #endif
  45. // #ifdef H5
  46. if (/^https?:\/\//i.test(url)) {
  47. window.location.href = url
  48. return
  49. }
  50. // #endif
  51. if (url.startsWith('/')) {
  52. uni.navigateTo({ url, fail: () => uni.switchTab({ url }) })
  53. }
  54. }
  55. }
  56. }
  57. </script>
  58. <style scoped>
  59. .gpa-mask {
  60. position: fixed;
  61. left: 0;
  62. right: 0;
  63. top: 0;
  64. bottom: 0;
  65. z-index: 99999;
  66. background: rgba(0, 0, 0, 0.55);
  67. display: flex;
  68. align-items: center;
  69. justify-content: center;
  70. padding: 48rpx;
  71. box-sizing: border-box;
  72. }
  73. .gpa-box {
  74. position: relative;
  75. max-width: 100%;
  76. max-height: 85vh;
  77. display: flex;
  78. flex-direction: column;
  79. align-items: center;
  80. }
  81. .gpa-img {
  82. width: 600rpx;
  83. max-width: 100%;
  84. display: block;
  85. border-radius: 16rpx;
  86. }
  87. .gpa-close {
  88. margin-top: 32rpx;
  89. width: 72rpx;
  90. height: 72rpx;
  91. line-height: 68rpx;
  92. text-align: center;
  93. font-size: 48rpx;
  94. color: #fff;
  95. background: rgba(0, 0, 0, 0.45);
  96. border-radius: 50%;
  97. flex-shrink: 0;
  98. }
  99. </style>