index.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <view class="main">
  3. <guide v-if="guidePages" :advData="advData" :time="advData.time"></guide>
  4. </view>
  5. </template>
  6. <script>
  7. import guide from '@/components/guide/index.vue';
  8. import Cache from '@/utils/cache';
  9. import { getOpenAdv } from '@/api/api.js';
  10. export default {
  11. components: {
  12. guide
  13. },
  14. data() {
  15. return {
  16. guidePages: false,
  17. advData: [],
  18. indexUrl: '/pages/index/index'
  19. };
  20. },
  21. onLoad(options) {
  22. if (options.spid) {
  23. this.indexUrl = this.indexUrl + '?spid=' + options.spid;
  24. }
  25. this.loadExecution();
  26. },
  27. methods: {
  28. loadExecution() {
  29. const tagDate = uni.getStorageSync('guideDate') || '',
  30. nowDate = new Date().toLocaleDateString();
  31. if (tagDate === nowDate) {
  32. uni.switchTab({
  33. url: this.indexUrl
  34. });
  35. return;
  36. }
  37. getOpenAdv()
  38. .then((res) => {
  39. if (res.data.status == 0 || res.data.value.length == 0) {
  40. uni.switchTab({
  41. url: this.indexUrl
  42. });
  43. } else if (res.data.status && (res.data.value.length || res.data.video_link)) {
  44. this.advData = res.data;
  45. uni.setStorageSync('guideDate', new Date().toLocaleDateString());
  46. this.guidePages = true;
  47. }
  48. })
  49. .catch((err) => {
  50. uni.switchTab({
  51. url: this.indexUrl
  52. });
  53. });
  54. }
  55. },
  56. onHide() {
  57. this.guidePages = false;
  58. }
  59. };
  60. </script>
  61. <style>
  62. page,
  63. .main {
  64. width: 100%;
  65. height: 100%;
  66. }
  67. </style>