index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <div class="index">
  3. <div v-if="isMobile">
  4. <Home></Home>
  5. </div>
  6. <div v-if="!isMobile">
  7. <christmas v-if="isOpen" @listenopen="listenOpen" :hasNewYear="hasNewYear"></christmas>
  8. <carousel>
  9. <kind-category @loadchild="loadProductKinds"></kind-category>
  10. </carousel>
  11. <advert></advert>
  12. <floor-list></floor-list>
  13. <news></news>
  14. <partner></partner>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. import { KindCategory, Carousel, Advert, FloorList, Partner, News } from '~components/home'
  20. import { Christmas } from '~components/default'
  21. import { Home } from '~components/mobile'
  22. export default {
  23. name: 'index',
  24. layout (context) {
  25. return context.store.state.option.isMobile ? 'mobile' : 'main'
  26. },
  27. data () {
  28. return {
  29. isOpen: false,
  30. hasNewYear: false
  31. }
  32. },
  33. components: {
  34. KindCategory,
  35. Carousel,
  36. Advert,
  37. FloorList,
  38. Partner,
  39. News,
  40. Christmas,
  41. Home
  42. },
  43. fetch ({store}) {
  44. return !store.state.option.isMobile ? Promise.all([
  45. store.dispatch('loadFloors'),
  46. store.dispatch('loadBanners', {type: 'home'}),
  47. store.dispatch('loadProductKinds', { id: 0 }),
  48. store.dispatch('loadNewsSnapshot', { page: 1, pageSize: 10 })
  49. ]) : []
  50. },
  51. mounted () {
  52. let user = this.user.logged
  53. let count = 1
  54. let self = this
  55. const nowDate = new Date()
  56. const activeStartDate = new Date('2017/12/20 00:00:00')
  57. const activeEndDate = new Date('2018/1/2 00:00:00')
  58. const EndDate = new Date('2017/12/26 00:00:00')
  59. this.hasNewYear = nowDate > EndDate
  60. if (nowDate > activeStartDate && nowDate < activeEndDate) {
  61. const endTime = window.localStorage.getItem('endTime')
  62. if (!user) {
  63. setInterval(function () {
  64. count++
  65. if (count >= 60 * 60 * 2) {
  66. count = 1
  67. self.isOpen = true
  68. }
  69. }, 1000)
  70. }
  71. if (endTime) {
  72. if (nowDate.getTime() - endTime >= 1000 * 60 * 60 * 2) {
  73. user ? this.isOpen = false : this.isOpen = true
  74. window.localStorage.setItem('endTime', nowDate.getTime())
  75. } else {
  76. this.isOpen = false
  77. }
  78. } else {
  79. user ? this.isOpen = false : this.isOpen = true
  80. window.localStorage.setItem('endTime', nowDate.getTime())
  81. }
  82. } else {
  83. this.isOpen = false
  84. }
  85. },
  86. computed: {
  87. user () {
  88. return this.$store.state.option.user
  89. },
  90. isMobile: function () {
  91. return this.$store.state.option.isMobile
  92. }
  93. },
  94. methods: {
  95. listenOpen () {
  96. this.isOpen = false
  97. },
  98. loadProductKinds (id) {
  99. this.$store.dispatch('loadAllProductKinds', {id})
  100. }
  101. }
  102. }
  103. </script>