index.vue 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. },
  26. onShow() {
  27. this.loadExecution();
  28. },
  29. methods: {
  30. loadExecution() {
  31. const tagDate = uni.getStorageSync('guideDate') || '',
  32. nowDate = new Date().toLocaleDateString();
  33. if (tagDate === nowDate) {
  34. uni.switchTab({
  35. url: this.indexUrl
  36. });
  37. return;
  38. }
  39. getOpenAdv()
  40. .then((res) => {
  41. if (res.data.status == 0 || res.data.value.length == 0) {
  42. uni.switchTab({
  43. url: this.indexUrl
  44. });
  45. } else if (res.data.status && (res.data.value.length || res.data.video_link)) {
  46. this.advData = res.data;
  47. uni.setStorageSync('guideDate', new Date().toLocaleDateString());
  48. this.guidePages = true;
  49. }
  50. })
  51. .catch((err) => {
  52. uni.switchTab({
  53. url: this.indexUrl
  54. });
  55. });
  56. }
  57. },
  58. onHide() {
  59. this.guidePages = false;
  60. }
  61. };
  62. </script>
  63. <style>
  64. page,
  65. .main {
  66. width: 100%;
  67. height: 100%;
  68. }
  69. </style>