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

feat(ssr): 真ssr实现

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