Skip to content

Commit 4e42a2f

Browse files
zoumiaojiangchenqiushi
authored andcommitted
add cambrian logo and title
1 parent 8414bba commit 4e42a2f

3 files changed

Lines changed: 62 additions & 2 deletions

File tree

packages/mip/examples/page/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ <h3>共享数据 checklist:</h3>
125125

126126
<a class="link" href="../builtin/mip-iframe.html" mip-link>Login</a>
127127
<a class="link" href="./tree.html?a=1#c=1&a=4" mip-link data-title="Customized title">Go to Tree</a>
128-
<a class="link" href="./tree.html" mip-link cache-first>Go to Tree cache first</a>
128+
<a class="link" href='./tree.html' mip-link cache-first>Go to Tree cache first</a>
129129
<a class="link" id="prerender">Prerender</a>
130130

131131
<br><br>

packages/mip/src/components/mip-shell/index.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ class MipShell extends CustomElement {
117117
window.MIP_SHELL_ROUTES_AUTO_GENERATED = true
118118
}
119119

120+
this.mergeCambrianData(tmpShellConfig)
121+
120122
if (page.isRootPage) {
121123
tmpShellConfig.routes.forEach(route => {
122124
!this.ignoreWarning && checkRouteConfig(route)
@@ -208,6 +210,61 @@ class MipShell extends CustomElement {
208210
}
209211
}
210212

213+
mergeCambrianData(tmpShellConfig) {
214+
let cambrianObj;
215+
let hashObj = {}
216+
if (location.hash) {
217+
let tmpHashArr = location.hash.replace('#', '').split('&')
218+
tmpHashArr.forEach(hashStr => {
219+
let hashSplitArr = hashStr.split('=')
220+
hashObj[hashSplitArr[0]] = hashSplitArr[1] || ''
221+
})
222+
}
223+
224+
// hash 传入的 logo 和 title 的优先级比直接配置在当前的 path 上的低,要比 * 的优先级高
225+
if (hashObj.cambrian) {
226+
try {
227+
cambrianObj = JSON.parse(decodeURIComponent(hashObj.cambrian))
228+
// 如果传入的参数出错或者解析不成功,就忽略这个 hash 参数
229+
} catch (e) {}
230+
}
231+
232+
if (cambrianObj && cambrianObj.title) {
233+
let cambrianRoute = {
234+
pattern: location.pathname,
235+
meta: {
236+
header: {
237+
show: true,
238+
title: cambrianObj.title || '',
239+
logo: cambrianObj.logo || ''
240+
},
241+
view: {
242+
isIndex: true
243+
}
244+
}
245+
}
246+
247+
if (tmpShellConfig.routes && tmpShellConfig.routes.length) {
248+
let injectFlag = true
249+
250+
for (let i = 0; i < tmpShellConfig.routes.length; i++) {
251+
let route = tmpShellConfig.routes[i]
252+
let re = convertPatternToRegexp(route.pattern)
253+
if (route.pattern !== '*' && re.test(page.pageId)) {
254+
tmpShellConfig.routes[i] = fn.extend(true, {}, cambrianRoute, route)
255+
injectFlag = false
256+
break
257+
}
258+
}
259+
injectFlag && tmpShellConfig.routes.unshift(cambrianRoute)
260+
} else {
261+
tmpShellConfig.routes = cambrianRoute
262+
}
263+
}
264+
265+
console.log(tmpShellConfig, page)
266+
}
267+
211268
prerenderAllowed () {
212269
return true
213270
}

packages/mip/src/viewer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ let viewer = {
274274
let retObj = Object.assign({}, targetHashObj, curHashObj)
275275

276276
for (let key in retObj) {
277-
hashStr += `${key}${retObj[key].sep}${retObj[key].value}&`
277+
// 不透传熊掌号相关的 hash,只保证第一次 logo + title 展现
278+
if (key !== 'cambrian') {
279+
hashStr += `${key}${retObj[key].sep}${retObj[key].value}&`
280+
}
278281
}
279282

280283
// hash 透传机制

0 commit comments

Comments
 (0)