popup-ad.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <van-overlay :show="show">
  3. <view class="popup-ad-wrapper">
  4. <view class="popup-ad">
  5. <view class="popup-ad-image" @click="onClickImage">
  6. <image :src="adImage" mode="widthFix"/>
  7. </view>
  8. <view class="popup-ad-close" @click="onClickClose">
  9. <van-icon name="close" />
  10. </view>
  11. </view>
  12. </view>
  13. <van-action-sheet
  14. :show="showActionSheet"
  15. :actions="actions"
  16. @select="onActionSelect"
  17. @cancel="onActionCancel"
  18. :close-on-click-overlay="true"
  19. :close-on-click-action="true"
  20. cancel-text="取消"
  21. />
  22. </van-overlay>
  23. </template>
  24. <script>
  25. import VanOverlay from '@/wxcomponents/vant/overlay/index'
  26. import VanActionSheet from '@/wxcomponents/vant/action-sheet/index'
  27. export default {
  28. options: {
  29. styleIsolation: 'shared'
  30. },
  31. components: {
  32. VanOverlay,
  33. VanActionSheet
  34. },
  35. props: {
  36. show: Boolean
  37. },
  38. data() {
  39. return {
  40. adUrl: 'https://file.smarket.net.cn/s/template/hOM48k/index.html?customFormId=2310071208827845&instanceId=387836&linkId=345547&configId=3439487%23%2Fwap_index%3FrandNum%3D1709540499#/pc_index?randNum=1709540499',
  41. adImage: 'https://oss.starify.cn/prod/starify/up/0001018678/20241107/672c895e605c9.png',
  42. showActionSheet: false,
  43. actions: [{
  44. name: '保存图片',
  45. value: 'save'
  46. }, {
  47. name: '识别二唯码',
  48. value: 'open'
  49. }]
  50. }
  51. },
  52. created() {
  53. },
  54. methods: {
  55. onClickClose() {
  56. this.$emit('update:show', false)
  57. },
  58. onClickImage() {
  59. this.showActionSheet = true
  60. // uni.previewImage({
  61. // current: this.adImage,
  62. // urls: [this.adImage],
  63. // })
  64. },
  65. onActionSelect(e) {
  66. if (e.detail.value === 'save') {
  67. uni.getImageInfo({
  68. src: this.adImage,
  69. success: (res) => {
  70. uni.saveImageToPhotosAlbum({
  71. filePath: res.path,
  72. success() {
  73. uni.showToast({
  74. title: '保存成功',
  75. icon: 'success',
  76. })
  77. },
  78. fail(err) {
  79. uni.showToast({
  80. title: '保存失败',
  81. icon: 'none',
  82. });
  83. console.error(err);
  84. },
  85. })
  86. },
  87. fail(err) {
  88. uni.showToast({
  89. title: '获取图片失败',
  90. icon: 'none',
  91. })
  92. console.error(err)
  93. },
  94. })
  95. } else if (e.detail.value === 'open') {
  96. this.navigateTo(this.adUrl)
  97. }
  98. this.showActionSheet = false
  99. },
  100. onActionCancel() {
  101. this.showActionSheet = false
  102. }
  103. }
  104. }
  105. </script>
  106. <style lang="scss">
  107. .popup-ad-wrapper{
  108. @include display-flex-center;
  109. height: 100%;
  110. .popup-ad{
  111. @include display-flex-center;
  112. width: 100%;
  113. position: relative;
  114. flex-direction: column;
  115. padding: 36rpx;
  116. }
  117. .popup-ad-image{
  118. width: 100%;
  119. image{
  120. width: 100%;
  121. height: auto;
  122. border-radius: 10rpx;
  123. overflow: hidden;
  124. }
  125. }
  126. .popup-ad-close{
  127. margin-top: 50rpx;
  128. .van-icon-close{
  129. font-size: 69rpx;
  130. color: #ffffff;
  131. cursor: pointer;
  132. }
  133. }
  134. }
  135. </style>