猎豆优选小程序

firstAdv.vue 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <u-mask :show="isShow" :mask-click-able="false">
  3. <view class="adv-wrap">
  4. <image class="adv-img" :src="advImg" mode="aspectFit" @click="onClickAd" />
  5. <image class="adv-close" src="https://ld.726p.com/ldyx_static/imgs/close.png" mode="widthFix" @click="onClickClose" />
  6. </view>
  7. </u-mask>
  8. </template>
  9. <script>
  10. const app = getApp();
  11. export default {
  12. name: "firstAdv",
  13. data() {
  14. return {
  15. isShow: false,
  16. advImg: '',
  17. advKeyword: '',
  18. };
  19. },
  20. mounted() {
  21. this.handleGetAdv();
  22. },
  23. methods: {
  24. async handleGetAdv() {
  25. try {
  26. const url = this.$api.home_advByType;
  27. const params = {
  28. adv_type: 6, // 6弹框广告
  29. ver_type: 1, // 1-h5
  30. device_type: 2, // 0不区分设备 1app广告 2小程序广告
  31. };
  32. const { data: res = {} } = await this.$get(url, params);
  33. if (res && res.errno == 0 && Array.isArray(res.rst.data)) {
  34. const adv = res.rst.data[0]
  35. if (!adv || adv.status != 1) return false
  36. this.advImg = adv.img
  37. this.advKeyword = adv.word
  38. this.isShow = true
  39. } else {
  40. this.isShow = false
  41. uni.showToast({ title: res.err || "操作失败", icon: "none" });
  42. }
  43. } catch (error) {
  44. this.isShow = false
  45. console.log('error => ', error)
  46. }
  47. },
  48. onClickAd() {
  49. this.$emit('confirm', { advKeyword: this.advKeyword })
  50. },
  51. onClickClose() {
  52. this.$emit('cancel')
  53. },
  54. },
  55. };
  56. </script>
  57. <style scoped lang="scss">
  58. .adv-wrap {
  59. display: flex;
  60. flex-direction: column;
  61. align-items: center;
  62. justify-content: center;
  63. height: 100%;
  64. width: 100%;
  65. .adv-img {
  66. height: 50%;
  67. }
  68. .adv-close {
  69. margin-top: 60rpx;
  70. width: 60rpx;
  71. height: 60rpx;
  72. }
  73. }
  74. </style>