Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Q
quantum-blocks-h5
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ui
quantum-blocks-h5
Commits
eb130f33
Commit
eb130f33
authored
Sep 03, 2021
by
郭志伟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(ssr): 真ssr实现
parent
a1c4515b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
19 deletions
+20
-19
activity.ts
app/controller/activity.ts
+15
-15
app.ts
app/web/framework/app.ts
+2
-2
sa.service.ts
app/web/service/sa.service.ts
+3
-2
No files found.
app/controller/activity.ts
View file @
eb130f33
...
...
@@ -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
app/web/framework/app.ts
View file @
eb130f33
...
...
@@ -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
,
...
...
app/web/service/sa.service.ts
View file @
eb130f33
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
)
{
cons
ole
.
log
(
'
initSa
'
,
EASY_ENV_IS_BROWSER
,
config
,
window
.
location
.
pathname
);
cons
t
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
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment