Skip to content

Commit

Permalink
feat: hash change
Browse files Browse the repository at this point in the history
  • Loading branch information
xsf0105 committed Jun 13, 2023
1 parent 395ad17 commit 19c84dc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quark-doc-header",
"version": "0.3.22",
"version": "0.3.23",
"keywords": [
"frontend",
"quark",
Expand Down
31 changes: 18 additions & 13 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { QuarkElement, Fragment, createRef, customElement, state, property } from "quarkc"
import { QuarkElement, createRef, customElement, state, property } from "quarkc"
import style from "./index.less?inline"
import "./dark-light-mode.mjs" // 备注:黑夜模式切换包含了全局css变量的更改,只在引用的工程中生效

Expand Down Expand Up @@ -97,8 +97,19 @@ class MyComponent extends QuarkElement {
}
}

// 菜单是否激活
navActive = () => {
if(location.hash.indexOf('guide') > -1) {
this.activeNav = 'guide'
} else if(location.hash.indexOf('component') > -1) {
this.activeNav = 'component'
}
}

componentDidMount(): void {

this.navActive()

// 默认设置语言
if(!localStorage.getItem('language')) {
localStorage.setItem('language', 'en-US')
Expand All @@ -109,13 +120,6 @@ class MyComponent extends QuarkElement {
localStorage.setItem('theme', 'light')
}

// 菜单是否激活
if(location.hash.indexOf('guide') > -1) {
this.activeNav = 'guide'
} else if(location.hash.indexOf('component') > -1) {
this.activeNav = 'component'
}

// 主页跳转地址
this.homeUrl = this.#curHost // e.g. https://vue-quarkdesign.hellobike.com
this.guideUrl = `${this.#curHost}/#/${localStorage.getItem("language")}/guide/quickstart`
Expand Down Expand Up @@ -152,7 +156,8 @@ class MyComponent extends QuarkElement {
window.addEventListener(
"hashchange",
() => {
console.log("The hash has changed!");
// console.log("The hash has changed!");
this.navActive()
},
false
);
Expand Down Expand Up @@ -197,7 +202,7 @@ class MyComponent extends QuarkElement {

render() {
return (
<Fragment>
<>
{
this.#isDocNotReady ?
<div className="toper-message">
Expand All @@ -219,7 +224,7 @@ class MyComponent extends QuarkElement {
<div class="menu-group">
{
this.#isQuarkc ? null :
<Fragment>
<>
<div class={this.activeNav === 'guide'? 'nav-item menu active-nav' : 'nav-item menu'}>
<a
href={this.guideUrl}
Expand All @@ -235,7 +240,7 @@ class MyComponent extends QuarkElement {
{this.#ecosystemLangs.component}
</a>
</div>
</Fragment>
</>
}

<div class="nav-item flyout">
Expand Down Expand Up @@ -507,7 +512,7 @@ class MyComponent extends QuarkElement {
</div>
</div>
</header>
</Fragment>
</>
);
}
}
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"strict": false,
"jsx": "react",
"jsxFactory": "QuarkElement.h",
"jsxFragmentFactory": "QuarkElement.Fragment",
"sourceMap": false,
"declaration": true,
"declarationDir": "lib/types",
Expand Down

0 comments on commit 19c84dc

Please sign in to comment.