Skip to content

Commit

Permalink
add cambrian logo and title
Browse files Browse the repository at this point in the history
  • Loading branch information
zoumiaojiang authored and chenqiushi committed Jul 23, 2019
1 parent 8414bba commit 4e42a2f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/mip/examples/page/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ <h3>共享数据 checklist:</h3>

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

<br><br>
Expand Down
57 changes: 57 additions & 0 deletions packages/mip/src/components/mip-shell/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class MipShell extends CustomElement {
window.MIP_SHELL_ROUTES_AUTO_GENERATED = true
}

this.mergeCambrianData(tmpShellConfig)

if (page.isRootPage) {
tmpShellConfig.routes.forEach(route => {
!this.ignoreWarning && checkRouteConfig(route)
Expand Down Expand Up @@ -208,6 +210,61 @@ class MipShell extends CustomElement {
}
}

mergeCambrianData(tmpShellConfig) {
let cambrianObj;
let hashObj = {}
if (location.hash) {
let tmpHashArr = location.hash.replace('#', '').split('&')
tmpHashArr.forEach(hashStr => {
let hashSplitArr = hashStr.split('=')
hashObj[hashSplitArr[0]] = hashSplitArr[1] || ''
})
}

// hash 传入的 logo 和 title 的优先级比直接配置在当前的 path 上的低,要比 * 的优先级高
if (hashObj.cambrian) {
try {
cambrianObj = JSON.parse(decodeURIComponent(hashObj.cambrian))
// 如果传入的参数出错或者解析不成功,就忽略这个 hash 参数
} catch (e) {}
}

if (cambrianObj && cambrianObj.title) {
let cambrianRoute = {
pattern: location.pathname,
meta: {
header: {
show: true,
title: cambrianObj.title || '',
logo: cambrianObj.logo || ''
},
view: {
isIndex: true
}
}
}

if (tmpShellConfig.routes && tmpShellConfig.routes.length) {
let injectFlag = true

for (let i = 0; i < tmpShellConfig.routes.length; i++) {
let route = tmpShellConfig.routes[i]
let re = convertPatternToRegexp(route.pattern)
if (route.pattern !== '*' && re.test(page.pageId)) {
tmpShellConfig.routes[i] = fn.extend(true, {}, cambrianRoute, route)
injectFlag = false
break
}
}
injectFlag && tmpShellConfig.routes.unshift(cambrianRoute)
} else {
tmpShellConfig.routes = cambrianRoute
}
}

console.log(tmpShellConfig, page)
}

prerenderAllowed () {
return true
}
Expand Down
5 changes: 4 additions & 1 deletion packages/mip/src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ let viewer = {
let retObj = Object.assign({}, targetHashObj, curHashObj)

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

// hash 透传机制
Expand Down

0 comments on commit 4e42a2f

Please sign in to comment.