Skip to content

Commit

Permalink
chore: avoid show tabbar in every page (#4974)
Browse files Browse the repository at this point in the history
Co-authored-by: ClarkXia <xiawenwu41@gmail.com>
  • Loading branch information
SoloJiang and ClarkXia authored Nov 30, 2021
1 parent e9179a4 commit 0607b72
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 75 deletions.
45 changes: 39 additions & 6 deletions packages/build-mpa-config/src/template/rax/TabBar.tsx.ejs
Original file line number Diff line number Diff line change
@@ -1,31 +1,64 @@
import { createElement, Component, Fragment } from 'rax';
import { isNode, isWeb } from 'universal-env';
import { isWeb } from 'universal-env';
import TabBar from '<%= tabBarPath %>';

declare const my:any;

const currentPageName = '<%= entryName %>';

const isPHA = isWeb && (window as any).pha;
const isFRM = isWeb && typeof my !== 'undefined' && my.isFRM === true;
const shouldRenderTabBar = isNode || (!isPHA && !isFRM);

interface ITabItem {
path?: string;
pageName?: string;
name?: string;
icon?: string;
activeIcon?: string;
}

interface ITabBarConfig {
textColor?: string;
selectedColor?: string;
backgroundColor?: string;
items?: ITabItem[];
list?: string[];
[key: string]: unknown;
}

export default class TabBarWrapper extends Component {
__shouldRenderTabBar = false;
config: ITabBarConfig = <%- JSON.stringify(tabBarConfig) %>

constructor(props) {
super(props);

if (isPHA || isFRM) {
this.__shouldRenderTabBar = false;
} else if (this.config.list) {
this.__shouldRenderTabBar = this.config.list.includes(currentPageName);
} else {
this.__shouldRenderTabBar = this.config.items.some(item => item.pageName === currentPageName);
}
}

handleTabItemClick = ({ path, pageName }) => {
if (path) {
(window as any).location.href = path;
} else {
(window as any).location.href = `./${pageName}.html`;
(window as any).location.href = `/${pageName}.html`;
}
}

render() {
if (!shouldRenderTabBar) return null;
if (!this.__shouldRenderTabBar) return null;
return <Fragment>
<% if (tabBarPath.indexOf('src') > -1) {%>
<div style={{ position: "fixed", bottom: 0, width: "750rpx", zIndex: 999 }}>
<TabBar config={<%- JSON.stringify(tabBarConfig) %>} currentPageName={currentPageName} />
<TabBar config={this.config} currentPageName={currentPageName} />
</div>
<% } else { %>
<TabBar config={<%- JSON.stringify(tabBarConfig) %>} onClick={this.handleTabItemClick} currentPageName={currentPageName} />
<TabBar config={this.config} onClick={this.handleTabItemClick} currentPageName={currentPageName} />
<% } %>
</Fragment>;
}
Expand Down
99 changes: 30 additions & 69 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,18 @@
resolved "https://registry.yarnpkg.com/@builder/swc-win32-x64-msvc/-/swc-win32-x64-msvc-0.1.2.tgz#49734c9e853b697871a62165d3e967525a4a33d6"
integrity sha512-ug9991/8sIJ0TqaiWmMEEnZvVcdeFMfdQFOU3OegWkxJRHMxK40BHJmEgXcOK2fznuvSKrIOZt4ghvfYRLECig==

"@builder/swc@^0.1.0":
version "0.1.3"
resolved "https://registry.yarnpkg.com/@builder/swc/-/swc-0.1.3.tgz#c3337e3a896d22dd179224674e58d062235da16e"
integrity sha512-faikwN1YjtS3JdLV8QMM7angXZuXhBPFnmgkXWP8iBh/wk+DGOWUkcybrgCt7B0rgceWHyZv/l2eNlAJI3bKfg==
dependencies:
"@napi-rs/triples" "^1.0.3"
optionalDependencies:
"@builder/swc-darwin-arm64" "^0.1.0"
"@builder/swc-darwin-x64" "^0.1.0"
"@builder/swc-linux-x64-gnu" "^0.1.0"
"@builder/swc-win32-x64-msvc" "^0.1.0"

"@cnakazawa/watch@^1.0.3":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@cnakazawa/watch/-/watch-1.0.4.tgz#f864ae85004d0fcab6f50be9141c4da368d1656a"
Expand Down Expand Up @@ -2990,13 +3002,6 @@
call-me-maybe "^1.0.1"
glob-to-regexp "^0.3.0"

"@napi-rs/cli@^1.1.0":
version "1.3.5"
resolved "https://registry.yarnpkg.com/@napi-rs/cli/-/cli-1.3.5.tgz#89e4d97127edc4ed10a06637a43d27a1ed3c288d"
integrity sha512-Z0KZIciemioYODTyO908v2AtL8Zg4sohQDD+dyHeHmOiOfaez/y/xQ8XnpOHc2W5fRidKUW+MVWyTtpLTbKsqw==
dependencies:
inquirer "^8.1.3"

"@napi-rs/triples@^1.0.3":
version "1.0.3"
resolved "https://registry.yarnpkg.com/@napi-rs/triples/-/triples-1.0.3.tgz#76d6d0c3f4d16013c61e45dfca5ff1e6c31ae53c"
Expand Down Expand Up @@ -4855,7 +4860,7 @@ bindings@^1.5.0:
dependencies:
file-uri-to-path "1.0.0"

bl@^4.0.3, bl@^4.1.0:
bl@^4.0.3:
version "4.1.0"
resolved "https://registry.yarnpkg.com/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a"
integrity sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==
Expand Down Expand Up @@ -5008,6 +5013,22 @@ buffer@^5.2.1, buffer@^5.5.0:
base64-js "^1.3.1"
ieee754 "^1.1.13"

build-plugin-ice-router@2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/build-plugin-ice-router/-/build-plugin-ice-router-2.0.3.tgz#e846fe052db186c01975426911a5d0521ca14081"
integrity sha512-GM4BhpwzYSSThh509OgDKMk4175tGKxj8zECJBkemu2egy5ytBwIJK9pTBqNwKsyTDBaIUW500ymKuL0JR4Mmw==
dependencies:
"@builder/app-helpers" "^2.0.2"
"@builder/pack" "^0.4.0"
"@types/react-router-dom" "^5.1.4"
fs-extra "^8.1.0"
glob "^7.1.6"
history "^4.10.1"
query-string "^6.12.1"
react "^16.12.0"
react-dom "^16.12.0"
react-router-dom "^5.1.2"

build-scripts-config@^3.0.0:
version "3.0.3"
resolved "https://registry.yarnpkg.com/build-scripts-config/-/build-scripts-config-3.0.3.tgz#bd97743a87f7f19fc36e799a2de06168352cd046"
Expand Down Expand Up @@ -5505,7 +5526,7 @@ cli-cursor@^3.1.0:
dependencies:
restore-cursor "^3.1.0"

cli-spinners@^2.2.0, cli-spinners@^2.5.0:
cli-spinners@^2.2.0:
version "2.6.1"
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-2.6.1.tgz#adc954ebe281c37a6319bfa401e6dd2488ffb70d"
integrity sha512-x/5fWmGMnbKQAaNwN+UZlV79qBLM9JFnJuJ03gIi5whrob0xV0ofNVHy9DhwGdsMJQc2OKv0oGmLzvaqvAVv+g==
Expand Down Expand Up @@ -9247,26 +9268,6 @@ inquirer@^7.0.4, inquirer@^7.1.0:
strip-ansi "^6.0.0"
through "^2.3.6"

inquirer@^8.1.3:
version "8.2.0"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.2.0.tgz#f44f008dd344bbfc4b30031f45d984e034a3ac3a"
integrity sha512-0crLweprevJ02tTuA6ThpoAERAGyVILC4sS74uib58Xf/zSr1/ZWtmm7D5CI+bSQEaA04f0K7idaHpQbSWgiVQ==
dependencies:
ansi-escapes "^4.2.1"
chalk "^4.1.1"
cli-cursor "^3.1.0"
cli-width "^3.0.0"
external-editor "^3.0.3"
figures "^3.0.0"
lodash "^4.17.21"
mute-stream "0.0.8"
ora "^5.4.1"
run-async "^2.4.0"
rxjs "^7.2.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"
through "^2.3.6"

inspector-dom@^0.1.1:
version "0.1.1"
resolved "https://registry.yarnpkg.com/inspector-dom/-/inspector-dom-0.1.1.tgz#08146b2db7c347d5e28737244b47f3eabe95686f"
Expand Down Expand Up @@ -9754,11 +9755,6 @@ is-unc-path@^1.0.0:
dependencies:
unc-path-regex "^0.1.2"

is-unicode-supported@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/is-unicode-supported/-/is-unicode-supported-0.1.0.tgz#3f26c76a809593b52bfa2ecb5710ed2779b522a7"
integrity sha512-knxG2q4UC3u8stRGyAVJCOdxFmv5DZiRcdlIaAQXAbSfJya+OhopNotLQrstBhququ4ZpuKbDc/8S6mgXgPFPw==

is-utf8@^0.2.0:
version "0.2.1"
resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72"
Expand Down Expand Up @@ -11350,14 +11346,6 @@ log-symbols@^3.0.0:
dependencies:
chalk "^2.4.2"

log-symbols@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-4.1.0.tgz#3fbdbb95b4683ac9fc785111e792e558d4abd503"
integrity sha512-8XPvpAA8uyhfteu8pIvQxpJZ7SYYdpUivZpGy6sFsBuKRY/7rQGavedeB8aK+Zkyq6upMFVL/9AW6vOYzfRyLg==
dependencies:
chalk "^4.1.0"
is-unicode-supported "^0.1.0"

lolex@^5.0.0:
version "5.1.2"
resolved "https://registry.yarnpkg.com/lolex/-/lolex-5.1.2.tgz#953694d098ce7c07bc5ed6d0e42bc6c0c6d5a367"
Expand Down Expand Up @@ -12555,21 +12543,6 @@ ora@^4.0.3:
strip-ansi "^6.0.0"
wcwidth "^1.0.1"

ora@^5.4.1:
version "5.4.1"
resolved "https://registry.yarnpkg.com/ora/-/ora-5.4.1.tgz#1b2678426af4ac4a509008e5e4ac9e9959db9e18"
integrity sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ==
dependencies:
bl "^4.1.0"
chalk "^4.1.0"
cli-cursor "^3.1.0"
cli-spinners "^2.5.0"
is-interactive "^1.0.0"
is-unicode-supported "^0.1.0"
log-symbols "^4.1.0"
strip-ansi "^6.0.0"
wcwidth "^1.0.1"

os-homedir@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3"
Expand Down Expand Up @@ -15017,13 +14990,6 @@ rxjs@^6.4.0, rxjs@^6.6.0:
dependencies:
tslib "^1.9.0"

rxjs@^7.2.0:
version "7.4.0"
resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.4.0.tgz#a12a44d7eebf016f5ff2441b87f28c9a51cebc68"
integrity sha512-7SQDi7xeTMCJpqViXh8gL/lebcwlp3d831F05+9B44A4B0WfsEwUQHR64gsH1kvJ+Ep/J9K2+n1hVl1CsGN23w==
dependencies:
tslib "~2.1.0"

safe-buffer@5.1.2, safe-buffer@~5.1.0, safe-buffer@~5.1.1:
version "5.1.2"
resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.2.tgz#991ec69d296e0313747d59bdfd2b745c35f8828d"
Expand Down Expand Up @@ -16679,11 +16645,6 @@ tslib@^2.0.3, tslib@^2.2.0, tslib@^2.3.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.3.1.tgz#e8a335add5ceae51aa261d32a490158ef042ef01"
integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==

tslib@~2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A==

tsscmp@1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/tsscmp/-/tsscmp-1.0.6.tgz#85b99583ac3589ec4bfef825b5000aa911d605eb"
Expand Down

0 comments on commit 0607b72

Please sign in to comment.