| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- <template>
- <div class="index">
- <div v-if="isMobile">
- <Home></Home>
- </div>
- <div v-if="!isMobile">
- <christmas v-if="isOpen" @listenopen="listenOpen" :hasNewYear="hasNewYear"></christmas>
- <carousel>
- <kind-category @loadchild="loadProductKinds"></kind-category>
- </carousel>
- <advert></advert>
- <floor-list></floor-list>
- <news></news>
- <partner></partner>
- </div>
- </div>
- </template>
- <script>
- import { KindCategory, Carousel, Advert, FloorList, Partner, News } from '~components/home'
- import { Christmas } from '~components/default'
- import { Home } from '~components/mobile'
- export default {
- name: 'index',
- layout (context) {
- return context.store.state.option.isMobile ? 'mobile' : 'main'
- },
- data () {
- return {
- isOpen: false,
- hasNewYear: false
- }
- },
- components: {
- KindCategory,
- Carousel,
- Advert,
- FloorList,
- Partner,
- News,
- Christmas,
- Home
- },
- fetch ({store}) {
- return !store.state.option.isMobile ? Promise.all([
- store.dispatch('loadFloors'),
- store.dispatch('loadBanners', {type: 'home'}),
- store.dispatch('loadProductKinds', { id: 0 }),
- store.dispatch('loadNewsSnapshot', { page: 1, pageSize: 10 })
- ]) : []
- },
- mounted () {
- let user = this.user.logged
- let count = 1
- let self = this
- const nowDate = new Date()
- const activeStartDate = new Date('2017/12/20 00:00:00')
- const activeEndDate = new Date('2018/1/2 00:00:00')
- const EndDate = new Date('2017/12/26 00:00:00')
- this.hasNewYear = nowDate > EndDate
- if (nowDate > activeStartDate && nowDate < activeEndDate) {
- const endTime = window.localStorage.getItem('endTime')
- if (!user) {
- setInterval(function () {
- count++
- if (count >= 60 * 60 * 2) {
- count = 1
- self.isOpen = true
- }
- }, 1000)
- }
- if (endTime) {
- if (nowDate.getTime() - endTime >= 1000 * 60 * 60 * 2) {
- user ? this.isOpen = false : this.isOpen = true
- window.localStorage.setItem('endTime', nowDate.getTime())
- } else {
- this.isOpen = false
- }
- } else {
- user ? this.isOpen = false : this.isOpen = true
- window.localStorage.setItem('endTime', nowDate.getTime())
- }
- } else {
- this.isOpen = false
- }
- },
- computed: {
- user () {
- return this.$store.state.option.user
- },
- isMobile: function () {
- return this.$store.state.option.isMobile
- }
- },
- methods: {
- listenOpen () {
- this.isOpen = false
- },
- loadProductKinds (id) {
- this.$store.dispatch('loadAllProductKinds', {id})
- }
- }
- }
- </script>
|