Commit b427abc1 authored by Xuguangxing's avatar Xuguangxing

feat: 处理时区偏移问题

parent 01de9870
...@@ -6,14 +6,8 @@ export default class ActivityController extends Controller { ...@@ -6,14 +6,8 @@ export default class ActivityController extends Controller {
// 开发环境不走redis缓存 // 开发环境不走redis缓存
const apollo = ctx.app.config.apollo || {}; const apollo = ctx.app.config.apollo || {};
let body = ''; let body = '';
// 获取服务器端当前时间,用于与页面有效期做对比
const currentTime = new Date().getTime();
const offsetTime = new Date(currentTime).getTimezoneOffset() * 60 * 1000;
// console.log(currentTime, offsetTime);
const serverTimeStamp = currentTime - offsetTime;
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
body = await ctx.renderToHtml('activity.js', { url: ctx.url, apollo, serverTimeStamp }); body = await ctx.renderToHtml('activity.js', { url: ctx.url, apollo });
} else { } else {
const redisKey = `quantum-blocks:page:${ctx.params.id}`; const redisKey = `quantum-blocks:page:${ctx.params.id}`;
body = await ctx.service.redis.get(redisKey); body = await ctx.service.redis.get(redisKey);
...@@ -21,7 +15,7 @@ export default class ActivityController extends Controller { ...@@ -21,7 +15,7 @@ export default class ActivityController extends Controller {
ctx.logger.info('请求redis成功 key: %j', redisKey); ctx.logger.info('请求redis成功 key: %j', redisKey);
} }
if (!body) { if (!body) {
body = await ctx.renderToHtml('activity.js', { url: ctx.url, apollo, serverTimeStamp }); body = await ctx.renderToHtml('activity.js', { url: ctx.url, apollo });
await ctx.service.redis.set(redisKey, body); await ctx.service.redis.set(redisKey, body);
} }
} }
......
...@@ -93,7 +93,7 @@ export default class App { ...@@ -93,7 +93,7 @@ export default class App {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
router.onReady(() => { router.onReady(() => {
this.fetch(vm).then(() => { this.fetch(vm).then(() => {
context.state = {...store.state, apollo: context.state.apollo || {}, serverTimestamp: context.state.serverTimeStamp}; context.state = {...store.state, apollo: context.state.apollo || {}};
return resolve(new Vue(vm)); return resolve(new Vue(vm));
}); });
}); });
......
...@@ -31,7 +31,6 @@ export default class Activity extends Mixins(TransformStyleMixin, BottomNavStyle ...@@ -31,7 +31,6 @@ export default class Activity extends Mixins(TransformStyleMixin, BottomNavStyle
@State(state => state.activity.pageInfo.appLoginState) appLoginState; @State(state => state.activity.pageInfo.appLoginState) appLoginState;
@State(state => state.activity.pageInfo.tenantId) tenantId; @State(state => state.activity.pageInfo.tenantId) tenantId;
@State(state => state.activity.gridLayout.rowHeight) rowHeight; @State(state => state.activity.gridLayout.rowHeight) rowHeight;
@State(state => state.serverTimestamp) serverTimestamp;
@Mutation('SET_PAGE_ELEMENTS') setPageElement; @Mutation('SET_PAGE_ELEMENTS') setPageElement;
@Mutation('UPDATE_APP_LOGIN_STATE') updateAppLoginState; @Mutation('UPDATE_APP_LOGIN_STATE') updateAppLoginState;
...@@ -154,11 +153,13 @@ export default class Activity extends Mixins(TransformStyleMixin, BottomNavStyle ...@@ -154,11 +153,13 @@ export default class Activity extends Mixins(TransformStyleMixin, BottomNavStyle
} }
comparePageTime() { comparePageTime() {
const { validStartTime, validEndTime } = this.pageInfo; const { validStartTime, validEndTime } = this.pageInfo;
// 获取服务器端当前时间,用于与页面有效期做对比
const currentTime = new Date().getTime();
if (validStartTime && validEndTime) { if (validStartTime && validEndTime) {
// todo 当设置了页面的有效时间起止,用当前服务器返回的时间作对比,判断页面是否在有效期内 // todo 当设置了页面的有效时间起止,用当前服务器返回的时间作对比,判断页面是否在有效期内
const startTime = new Date(validStartTime).getTime(); const startTime = new Date(validStartTime).getTime();
const endTime = new Date(validEndTime).getTime(); const endTime = new Date(validEndTime).getTime();
if (this.serverTimestamp < startTime || this.serverTimestamp > endTime) { if (currentTime < startTime || currentTime > endTime) {
this.pageInvalid = true; this.pageInvalid = true;
} }
} }
......
<template> <template>
<div class="pageContent"> <div class="pageContent">
{{serverTimestamp}}
<div class="activity" :class="{hasBottomNav: navigatorConfig}" :style="transformStyle(pageData.commonStyle)"> <div class="activity" :class="{hasBottomNav: navigatorConfig}" :style="transformStyle(pageData.commonStyle)">
<template v-if="!noPageData && tenantIdCorrect"> <template v-if="!noPageData && tenantIdCorrect">
<div class="layout"> <div class="layout">
......
...@@ -7,8 +7,8 @@ import Activity from './modules/activity'; ...@@ -7,8 +7,8 @@ import Activity from './modules/activity';
Vue.use(Vuex); Vue.use(Vuex);
export default function createStore(initState: any = {}) { export default function createStore(initState: any = {}) {
const { title, url, origin, locale, csrf, activity, serverTimestamp } = initState; const { title, url, origin, locale, csrf, activity } = initState;
const state = { title, url, origin, locale, csrf, serverTimestamp }; const state = { title, url, origin, locale, csrf };
return new Vuex.Store<RootState>({ return new Vuex.Store<RootState>({
state, state,
modules: { modules: {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment