app-popup-ad.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. <template>
  2. <view class="app-popup-ad">
  3. <block v-for="(item, index) in newList" :key="index">
  4. <template v-if="item && item.length > 0">
  5. <view class="modal dir-left-nowrap main-center cross-center"
  6. :class="popupActive === index ? 'show' : ''">
  7. <view class="body dir-top-nowrap cross-center">
  8. <swiper circular autoplay indicator-dots class="app-popup-ad-wh" v-if="item.length > 1">
  9. <swiper-item v-for="(modal, key) in item" :key="key" class="main-center">
  10. <app-jump-button :url="modal.link.url" :open_type="modal.link.openType"
  11. @click="closePopupModal">
  12. <image :src="modal.picUrl" mode="aspectFit" class="app-popup-ad-wh"></image>
  13. </app-jump-button>
  14. </swiper-item>
  15. </swiper>
  16. <template v-else>
  17. <block v-for="(modal, key) in item" :key="key">
  18. <app-jump-button :url="modal.link.url" :open_type="modal.link.openType"
  19. @click="closePopupModal">
  20. <image :src="modal.picUrl" mode="aspectFit" class="app-popup-ad-wh"></image>
  21. </app-jump-button>
  22. </block>
  23. </template>
  24. <view class="close" @click="closePopupModal">
  25. <image src="../../../static/image/icon/icon-popup-close.png"></image>
  26. </view>
  27. </view>
  28. </view>
  29. </template>
  30. </block>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. name: "app-model-ad",
  36. props: {
  37. opened: {
  38. type: Boolean,
  39. default() {
  40. return true;
  41. }
  42. },
  43. times: {
  44. type: Number,
  45. default() {
  46. return 1;
  47. }
  48. },
  49. list: {
  50. type: Array,
  51. default() {
  52. return [];
  53. }
  54. },
  55. multiple: {
  56. type: Boolean,
  57. default() {
  58. return false;
  59. }
  60. },
  61. mark: {
  62. type: String,
  63. default() {
  64. return 'fxhb';
  65. }
  66. },
  67. is_storage: Boolean,
  68. },
  69. data() {
  70. return {
  71. newList: [],
  72. popupActive: -1,
  73. };
  74. },
  75. computed: {
  76. listenChange() {
  77. return {
  78. multiple: this.multiple,
  79. list: this.list,
  80. is_storage: this.is_storage,
  81. times: this.times,
  82. };
  83. }
  84. },
  85. watch: {
  86. listenChange: {
  87. handler(v) {
  88. this.init()
  89. },
  90. immediate: true
  91. }
  92. },
  93. methods: {
  94. init() {
  95. if (!this.multiple) {
  96. this.newList = [this.list];
  97. } else {
  98. this.newList = this.list;
  99. }
  100. if (!this.opened) {
  101. return;
  102. }
  103. if (typeof this.$popupAd.list[this.mark] === 'undefined') {
  104. this.$popupAd.list[this.mark] = true;
  105. this.$event.on(this.$const.EVENT_POPUP, false).then(mark => {
  106. if (mark === this.mark) {
  107. this.showPopupModal();
  108. }
  109. });
  110. }
  111. this.showPopupModal();
  112. },
  113. showPopupModal() {
  114. if (this.$popupAd.show) {
  115. return;
  116. }
  117. let first = 'popUpFirst' + this.mark;
  118. this.$popupAd.show = this.mark;
  119. let active = -1;
  120. if (this.times === 0) {
  121. active = 0;
  122. } else {
  123. if (this.$popupAd.first[first]) {
  124. active = -1;
  125. } else {
  126. active = 0;
  127. }
  128. }
  129. if (!this.is_storage) {
  130. this.$popupAd.first[first] = true;
  131. }
  132. this.popupActive = active;
  133. this.nextModal();
  134. },
  135. nextModal() {
  136. if (this.list.length <= this.popupActive || this.popupActive === -1) {
  137. let list = this.$popupAd.list;
  138. let next = false;
  139. for (let i in list) {
  140. if (next) {
  141. next = false;
  142. this.$event.trigger(this.$const.EVENT_POPUP, i);
  143. break;
  144. }
  145. if (i === this.mark) {
  146. next = true;
  147. }
  148. }
  149. if (!next) {
  150. this.$popupAd.show = null;
  151. }
  152. }
  153. },
  154. closePopupModal() {
  155. let popupActive = this.popupActive;
  156. popupActive += 1;
  157. this.popupActive = popupActive;
  158. this.$popupAd.show = null;
  159. this.nextModal();
  160. }
  161. }
  162. }
  163. </script>
  164. <style scoped lang="scss">
  165. .modal {
  166. position: fixed;
  167. width: 100%;
  168. height: 100%;
  169. left: 0;
  170. top: 0;
  171. z-index: 1500;
  172. background-color: rgba(0, 0, 0, 0.4);
  173. transform: translateY(100%);
  174. opacity: 0;
  175. &.show {
  176. transform: translateY(0%);
  177. opacity: 1;
  178. }
  179. .body {
  180. .app-popup-ad-wh {
  181. width: #{650rpx};
  182. height: #{700rpx};
  183. }
  184. .close {
  185. margin-top: #{30rpx};
  186. padding: #{20rpx};
  187. image {
  188. width: #{30rpx};
  189. height: #{30rpx};
  190. display: block;
  191. }
  192. }
  193. }
  194. }
  195. </style>