index.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <template>
  2. <view>
  3. <guide v-if="guidePages" :advData="advData"></guide>
  4. </view>
  5. </template>
  6. <script>
  7. import guide from './guide.vue'
  8. import Cache from '@/utils/cache';
  9. import {
  10. getOpenAdvApi
  11. } from '@/api/api.js'
  12. export default {
  13. components: {
  14. guide
  15. },
  16. data() {
  17. return {
  18. guidePages: false,
  19. advData: []
  20. }
  21. },
  22. onShow() {
  23. // #ifdef H5
  24. if (this.$wechat.isWeixin()) {
  25. this.$wechat.wechat();
  26. }
  27. // #endif
  28. this.loadExecution()
  29. },
  30. methods: {
  31. loadExecution() {
  32. const tagDate = uni.getStorageSync('guideDate') || 0,
  33. nowDate = new Date().getTime();
  34. if ((nowDate - tagDate) <= uni.getStorageSync('intervalTime')) {
  35. this.$util.navigateTo('/pages/index/index');
  36. return
  37. }
  38. getOpenAdvApi().then(res => {
  39. if (res.data.splashAdSwitch == 0 || res.data.adList.length == 0) {
  40. this.$util.navigateTo('/pages/index/index');
  41. } else if (res.data.splashAdSwitch && res.data.adList.length) {
  42. this.advData = res.data
  43. let intervalTime = parseFloat(res.data.splashAdShowInterval) * 60 * 60 * 1000 || 0;
  44. uni.setStorageSync('intervalTime', intervalTime);
  45. uni.setStorageSync('guideDate', new Date().getTime());
  46. this.guidePages = true
  47. }
  48. }).catch(err => {
  49. this.$util.navigateTo('/pages/index/index');
  50. })
  51. }
  52. },
  53. onHide() {
  54. this.guidePages = false
  55. }
  56. }
  57. </script>
  58. <style>
  59. page,
  60. .main {
  61. width: 100%;
  62. height: 100%;
  63. }
  64. </style>