@tarojs/router 4.0.0-alpha.0 → 4.0.0-alpha.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 +11 -4
- package/dist/api.js +30 -22
- package/dist/events/resize.d.ts +1 -1
- package/dist/events/resize.js +15 -7
- package/dist/events/scroll.d.ts +1 -1
- package/dist/events/scroll.js +4 -1
- package/dist/history.d.ts +22 -1
- package/dist/history.js +20 -8
- package/dist/index.cjs.js +767 -321
- package/dist/index.d.ts +6 -1
- package/dist/index.esm.js +727 -293
- package/dist/index.js +52 -4
- package/dist/navigationBar.d.ts +2 -0
- package/dist/navigationBar.js +44 -0
- package/dist/router/index.js +7 -3
- package/dist/router/mpa.d.ts +2 -1
- package/dist/router/mpa.js +29 -19
- package/dist/router/multi-page.d.ts +5 -2
- package/dist/router/multi-page.js +27 -43
- package/dist/router/navigation-bar.d.ts +36 -0
- package/dist/router/navigation-bar.js +252 -0
- package/dist/router/page.d.ts +11 -4
- package/dist/router/page.js +62 -59
- package/dist/router/spa.d.ts +2 -1
- package/dist/router/spa.js +57 -31
- package/dist/router/stack.d.ts +1 -1
- package/dist/router/stack.js +2 -1
- package/dist/style.d.ts +6 -1
- package/dist/style.js +106 -7
- package/dist/tabbar.d.ts +2 -1
- package/dist/tabbar.js +4 -3
- package/dist/utils/index.d.ts +1 -8
- package/dist/utils/index.js +5 -20
- package/dist/utils/navigate.d.ts +9 -5
- package/dist/utils/navigate.js +24 -37
- package/package.json +28 -27
- package/types/api.d.ts +5 -0
- package/types/component.d.ts +5 -0
- package/types/taro.d.ts +8 -0
- package/dist/index.cjs.d.ts +0 -22
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.d.ts +0 -22
- package/dist/index.esm.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,52 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
import { initNavigationBar } from './navigationBar.js';
|
|
2
|
+
import { initTabbar } from './tabbar.js';
|
|
3
|
+
export { getCurrentPages, navigateBack, navigateTo, reLaunch, redirectTo, switchTab } from './api.js';
|
|
4
|
+
export { createMpaHistory, history, prependBasename, setHistory, setHistoryMode } from './history.js';
|
|
5
|
+
export { createMultiRouter } from './router/mpa.js';
|
|
6
|
+
export { createRouter } from './router/spa.js';
|
|
7
|
+
export { routesAlias } from './utils/index.js';
|
|
8
|
+
export { createBrowserHistory, createHashHistory } from 'history';
|
|
9
|
+
export { isDingTalk, isWeixin, setMpaTitle, setNavigationBarLoading, setNavigationBarStyle, setTitle } from './utils/navigate.js';
|
|
10
|
+
|
|
11
|
+
function handleAppMount(config, _, appId = config.appId || 'app') {
|
|
12
|
+
let app = document.getElementById(appId);
|
|
13
|
+
let isPosition = true;
|
|
14
|
+
if (!app) {
|
|
15
|
+
app = document.createElement('div');
|
|
16
|
+
app.id = appId;
|
|
17
|
+
isPosition = false;
|
|
18
|
+
}
|
|
19
|
+
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
20
|
+
app.classList.add('taro_router');
|
|
21
|
+
if (!isPosition)
|
|
22
|
+
appWrapper.appendChild(app);
|
|
23
|
+
initNavigationBar(config, appWrapper);
|
|
24
|
+
}
|
|
25
|
+
function handleAppMountWithTabbar(config, history, appId = config.appId || 'app') {
|
|
26
|
+
let app = document.getElementById(appId);
|
|
27
|
+
let isPosition = true;
|
|
28
|
+
if (!app) {
|
|
29
|
+
app = document.createElement('div');
|
|
30
|
+
app.id = appId;
|
|
31
|
+
isPosition = false;
|
|
32
|
+
}
|
|
33
|
+
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
34
|
+
app.classList.add('taro_router');
|
|
35
|
+
const container = document.createElement('div');
|
|
36
|
+
container.classList.add('taro-tabbar__container');
|
|
37
|
+
container.id = 'container';
|
|
38
|
+
const panel = document.createElement('div');
|
|
39
|
+
panel.classList.add('taro-tabbar__panel');
|
|
40
|
+
panel.appendChild(app.cloneNode(true));
|
|
41
|
+
container.appendChild(panel);
|
|
42
|
+
if (!isPosition) {
|
|
43
|
+
appWrapper.appendChild(container);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
appWrapper.replaceChild(container, app);
|
|
47
|
+
}
|
|
48
|
+
initTabbar(config, history);
|
|
49
|
+
initNavigationBar(config, container);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { handleAppMount, handleAppMountWithTabbar };
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { loadNavigationBarStyle } from './style.js';
|
|
2
|
+
|
|
3
|
+
const home_svg_str = `
|
|
4
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
5
|
+
<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"/>
|
|
6
|
+
</svg>
|
|
7
|
+
`;
|
|
8
|
+
const back_svg_str = `
|
|
9
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
10
|
+
<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"/>
|
|
11
|
+
</svg>
|
|
12
|
+
`;
|
|
13
|
+
const loading_svg_str = `
|
|
14
|
+
<svg t="1709608074670" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="4741" width="24" height="24"><path d="M256 529.066667H85.333333a17.066667 17.066667 0 1 1 0-34.133334h170.666667a17.066667 17.066667 0 0 1 0 34.133334z" opacity=".278" p-id="4742"></path><path d="M99.84 640a17.066667 17.066667 0 0 1-4.437333-33.553067l164.693333-44.373333a17.066667 17.066667 0 1 1 8.891733 32.9728l-164.693333 44.373333a17.544533 17.544533 0 0 1-4.4544 0.580267z" opacity=".322" p-id="4743"></path><path d="M264.533333 462.523733a16.896 16.896 0 0 1-4.369066-0.580266l-164.693334-43.52a17.0496 17.0496 0 1 1 8.721067-32.989867l164.693333 43.52a17.066667 17.066667 0 1 1-4.352 33.570133z" opacity=".239" p-id="4744"></path><path d="M384.017067 307.2a17.032533 17.032533 0 0 1-14.7968-8.533333l-85.333334-147.626667a17.066667 17.066667 0 0 1 29.559467-17.083733l85.333333 147.626666A17.066667 17.066667 0 0 1 384.017067 307.2z" opacity=".122" p-id="4745"></path><path d="M639.982933 307.2a17.0496 17.0496 0 0 1-14.762666-25.6l85.333333-147.626667a17.066667 17.066667 0 1 1 29.559467 17.066667l-85.333334 147.626667a17.032533 17.032533 0 0 1-14.7968 8.533333z" opacity=".922" p-id="4746"></path><path d="M692.906667 347.306667a17.066667 17.066667 0 0 1-12.117334-29.098667l120.337067-121.173333a17.066667 17.066667 0 1 1 24.234667 24.046933l-120.337067 121.173333a17.1008 17.1008 0 0 1-12.117333 5.051734z" opacity=".878" p-id="4747"></path><path d="M733.883733 401.066667a17.066667 17.066667 0 0 1-8.5504-31.8464l147.626667-85.333334a17.0496 17.0496 0 1 1 17.066667 29.5424l-147.626667 85.333334a16.776533 16.776533 0 0 1-8.516267 2.304z" opacity=".839" p-id="4748"></path><path d="M512 273.066667a17.066667 17.066667 0 0 1-17.066667-17.066667V85.333333a17.066667 17.066667 0 0 1 34.133334 0v170.666667a17.066667 17.066667 0 0 1-17.066667 17.066667z" p-id="4749"></path><path d="M578.577067 281.6a17.066667 17.066667 0 0 1-16.520534-21.418667l43.52-164.693333a17.066667 17.066667 0 0 1 33.006934 8.721067l-43.52 164.693333a17.066667 17.066667 0 0 1-16.4864 12.6976z" opacity=".961" p-id="4750"></path><path d="M445.44 282.453333a17.066667 17.066667 0 0 1-16.469333-12.629333l-44.373334-164.693333a17.066667 17.066667 0 0 1 32.955734-8.891734l44.373333 164.693334a17.066667 17.066667 0 0 1-16.4864 21.521066z" opacity=".078" p-id="4751"></path><path d="M924.177067 640c-1.4848 0-2.9696-0.187733-4.4544-0.580267l-164.693334-44.373333a17.066667 17.066667 0 0 1 8.874667-32.9728l164.693333 44.373333a17.066667 17.066667 0 0 1-4.420266 33.553067z" opacity=".722" p-id="4752"></path><path d="M881.476267 742.4a17.015467 17.015467 0 0 1-8.482134-2.269867l-148.48-85.333333a17.0496 17.0496 0 1 1 16.9984-29.5936l148.48 85.333333a17.0496 17.0496 0 0 1-8.516266 31.863467z" opacity=".678" p-id="4753"></path><path d="M813.226667 830.293333a17.015467 17.015467 0 0 1-12.066134-5.000533l-120.337066-120.337067a17.0496 17.0496 0 1 1 24.132266-24.132266l120.337067 120.337066a17.0496 17.0496 0 0 1-12.066133 29.1328z" opacity=".639" p-id="4754"></path><path d="M938.666667 529.066667H768a17.066667 17.066667 0 1 1 0-34.133334h170.666667a17.066667 17.066667 0 1 1 0 34.133334z" opacity=".761" p-id="4755"></path><path d="M401.066667 941.226667a17.066667 17.066667 0 0 1-16.4864-21.504l44.373333-164.693334a17.066667 17.066667 0 1 1 32.955733 8.874667l-44.373333 164.693333a17.066667 17.066667 0 0 1-16.469333 12.629334z" opacity=".478" p-id="4756"></path><path d="M298.6496 898.56a17.066667 17.066667 0 0 1-14.779733-25.565867l85.333333-148.48a17.083733 17.083733 0 0 1 29.5936 16.9984l-85.333333 148.48a17.032533 17.032533 0 0 1-14.813867 8.567467z" opacity=".439" p-id="4757"></path><path d="M512 955.733333a17.066667 17.066667 0 0 1-17.066667-17.066666V768a17.066667 17.066667 0 1 1 34.133334 0v170.666667a17.066667 17.066667 0 0 1-17.066667 17.066666z" opacity=".522" p-id="4758"></path><path d="M725.3504 898.56a17.032533 17.032533 0 0 1-14.7968-8.533333l-85.333333-147.626667a17.066667 17.066667 0 0 1 29.559466-17.066667l85.333334 147.626667a17.066667 17.066667 0 0 1-14.762667 25.6z" opacity=".6" p-id="4759"></path><path d="M622.062933 942.08c-7.509333 0-14.421333-5.0176-16.469333-12.629333l-44.3904-164.693334a17.066667 17.066667 0 1 1 32.9728-8.874666l44.3904 164.693333a17.066667 17.066667 0 0 1-16.503467 21.504z" opacity=".561" p-id="4760"></path><path d="M759.4496 463.36a17.083733 17.083733 0 0 1-4.420267-33.553067l164.693334-44.373333a17.066667 17.066667 0 0 1 8.874666 32.955733l-164.693333 44.373334a16.657067 16.657067 0 0 1-4.4544 0.597333z" opacity=".702" p-id="4761"></path><path d="M330.24 347.306667a17.015467 17.015467 0 0 1-12.066133-5.000534l-120.32-120.32a17.0496 17.0496 0 1 1 24.132266-24.132266l120.32 120.32a17.0496 17.0496 0 0 1-12.066133 29.1328z" opacity=".161" p-id="4762"></path><path d="M290.116267 401.066667a17.032533 17.032533 0 0 1-8.533334-2.286934l-147.626666-85.333333a17.066667 17.066667 0 1 1 17.083733-29.5424l147.626667 85.333333a17.066667 17.066667 0 0 1-8.5504 31.829334z" opacity=".2" p-id="4763"></path><path d="M142.523733 742.4a17.066667 17.066667 0 0 1-8.567466-31.8464l147.626666-85.333333a17.066667 17.066667 0 1 1 17.083734 29.559466l-147.626667 85.333334a16.930133 16.930133 0 0 1-8.516267 2.286933z" opacity=".361" p-id="4764"></path><path d="M209.92 830.293333a17.066667 17.066667 0 0 1-12.117333-29.098666l120.32-121.173334a17.066667 17.066667 0 0 1 24.2176 24.029867l-120.32 121.1904a16.896 16.896 0 0 1-12.100267 5.051733z" opacity=".4" p-id="4765"></path></svg>
|
|
15
|
+
`;
|
|
16
|
+
function initNavigationBar(config, container) {
|
|
17
|
+
if (config.router.mode === 'multi')
|
|
18
|
+
return;
|
|
19
|
+
const navigationBar = document.createElement('div');
|
|
20
|
+
navigationBar.classList.add('taro-navigation-bar-no-icon');
|
|
21
|
+
const navigationBarBackBtn = document.createElement('div');
|
|
22
|
+
navigationBarBackBtn.classList.add('taro-navigation-bar-back');
|
|
23
|
+
const navigationBarHomeBtn = document.createElement('div');
|
|
24
|
+
navigationBarHomeBtn.classList.add('taro-navigation-bar-home');
|
|
25
|
+
navigationBarBackBtn.innerHTML = back_svg_str;
|
|
26
|
+
navigationBarHomeBtn.innerHTML = home_svg_str;
|
|
27
|
+
const navigationBarTitleWrap = document.createElement('div');
|
|
28
|
+
navigationBarTitleWrap.classList.add('taro-navigation-bar-title-wrap');
|
|
29
|
+
const navigationBarLoading = document.createElement('div');
|
|
30
|
+
navigationBarLoading.classList.add('taro-navigation-bar-loading');
|
|
31
|
+
navigationBarLoading.innerHTML = loading_svg_str;
|
|
32
|
+
const navigationBarTitle = document.createElement('div');
|
|
33
|
+
navigationBarTitle.classList.add('taro-navigation-bar-title');
|
|
34
|
+
navigationBarTitleWrap.appendChild(navigationBarLoading);
|
|
35
|
+
navigationBarTitleWrap.appendChild(navigationBarTitle);
|
|
36
|
+
navigationBar.appendChild(navigationBarHomeBtn);
|
|
37
|
+
navigationBar.appendChild(navigationBarBackBtn);
|
|
38
|
+
navigationBar.appendChild(navigationBarTitleWrap);
|
|
39
|
+
navigationBar.id = 'taro-navigation-bar';
|
|
40
|
+
container.prepend(navigationBar);
|
|
41
|
+
loadNavigationBarStyle();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { initNavigationBar };
|
package/dist/router/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { addLeadingSlash } from '@tarojs/runtime';
|
|
2
|
+
|
|
3
|
+
class RouterConfig {
|
|
3
4
|
static set config(e) {
|
|
4
5
|
this.__config = e;
|
|
5
6
|
}
|
|
@@ -16,7 +17,10 @@ export class RouterConfig {
|
|
|
16
17
|
return this.router.mode || 'hash';
|
|
17
18
|
}
|
|
18
19
|
static get customRoutes() { return this.router.customRoutes || {}; }
|
|
20
|
+
// 这个方法不考虑 basename 和 customRoutes,只判断原始的 url 是否在 pages 中
|
|
19
21
|
static isPage(url = '') {
|
|
20
|
-
return this.pages.findIndex(e =>
|
|
22
|
+
return this.pages.findIndex(e => addLeadingSlash(e) === url) !== -1;
|
|
21
23
|
}
|
|
22
24
|
}
|
|
25
|
+
|
|
26
|
+
export { RouterConfig };
|
package/dist/router/mpa.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AppInstance } from '@tarojs/runtime';
|
|
2
|
+
import type { History } from 'history';
|
|
2
3
|
import type { MpaRouterConfig } from '../../types/router';
|
|
3
4
|
/** Note: 关于多页面应用
|
|
4
5
|
* - 需要配置路由映射(根目录跳转、404 页面……)
|
|
@@ -7,4 +8,4 @@ import type { MpaRouterConfig } from '../../types/router';
|
|
|
7
8
|
* - TabBar 会多次加载
|
|
8
9
|
* - 不支持路由动画
|
|
9
10
|
*/
|
|
10
|
-
export declare function createMultiRouter(app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
|
|
11
|
+
export declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
|
package/dist/router/mpa.js
CHANGED
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
/* eslint-disable dot-notation */
|
|
11
|
-
import { createPageConfig, eventCenter, hooks, incrementId, stringify, } from '@tarojs/runtime';
|
|
12
|
-
import { setTitle } from '../utils/navigate';
|
|
13
|
-
import { RouterConfig } from '.';
|
|
14
|
-
import MultiPageHandler from './multi-page';
|
|
1
|
+
import { __awaiter } from 'tslib';
|
|
2
|
+
import { incrementId, eventCenter, createPageConfig, hooks, stringify, Current } from '@tarojs/runtime';
|
|
3
|
+
import '../utils/index.js';
|
|
4
|
+
import { RouterConfig } from './index.js';
|
|
5
|
+
import MultiPageHandler from './multi-page.js';
|
|
6
|
+
import { setMpaTitle } from '../utils/navigate.js';
|
|
7
|
+
|
|
15
8
|
const createStampId = incrementId();
|
|
16
9
|
const launchStampId = createStampId();
|
|
17
10
|
// TODO 支持多路由 (APP 生命周期仅触发一次)
|
|
@@ -22,16 +15,17 @@ const launchStampId = createStampId();
|
|
|
22
15
|
* - TabBar 会多次加载
|
|
23
16
|
* - 不支持路由动画
|
|
24
17
|
*/
|
|
25
|
-
|
|
26
|
-
var _a, _b, _c, _d, _e, _f;
|
|
18
|
+
function createMultiRouter(history, app, config, framework) {
|
|
27
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
var _a, _b, _c, _d, _e, _f;
|
|
28
21
|
if (typeof app.onUnhandledRejection === 'function') {
|
|
29
22
|
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
30
23
|
}
|
|
24
|
+
eventCenter.on('__taroH5SetNavigationBarTitle', setMpaTitle);
|
|
31
25
|
RouterConfig.config = config;
|
|
32
|
-
const handler = new MultiPageHandler(config);
|
|
26
|
+
const handler = new MultiPageHandler(config, history);
|
|
33
27
|
const launchParam = {
|
|
34
|
-
path: config.pageName,
|
|
28
|
+
path: config.pageName, // 多页面模式没新开一个页面相当于重启,所以直接使用当前页面路径
|
|
35
29
|
query: handler.getQuery(launchStampId),
|
|
36
30
|
scene: 0,
|
|
37
31
|
shareTicket: '',
|
|
@@ -61,7 +55,7 @@ export function createMultiRouter(app, config, framework) {
|
|
|
61
55
|
return;
|
|
62
56
|
let enablePullDownRefresh = ((_c = config === null || config === void 0 ? void 0 : config.window) === null || _c === void 0 ? void 0 : _c.enablePullDownRefresh) || false;
|
|
63
57
|
if (pageConfig) {
|
|
64
|
-
|
|
58
|
+
setMpaTitle((_d = pageConfig.navigationBarTitleText) !== null && _d !== void 0 ? _d : document.title);
|
|
65
59
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
66
60
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
67
61
|
}
|
|
@@ -73,5 +67,21 @@ export function createMultiRouter(app, config, framework) {
|
|
|
73
67
|
const page = createPageConfig(enablePullDownRefresh ? hooks.call('createPullDownComponent', el, pathName, framework, handler.PullDownRefresh) : el, pathName + stringify(launchParam), {}, loadConfig);
|
|
74
68
|
handler.load(page, pageConfig);
|
|
75
69
|
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);
|
|
70
|
+
window.addEventListener('visibilitychange', () => {
|
|
71
|
+
var _a, _b, _c;
|
|
72
|
+
const currentPath = ((_a = Current.page) === null || _a === void 0 ? void 0 : _a.path) || '';
|
|
73
|
+
const path = currentPath.substring(0, currentPath.indexOf('?'));
|
|
74
|
+
const param = {};
|
|
75
|
+
// app的 onShow/onHide 生命周期的路径信息为当前页面的路径
|
|
76
|
+
Object.assign(param, launchParam, { path });
|
|
77
|
+
if (document.visibilityState === 'visible') {
|
|
78
|
+
(_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, param);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
(_c = app.onHide) === null || _c === void 0 ? void 0 : _c.call(app, param);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
76
84
|
});
|
|
77
85
|
}
|
|
86
|
+
|
|
87
|
+
export { createMultiRouter };
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { PageInstance } from '@tarojs/runtime';
|
|
1
|
+
import type { PageInstance } from '@tarojs/runtime';
|
|
2
2
|
import type { PageConfig } from '@tarojs/taro';
|
|
3
|
+
import type { History } from 'history';
|
|
3
4
|
import type { MpaRouterConfig, Route } from '../../types/router';
|
|
4
5
|
export default class MultiPageHandler {
|
|
6
|
+
history: History;
|
|
5
7
|
protected config: MpaRouterConfig;
|
|
6
|
-
constructor(config: MpaRouterConfig);
|
|
8
|
+
constructor(config: MpaRouterConfig, history: History);
|
|
7
9
|
get appId(): string;
|
|
8
10
|
get router(): import("../../types/router").Router;
|
|
9
11
|
get routerMode(): "hash" | "browser" | "multi";
|
|
@@ -20,6 +22,7 @@ export default class MultiPageHandler {
|
|
|
20
22
|
getQuery(search?: string, options?: Record<string, unknown>): {
|
|
21
23
|
[x: string]: unknown;
|
|
22
24
|
};
|
|
25
|
+
isDefaultNavigationStyle(): boolean;
|
|
23
26
|
mount(): void;
|
|
24
27
|
onReady(page: PageInstance, onLoad?: boolean): void;
|
|
25
28
|
load(page: PageInstance, pageConfig?: Route): void;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
import { Current, eventCenter } from '@tarojs/runtime';
|
|
1
|
+
import { addLeadingSlash, stripBasename, Current, eventCenter } from '@tarojs/runtime';
|
|
3
2
|
import queryString from 'query-string';
|
|
4
|
-
import { bindPageResize } from '../events/resize';
|
|
5
|
-
import { bindPageScroll } from '../events/scroll';
|
|
6
|
-
import {
|
|
7
|
-
import { loadRouterStyle } from '../style';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
constructor(config) {
|
|
3
|
+
import { bindPageResize } from '../events/resize.js';
|
|
4
|
+
import { bindPageScroll } from '../events/scroll.js';
|
|
5
|
+
import { setHistory } from '../history.js';
|
|
6
|
+
import { loadRouterStyle } from '../style.js';
|
|
7
|
+
|
|
8
|
+
/* eslint-disable dot-notation */
|
|
9
|
+
class MultiPageHandler {
|
|
10
|
+
constructor(config, history) {
|
|
11
|
+
this.history = history;
|
|
12
12
|
this.config = config;
|
|
13
13
|
this.mount();
|
|
14
14
|
}
|
|
@@ -55,39 +55,18 @@ export default class MultiPageHandler {
|
|
|
55
55
|
: {};
|
|
56
56
|
return Object.assign(Object.assign({}, query), options);
|
|
57
57
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
let isPosition = true;
|
|
64
|
-
if (!app) {
|
|
65
|
-
app = document.createElement('div');
|
|
66
|
-
app.id = appId;
|
|
67
|
-
isPosition = false;
|
|
68
|
-
}
|
|
69
|
-
const appWrapper = (app === null || app === void 0 ? void 0 : app.parentNode) || (app === null || app === void 0 ? void 0 : app.parentElement) || document.body;
|
|
70
|
-
app.classList.add('taro_router');
|
|
71
|
-
if (this.tabBarList.length > 1) {
|
|
72
|
-
const container = document.createElement('div');
|
|
73
|
-
container.classList.add('taro-tabbar__container');
|
|
74
|
-
container.id = 'container';
|
|
75
|
-
const panel = document.createElement('div');
|
|
76
|
-
panel.classList.add('taro-tabbar__panel');
|
|
77
|
-
panel.appendChild(app.cloneNode(true));
|
|
78
|
-
container.appendChild(panel);
|
|
79
|
-
if (!isPosition) {
|
|
80
|
-
appWrapper.appendChild(container);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
appWrapper.replaceChild(container, app);
|
|
84
|
-
}
|
|
85
|
-
initTabbar(this.config);
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
if (!isPosition)
|
|
89
|
-
appWrapper.appendChild(app);
|
|
58
|
+
isDefaultNavigationStyle() {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
let style = (_a = this.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
|
|
61
|
+
if (typeof ((_b = this.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
|
|
62
|
+
style = this.pageConfig.navigationStyle;
|
|
90
63
|
}
|
|
64
|
+
return style !== 'custom';
|
|
65
|
+
}
|
|
66
|
+
mount() {
|
|
67
|
+
setHistory(this.history, this.basename);
|
|
68
|
+
// Note: 注入页面样式
|
|
69
|
+
loadRouterStyle(this.tabBarList.length > 1, this.usingWindowScroll);
|
|
91
70
|
}
|
|
92
71
|
onReady(page, onLoad = true) {
|
|
93
72
|
var _a;
|
|
@@ -117,10 +96,13 @@ export default class MultiPageHandler {
|
|
|
117
96
|
return;
|
|
118
97
|
(_a = page.onLoad) === null || _a === void 0 ? void 0 : _a.call(page, this.getQuery('', page.options), () => {
|
|
119
98
|
var _a;
|
|
99
|
+
const pageEl = this.getPageContainer(page);
|
|
120
100
|
if (this.isTabBar) {
|
|
121
|
-
const pageEl = this.getPageContainer(page);
|
|
122
101
|
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_tabbar_page');
|
|
123
102
|
}
|
|
103
|
+
if (this.isDefaultNavigationStyle()) {
|
|
104
|
+
pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page');
|
|
105
|
+
}
|
|
124
106
|
this.onReady(page, true);
|
|
125
107
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
126
108
|
this.bindPageEvents(page, pageConfig);
|
|
@@ -166,3 +148,5 @@ export default class MultiPageHandler {
|
|
|
166
148
|
}, 0);
|
|
167
149
|
}
|
|
168
150
|
}
|
|
151
|
+
|
|
152
|
+
export { MultiPageHandler as default };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type PageHandler from './page';
|
|
2
|
+
interface NavigationBarCache {
|
|
3
|
+
backgroundColor?: string;
|
|
4
|
+
fontColor?: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
show?: boolean;
|
|
7
|
+
loading?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export default class NavigationBarHandler {
|
|
10
|
+
pageContext: PageHandler;
|
|
11
|
+
navigationBarElement: HTMLElement;
|
|
12
|
+
cache: Record<string, NavigationBarCache>;
|
|
13
|
+
isLoadDdEntry: boolean;
|
|
14
|
+
constructor(pageContext: PageHandler);
|
|
15
|
+
private toHomeFn;
|
|
16
|
+
private backFn;
|
|
17
|
+
get homeBtnElement(): Element | null;
|
|
18
|
+
get backBtnElement(): Element | null;
|
|
19
|
+
get titleElement(): Element | null;
|
|
20
|
+
get loadingElement(): Element | null;
|
|
21
|
+
init(): void;
|
|
22
|
+
setNavigationBarElement(): void;
|
|
23
|
+
load(): void;
|
|
24
|
+
setCacheValue(): void;
|
|
25
|
+
setFnBtnState(): void;
|
|
26
|
+
shiftLoadingState(show: boolean): void;
|
|
27
|
+
setNavigationLoading(show?: boolean): void;
|
|
28
|
+
setNavigationBarBackground(backgroundColor?: string): void;
|
|
29
|
+
setNavigationBarTextStyle(fontColor?: string): void;
|
|
30
|
+
setTitle(title?: any): void;
|
|
31
|
+
fnBtnToggleToHome(): void;
|
|
32
|
+
fnBtnToggleToBack(): void;
|
|
33
|
+
fnBtnToggleToNone(): void;
|
|
34
|
+
setNavigationBarVisible(show?: any): void;
|
|
35
|
+
}
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { eventCenter } from '@tarojs/runtime';
|
|
2
|
+
import { reLaunch, navigateBack } from '../api.js';
|
|
3
|
+
import '../utils/index.js';
|
|
4
|
+
import stacks from './stack.js';
|
|
5
|
+
import { isDingTalk } from '../utils/navigate.js';
|
|
6
|
+
|
|
7
|
+
class NavigationBarHandler {
|
|
8
|
+
constructor(pageContext) {
|
|
9
|
+
this.isLoadDdEntry = false;
|
|
10
|
+
this.cache = {};
|
|
11
|
+
this.pageContext = pageContext;
|
|
12
|
+
this.init();
|
|
13
|
+
eventCenter.on('__taroH5SetNavigationBarTitle', (title) => {
|
|
14
|
+
this.setTitle(title);
|
|
15
|
+
});
|
|
16
|
+
eventCenter.on('__taroH5setNavigationBarLoading', (loading) => {
|
|
17
|
+
this.setNavigationLoading(loading);
|
|
18
|
+
});
|
|
19
|
+
eventCenter.on('__taroH5setNavigationBarColor', ({ backgroundColor, frontColor }) => {
|
|
20
|
+
if (typeof backgroundColor === 'string')
|
|
21
|
+
this.setNavigationBarBackground(backgroundColor);
|
|
22
|
+
if (typeof frontColor === 'string')
|
|
23
|
+
this.setNavigationBarTextStyle(frontColor);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
toHomeFn() {
|
|
27
|
+
reLaunch({ url: this.pageContext.originHomePage });
|
|
28
|
+
}
|
|
29
|
+
backFn() {
|
|
30
|
+
navigateBack();
|
|
31
|
+
}
|
|
32
|
+
get homeBtnElement() {
|
|
33
|
+
var _a;
|
|
34
|
+
if (!this.navigationBarElement)
|
|
35
|
+
return null;
|
|
36
|
+
return (_a = this.navigationBarElement.getElementsByClassName('taro-navigation-bar-home')) === null || _a === void 0 ? void 0 : _a[0];
|
|
37
|
+
}
|
|
38
|
+
get backBtnElement() {
|
|
39
|
+
var _a;
|
|
40
|
+
if (!this.navigationBarElement)
|
|
41
|
+
return null;
|
|
42
|
+
return (_a = this.navigationBarElement.getElementsByClassName('taro-navigation-bar-back')) === null || _a === void 0 ? void 0 : _a[0];
|
|
43
|
+
}
|
|
44
|
+
get titleElement() {
|
|
45
|
+
var _a;
|
|
46
|
+
if (!this.navigationBarElement)
|
|
47
|
+
return null;
|
|
48
|
+
return (_a = this.navigationBarElement.getElementsByClassName('taro-navigation-bar-title')) === null || _a === void 0 ? void 0 : _a[0];
|
|
49
|
+
}
|
|
50
|
+
get loadingElement() {
|
|
51
|
+
if (!this.navigationBarElement)
|
|
52
|
+
return null;
|
|
53
|
+
return this.navigationBarElement.getElementsByClassName('taro-navigation-bar-loading')[0];
|
|
54
|
+
}
|
|
55
|
+
init() {
|
|
56
|
+
var _a, _b;
|
|
57
|
+
this.setNavigationBarElement();
|
|
58
|
+
if (!this.navigationBarElement)
|
|
59
|
+
return;
|
|
60
|
+
(_a = this.homeBtnElement) === null || _a === void 0 ? void 0 : _a.addEventListener('click', this.toHomeFn.bind(this));
|
|
61
|
+
(_b = this.backBtnElement) === null || _b === void 0 ? void 0 : _b.addEventListener('click', this.backFn.bind(this));
|
|
62
|
+
}
|
|
63
|
+
setNavigationBarElement() {
|
|
64
|
+
this.navigationBarElement = document.getElementById('taro-navigation-bar');
|
|
65
|
+
}
|
|
66
|
+
load() {
|
|
67
|
+
this.setCacheValue();
|
|
68
|
+
this.setTitle();
|
|
69
|
+
this.setNavigationBarVisible();
|
|
70
|
+
this.setFnBtnState();
|
|
71
|
+
this.setNavigationBarBackground();
|
|
72
|
+
this.setNavigationBarTextStyle();
|
|
73
|
+
this.setNavigationLoading();
|
|
74
|
+
}
|
|
75
|
+
setCacheValue() {
|
|
76
|
+
const currentPage = this.pageContext.originPathname;
|
|
77
|
+
if (typeof this.cache[currentPage] !== 'object') {
|
|
78
|
+
this.cache[currentPage] = {};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
setFnBtnState() {
|
|
82
|
+
const currentRouter = this.pageContext.currentPage;
|
|
83
|
+
if (this.pageContext.isTabBar(currentRouter) || this.pageContext.homePage === currentRouter) {
|
|
84
|
+
this.fnBtnToggleToNone();
|
|
85
|
+
}
|
|
86
|
+
else if (stacks.length > 1) {
|
|
87
|
+
this.fnBtnToggleToBack();
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
this.fnBtnToggleToHome();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
shiftLoadingState(show) {
|
|
94
|
+
if (!this.loadingElement)
|
|
95
|
+
return;
|
|
96
|
+
if (show) {
|
|
97
|
+
this.loadingElement.classList.add('taro-navigation-bar-loading-show');
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
this.loadingElement.classList.remove('taro-navigation-bar-loading-show');
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
setNavigationLoading(show) {
|
|
104
|
+
var _a;
|
|
105
|
+
if (!this.navigationBarElement)
|
|
106
|
+
return;
|
|
107
|
+
const currentPage = this.pageContext.originPathname;
|
|
108
|
+
let isShow;
|
|
109
|
+
if (typeof show === 'boolean') {
|
|
110
|
+
isShow = show;
|
|
111
|
+
this.cache[currentPage] &&
|
|
112
|
+
(this.cache[currentPage].loading = isShow);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.loading;
|
|
116
|
+
if (typeof cacheValue === 'boolean') {
|
|
117
|
+
isShow = cacheValue;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
// 默认值为 false
|
|
121
|
+
isShow = false;
|
|
122
|
+
this.cache[currentPage] &&
|
|
123
|
+
(this.cache[currentPage].loading = isShow);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
this.shiftLoadingState(isShow);
|
|
127
|
+
}
|
|
128
|
+
setNavigationBarBackground(backgroundColor) {
|
|
129
|
+
var _a, _b, _c;
|
|
130
|
+
if (!this.navigationBarElement)
|
|
131
|
+
return;
|
|
132
|
+
const currentPage = this.pageContext.originPathname;
|
|
133
|
+
let color;
|
|
134
|
+
if (typeof backgroundColor === 'string') {
|
|
135
|
+
color = backgroundColor;
|
|
136
|
+
this.cache[currentPage] &&
|
|
137
|
+
(this.cache[currentPage].backgroundColor = color);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.backgroundColor;
|
|
141
|
+
if (typeof cacheValue === 'string') {
|
|
142
|
+
color = cacheValue;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarBackgroundColor) || '#000000';
|
|
146
|
+
this.cache[currentPage] &&
|
|
147
|
+
(this.cache[currentPage].backgroundColor = color);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
this.navigationBarElement.style.background = color;
|
|
151
|
+
}
|
|
152
|
+
setNavigationBarTextStyle(fontColor) {
|
|
153
|
+
var _a, _b, _c;
|
|
154
|
+
if (!this.navigationBarElement)
|
|
155
|
+
return;
|
|
156
|
+
const currentPage = this.pageContext.originPathname;
|
|
157
|
+
let color;
|
|
158
|
+
if (typeof fontColor === 'string') {
|
|
159
|
+
color = fontColor;
|
|
160
|
+
this.cache[currentPage] &&
|
|
161
|
+
(this.cache[currentPage].fontColor = color);
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.fontColor;
|
|
165
|
+
if (typeof cacheValue === 'string') {
|
|
166
|
+
color = cacheValue;
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarTextStyle) || 'white';
|
|
170
|
+
this.cache[currentPage] &&
|
|
171
|
+
(this.cache[currentPage].fontColor = color);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
this.navigationBarElement.style.color = color;
|
|
175
|
+
}
|
|
176
|
+
setTitle(title) {
|
|
177
|
+
var _a, _b, _c;
|
|
178
|
+
const currentPage = this.pageContext.originPathname;
|
|
179
|
+
let proceedTitle;
|
|
180
|
+
if (typeof title === 'string') {
|
|
181
|
+
proceedTitle = title;
|
|
182
|
+
this.cache[currentPage] &&
|
|
183
|
+
(this.cache[currentPage].title = proceedTitle);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.title;
|
|
187
|
+
if (typeof cacheValue === 'string') {
|
|
188
|
+
proceedTitle = cacheValue;
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
proceedTitle = (_c = (_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationBarTitleText) !== null && _c !== void 0 ? _c : document.title;
|
|
192
|
+
this.cache[currentPage] &&
|
|
193
|
+
(this.cache[currentPage].title = proceedTitle);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
|
|
197
|
+
if (!this.isLoadDdEntry) {
|
|
198
|
+
this.isLoadDdEntry = true;
|
|
199
|
+
require('dingtalk-jsapi/platform');
|
|
200
|
+
}
|
|
201
|
+
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
202
|
+
setDingTitle({ proceedTitle });
|
|
203
|
+
}
|
|
204
|
+
document.title = proceedTitle;
|
|
205
|
+
if (!this.titleElement)
|
|
206
|
+
return;
|
|
207
|
+
this.titleElement.innerHTML = proceedTitle;
|
|
208
|
+
}
|
|
209
|
+
fnBtnToggleToHome() {
|
|
210
|
+
if (!this.navigationBarElement)
|
|
211
|
+
return;
|
|
212
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-home-icon');
|
|
213
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-back-icon');
|
|
214
|
+
}
|
|
215
|
+
fnBtnToggleToBack() {
|
|
216
|
+
if (!this.navigationBarElement)
|
|
217
|
+
return;
|
|
218
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-home-icon');
|
|
219
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-back-icon');
|
|
220
|
+
}
|
|
221
|
+
fnBtnToggleToNone() {
|
|
222
|
+
if (!this.navigationBarElement)
|
|
223
|
+
return;
|
|
224
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-home-icon');
|
|
225
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-back-icon');
|
|
226
|
+
}
|
|
227
|
+
setNavigationBarVisible(show) {
|
|
228
|
+
var _a, _b;
|
|
229
|
+
if (!this.navigationBarElement)
|
|
230
|
+
return;
|
|
231
|
+
let shouldShow;
|
|
232
|
+
if (typeof show === 'boolean') {
|
|
233
|
+
shouldShow = show;
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
shouldShow = (_a = this.pageContext.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
|
|
237
|
+
if (typeof ((_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
|
|
238
|
+
shouldShow = this.pageContext.pageConfig.navigationStyle;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (shouldShow === 'default') {
|
|
242
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-show');
|
|
243
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-hide');
|
|
244
|
+
}
|
|
245
|
+
else {
|
|
246
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-hide');
|
|
247
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-show');
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export { NavigationBarHandler as default };
|