diff --git a/src/views/pageFour/index.vue b/src/views/pageFour/index.vue index fddccb4..11313b1 100644 --- a/src/views/pageFour/index.vue +++ b/src/views/pageFour/index.vue @@ -167,6 +167,7 @@ export default { }, activated() { // this.getVideoResource() + this.getNotice() this.load() if (this.rankingData.length !== 0) { this.currentHover = -1 diff --git a/src/views/pageOne/index.vue b/src/views/pageOne/index.vue index 5d0ee68..2b89e87 100644 --- a/src/views/pageOne/index.vue +++ b/src/views/pageOne/index.vue @@ -217,10 +217,10 @@ export default { handler(result) { if (!result) return - this.pageOneVisitBase = result.visit_base?.context || '0' this.wecharQrCodeSrc = result.wechar_qr_code?.context || '' if (result.visit_base && result.wechar_qr_code) { + this.pageOneVisitBase = result.visit_base.context this.initLeftPreview(result) } @@ -236,12 +236,12 @@ export default { } }, async created() { - // if (localStorage.getItem('yesterdayCountCache')) { - // localStorage.removeItem('yesterdayCountCache') - // } - // if (localStorage.getItem('lastMonthCountCache')) { - // localStorage.removeItem('lastMonthCountCache') - // } + if (localStorage.getItem('yesterdayCountCache')) { + localStorage.removeItem('yesterdayCountCache') + } + if (localStorage.getItem('lastMonthCountCache')) { + localStorage.removeItem('lastMonthCountCache') + } // this.getInitData() this.getNewBook() }, @@ -250,7 +250,7 @@ export default { this.intervalLeft = null }, activated() { - this.pageOneVisitBase = 0 + // this.pageOneVisitBase = 0 // this.getInitData() }, deactivated() { @@ -277,13 +277,13 @@ export default { this.getMiddleAllData(result) }) }, - initLeftPreview(result) { + initLeftPreview2(result) { // visitBase 本年累计人次 visitBaseCheck 是否直接显示 0false 1true - // lastYearVisitBase 去年累计人次 - // todayVisitBase 今日人次 todayVisitBaseCheck 是否显示 - // yesterdayVisitBase 昨天人次 yesterdayVisitBaseCheck 是否显示 - // thisMonthVisitBase 本月人次 thisMonthVisitBaseCheck 是否显示 - // lastMonthVisitBase 上个月人次 lastMonthVisitBaseCheck 是否显示 + // last_year_visit_base 去年累计人次 + // today_visit 今日人次 remarks 是否显示 + // yesterday_visit 昨天人次 remarks 是否显示 + // this_month_visit 本月人次 remarks 是否显示 + // last_month_visit 上个月人次 remarks 是否显示 this.progressData = [] this.leftData = [] this.progressData.push( @@ -318,7 +318,6 @@ export default { type: 4 } ) - // 更新数据 const newData = [{ id: 'totayTotal', name: '今日到馆', @@ -331,151 +330,171 @@ export default { this.$parent.timedRefresh(this.leftData, 'left') }, - // initLeftPreview(result) { - // this.progressData = [] - // this.leftData = [] - - // // visitBase 本年累计人次 - // // visitBaseCheck 是否直接显示 0false 1true - - // // lastYearVisitBase 去年累计人次 - - // // todayVisitBase 今日人次 - // // todayVisitBaseCheck 是否显示 - - // // yesterdayVisitBase 昨天人次 - // // yesterdayVisitBaseCheck 是否显示 - - // // thisMonthVisitBase 本月人次 - // // thisMonthVisitBaseCheck 是否显示 - - // // lastMonthVisitBase 上个月人次 - // // lastMonthVisitBaseCheck 是否显示 - - // const baseTotal = this.pageOneVisitBase // 本年到馆人数 - // console.log('假设本年到馆人数', baseTotal) - // // 本年到馆/12个月 = 月基数 - // const monthBase = Math.floor(baseTotal / 12) // 月基数 - // console.log('月基数', monthBase) - // // 月随机数(-100到200之间) - // const randomMonth = Math.floor(Math.random() * (200 - (-100) + 1)) + (-100) - - // const now = new Date() - // const year = now.getFullYear() // 当前年份 - // const month = now.getMonth() + 1 // 当前月份 - // const daysInMonth = new Date(year, month, 0).getDate() // 当月天数 - // console.log('当月天数', daysInMonth) - // // 月基数/当月天数(28、29、30、31)= 日基数 - // const dayBase = Math.floor(monthBase / daysInMonth) // 日基数 - // console.log('日基数', dayBase) - // // 本年累计=月基数*月份+月随机数(-100到200之间) - // let nowYearCount - // if (result.visitBaseCheck === '1') { - // nowYearCount = result.visitBase - // } else { - // nowYearCount = Math.floor(monthBase * month + randomMonth) // 本年累计 - // } - // console.log('本年累计', nowYearCount) - // // 昨日到馆=日基数+日随机数(-20到50之间) - // let yesterdayCount = 0 - // if (result.yesterdayVisitBaseCheck === '1') { - // yesterdayCount = result.yesterdayVisitBase - // } else { - // const randomDay = Math.floor(Math.random() * (50 - (-20) + 1)) + (-20) // 日随机数(-20到50之间) - // // yesterdayCount = localStorage.getItem('yesterdayCountCache') ? localStorage.getItem('yesterdayCountCache') : dayBase + randomDay // 昨日到馆 - // yesterdayCount = dayBase + randomDay // 昨日到馆 - // } - // console.log('昨日到馆', yesterdayCount) - // // 上月到馆=月基数+月随机数(-100到200之间) - // let lastMonthCount = 0 - // if (result.lastMonthVisitBaseCheck === '1') { - // lastMonthCount = result.lastMonthVisitBase - // } else { - // // lastMonthCount = localStorage.getItem('lastMonthCountCache') ? localStorage.getItem('lastMonthCountCache') : monthBase + randomMonth - // lastMonthCount = monthBase + randomMonth - // } - // console.log('上月到馆', lastMonthCount) - - // // 日基数/10小时=小时基数 - // const hourBase = Math.floor(dayBase / 10) // 小时基数 - // console.log('小时基数', hourBase) - // // 图书馆营业时间(8:00-18:00共10小时) - // // 8:00-9:00 算第1个小时、9:00-10:00算第2个小时、以此类推 - // const openTime = 8 // 开门时间 - // const closeTime = 18 // 结束时间 - // const currentHour = now.getHours() // 当前时间点 - - // // 今日到馆=小时基数 * 第N小时+小时随机数(-5到10之间) - // let todayCount = 0 - // if (result.todayVisitBaseCheck === '1') { - // todayCount = result.todayVisitBase - // } else { - // if (currentHour < openTime || currentHour >= closeTime) { - // console.log('当前时间不在图书馆营业时间内') - // todayCount = 0 - // } else { - // const N = currentHour - openTime - // // console.log('第N个小时', N) - // const randomHour = Math.floor(Math.random() * (10 - (-5) + 1)) + (-5) // 小时随机数(-5到10之间) - // todayCount = Math.floor(hourBase * N + randomHour) // 今日到馆 - // } - // } - // console.log('今日到馆', todayCount) - // // 本月到馆=月基数 * (当前月的日期dd/当前月的天数)+ 月随机数(-100到200之间) - // let nowMonthCount = 0 - // if (result.thisMonthVisitBaseCheck === '1') { - // nowMonthCount = result.thisMonthVisitBase - // } else { - // if (now.getDate() === 1) { - // nowMonthCount = todayCount - // } else { - // nowMonthCount = Math.floor(monthBase * (now.getDate() / daysInMonth) + randomMonth) // 本月到馆 - // } - // } - // console.log('本月到馆', nowMonthCount) - - // this.progressData.push( - // { - // name: '今日到馆', - // value: todayCount, - // type: 1 - // }, - // { - // name: '本月到馆', - // value: nowMonthCount, - // type: 2 - // }, - // { - // name: '昨日到馆', - // value: yesterdayCount, - // type: 3 - // }, - // { - // name: '上月到馆', - // value: lastMonthCount, - // type: 4 - // } - // ) - - // this.leftData.push({ - // id: 'allTotal', - // name: '本年累计到馆', - // value: this.$parent.formatter(nowYearCount), - // valueArr: this.$parent.formatter(nowYearCount).split('') - // }, - // { - // id: 'lastYearTotal', - // name: '去年累计到馆', - // value: this.$parent.formatter(result.lastYearVisitBase), - // valueArr: this.$parent.formatter(result.lastYearVisitBase).split('') - // }) - - // this.$parent.timedRefresh(this.leftData, 'left') - - // // 昨日到馆、上月到馆存一个缓存!当前第一次计算好之后就不变了! - // // localStorage.setItem('yesterdayCountCache', yesterdayCount) - // // localStorage.setItem('lastMonthCountCache', lastMonthCount) - // }, + initLeftPreview(result) { + this.progressData = [] + this.leftData = [] + + // visit_base 本年累计人次 + // remarks 是否直接显示 0false 1true + + // last_year_visit_base 去年累计人次 + + // today_visit 今日人次 + // remarks 是否显示 + + // yesterday_visit 昨天人次 + // remarks 是否显示 + + // this_month_visit 本月人次 + // remarks 是否显示 + + // last_month_visit 上个月人次 + // remarks 是否显示 + this.pageOneVisitBase = result.visit_base.context + const baseTotal = this.pageOneVisitBase // 本年到馆人数 + console.log('假设本年到馆人数', baseTotal) + // 本年到馆/12个月 = 月基数 + const monthBase = Math.floor(baseTotal / 12) // 月基数 + console.log('月基数', monthBase) + // 月随机数(-100到200之间) + const randomMonth = Math.floor(Math.random() * (200 - (-100) + 1)) + (-100) + + const now = new Date() + const year = now.getFullYear() // 当前年份 + const month = now.getMonth() + 1 // 当前月份 + const daysInMonth = new Date(year, month, 0).getDate() // 当月天数 + console.log('当月天数', daysInMonth) + // 月基数/当月天数(28、29、30、31)= 日基数 + const dayBase = Math.floor(monthBase / daysInMonth) // 日基数 + console.log('日基数', dayBase) + // 本年累计=月基数*月份+月随机数(-100到200之间) + let nowYearCount + if (result.visit_base.remarks === '1') { + nowYearCount = result.visit_base.context + } else { + nowYearCount = Math.floor(monthBase * month + randomMonth) // 本年累计 + } + console.log('本年累计', nowYearCount) + // 昨日到馆=日基数+日随机数(-20到50之间) + let yesterdayCount = 0 + if (result.yesterday_visit.remarks === '1') { + yesterdayCount = result.yesterday_visit.context + } else { + const randomDay = Math.floor(Math.random() * (50 - (-20) + 1)) + (-20) // 日随机数(-20到50之间) + // yesterdayCount = localStorage.getItem('yesterdayCountCache') ? localStorage.getItem('yesterdayCountCache') : dayBase + randomDay // 昨日到馆 + yesterdayCount = dayBase + randomDay // 昨日到馆 + } + console.log('昨日到馆', yesterdayCount) + // 上月到馆=月基数+月随机数(-100到200之间) + let lastMonthCount = 0 + if (result.last_month_visit.remarks === '1') { + lastMonthCount = result.last_month_visit.context + } else { + // lastMonthCount = localStorage.getItem('lastMonthCountCache') ? localStorage.getItem('lastMonthCountCache') : monthBase + randomMonth + lastMonthCount = monthBase + randomMonth + } + console.log('上月到馆', lastMonthCount) + + // 日基数/10小时=小时基数 + const hourBase = Math.floor(dayBase / 10) // 小时基数 + console.log('小时基数', hourBase) + // 图书馆营业时间(8:00-18:00共10小时) + // 8:00-9:00 算第1个小时、9:00-10:00算第2个小时、以此类推 + const openTime = 8 // 开门时间 + const closeTime = 18 // 结束时间 + const currentHour = now.getHours() // 当前时间点 + + // 今日到馆=小时基数 * 第N小时+小时随机数(-5到10之间) + let todayCount = 0 + if (result.today_visit.remarks === '1') { + todayCount = result.today_visit.context + } else { + if (currentHour < openTime || currentHour >= closeTime) { + console.log('当前时间不在图书馆营业时间内') + todayCount = 0 + } else { + const N = currentHour - openTime + // console.log('第N个小时', N) + const randomHour = Math.floor(Math.random() * (10 - (-5) + 1)) + (-5) // 小时随机数(-5到10之间) + todayCount = Math.floor(hourBase * N + randomHour) // 今日到馆 + } + } + console.log('今日到馆', todayCount) + // 本月到馆=月基数 * (当前月的日期dd/当前月的天数)+ 月随机数(-100到200之间) + let nowMonthCount = 0 + if (result.this_month_visit.remarks === '1') { + nowMonthCount = result.this_month_visit.context + } else { + if (now.getDate() === 1) { + nowMonthCount = todayCount + } else { + nowMonthCount = Math.floor(monthBase * (now.getDate() / daysInMonth) + randomMonth) // 本月到馆 + } + } + console.log('本月到馆', nowMonthCount) + + this.progressData.push( + // { + // name: '今日到馆', + // value: todayCount, + // type: 1 + // }, + { + name: '本年到馆', + value: nowYearCount, + type: 1 + }, + { + name: '本月到馆', + value: nowMonthCount, + type: 2 + }, + // { + // name: '昨日到馆', + // value: yesterdayCount, + // type: 3 + // }, + { + name: '去年到馆', + value: result.last_year_visit_base.context, + type: 3 + }, + { + name: '上月到馆', + value: lastMonthCount, + type: 4 + } + ) + + const newData = [{ + id: 'totayTotal', + name: '今日到馆', + value: this.$parent.formatter(todayCount), + valueArr: this.$parent.formatter(todayCount).split(''), + timestamp: Date.now() + }] + + this.$set(this, 'leftData', newData) + + // this.leftData.push({ + // id: 'allTotal', + // name: '本年累计到馆', + // value: this.$parent.formatter(nowYearCount), + // valueArr: this.$parent.formatter(nowYearCount).split('') + // }, + // { + // id: 'lastYearTotal', + // name: '去年累计到馆', + // value: this.$parent.formatter(result.last_year_visit_base), + // valueArr: this.$parent.formatter(result.last_year_visit_base).split('') + // }) + + this.$parent.timedRefresh(this.leftData, 'left') + + // 昨日到馆、上月到馆存一个缓存!当前第一次计算好之后就不变了! + // localStorage.setItem('yesterdayCountCache', yesterdayCount) + // localStorage.setItem('lastMonthCountCache', lastMonthCount) + }, // 热门搜索 getHotSearch(hotUrl) {