@tarojs/router 4.0.0-beta.2 → 4.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +21 -1
- package/dist/events/resize.js +12 -6
- package/dist/history.js +1 -1
- package/dist/index.cjs.d.ts +7 -2
- package/dist/index.cjs.js +370 -30
- package/dist/index.esm.d.ts +7 -2
- package/dist/index.esm.js +370 -32
- package/dist/index.js +4 -1
- package/dist/navigationBar.d.ts +2 -0
- package/dist/navigationBar.js +27 -0
- package/dist/router/mpa.js +13 -2
- package/dist/router/navigation-bar.d.ts +32 -0
- package/dist/router/navigation-bar.js +209 -0
- package/dist/router/page.d.ts +3 -1
- package/dist/router/page.js +6 -0
- package/dist/router/spa.js +12 -5
- package/dist/style.d.ts +5 -1
- package/dist/style.js +58 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/navigate.d.ts +7 -2
- package/dist/utils/navigate.js +22 -19
- package/package.json +5 -5
package/dist/index.esm.js
CHANGED
|
@@ -1,12 +1,38 @@
|
|
|
1
1
|
import { defineCustomElementTaroTabbar } from '@tarojs/components/dist/components';
|
|
2
2
|
import { initTabBarApis } from '@tarojs/taro';
|
|
3
3
|
import { __awaiter } from 'tslib';
|
|
4
|
-
import { addLeadingSlash, Current, stripBasename,
|
|
4
|
+
import { eventCenter, addLeadingSlash, Current, stripBasename, incrementId, createPageConfig, hooks, stringify, getHomePage, getCurrentPage, stripTrailing, requestAnimationFrame as requestAnimationFrame$1 } from '@tarojs/runtime';
|
|
5
5
|
import { createBrowserHistory, createHashHistory, Action, parsePath } from 'history';
|
|
6
6
|
export { createBrowserHistory, createHashHistory } from 'history';
|
|
7
7
|
import queryString from 'query-string';
|
|
8
8
|
import UniversalRouter from 'universal-router';
|
|
9
9
|
|
|
10
|
+
const home_svg_str = `
|
|
11
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
12
|
+
<path d="M23.8899 12.2737C23.8232 12.3584 23.7237 12.3997 23.6198 12.3974H20.7994V23.5996C20.7994 23.8194 20.6213 24 20.4001 24H14.7994C14.5791 24 14.4002 23.8194 14.4002 23.5996V15.6H9.59963V23.5996C9.59963 23.8194 9.42075 24 9.20033 24H3.59968C3.48981 24 3.38964 23.954 3.31764 23.8811C3.24495 23.8091 3.2004 23.7087 3.2004 23.5996V12.3975H0.398546V12.3967C0.296893 12.396 0.194446 12.3544 0.11579 12.2738C-0.0371146 12.114 -0.0400714 11.864 0.11579 11.7076L11.7201 0.117284C11.8767 -0.0390948 12.1298 -0.0390948 12.2863 0.117284L23.8899 11.7076C24.0465 11.864 24.0265 12.0995 23.8899 12.2737ZM12.0029 0.964625L1.37086 11.5854L3.59968 11.5839V11.5999C3.65537 11.5999 3.70804 11.611 3.75557 11.6307C3.89952 11.692 4.00046 11.8339 4.00046 11.9996V23.1991H8.79955V15.2003C8.79955 14.9789 8.97917 14.8002 9.20033 14.8002H14.7995C15.0207 14.8002 15.2003 14.9789 15.2003 15.2003V23.1991H20.0001V11.9996C20.0001 11.8339 20.1003 11.692 20.2443 11.6307C20.2918 11.611 20.3453 11.5999 20.4001 11.5999V11.5713L22.6193 11.5691L12.0029 0.964625Z" fill="currentColor"/>
|
|
13
|
+
</svg>
|
|
14
|
+
`;
|
|
15
|
+
const back_svg_str = `
|
|
16
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
17
|
+
<path d="M17.8206 22.9016L7.45515 11.8756L17.8206 1.09845C18.0598 0.849741 18.0598 0.435233 17.8206 0.186528C17.5814 -0.0621762 17.1827 -0.0621762 16.9435 0.186528L6.1794 11.4611C5.9402 11.7098 5.9402 12.1244 6.1794 12.3731L16.9435 23.8135C17.1827 24.0622 17.5814 24.0622 17.8206 23.8135C18.0598 23.5648 18.0598 23.1503 17.8206 22.9016Z" fill="currentColor"/>
|
|
18
|
+
</svg>
|
|
19
|
+
|
|
20
|
+
`;
|
|
21
|
+
function initNavigationBar(container) {
|
|
22
|
+
const navigationBar = document.createElement('taro-navigation-bar-wrap');
|
|
23
|
+
navigationBar.classList.add('taro-navigation-bar-no-icon');
|
|
24
|
+
const navigationBarBackBtn = document.createElement('taro-navigation-bar-back');
|
|
25
|
+
const navigationBarHomeBtn = document.createElement('taro-navigation-bar-home');
|
|
26
|
+
navigationBarBackBtn.innerHTML = back_svg_str;
|
|
27
|
+
navigationBarHomeBtn.innerHTML = home_svg_str;
|
|
28
|
+
const navigationBarTitle = document.createElement('taro-navigation-bar-title');
|
|
29
|
+
navigationBar.appendChild(navigationBarHomeBtn);
|
|
30
|
+
navigationBar.appendChild(navigationBarBackBtn);
|
|
31
|
+
navigationBar.appendChild(navigationBarTitle);
|
|
32
|
+
navigationBar.id = 'taro-navigation-bar';
|
|
33
|
+
container.prepend(navigationBar);
|
|
34
|
+
}
|
|
35
|
+
|
|
10
36
|
function initTabbar(config, history) {
|
|
11
37
|
if (config.tabBar == null || config.tabBar.custom) {
|
|
12
38
|
return;
|
|
@@ -87,7 +113,7 @@ class MpaHistory {
|
|
|
87
113
|
url += `?${to.search}`;
|
|
88
114
|
}
|
|
89
115
|
if (to.hash) {
|
|
90
|
-
url += `#${to.hash}`;
|
|
116
|
+
url += to.hash.startsWith('#') ? to.hash : `#${to.hash}`;
|
|
91
117
|
}
|
|
92
118
|
return url;
|
|
93
119
|
}
|
|
@@ -244,26 +270,29 @@ class Stacks {
|
|
|
244
270
|
}
|
|
245
271
|
const stacks = new Stacks();
|
|
246
272
|
|
|
247
|
-
let preTitle = document.title;
|
|
248
|
-
let isLoadDdEntry = false;
|
|
249
273
|
const isWeixin = () => !!navigator.userAgent.match(/\bMicroMessenger\b/ig);
|
|
250
274
|
const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
263
|
-
setDingTitle({ title });
|
|
275
|
+
let preTitle = document.title;
|
|
276
|
+
let isLoadDdEntry = false;
|
|
277
|
+
function setMpaTitle(title) {
|
|
278
|
+
if (preTitle === title)
|
|
279
|
+
return;
|
|
280
|
+
document.title = title;
|
|
281
|
+
preTitle = title;
|
|
282
|
+
if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
|
|
283
|
+
if (!isLoadDdEntry) {
|
|
284
|
+
isLoadDdEntry = true;
|
|
285
|
+
require('dingtalk-jsapi/platform');
|
|
264
286
|
}
|
|
265
|
-
|
|
266
|
-
|
|
287
|
+
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
288
|
+
setDingTitle({ title });
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
function setTitle(title) {
|
|
292
|
+
eventCenter.trigger('__taroH5SetNavigationTitle', title);
|
|
293
|
+
}
|
|
294
|
+
function setNavigationBarStyle(option) {
|
|
295
|
+
eventCenter.trigger('__taroH5setNavigationBarColor', option);
|
|
267
296
|
}
|
|
268
297
|
|
|
269
298
|
class RoutesAlias {
|
|
@@ -347,6 +376,21 @@ function navigate(option, method) {
|
|
|
347
376
|
if ('url' in option) {
|
|
348
377
|
const pathPieces = processNavigateUrl(option);
|
|
349
378
|
const state = { timestamp: Date.now() };
|
|
379
|
+
if (pathPieces.pathname) {
|
|
380
|
+
const originPath = routesAlias.getOrigin(pathPieces.pathname);
|
|
381
|
+
const pagePath = originPath.startsWith('/') ? originPath.substring(1) : originPath;
|
|
382
|
+
if (!RouterConfig.pages.includes(pagePath)) {
|
|
383
|
+
const res = { errMsg: `${method}:fail page ${pagePath} is not found` };
|
|
384
|
+
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
385
|
+
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
386
|
+
if (fail || complete) {
|
|
387
|
+
return resolve(res);
|
|
388
|
+
}
|
|
389
|
+
else {
|
|
390
|
+
return reject(res);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
}
|
|
350
394
|
if (method === 'navigateTo') {
|
|
351
395
|
history.push(pathPieces, state);
|
|
352
396
|
}
|
|
@@ -372,7 +416,12 @@ function navigate(option, method) {
|
|
|
372
416
|
const res = { errMsg: `${method}:fail ${error.message || error}` };
|
|
373
417
|
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
374
418
|
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
375
|
-
|
|
419
|
+
if (fail || complete) {
|
|
420
|
+
return resolve(res);
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
return reject(res);
|
|
424
|
+
}
|
|
376
425
|
}
|
|
377
426
|
});
|
|
378
427
|
});
|
|
@@ -407,12 +456,18 @@ let pageResizeFn;
|
|
|
407
456
|
function bindPageResize(page) {
|
|
408
457
|
pageResizeFn && window.removeEventListener('resize', pageResizeFn);
|
|
409
458
|
pageResizeFn = function () {
|
|
410
|
-
page.onResize
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
459
|
+
if (page.onResize) {
|
|
460
|
+
const mediaQuery = window.matchMedia('(orientation: portrait)');
|
|
461
|
+
page.onResize({
|
|
462
|
+
deviceOrientation: mediaQuery.matches ? 'portrait' : 'landscape',
|
|
463
|
+
size: {
|
|
464
|
+
windowHeight: window.innerHeight,
|
|
465
|
+
windowWidth: window.innerWidth,
|
|
466
|
+
screenHeight: window.screen.height,
|
|
467
|
+
screenWidth: window.screen.width,
|
|
468
|
+
}
|
|
469
|
+
});
|
|
470
|
+
}
|
|
416
471
|
};
|
|
417
472
|
window.addEventListener('resize', pageResizeFn, false);
|
|
418
473
|
}
|
|
@@ -456,6 +511,9 @@ function getOffset() {
|
|
|
456
511
|
*/
|
|
457
512
|
function loadAnimateStyle(ms = 300) {
|
|
458
513
|
const css = `
|
|
514
|
+
body {
|
|
515
|
+
overflow: hidden; // 防止 iOS 页面滚动
|
|
516
|
+
}
|
|
459
517
|
.taro_router > .taro_page {
|
|
460
518
|
position: absolute;
|
|
461
519
|
left: 0;
|
|
@@ -517,6 +575,60 @@ ${enableTabBar ? `
|
|
|
517
575
|
`;
|
|
518
576
|
addStyle(css);
|
|
519
577
|
}
|
|
578
|
+
/**
|
|
579
|
+
* 插入导航栏相关的样式
|
|
580
|
+
*/
|
|
581
|
+
function loadNavigationBarStyle() {
|
|
582
|
+
const css = `
|
|
583
|
+
.taro-navigation-bar-show {
|
|
584
|
+
background: white;
|
|
585
|
+
position: sticky;
|
|
586
|
+
z-index: 500;
|
|
587
|
+
top: 0;
|
|
588
|
+
padding-bottom: 8px;
|
|
589
|
+
padding-top: calc(env(safe-area-inset-top) + 8px);
|
|
590
|
+
display: flex;
|
|
591
|
+
justify-content: center;
|
|
592
|
+
align-items: center;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
.taro-navigation-bar-hide {
|
|
596
|
+
display: none;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
taro-navigation-bar-title {
|
|
600
|
+
font-size: 24px;
|
|
601
|
+
height: 24px;
|
|
602
|
+
line-height: 24px;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
.taro-navigation-bar-no-icon > taro-navigation-bar-home {
|
|
606
|
+
display: none;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
.taro-navigation-bar-no-icon > taro-navigation-bar-back {
|
|
610
|
+
display: none;
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
.taro-navigation-bar-home > taro-navigation-bar-home {
|
|
614
|
+
display: block;
|
|
615
|
+
left: 8px;
|
|
616
|
+
position: absolute;
|
|
617
|
+
width: 24px;
|
|
618
|
+
height: 24px;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
.taro-navigation-bar-back > taro-navigation-bar-back {
|
|
622
|
+
display: block;
|
|
623
|
+
left: 8px;
|
|
624
|
+
position: absolute;
|
|
625
|
+
width: 24px;
|
|
626
|
+
height: 24px;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
`;
|
|
630
|
+
addStyle(css);
|
|
631
|
+
}
|
|
520
632
|
function addStyle(css) {
|
|
521
633
|
if (!css)
|
|
522
634
|
return;
|
|
@@ -685,6 +797,7 @@ function createMultiRouter(history, app, config, framework) {
|
|
|
685
797
|
if (typeof app.onUnhandledRejection === 'function') {
|
|
686
798
|
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
687
799
|
}
|
|
800
|
+
eventCenter.on('__taroH5SetNavigationTitle', setMpaTitle);
|
|
688
801
|
RouterConfig.config = config;
|
|
689
802
|
const handler = new MultiPageHandler(config, history);
|
|
690
803
|
const launchParam = {
|
|
@@ -718,7 +831,7 @@ function createMultiRouter(history, app, config, framework) {
|
|
|
718
831
|
return;
|
|
719
832
|
let enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
|
|
720
833
|
if (pageConfig) {
|
|
721
|
-
|
|
834
|
+
setMpaTitle((_d = pageConfig.navigationBarTitleText) !== null && _d !== void 0 ? _d : document.title);
|
|
722
835
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
723
836
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
724
837
|
}
|
|
@@ -730,9 +843,219 @@ function createMultiRouter(history, app, config, framework) {
|
|
|
730
843
|
const page = createPageConfig(enablePullDownRefresh ? hooks.call('createPullDownComponent', el, pathName, framework, handler.PullDownRefresh) : el, pathName + stringify(launchParam), {}, loadConfig);
|
|
731
844
|
handler.load(page, pageConfig);
|
|
732
845
|
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);
|
|
846
|
+
window.addEventListener('visibilitychange', () => {
|
|
847
|
+
var _a, _b;
|
|
848
|
+
if (document.visibilityState === 'visible') {
|
|
849
|
+
(_a = app.onShow) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
850
|
+
}
|
|
851
|
+
else {
|
|
852
|
+
(_b = app.onHide) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
|
|
853
|
+
}
|
|
854
|
+
});
|
|
733
855
|
});
|
|
734
856
|
}
|
|
735
857
|
|
|
858
|
+
class NavigationBarHandler {
|
|
859
|
+
constructor(pageContext) {
|
|
860
|
+
this.isLoadDdEntry = false;
|
|
861
|
+
this.cache = {};
|
|
862
|
+
this.pageContext = pageContext;
|
|
863
|
+
this.init();
|
|
864
|
+
loadNavigationBarStyle();
|
|
865
|
+
eventCenter.on('__taroH5SetNavigationTitle', (title) => {
|
|
866
|
+
this.setTitle(title);
|
|
867
|
+
});
|
|
868
|
+
eventCenter.on('__taroH5setNavigationBarColor', ({ backgroundColor, frontColor }) => {
|
|
869
|
+
if (typeof backgroundColor === 'string')
|
|
870
|
+
this.setNavigationBarBackground(backgroundColor);
|
|
871
|
+
if (typeof frontColor === 'string')
|
|
872
|
+
this.setNavigationBarTextStyle(frontColor);
|
|
873
|
+
});
|
|
874
|
+
}
|
|
875
|
+
toHomeFn() {
|
|
876
|
+
reLaunch({ url: this.pageContext.homePage });
|
|
877
|
+
}
|
|
878
|
+
backFn() {
|
|
879
|
+
navigateBack();
|
|
880
|
+
}
|
|
881
|
+
get homeBtnElement() {
|
|
882
|
+
var _a;
|
|
883
|
+
if (!this.navigationBarElement)
|
|
884
|
+
return null;
|
|
885
|
+
return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-home')) === null || _a === void 0 ? void 0 : _a[0];
|
|
886
|
+
}
|
|
887
|
+
get backBtnElement() {
|
|
888
|
+
var _a;
|
|
889
|
+
if (!this.navigationBarElement)
|
|
890
|
+
return null;
|
|
891
|
+
return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-back')) === null || _a === void 0 ? void 0 : _a[0];
|
|
892
|
+
}
|
|
893
|
+
get titleElement() {
|
|
894
|
+
var _a;
|
|
895
|
+
if (!this.navigationBarElement)
|
|
896
|
+
return null;
|
|
897
|
+
return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-title')) === null || _a === void 0 ? void 0 : _a[0];
|
|
898
|
+
}
|
|
899
|
+
init() {
|
|
900
|
+
var _a, _b;
|
|
901
|
+
this.setNavigationBarElement();
|
|
902
|
+
if (!this.navigationBarElement)
|
|
903
|
+
return;
|
|
904
|
+
(_a = this.homeBtnElement) === null || _a === void 0 ? void 0 : _a.addEventListener('click', this.toHomeFn.bind(this));
|
|
905
|
+
(_b = this.backBtnElement) === null || _b === void 0 ? void 0 : _b.addEventListener('click', this.backFn.bind(this));
|
|
906
|
+
}
|
|
907
|
+
setNavigationBarElement() {
|
|
908
|
+
var _a;
|
|
909
|
+
this.navigationBarElement = (_a = document.getElementsByTagName('taro-navigation-bar-wrap')) === null || _a === void 0 ? void 0 : _a[0];
|
|
910
|
+
}
|
|
911
|
+
load() {
|
|
912
|
+
this.setCacheValue();
|
|
913
|
+
this.setTitle();
|
|
914
|
+
this.setNavigationBarVisible();
|
|
915
|
+
this.setFnBtnState();
|
|
916
|
+
this.setNavigationBarBackground();
|
|
917
|
+
this.setNavigationBarTextStyle();
|
|
918
|
+
}
|
|
919
|
+
setCacheValue() {
|
|
920
|
+
const currentPage = this.pageContext.currentPage;
|
|
921
|
+
if (typeof this.cache[currentPage] !== 'object') {
|
|
922
|
+
this.cache[currentPage] = {};
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
setFnBtnState() {
|
|
926
|
+
const currentRouter = this.pageContext.currentPage;
|
|
927
|
+
if (this.pageContext.isTabBar(currentRouter) || this.pageContext.homePage === currentRouter) {
|
|
928
|
+
this.fnBtnToggleToNone();
|
|
929
|
+
}
|
|
930
|
+
else if (stacks.length > 1) {
|
|
931
|
+
this.fnBtnToggleToBack();
|
|
932
|
+
}
|
|
933
|
+
else {
|
|
934
|
+
this.fnBtnToggleToHome();
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
setNavigationBarBackground(backgroundColor) {
|
|
938
|
+
var _a, _b, _c;
|
|
939
|
+
if (!this.navigationBarElement)
|
|
940
|
+
return;
|
|
941
|
+
const currentPage = this.pageContext.currentPage;
|
|
942
|
+
let color;
|
|
943
|
+
if (typeof backgroundColor === 'string') {
|
|
944
|
+
color = backgroundColor;
|
|
945
|
+
this.cache[currentPage] &&
|
|
946
|
+
(this.cache[currentPage].backgroundColor = color);
|
|
947
|
+
}
|
|
948
|
+
else {
|
|
949
|
+
const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.backgroundColor;
|
|
950
|
+
if (typeof cacheValue === 'string') {
|
|
951
|
+
color = cacheValue;
|
|
952
|
+
}
|
|
953
|
+
else {
|
|
954
|
+
color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarBackgroundColor) || '#000000';
|
|
955
|
+
this.cache[currentPage] &&
|
|
956
|
+
(this.cache[currentPage].backgroundColor = color);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
this.navigationBarElement.style.background = color;
|
|
960
|
+
}
|
|
961
|
+
setNavigationBarTextStyle(fontColor) {
|
|
962
|
+
var _a, _b, _c;
|
|
963
|
+
if (!this.navigationBarElement)
|
|
964
|
+
return;
|
|
965
|
+
const currentPage = this.pageContext.currentPage;
|
|
966
|
+
let color;
|
|
967
|
+
if (typeof fontColor === 'string') {
|
|
968
|
+
color = fontColor;
|
|
969
|
+
this.cache[currentPage] &&
|
|
970
|
+
(this.cache[currentPage].fontColor = color);
|
|
971
|
+
}
|
|
972
|
+
else {
|
|
973
|
+
const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.fontColor;
|
|
974
|
+
if (typeof cacheValue === 'string') {
|
|
975
|
+
color = cacheValue;
|
|
976
|
+
}
|
|
977
|
+
else {
|
|
978
|
+
color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarTextStyle) || 'white';
|
|
979
|
+
this.cache[currentPage] &&
|
|
980
|
+
(this.cache[currentPage].fontColor = color);
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
this.navigationBarElement.style.color = color;
|
|
984
|
+
}
|
|
985
|
+
setTitle(title) {
|
|
986
|
+
var _a, _b, _c;
|
|
987
|
+
const currentPage = this.pageContext.currentPage;
|
|
988
|
+
let proceedTitle;
|
|
989
|
+
if (typeof title === 'string') {
|
|
990
|
+
proceedTitle = title;
|
|
991
|
+
this.cache[currentPage] &&
|
|
992
|
+
(this.cache[currentPage].title = proceedTitle);
|
|
993
|
+
}
|
|
994
|
+
else {
|
|
995
|
+
const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.title;
|
|
996
|
+
if (typeof cacheValue === 'string') {
|
|
997
|
+
proceedTitle = cacheValue;
|
|
998
|
+
}
|
|
999
|
+
else {
|
|
1000
|
+
proceedTitle = (_c = (_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationBarTitleText) !== null && _c !== void 0 ? _c : document.title;
|
|
1001
|
+
this.cache[currentPage] &&
|
|
1002
|
+
(this.cache[currentPage].title = proceedTitle);
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
|
|
1006
|
+
if (!this.isLoadDdEntry) {
|
|
1007
|
+
this.isLoadDdEntry = true;
|
|
1008
|
+
require('dingtalk-jsapi/platform');
|
|
1009
|
+
}
|
|
1010
|
+
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
1011
|
+
setDingTitle({ proceedTitle });
|
|
1012
|
+
}
|
|
1013
|
+
document.title = proceedTitle;
|
|
1014
|
+
if (!this.titleElement)
|
|
1015
|
+
return;
|
|
1016
|
+
this.titleElement.innerHTML = proceedTitle;
|
|
1017
|
+
}
|
|
1018
|
+
fnBtnToggleToHome() {
|
|
1019
|
+
if (!this.navigationBarElement)
|
|
1020
|
+
return;
|
|
1021
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-home');
|
|
1022
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-back');
|
|
1023
|
+
}
|
|
1024
|
+
fnBtnToggleToBack() {
|
|
1025
|
+
if (!this.navigationBarElement)
|
|
1026
|
+
return;
|
|
1027
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-home');
|
|
1028
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-back');
|
|
1029
|
+
}
|
|
1030
|
+
fnBtnToggleToNone() {
|
|
1031
|
+
if (!this.navigationBarElement)
|
|
1032
|
+
return;
|
|
1033
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-home');
|
|
1034
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-back');
|
|
1035
|
+
}
|
|
1036
|
+
setNavigationBarVisible(show) {
|
|
1037
|
+
var _a, _b;
|
|
1038
|
+
let shouldShow;
|
|
1039
|
+
if (typeof show === 'boolean') {
|
|
1040
|
+
shouldShow = show;
|
|
1041
|
+
}
|
|
1042
|
+
else {
|
|
1043
|
+
shouldShow = (_a = this.pageContext.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
|
|
1044
|
+
if (typeof ((_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
|
|
1045
|
+
shouldShow = this.pageContext.pageConfig.navigationStyle;
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
if (shouldShow === 'default') {
|
|
1049
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-show');
|
|
1050
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-hide');
|
|
1051
|
+
}
|
|
1052
|
+
else {
|
|
1053
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-hide');
|
|
1054
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-show');
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
|
|
736
1059
|
/* eslint-disable dot-notation */
|
|
737
1060
|
class PageHandler {
|
|
738
1061
|
constructor(config, history) {
|
|
@@ -741,6 +1064,7 @@ class PageHandler {
|
|
|
741
1064
|
this.config = config;
|
|
742
1065
|
this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
|
|
743
1066
|
this.mount();
|
|
1067
|
+
this.navigationBarHandler = new NavigationBarHandler(this);
|
|
744
1068
|
}
|
|
745
1069
|
get currentPage() {
|
|
746
1070
|
const routePath = getCurrentPage(this.routerMode, this.basename);
|
|
@@ -884,6 +1208,7 @@ class PageHandler {
|
|
|
884
1208
|
this.isDefaultNavigationStyle() && pageEl.classList.add('taro_navigation_page');
|
|
885
1209
|
this.addAnimation(pageEl, pageNo === 0);
|
|
886
1210
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
1211
|
+
this.navigationBarHandler.load();
|
|
887
1212
|
this.bindPageEvents(page, pageConfig);
|
|
888
1213
|
this.triggerRouterChange();
|
|
889
1214
|
}
|
|
@@ -896,6 +1221,7 @@ class PageHandler {
|
|
|
896
1221
|
this.isDefaultNavigationStyle() && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page'));
|
|
897
1222
|
this.addAnimation(pageEl, pageNo === 0);
|
|
898
1223
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
1224
|
+
this.navigationBarHandler.load();
|
|
899
1225
|
this.onReady(page, true);
|
|
900
1226
|
this.bindPageEvents(page, pageConfig);
|
|
901
1227
|
this.triggerRouterChange();
|
|
@@ -950,6 +1276,7 @@ class PageHandler {
|
|
|
950
1276
|
pageEl.classList.remove('taro_page_shade');
|
|
951
1277
|
this.addAnimation(pageEl, pageNo === 0);
|
|
952
1278
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
1279
|
+
this.navigationBarHandler.load();
|
|
953
1280
|
this.bindPageEvents(page, pageConfig);
|
|
954
1281
|
this.triggerRouterChange();
|
|
955
1282
|
}
|
|
@@ -959,6 +1286,7 @@ class PageHandler {
|
|
|
959
1286
|
pageEl = this.getPageContainer(page);
|
|
960
1287
|
this.addAnimation(pageEl, pageNo === 0);
|
|
961
1288
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
1289
|
+
this.navigationBarHandler.load();
|
|
962
1290
|
this.onReady(page, false);
|
|
963
1291
|
this.bindPageEvents(page, pageConfig);
|
|
964
1292
|
this.triggerRouterChange();
|
|
@@ -1075,7 +1403,7 @@ function createRouter(history, app, config, framework) {
|
|
|
1075
1403
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
1076
1404
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
1077
1405
|
const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
|
|
1078
|
-
var _c, _d, _e, _f, _g, _h, _j, _k
|
|
1406
|
+
var _c, _d, _e, _f, _g, _h, _j, _k;
|
|
1079
1407
|
handler.pathname = decodeURI(location.pathname);
|
|
1080
1408
|
if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
|
|
1081
1409
|
window.scrollTo(0, 0);
|
|
@@ -1115,7 +1443,6 @@ function createRouter(history, app, config, framework) {
|
|
|
1115
1443
|
let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
|
|
1116
1444
|
let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
|
|
1117
1445
|
if (pageConfig) {
|
|
1118
|
-
setTitle((_j = pageConfig.navigationBarTitleText) !== null && _j !== void 0 ? _j : document.title);
|
|
1119
1446
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
1120
1447
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
1121
1448
|
}
|
|
@@ -1132,7 +1459,7 @@ function createRouter(history, app, config, framework) {
|
|
|
1132
1459
|
eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
|
|
1133
1460
|
const currentPage = Current.page;
|
|
1134
1461
|
const pathname = handler.pathname;
|
|
1135
|
-
const methodName = (
|
|
1462
|
+
const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
|
|
1136
1463
|
const cacheTabs = stacks.getTabs();
|
|
1137
1464
|
let shouldLoad = false;
|
|
1138
1465
|
stacks.method = '';
|
|
@@ -1198,7 +1525,7 @@ function createRouter(history, app, config, framework) {
|
|
|
1198
1525
|
shouldLoad = true;
|
|
1199
1526
|
}
|
|
1200
1527
|
if (shouldLoad || stacks.length < 1) {
|
|
1201
|
-
const el = (
|
|
1528
|
+
const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
|
|
1202
1529
|
const loadConfig = Object.assign({}, pageConfig);
|
|
1203
1530
|
const stacksIndex = stacks.length;
|
|
1204
1531
|
delete loadConfig['path'];
|
|
@@ -1223,6 +1550,15 @@ function createRouter(history, app, config, framework) {
|
|
|
1223
1550
|
}
|
|
1224
1551
|
render({ location: history.location, action: Action.Push });
|
|
1225
1552
|
(_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
|
|
1553
|
+
window.addEventListener('visibilitychange', () => {
|
|
1554
|
+
var _a, _b;
|
|
1555
|
+
if (document.visibilityState === 'visible') {
|
|
1556
|
+
(_a = app.onShow) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
1557
|
+
}
|
|
1558
|
+
else {
|
|
1559
|
+
(_b = app.onHide) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
|
|
1560
|
+
}
|
|
1561
|
+
});
|
|
1226
1562
|
return history.listen(render);
|
|
1227
1563
|
}
|
|
1228
1564
|
|
|
@@ -1238,6 +1574,7 @@ function handleAppMount(config, _, appId = config.appId || 'app') {
|
|
|
1238
1574
|
app.classList.add('taro_router');
|
|
1239
1575
|
if (!isPosition)
|
|
1240
1576
|
appWrapper.appendChild(app);
|
|
1577
|
+
initNavigationBar(appWrapper);
|
|
1241
1578
|
}
|
|
1242
1579
|
function handleAppMountWithTabbar(config, history, appId = config.appId || 'app') {
|
|
1243
1580
|
let app = document.getElementById(appId);
|
|
@@ -1263,6 +1600,7 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
|
|
|
1263
1600
|
appWrapper.replaceChild(container, app);
|
|
1264
1601
|
}
|
|
1265
1602
|
initTabbar(config, history);
|
|
1603
|
+
initNavigationBar(container);
|
|
1266
1604
|
}
|
|
1267
1605
|
|
|
1268
|
-
export { createMpaHistory, createMultiRouter, createRouter, getCurrentPages, handleAppMount, handleAppMountWithTabbar, history, isDingTalk, isWeixin, navigateBack, navigateTo, prependBasename, reLaunch, redirectTo, routesAlias, setHistory, setHistoryMode, setTitle, switchTab };
|
|
1606
|
+
export { createMpaHistory, createMultiRouter, createRouter, getCurrentPages, handleAppMount, handleAppMountWithTabbar, history, isDingTalk, isWeixin, navigateBack, navigateTo, prependBasename, reLaunch, redirectTo, routesAlias, setHistory, setHistoryMode, setMpaTitle, setNavigationBarStyle, setTitle, switchTab };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { initNavigationBar } from './navigationBar.js';
|
|
1
2
|
import { initTabbar } from './tabbar.js';
|
|
2
3
|
export { getCurrentPages, navigateBack, navigateTo, reLaunch, redirectTo, switchTab } from './api.js';
|
|
3
4
|
export { createMpaHistory, history, prependBasename, setHistory, setHistoryMode } from './history.js';
|
|
@@ -5,7 +6,7 @@ export { createMultiRouter } from './router/mpa.js';
|
|
|
5
6
|
export { createRouter } from './router/spa.js';
|
|
6
7
|
export { routesAlias } from './utils/index.js';
|
|
7
8
|
export { createBrowserHistory, createHashHistory } from 'history';
|
|
8
|
-
export { isDingTalk, isWeixin, setTitle } from './utils/navigate.js';
|
|
9
|
+
export { isDingTalk, isWeixin, setMpaTitle, setNavigationBarStyle, setTitle } from './utils/navigate.js';
|
|
9
10
|
|
|
10
11
|
function handleAppMount(config, _, appId = config.appId || 'app') {
|
|
11
12
|
let app = document.getElementById(appId);
|
|
@@ -19,6 +20,7 @@ function handleAppMount(config, _, appId = config.appId || 'app') {
|
|
|
19
20
|
app.classList.add('taro_router');
|
|
20
21
|
if (!isPosition)
|
|
21
22
|
appWrapper.appendChild(app);
|
|
23
|
+
initNavigationBar(appWrapper);
|
|
22
24
|
}
|
|
23
25
|
function handleAppMountWithTabbar(config, history, appId = config.appId || 'app') {
|
|
24
26
|
let app = document.getElementById(appId);
|
|
@@ -44,6 +46,7 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
|
|
|
44
46
|
appWrapper.replaceChild(container, app);
|
|
45
47
|
}
|
|
46
48
|
initTabbar(config, history);
|
|
49
|
+
initNavigationBar(container);
|
|
47
50
|
}
|
|
48
51
|
|
|
49
52
|
export { handleAppMount, handleAppMountWithTabbar };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const home_svg_str = `
|
|
2
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
3
|
+
<path d="M23.8899 12.2737C23.8232 12.3584 23.7237 12.3997 23.6198 12.3974H20.7994V23.5996C20.7994 23.8194 20.6213 24 20.4001 24H14.7994C14.5791 24 14.4002 23.8194 14.4002 23.5996V15.6H9.59963V23.5996C9.59963 23.8194 9.42075 24 9.20033 24H3.59968C3.48981 24 3.38964 23.954 3.31764 23.8811C3.24495 23.8091 3.2004 23.7087 3.2004 23.5996V12.3975H0.398546V12.3967C0.296893 12.396 0.194446 12.3544 0.11579 12.2738C-0.0371146 12.114 -0.0400714 11.864 0.11579 11.7076L11.7201 0.117284C11.8767 -0.0390948 12.1298 -0.0390948 12.2863 0.117284L23.8899 11.7076C24.0465 11.864 24.0265 12.0995 23.8899 12.2737ZM12.0029 0.964625L1.37086 11.5854L3.59968 11.5839V11.5999C3.65537 11.5999 3.70804 11.611 3.75557 11.6307C3.89952 11.692 4.00046 11.8339 4.00046 11.9996V23.1991H8.79955V15.2003C8.79955 14.9789 8.97917 14.8002 9.20033 14.8002H14.7995C15.0207 14.8002 15.2003 14.9789 15.2003 15.2003V23.1991H20.0001V11.9996C20.0001 11.8339 20.1003 11.692 20.2443 11.6307C20.2918 11.611 20.3453 11.5999 20.4001 11.5999V11.5713L22.6193 11.5691L12.0029 0.964625Z" fill="currentColor"/>
|
|
4
|
+
</svg>
|
|
5
|
+
`;
|
|
6
|
+
const back_svg_str = `
|
|
7
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
8
|
+
<path d="M17.8206 22.9016L7.45515 11.8756L17.8206 1.09845C18.0598 0.849741 18.0598 0.435233 17.8206 0.186528C17.5814 -0.0621762 17.1827 -0.0621762 16.9435 0.186528L6.1794 11.4611C5.9402 11.7098 5.9402 12.1244 6.1794 12.3731L16.9435 23.8135C17.1827 24.0622 17.5814 24.0622 17.8206 23.8135C18.0598 23.5648 18.0598 23.1503 17.8206 22.9016Z" fill="currentColor"/>
|
|
9
|
+
</svg>
|
|
10
|
+
|
|
11
|
+
`;
|
|
12
|
+
function initNavigationBar(container) {
|
|
13
|
+
const navigationBar = document.createElement('taro-navigation-bar-wrap');
|
|
14
|
+
navigationBar.classList.add('taro-navigation-bar-no-icon');
|
|
15
|
+
const navigationBarBackBtn = document.createElement('taro-navigation-bar-back');
|
|
16
|
+
const navigationBarHomeBtn = document.createElement('taro-navigation-bar-home');
|
|
17
|
+
navigationBarBackBtn.innerHTML = back_svg_str;
|
|
18
|
+
navigationBarHomeBtn.innerHTML = home_svg_str;
|
|
19
|
+
const navigationBarTitle = document.createElement('taro-navigation-bar-title');
|
|
20
|
+
navigationBar.appendChild(navigationBarHomeBtn);
|
|
21
|
+
navigationBar.appendChild(navigationBarBackBtn);
|
|
22
|
+
navigationBar.appendChild(navigationBarTitle);
|
|
23
|
+
navigationBar.id = 'taro-navigation-bar';
|
|
24
|
+
container.prepend(navigationBar);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export { initNavigationBar };
|
package/dist/router/mpa.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { __awaiter } from 'tslib';
|
|
2
2
|
import { incrementId, eventCenter, createPageConfig, hooks, stringify } from '@tarojs/runtime';
|
|
3
|
-
import
|
|
3
|
+
import '../utils/index.js';
|
|
4
4
|
import { RouterConfig } from './index.js';
|
|
5
5
|
import MultiPageHandler from './multi-page.js';
|
|
6
|
+
import { setMpaTitle } from '../utils/navigate.js';
|
|
6
7
|
|
|
7
8
|
const createStampId = incrementId();
|
|
8
9
|
const launchStampId = createStampId();
|
|
@@ -20,6 +21,7 @@ function createMultiRouter(history, app, config, framework) {
|
|
|
20
21
|
if (typeof app.onUnhandledRejection === 'function') {
|
|
21
22
|
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
22
23
|
}
|
|
24
|
+
eventCenter.on('__taroH5SetNavigationTitle', setMpaTitle);
|
|
23
25
|
RouterConfig.config = config;
|
|
24
26
|
const handler = new MultiPageHandler(config, history);
|
|
25
27
|
const launchParam = {
|
|
@@ -53,7 +55,7 @@ function createMultiRouter(history, app, config, framework) {
|
|
|
53
55
|
return;
|
|
54
56
|
let enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
|
|
55
57
|
if (pageConfig) {
|
|
56
|
-
|
|
58
|
+
setMpaTitle((_d = pageConfig.navigationBarTitleText) !== null && _d !== void 0 ? _d : document.title);
|
|
57
59
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
58
60
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
59
61
|
}
|
|
@@ -65,6 +67,15 @@ function createMultiRouter(history, app, config, framework) {
|
|
|
65
67
|
const page = createPageConfig(enablePullDownRefresh ? hooks.call('createPullDownComponent', el, pathName, framework, handler.PullDownRefresh) : el, pathName + stringify(launchParam), {}, loadConfig);
|
|
66
68
|
handler.load(page, pageConfig);
|
|
67
69
|
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);
|
|
70
|
+
window.addEventListener('visibilitychange', () => {
|
|
71
|
+
var _a, _b;
|
|
72
|
+
if (document.visibilityState === 'visible') {
|
|
73
|
+
(_a = app.onShow) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
(_b = app.onHide) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
68
79
|
});
|
|
69
80
|
}
|
|
70
81
|
|