app-popup-ad.vue 6.5 KB

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