index.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <view class="main">
  3. <guide v-if="guidePages" :advData="advData"></guide>
  4. </view>
  5. </template>
  6. <script>
  7. import guide from '@/components/guide/index.vue'
  8. import Cache from '@/utils/cache';
  9. import {
  10. getOpenAdv
  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. uni.switchTab({
  36. url: '/pages/index/index'
  37. });
  38. return
  39. }
  40. getOpenAdv().then(res => {
  41. if (res.data.status == 0 || res.data.value.length == 0) {
  42. uni.switchTab({
  43. url: '/pages/index/index'
  44. });
  45. } else if (res.data.status && (res.data.value.length || res.data.video_link)) {
  46. this.advData = res.data
  47. let intervalTime = parseFloat(res.data.interval_time)*60*60*1000 || 0;
  48. uni.setStorageSync('intervalTime', intervalTime);
  49. uni.setStorageSync('guideDate', new Date().getTime());
  50. this.guidePages = true
  51. }
  52. }).catch(err => {
  53. uni.switchTab({
  54. url: '/pages/index/index'
  55. });
  56. })
  57. }
  58. },
  59. onHide() {
  60. this.guidePages = false
  61. }
  62. }
  63. </script>
  64. <style>
  65. page,
  66. .main {
  67. width: 100%;
  68. height: 100%;
  69. }
  70. </style>