@tarojs/router 4.0.0-beta.0 → 4.0.0-beta.10
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/LICENSE +14 -0
- package/dist/api.d.ts +7 -6
- package/dist/api.js +36 -20
- package/dist/events/resize.d.ts +2 -1
- package/dist/events/resize.js +15 -7
- package/dist/events/scroll.d.ts +2 -1
- package/dist/events/scroll.js +4 -1
- package/dist/history.d.ts +24 -5
- package/dist/history.js +18 -7
- package/dist/index.cjs.d.ts +49 -6
- package/dist/index.cjs.js +551 -229
- package/dist/index.d.ts +10 -4
- package/dist/index.esm.d.ts +49 -6
- package/dist/index.esm.js +510 -199
- package/dist/index.js +52 -4
- package/dist/navigationBar.d.ts +2 -0
- package/dist/navigationBar.js +27 -0
- package/dist/router/index.d.ts +4 -3
- package/dist/router/index.js +5 -2
- package/dist/router/mpa.d.ts +5 -3
- package/dist/router/mpa.js +22 -17
- package/dist/router/multi-page.d.ts +10 -6
- package/dist/router/multi-page.js +27 -43
- package/dist/router/navigation-bar.d.ts +32 -0
- package/dist/router/navigation-bar.js +209 -0
- package/dist/router/page.d.ts +13 -7
- package/dist/router/page.js +36 -45
- package/dist/router/spa.d.ts +5 -3
- package/dist/router/spa.js +40 -26
- package/dist/router/stack.d.ts +1 -1
- package/dist/router/stack.js +2 -1
- package/dist/style.d.ts +8 -2
- package/dist/style.js +65 -5
- package/dist/tabbar.d.ts +3 -1
- package/dist/tabbar.js +4 -3
- package/dist/utils/index.d.ts +3 -9
- package/dist/utils/index.js +5 -20
- package/dist/utils/navigate.d.ts +9 -5
- package/dist/utils/navigate.js +22 -38
- package/package.json +21 -11
- package/types/component.d.ts +5 -0
- package/types/taro.d.ts +8 -0
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js.map +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -1,34 +1,64 @@
|
|
|
1
|
-
import { createBrowserHistory, createHashHistory, Action, parsePath } from 'history';
|
|
2
|
-
import { Current, eventCenter, incrementId, createPageConfig, hooks, stringify, requestAnimationFrame as requestAnimationFrame$1 } from '@tarojs/runtime';
|
|
3
|
-
import MobileDetect from 'mobile-detect';
|
|
4
|
-
import queryString from 'query-string';
|
|
5
1
|
import { defineCustomElementTaroTabbar } from '@tarojs/components/dist/components';
|
|
6
2
|
import { initTabBarApis } from '@tarojs/taro';
|
|
3
|
+
import { __awaiter } from 'tslib';
|
|
4
|
+
import { eventCenter, addLeadingSlash, Current, stripBasename, incrementId, createPageConfig, hooks, stringify, getHomePage, getCurrentPage, stripTrailing, requestAnimationFrame as requestAnimationFrame$1 } from '@tarojs/runtime';
|
|
5
|
+
import { createBrowserHistory, createHashHistory, Action, parsePath } from 'history';
|
|
6
|
+
export { createBrowserHistory, createHashHistory } from 'history';
|
|
7
|
+
import queryString from 'query-string';
|
|
7
8
|
import UniversalRouter from 'universal-router';
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
+
|
|
36
|
+
function initTabbar(config, history) {
|
|
37
|
+
if (config.tabBar == null || config.tabBar.custom) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// TODO: custom-tab-bar
|
|
41
|
+
defineCustomElementTaroTabbar();
|
|
42
|
+
const tabbar = document.createElement('taro-tabbar');
|
|
43
|
+
const homePage = config.entryPagePath || (config.pages ? config.pages[0] : '');
|
|
44
|
+
tabbar.conf = config.tabBar;
|
|
45
|
+
tabbar.conf.homePage = history.location.pathname === '/' ? homePage : history.location.pathname;
|
|
46
|
+
const routerConfig = config.router;
|
|
47
|
+
tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
|
|
48
|
+
if (routerConfig.customRoutes) {
|
|
49
|
+
tabbar.conf.custom = true;
|
|
50
|
+
tabbar.conf.customRoutes = routerConfig.customRoutes;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
tabbar.conf.custom = false;
|
|
54
|
+
tabbar.conf.customRoutes = {};
|
|
55
|
+
}
|
|
56
|
+
if (typeof routerConfig.basename !== 'undefined') {
|
|
57
|
+
tabbar.conf.basename = routerConfig.basename;
|
|
58
|
+
}
|
|
59
|
+
const container = document.getElementById('container');
|
|
60
|
+
container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
|
|
61
|
+
initTabBarApis(config);
|
|
32
62
|
}
|
|
33
63
|
|
|
34
64
|
class RouterConfig {
|
|
@@ -83,7 +113,7 @@ class MpaHistory {
|
|
|
83
113
|
url += `?${to.search}`;
|
|
84
114
|
}
|
|
85
115
|
if (to.hash) {
|
|
86
|
-
url += `#${to.hash}`;
|
|
116
|
+
url += to.hash.startsWith('#') ? to.hash : `#${to.hash}`;
|
|
87
117
|
}
|
|
88
118
|
return url;
|
|
89
119
|
}
|
|
@@ -132,6 +162,13 @@ class MpaHistory {
|
|
|
132
162
|
};
|
|
133
163
|
}
|
|
134
164
|
}
|
|
165
|
+
function setHistory(h, base = '/') {
|
|
166
|
+
history = h;
|
|
167
|
+
basename = base;
|
|
168
|
+
}
|
|
169
|
+
function createMpaHistory(_) {
|
|
170
|
+
return new MpaHistory();
|
|
171
|
+
}
|
|
135
172
|
function setHistoryMode(mode, base = '/') {
|
|
136
173
|
const options = {
|
|
137
174
|
window
|
|
@@ -141,7 +178,7 @@ function setHistoryMode(mode, base = '/') {
|
|
|
141
178
|
history = createBrowserHistory(options);
|
|
142
179
|
}
|
|
143
180
|
else if (mode === 'multi') {
|
|
144
|
-
history =
|
|
181
|
+
history = createMpaHistory();
|
|
145
182
|
}
|
|
146
183
|
else {
|
|
147
184
|
// default is hash
|
|
@@ -233,24 +270,31 @@ class Stacks {
|
|
|
233
270
|
}
|
|
234
271
|
const stacks = new Stacks();
|
|
235
272
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
273
|
+
const isWeixin = () => !!navigator.userAgent.match(/\bMicroMessenger\b/ig);
|
|
274
|
+
const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
|
|
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');
|
|
286
|
+
}
|
|
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);
|
|
296
|
+
}
|
|
297
|
+
|
|
254
298
|
class RoutesAlias {
|
|
255
299
|
constructor() {
|
|
256
300
|
this.conf = [];
|
|
@@ -332,6 +376,21 @@ function navigate(option, method) {
|
|
|
332
376
|
if ('url' in option) {
|
|
333
377
|
const pathPieces = processNavigateUrl(option);
|
|
334
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
|
+
}
|
|
335
394
|
if (method === 'navigateTo') {
|
|
336
395
|
history.push(pathPieces, state);
|
|
337
396
|
}
|
|
@@ -357,7 +416,12 @@ function navigate(option, method) {
|
|
|
357
416
|
const res = { errMsg: `${method}:fail ${error.message || error}` };
|
|
358
417
|
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
359
418
|
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
360
|
-
|
|
419
|
+
if (fail || complete) {
|
|
420
|
+
return resolve(res);
|
|
421
|
+
}
|
|
422
|
+
else {
|
|
423
|
+
return reject(res);
|
|
424
|
+
}
|
|
361
425
|
}
|
|
362
426
|
});
|
|
363
427
|
});
|
|
@@ -388,47 +452,22 @@ function getCurrentPages() {
|
|
|
388
452
|
return pages.map(e => { var _a; return (Object.assign(Object.assign({}, e), { route: ((_a = e.path) === null || _a === void 0 ? void 0 : _a.replace(/\?.*/g, '')) || '' })); });
|
|
389
453
|
}
|
|
390
454
|
|
|
391
|
-
let md;
|
|
392
|
-
let preTitle = document.title;
|
|
393
|
-
let isLoadDdEntry = false;
|
|
394
|
-
function getMobileDetect() {
|
|
395
|
-
if (!md) {
|
|
396
|
-
md = new MobileDetect(navigator.userAgent);
|
|
397
|
-
}
|
|
398
|
-
return md;
|
|
399
|
-
}
|
|
400
|
-
function setTitle(title) {
|
|
401
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
402
|
-
if (preTitle === title)
|
|
403
|
-
return title;
|
|
404
|
-
document.title = title;
|
|
405
|
-
preTitle = title;
|
|
406
|
-
if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
|
|
407
|
-
if (!isLoadDdEntry) {
|
|
408
|
-
isLoadDdEntry = true;
|
|
409
|
-
require('dingtalk-jsapi/platform');
|
|
410
|
-
}
|
|
411
|
-
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
412
|
-
setDingTitle({ title });
|
|
413
|
-
}
|
|
414
|
-
return title;
|
|
415
|
-
});
|
|
416
|
-
}
|
|
417
|
-
function isDingTalk() {
|
|
418
|
-
const md = getMobileDetect();
|
|
419
|
-
return md.match(/DingTalk/ig);
|
|
420
|
-
}
|
|
421
|
-
|
|
422
455
|
let pageResizeFn;
|
|
423
456
|
function bindPageResize(page) {
|
|
424
457
|
pageResizeFn && window.removeEventListener('resize', pageResizeFn);
|
|
425
458
|
pageResizeFn = function () {
|
|
426
|
-
page.onResize
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
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
|
+
}
|
|
432
471
|
};
|
|
433
472
|
window.addEventListener('resize', pageResizeFn, false);
|
|
434
473
|
}
|
|
@@ -472,6 +511,9 @@ function getOffset() {
|
|
|
472
511
|
*/
|
|
473
512
|
function loadAnimateStyle(ms = 300) {
|
|
474
513
|
const css = `
|
|
514
|
+
body {
|
|
515
|
+
overflow: hidden; // 防止 iOS 页面滚动
|
|
516
|
+
}
|
|
475
517
|
.taro_router > .taro_page {
|
|
476
518
|
position: absolute;
|
|
477
519
|
left: 0;
|
|
@@ -498,7 +540,7 @@ function loadAnimateStyle(ms = 300) {
|
|
|
498
540
|
/**
|
|
499
541
|
* 插入路由相关样式
|
|
500
542
|
*/
|
|
501
|
-
function loadRouterStyle(
|
|
543
|
+
function loadRouterStyle(enableTabBar, enableWindowScroll) {
|
|
502
544
|
const css = `
|
|
503
545
|
.taro_router {
|
|
504
546
|
position: relative;
|
|
@@ -509,13 +551,13 @@ function loadRouterStyle(usingWindowScroll) {
|
|
|
509
551
|
.taro_page {
|
|
510
552
|
width: 100%;
|
|
511
553
|
height: 100%;
|
|
512
|
-
|
|
554
|
+
${enableWindowScroll ? '' : `
|
|
513
555
|
overflow-x: hidden;
|
|
514
556
|
overflow-y: scroll;
|
|
515
557
|
max-height: 100vh;
|
|
516
|
-
|
|
558
|
+
`}
|
|
517
559
|
}
|
|
518
|
-
|
|
560
|
+
${enableTabBar ? `
|
|
519
561
|
.taro-tabbar__container > .taro-tabbar__panel {
|
|
520
562
|
overflow: hidden;
|
|
521
563
|
}
|
|
@@ -525,6 +567,7 @@ function loadRouterStyle(usingWindowScroll) {
|
|
|
525
567
|
max-height: calc(100vh - var(--taro-tabbar-height) - env(safe-area-inset-bottom));
|
|
526
568
|
}
|
|
527
569
|
|
|
570
|
+
` : ''}
|
|
528
571
|
.taro_page_shade,
|
|
529
572
|
.taro_router > .taro_page.taro_page_show.taro_page_stationed:not(.taro_page_shade):not(.taro_tabbar_page):not(:last-child) {
|
|
530
573
|
display: none;
|
|
@@ -532,6 +575,60 @@ function loadRouterStyle(usingWindowScroll) {
|
|
|
532
575
|
`;
|
|
533
576
|
addStyle(css);
|
|
534
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
|
+
}
|
|
535
632
|
function addStyle(css) {
|
|
536
633
|
if (!css)
|
|
537
634
|
return;
|
|
@@ -540,38 +637,10 @@ function addStyle(css) {
|
|
|
540
637
|
document.getElementsByTagName('head')[0].appendChild(style);
|
|
541
638
|
}
|
|
542
639
|
|
|
543
|
-
// @ts-nocheck
|
|
544
|
-
function initTabbar(config) {
|
|
545
|
-
if (config.tabBar == null || config.tabBar.custom) {
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
// TODO: custom-tab-bar
|
|
549
|
-
defineCustomElementTaroTabbar();
|
|
550
|
-
const tabbar = document.createElement('taro-tabbar');
|
|
551
|
-
const homePage = config.entryPagePath || (config.pages ? config.pages[0] : '');
|
|
552
|
-
tabbar.conf = config.tabBar;
|
|
553
|
-
tabbar.conf.homePage = history.location.pathname === '/' ? homePage : history.location.pathname;
|
|
554
|
-
const routerConfig = config.router;
|
|
555
|
-
tabbar.conf.mode = routerConfig && routerConfig.mode ? routerConfig.mode : 'hash';
|
|
556
|
-
if (routerConfig.customRoutes) {
|
|
557
|
-
tabbar.conf.custom = true;
|
|
558
|
-
tabbar.conf.customRoutes = routerConfig.customRoutes;
|
|
559
|
-
}
|
|
560
|
-
else {
|
|
561
|
-
tabbar.conf.custom = false;
|
|
562
|
-
tabbar.conf.customRoutes = {};
|
|
563
|
-
}
|
|
564
|
-
if (typeof routerConfig.basename !== 'undefined') {
|
|
565
|
-
tabbar.conf.basename = routerConfig.basename;
|
|
566
|
-
}
|
|
567
|
-
const container = document.getElementById('container');
|
|
568
|
-
container === null || container === void 0 ? void 0 : container.appendChild(tabbar);
|
|
569
|
-
initTabBarApis(config);
|
|
570
|
-
}
|
|
571
|
-
|
|
572
640
|
/* eslint-disable dot-notation */
|
|
573
641
|
class MultiPageHandler {
|
|
574
|
-
constructor(config) {
|
|
642
|
+
constructor(config, history) {
|
|
643
|
+
this.history = history;
|
|
575
644
|
this.config = config;
|
|
576
645
|
this.mount();
|
|
577
646
|
}
|
|
@@ -618,39 +687,18 @@ class MultiPageHandler {
|
|
|
618
687
|
: {};
|
|
619
688
|
return Object.assign(Object.assign({}, query), options);
|
|
620
689
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
let isPosition = true;
|
|
627
|
-
if (!app) {
|
|
628
|
-
app = document.createElement('div');
|
|
629
|
-
app.id = appId;
|
|
630
|
-
isPosition = false;
|
|
631
|
-
}
|
|
632
|
-
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
633
|
-
app.classList.add('taro_router');
|
|
634
|
-
if (this.tabBarList.length > 1) {
|
|
635
|
-
const container = document.createElement('div');
|
|
636
|
-
container.classList.add('taro-tabbar__container');
|
|
637
|
-
container.id = 'container';
|
|
638
|
-
const panel = document.createElement('div');
|
|
639
|
-
panel.classList.add('taro-tabbar__panel');
|
|
640
|
-
panel.appendChild(app.cloneNode(true));
|
|
641
|
-
container.appendChild(panel);
|
|
642
|
-
if (!isPosition) {
|
|
643
|
-
appWrapper.appendChild(container);
|
|
644
|
-
}
|
|
645
|
-
else {
|
|
646
|
-
appWrapper.replaceChild(container, app);
|
|
647
|
-
}
|
|
648
|
-
initTabbar(this.config);
|
|
649
|
-
}
|
|
650
|
-
else {
|
|
651
|
-
if (!isPosition)
|
|
652
|
-
appWrapper.appendChild(app);
|
|
690
|
+
isDefaultNavigationStyle() {
|
|
691
|
+
var _a, _b;
|
|
692
|
+
let style = (_a = this.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
|
|
693
|
+
if (typeof ((_b = this.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
|
|
694
|
+
style = this.pageConfig.navigationStyle;
|
|
653
695
|
}
|
|
696
|
+
return style !== 'custom';
|
|
697
|
+
}
|
|
698
|
+
mount() {
|
|
699
|
+
setHistory(this.history, this.basename);
|
|
700
|
+
// Note: 注入页面样式
|
|
701
|
+
loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
|
|
654
702
|
}
|
|
655
703
|
onReady(page, onLoad = true) {
|
|
656
704
|
var _a;
|
|
@@ -680,10 +728,13 @@ class MultiPageHandler {
|
|
|
680
728
|
return;
|
|
681
729
|
(_a = page.onLoad) === null || _a === void 0 ? void 0 : _a.call(page, this.getQuery('', page.options), () => {
|
|
682
730
|
var _a;
|
|
731
|
+
const pageEl = this.getPageContainer(page);
|
|
683
732
|
if (this.isTabBar) {
|
|
684
|
-
const pageEl = this.getPageContainer(page);
|
|
685
733
|
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page');
|
|
686
734
|
}
|
|
735
|
+
if (this.isDefaultNavigationStyle()) {
|
|
736
|
+
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page');
|
|
737
|
+
}
|
|
687
738
|
this.onReady(page, true);
|
|
688
739
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
689
740
|
this.bindPageEvents(page, pageConfig);
|
|
@@ -740,14 +791,15 @@ const launchStampId$1 = createStampId$1();
|
|
|
740
791
|
* - TabBar 会多次加载
|
|
741
792
|
* - 不支持路由动画
|
|
742
793
|
*/
|
|
743
|
-
function createMultiRouter(app, config, framework) {
|
|
794
|
+
function createMultiRouter(history, app, config, framework) {
|
|
744
795
|
var _a, _b, _c, _d, _e, _f;
|
|
745
796
|
return __awaiter(this, void 0, void 0, function* () {
|
|
746
797
|
if (typeof app.onUnhandledRejection === 'function') {
|
|
747
798
|
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
748
799
|
}
|
|
800
|
+
eventCenter.on('__taroH5SetNavigationTitle', setMpaTitle);
|
|
749
801
|
RouterConfig.config = config;
|
|
750
|
-
const handler = new MultiPageHandler(config);
|
|
802
|
+
const handler = new MultiPageHandler(config, history);
|
|
751
803
|
const launchParam = {
|
|
752
804
|
path: config.pageName,
|
|
753
805
|
query: handler.getQuery(launchStampId$1),
|
|
@@ -779,7 +831,7 @@ function createMultiRouter(app, config, framework) {
|
|
|
779
831
|
return;
|
|
780
832
|
let enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
|
|
781
833
|
if (pageConfig) {
|
|
782
|
-
|
|
834
|
+
setMpaTitle((_d = pageConfig.navigationBarTitleText) !== null && _d !== void 0 ? _d : document.title);
|
|
783
835
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
784
836
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
785
837
|
}
|
|
@@ -791,16 +843,228 @@ function createMultiRouter(app, config, framework) {
|
|
|
791
843
|
const page = createPageConfig(enablePullDownRefresh ? hooks.call('createPullDownComponent', el, pathName, framework, handler.PullDownRefresh) : el, pathName + stringify(launchParam), {}, loadConfig);
|
|
792
844
|
handler.load(page, pageConfig);
|
|
793
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
|
+
});
|
|
794
855
|
});
|
|
795
856
|
}
|
|
796
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
|
+
|
|
797
1059
|
/* eslint-disable dot-notation */
|
|
798
1060
|
class PageHandler {
|
|
799
|
-
constructor(config) {
|
|
1061
|
+
constructor(config, history) {
|
|
1062
|
+
this.history = history;
|
|
800
1063
|
this.defaultAnimation = { duration: 300, delay: 50 };
|
|
801
1064
|
this.config = config;
|
|
802
1065
|
this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
|
|
803
1066
|
this.mount();
|
|
1067
|
+
this.navigationBarHandler = new NavigationBarHandler(this);
|
|
804
1068
|
}
|
|
805
1069
|
get currentPage() {
|
|
806
1070
|
const routePath = getCurrentPage(this.routerMode, this.basename);
|
|
@@ -856,6 +1120,14 @@ class PageHandler {
|
|
|
856
1120
|
})) === null || _a === void 0 ? void 0 : _a[0]) || routePath;
|
|
857
1121
|
return !!pagePath && this.tabBarList.some(t => stripTrailing(t.pagePath) === pagePath);
|
|
858
1122
|
}
|
|
1123
|
+
isDefaultNavigationStyle() {
|
|
1124
|
+
var _a, _b;
|
|
1125
|
+
let style = (_a = this.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
|
|
1126
|
+
if (typeof ((_b = this.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
|
|
1127
|
+
style = this.pageConfig.navigationStyle;
|
|
1128
|
+
}
|
|
1129
|
+
return style !== 'custom';
|
|
1130
|
+
}
|
|
859
1131
|
isSamePage(page) {
|
|
860
1132
|
const routePath = stripBasename(this.pathname, this.basename);
|
|
861
1133
|
const pagePath = stripBasename(page === null || page === void 0 ? void 0 : page.path, this.basename);
|
|
@@ -894,40 +1166,11 @@ class PageHandler {
|
|
|
894
1166
|
return Object.assign(Object.assign({}, query), options);
|
|
895
1167
|
}
|
|
896
1168
|
mount() {
|
|
897
|
-
|
|
1169
|
+
setHistory(this.history, this.basename);
|
|
898
1170
|
this.pathname = history.location.pathname;
|
|
1171
|
+
// Note: 注入页面样式
|
|
899
1172
|
this.animation && loadAnimateStyle(this.animationDuration);
|
|
900
|
-
loadRouterStyle(this.usingWindowScroll);
|
|
901
|
-
const appId = this.appId;
|
|
902
|
-
let app = document.getElementById(appId);
|
|
903
|
-
let isPosition = true;
|
|
904
|
-
if (!app) {
|
|
905
|
-
app = document.createElement('div');
|
|
906
|
-
app.id = appId;
|
|
907
|
-
isPosition = false;
|
|
908
|
-
}
|
|
909
|
-
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
910
|
-
app.classList.add('taro_router');
|
|
911
|
-
if (this.tabBarList.length > 1) {
|
|
912
|
-
const container = document.createElement('div');
|
|
913
|
-
container.classList.add('taro-tabbar__container');
|
|
914
|
-
container.id = 'container';
|
|
915
|
-
const panel = document.createElement('div');
|
|
916
|
-
panel.classList.add('taro-tabbar__panel');
|
|
917
|
-
panel.appendChild(app.cloneNode(true));
|
|
918
|
-
container.appendChild(panel);
|
|
919
|
-
if (!isPosition) {
|
|
920
|
-
appWrapper.appendChild(container);
|
|
921
|
-
}
|
|
922
|
-
else {
|
|
923
|
-
appWrapper.replaceChild(container, app);
|
|
924
|
-
}
|
|
925
|
-
initTabbar(this.config);
|
|
926
|
-
}
|
|
927
|
-
else {
|
|
928
|
-
if (!isPosition)
|
|
929
|
-
appWrapper.appendChild(app);
|
|
930
|
-
}
|
|
1173
|
+
loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
|
|
931
1174
|
}
|
|
932
1175
|
onReady(page, onLoad = true) {
|
|
933
1176
|
var _a;
|
|
@@ -962,19 +1205,24 @@ class PageHandler {
|
|
|
962
1205
|
if (pageEl) {
|
|
963
1206
|
pageEl.classList.remove('taro_page_shade');
|
|
964
1207
|
this.isTabBar(this.pathname) && pageEl.classList.add('taro_tabbar_page');
|
|
1208
|
+
this.isDefaultNavigationStyle() && pageEl.classList.add('taro_navigation_page');
|
|
965
1209
|
this.addAnimation(pageEl, pageNo === 0);
|
|
966
1210
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
1211
|
+
this.navigationBarHandler.load();
|
|
967
1212
|
this.bindPageEvents(page, pageConfig);
|
|
968
1213
|
this.triggerRouterChange();
|
|
969
1214
|
}
|
|
970
1215
|
else {
|
|
1216
|
+
// FIXME 在 iOS 端快速切换页面时,可能不会执行回调注入对应类名导致 TabBar 白屏
|
|
971
1217
|
(_b = page.onLoad) === null || _b === void 0 ? void 0 : _b.call(page, param, () => {
|
|
972
1218
|
var _a;
|
|
973
1219
|
pageEl = this.getPageContainer(page);
|
|
974
1220
|
this.isTabBar(this.pathname) && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page'));
|
|
1221
|
+
this.isDefaultNavigationStyle() && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page'));
|
|
975
1222
|
this.addAnimation(pageEl, pageNo === 0);
|
|
976
|
-
this.onReady(page, true);
|
|
977
1223
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
1224
|
+
this.navigationBarHandler.load();
|
|
1225
|
+
this.onReady(page, true);
|
|
978
1226
|
this.bindPageEvents(page, pageConfig);
|
|
979
1227
|
this.triggerRouterChange();
|
|
980
1228
|
});
|
|
@@ -1028,6 +1276,7 @@ class PageHandler {
|
|
|
1028
1276
|
pageEl.classList.remove('taro_page_shade');
|
|
1029
1277
|
this.addAnimation(pageEl, pageNo === 0);
|
|
1030
1278
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
1279
|
+
this.navigationBarHandler.load();
|
|
1031
1280
|
this.bindPageEvents(page, pageConfig);
|
|
1032
1281
|
this.triggerRouterChange();
|
|
1033
1282
|
}
|
|
@@ -1036,8 +1285,9 @@ class PageHandler {
|
|
|
1036
1285
|
var _a;
|
|
1037
1286
|
pageEl = this.getPageContainer(page);
|
|
1038
1287
|
this.addAnimation(pageEl, pageNo === 0);
|
|
1039
|
-
this.onReady(page, false);
|
|
1040
1288
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
1289
|
+
this.navigationBarHandler.load();
|
|
1290
|
+
this.onReady(page, false);
|
|
1041
1291
|
this.bindPageEvents(page, pageConfig);
|
|
1042
1292
|
this.triggerRouterChange();
|
|
1043
1293
|
});
|
|
@@ -1124,13 +1374,13 @@ class PageHandler {
|
|
|
1124
1374
|
|
|
1125
1375
|
const createStampId = incrementId();
|
|
1126
1376
|
let launchStampId = createStampId();
|
|
1127
|
-
function createRouter(app, config, framework) {
|
|
1377
|
+
function createRouter(history, app, config, framework) {
|
|
1128
1378
|
var _a, _b;
|
|
1129
1379
|
if (typeof app.onUnhandledRejection === 'function') {
|
|
1130
1380
|
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
1131
1381
|
}
|
|
1132
1382
|
RouterConfig.config = config;
|
|
1133
|
-
const handler = new PageHandler(config);
|
|
1383
|
+
const handler = new PageHandler(config, history);
|
|
1134
1384
|
routesAlias.set(handler.router.customRoutes);
|
|
1135
1385
|
const basename = handler.router.basename;
|
|
1136
1386
|
const routes = handler.routes.map(route => {
|
|
@@ -1153,7 +1403,7 @@ function createRouter(app, config, framework) {
|
|
|
1153
1403
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
1154
1404
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
1155
1405
|
const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
|
|
1156
|
-
var _c, _d, _e, _f, _g, _h;
|
|
1406
|
+
var _c, _d, _e, _f, _g, _h, _j, _k;
|
|
1157
1407
|
handler.pathname = decodeURI(location.pathname);
|
|
1158
1408
|
if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
|
|
1159
1409
|
window.scrollTo(0, 0);
|
|
@@ -1182,22 +1432,34 @@ function createRouter(app, config, framework) {
|
|
|
1182
1432
|
window.location.reload();
|
|
1183
1433
|
}
|
|
1184
1434
|
else {
|
|
1185
|
-
throw
|
|
1435
|
+
throw error;
|
|
1186
1436
|
}
|
|
1187
1437
|
}
|
|
1188
1438
|
if (!element)
|
|
1189
1439
|
return;
|
|
1190
1440
|
const pageConfig = handler.pageConfig;
|
|
1191
1441
|
let enablePullDownRefresh = ((_e = config === null || config === void 0 ? void 0 : config.window) === null || _e === void 0 ? void 0 : _e.enablePullDownRefresh) || false;
|
|
1442
|
+
let navigationStyle = ((_f = config === null || config === void 0 ? void 0 : config.window) === null || _f === void 0 ? void 0 : _f.navigationStyle) || 'default';
|
|
1443
|
+
let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
|
|
1444
|
+
let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
|
|
1192
1445
|
if (pageConfig) {
|
|
1193
|
-
setTitle((_f = pageConfig.navigationBarTitleText) !== null && _f !== void 0 ? _f : document.title);
|
|
1194
1446
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
1195
1447
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
1196
1448
|
}
|
|
1449
|
+
if (typeof pageConfig.navigationStyle === 'string') {
|
|
1450
|
+
navigationStyle = pageConfig.navigationStyle;
|
|
1451
|
+
}
|
|
1452
|
+
if (typeof pageConfig.navigationBarTextStyle === 'string') {
|
|
1453
|
+
navigationBarTextStyle = pageConfig.navigationBarTextStyle;
|
|
1454
|
+
}
|
|
1455
|
+
if (typeof pageConfig.navigationBarBackgroundColor === 'string') {
|
|
1456
|
+
navigationBarBackgroundColor = pageConfig.navigationBarBackgroundColor;
|
|
1457
|
+
}
|
|
1197
1458
|
}
|
|
1459
|
+
eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
|
|
1198
1460
|
const currentPage = Current.page;
|
|
1199
1461
|
const pathname = handler.pathname;
|
|
1200
|
-
const methodName = (
|
|
1462
|
+
const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
|
|
1201
1463
|
const cacheTabs = stacks.getTabs();
|
|
1202
1464
|
let shouldLoad = false;
|
|
1203
1465
|
stacks.method = '';
|
|
@@ -1263,7 +1525,7 @@ function createRouter(app, config, framework) {
|
|
|
1263
1525
|
shouldLoad = true;
|
|
1264
1526
|
}
|
|
1265
1527
|
if (shouldLoad || stacks.length < 1) {
|
|
1266
|
-
const el = (
|
|
1528
|
+
const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
|
|
1267
1529
|
const loadConfig = Object.assign({}, pageConfig);
|
|
1268
1530
|
const stacksIndex = stacks.length;
|
|
1269
1531
|
delete loadConfig['path'];
|
|
@@ -1288,8 +1550,57 @@ function createRouter(app, config, framework) {
|
|
|
1288
1550
|
}
|
|
1289
1551
|
render({ location: history.location, action: Action.Push });
|
|
1290
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
|
+
});
|
|
1291
1562
|
return history.listen(render);
|
|
1292
1563
|
}
|
|
1293
1564
|
|
|
1294
|
-
|
|
1295
|
-
|
|
1565
|
+
function handleAppMount(config, _, appId = config.appId || 'app') {
|
|
1566
|
+
let app = document.getElementById(appId);
|
|
1567
|
+
let isPosition = true;
|
|
1568
|
+
if (!app) {
|
|
1569
|
+
app = document.createElement('div');
|
|
1570
|
+
app.id = appId;
|
|
1571
|
+
isPosition = false;
|
|
1572
|
+
}
|
|
1573
|
+
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
1574
|
+
app.classList.add('taro_router');
|
|
1575
|
+
if (!isPosition)
|
|
1576
|
+
appWrapper.appendChild(app);
|
|
1577
|
+
initNavigationBar(appWrapper);
|
|
1578
|
+
}
|
|
1579
|
+
function handleAppMountWithTabbar(config, history, appId = config.appId || 'app') {
|
|
1580
|
+
let app = document.getElementById(appId);
|
|
1581
|
+
let isPosition = true;
|
|
1582
|
+
if (!app) {
|
|
1583
|
+
app = document.createElement('div');
|
|
1584
|
+
app.id = appId;
|
|
1585
|
+
isPosition = false;
|
|
1586
|
+
}
|
|
1587
|
+
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
1588
|
+
app.classList.add('taro_router');
|
|
1589
|
+
const container = document.createElement('div');
|
|
1590
|
+
container.classList.add('taro-tabbar__container');
|
|
1591
|
+
container.id = 'container';
|
|
1592
|
+
const panel = document.createElement('div');
|
|
1593
|
+
panel.classList.add('taro-tabbar__panel');
|
|
1594
|
+
panel.appendChild(app.cloneNode(true));
|
|
1595
|
+
container.appendChild(panel);
|
|
1596
|
+
if (!isPosition) {
|
|
1597
|
+
appWrapper.appendChild(container);
|
|
1598
|
+
}
|
|
1599
|
+
else {
|
|
1600
|
+
appWrapper.replaceChild(container, app);
|
|
1601
|
+
}
|
|
1602
|
+
initTabbar(config, history);
|
|
1603
|
+
initNavigationBar(container);
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
export { createMpaHistory, createMultiRouter, createRouter, getCurrentPages, handleAppMount, handleAppMountWithTabbar, history, isDingTalk, isWeixin, navigateBack, navigateTo, prependBasename, reLaunch, redirectTo, routesAlias, setHistory, setHistoryMode, setMpaTitle, setNavigationBarStyle, setTitle, switchTab };
|