Commit eb130f33 authored by 郭志伟's avatar 郭志伟

feat(ssr): 真ssr实现

parent a1c4515b
......@@ -2,20 +2,20 @@ import { Controller, Context } from 'egg';
export default class ActivityController extends Controller {
public async home(ctx: Context) {
// const redisKey = `quantum-blocks:page:${ctx.params.id}`;
// let body = await ctx.service.redis.get(redisKey);
// if (body) {
// ctx.logger.info('请求redis成功 key: %j', redisKey);
// }
// if (!body) {
// let apollo = {};
// if (process.env.NODE_ENV === 'production' && process.env.EGG_SERVER_ENV === 'sit') {
// apollo = ctx.app.config.apollo || {};
// }
// body = await ctx.renderView('activity.js', { url: ctx.url, apollo });
// await ctx.service.redis.set(redisKey, body);
// }
// ctx.body = body;
ctx.body = await ctx.renderView('activity.js', { url: ctx.url });
const redisKey = `quantum-blocks:page:${ctx.params.id}`;
let body = await ctx.service.redis.get(redisKey);
if (body) {
ctx.logger.info('请求redis成功 key: %j', redisKey);
}
if (!body) {
let apollo = {};
if (process.env.NODE_ENV === 'production' && process.env.EGG_SERVER_ENV === 'sit') {
apollo = ctx.app.config.apollo || {};
}
body = await ctx.renderToHtml('activity.js', { url: ctx.url, apollo });
await ctx.service.redis.set(redisKey, body);
}
ctx.body = body;
// ctx.body = await ctx.renderToHtml('activity.js', { url: ctx.url });
}
}
\ No newline at end of file
......@@ -22,9 +22,9 @@ export default class App {
const router = createRouter();
sync(store, router);
if (EASY_ENV_IS_BROWSER) {
// const { initSa } = require('@/service/sa.service');
const { initSa } = require('@/service/sa.service');
initService.init(router);
// initSa(router);
initSa(router);
}
return {
router,
......
import Vue from 'vue';
import sa from 'sa-sdk-javascript';
import config from '@/config';
import Storage from '@/service/localStorage.service';
import { getParameterByName, isWxMp, isApp } from '@/service/utils.service';
export function initSa(router) {
console.log('initSa', EASY_ENV_IS_BROWSER, config, window.location.pathname);
const sa = require('sa-sdk-javascript');
const activityId = window.location.pathname.split('/')?.[2] || '';
const vccChannel = getParameterByName('vccChannel') || getParameterByName('registerFrom');
const sonVccChannel = getParameterByName('sonVccChannel');
......@@ -38,11 +37,13 @@ export function initSa(router) {
}
export function registeredEvents(eventName, eventData) {
const sa = require('sa-sdk-javascript');
sa.track(eventName, eventData);
}
// 用户登录神策埋点
export function loginSa(uuid = Storage.get('uuid')) {
if (!uuid) { return; }
Storage.set('uuid', uuid);
const sa = require('sa-sdk-javascript');
sa.login(uuid);
}
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