@tarojs/router 4.0.0-alpha.2 → 4.0.0-alpha.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/LICENSE +8 -8
- package/dist/api.d.ts +6 -7
- package/dist/api.js +10 -17
- package/dist/events/resize.d.ts +2 -3
- package/dist/events/scroll.d.ts +2 -3
- package/dist/history.d.ts +10 -8
- package/dist/history.js +2 -1
- package/dist/index.cjs.js +363 -226
- package/dist/index.d.ts +9 -10
- package/dist/index.esm.js +362 -226
- package/dist/index.js +3 -3
- package/dist/navigationBar.d.ts +2 -2
- package/dist/navigationBar.js +24 -7
- package/dist/router/index.d.ts +3 -4
- package/dist/router/index.js +3 -2
- package/dist/router/mpa.d.ts +4 -5
- package/dist/router/mpa.js +12 -7
- package/dist/router/multi-page.d.ts +7 -8
- package/dist/router/navigation-bar.d.ts +8 -4
- package/dist/router/navigation-bar.js +62 -19
- package/dist/router/page.d.ts +11 -10
- package/dist/router/page.js +26 -14
- package/dist/router/spa.d.ts +4 -5
- package/dist/router/spa.js +51 -27
- package/dist/router/stack.d.ts +2 -2
- package/dist/style.d.ts +4 -5
- package/dist/style.js +52 -13
- package/dist/tabbar.d.ts +2 -3
- package/dist/utils/index.d.ts +2 -3
- package/dist/utils/navigate.d.ts +6 -6
- package/dist/utils/navigate.js +5 -2
- package/package.json +18 -27
- package/types/api.d.ts +5 -0
- package/dist/index.cjs.d.ts +0 -65
- package/dist/index.esm.d.ts +0 -65
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export { createMultiRouter } from './router/mpa.js';
|
|
|
6
6
|
export { createRouter } from './router/spa.js';
|
|
7
7
|
export { routesAlias } from './utils/index.js';
|
|
8
8
|
export { createBrowserHistory, createHashHistory } from 'history';
|
|
9
|
-
export { isDingTalk, isWeixin, setMpaTitle, setNavigationBarStyle, setTitle } from './utils/navigate.js';
|
|
9
|
+
export { isDingTalk, isWeixin, setMpaTitle, setNavigationBarLoading, setNavigationBarStyle, setTitle } from './utils/navigate.js';
|
|
10
10
|
|
|
11
11
|
function handleAppMount(config, _, appId = config.appId || 'app') {
|
|
12
12
|
let app = document.getElementById(appId);
|
|
@@ -20,7 +20,7 @@ function handleAppMount(config, _, appId = config.appId || 'app') {
|
|
|
20
20
|
app.classList.add('taro_router');
|
|
21
21
|
if (!isPosition)
|
|
22
22
|
appWrapper.appendChild(app);
|
|
23
|
-
initNavigationBar(appWrapper);
|
|
23
|
+
initNavigationBar(config, appWrapper);
|
|
24
24
|
}
|
|
25
25
|
function handleAppMountWithTabbar(config, history, appId = config.appId || 'app') {
|
|
26
26
|
let app = document.getElementById(appId);
|
|
@@ -46,7 +46,7 @@ function handleAppMountWithTabbar(config, history, appId = config.appId || 'app'
|
|
|
46
46
|
appWrapper.replaceChild(container, app);
|
|
47
47
|
}
|
|
48
48
|
initTabbar(config, history);
|
|
49
|
-
initNavigationBar(container);
|
|
49
|
+
initNavigationBar(config, container);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
export { handleAppMount, handleAppMountWithTabbar };
|
package/dist/navigationBar.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
import type { MpaRouterConfig, SpaRouterConfig } from '../types/router';
|
|
2
|
+
export declare function initNavigationBar(config: SpaRouterConfig | MpaRouterConfig, container: HTMLElement): void;
|
package/dist/navigationBar.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { loadNavigationBarStyle } from './style.js';
|
|
2
|
+
|
|
1
3
|
const home_svg_str = `
|
|
2
4
|
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
3
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"/>
|
|
@@ -7,21 +9,36 @@ const back_svg_str = `
|
|
|
7
9
|
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
8
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"/>
|
|
9
11
|
</svg>
|
|
10
|
-
|
|
11
12
|
`;
|
|
12
|
-
|
|
13
|
-
|
|
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');
|
|
14
20
|
navigationBar.classList.add('taro-navigation-bar-no-icon');
|
|
15
|
-
const navigationBarBackBtn = document.createElement('
|
|
16
|
-
|
|
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');
|
|
17
25
|
navigationBarBackBtn.innerHTML = back_svg_str;
|
|
18
26
|
navigationBarHomeBtn.innerHTML = home_svg_str;
|
|
19
|
-
const
|
|
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);
|
|
20
36
|
navigationBar.appendChild(navigationBarHomeBtn);
|
|
21
37
|
navigationBar.appendChild(navigationBarBackBtn);
|
|
22
|
-
navigationBar.appendChild(
|
|
38
|
+
navigationBar.appendChild(navigationBarTitleWrap);
|
|
23
39
|
navigationBar.id = 'taro-navigation-bar';
|
|
24
40
|
container.prepend(navigationBar);
|
|
41
|
+
loadNavigationBarStyle();
|
|
25
42
|
}
|
|
26
43
|
|
|
27
44
|
export { initNavigationBar };
|
package/dist/router/index.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { MpaRouterConfig, SpaRouterConfig } from '../../types/router';
|
|
2
|
-
declare class RouterConfig {
|
|
1
|
+
import type { MpaRouterConfig, SpaRouterConfig } from '../../types/router';
|
|
2
|
+
export declare class RouterConfig {
|
|
3
3
|
private static __config;
|
|
4
4
|
static set config(e: SpaRouterConfig | MpaRouterConfig);
|
|
5
5
|
static get config(): SpaRouterConfig | MpaRouterConfig;
|
|
6
6
|
static get pages(): string[];
|
|
7
|
-
static get router(): import("
|
|
7
|
+
static get router(): import("../../types/router").Router;
|
|
8
8
|
static get mode(): "hash" | "browser" | "multi";
|
|
9
9
|
static get customRoutes(): Record<string, string | string[]>;
|
|
10
10
|
static isPage(url?: string): boolean;
|
|
11
11
|
}
|
|
12
|
-
export { RouterConfig };
|
package/dist/router/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { addLeadingSlash } from '@tarojs/runtime';
|
|
2
2
|
|
|
3
3
|
class RouterConfig {
|
|
4
4
|
static set config(e) {
|
|
@@ -17,8 +17,9 @@ class RouterConfig {
|
|
|
17
17
|
return this.router.mode || 'hash';
|
|
18
18
|
}
|
|
19
19
|
static get customRoutes() { return this.router.customRoutes || {}; }
|
|
20
|
+
// 这个方法不考虑 basename 和 customRoutes,只判断原始的 url 是否在 pages 中
|
|
20
21
|
static isPage(url = '') {
|
|
21
|
-
return this.pages.findIndex(e =>
|
|
22
|
+
return this.pages.findIndex(e => addLeadingSlash(e) === url) !== -1;
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
package/dist/router/mpa.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AppInstance } from '@tarojs/runtime';
|
|
2
|
-
import { History } from
|
|
3
|
-
import { MpaRouterConfig } from '../../types/router';
|
|
1
|
+
import type { AppInstance } from '@tarojs/runtime';
|
|
2
|
+
import type { History } from 'history';
|
|
3
|
+
import type { MpaRouterConfig } from '../../types/router';
|
|
4
4
|
/** Note: 关于多页面应用
|
|
5
5
|
* - 需要配置路由映射(根目录跳转、404 页面……)
|
|
6
6
|
* - app.onPageNotFound 事件不支持
|
|
@@ -8,5 +8,4 @@ import { MpaRouterConfig } from '../../types/router';
|
|
|
8
8
|
* - TabBar 会多次加载
|
|
9
9
|
* - 不支持路由动画
|
|
10
10
|
*/
|
|
11
|
-
declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
|
|
12
|
-
export { createMultiRouter };
|
|
11
|
+
export declare function createMultiRouter(history: History, app: AppInstance, config: MpaRouterConfig, framework?: string): Promise<void>;
|
package/dist/router/mpa.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from 'tslib';
|
|
2
|
-
import { incrementId, eventCenter, createPageConfig, hooks, stringify } from '@tarojs/runtime';
|
|
2
|
+
import { incrementId, eventCenter, createPageConfig, hooks, stringify, Current } from '@tarojs/runtime';
|
|
3
3
|
import '../utils/index.js';
|
|
4
4
|
import { RouterConfig } from './index.js';
|
|
5
5
|
import MultiPageHandler from './multi-page.js';
|
|
@@ -16,16 +16,16 @@ const launchStampId = createStampId();
|
|
|
16
16
|
* - 不支持路由动画
|
|
17
17
|
*/
|
|
18
18
|
function createMultiRouter(history, app, config, framework) {
|
|
19
|
-
var _a, _b, _c, _d, _e, _f;
|
|
20
19
|
return __awaiter(this, void 0, void 0, function* () {
|
|
20
|
+
var _a, _b, _c, _d, _e, _f;
|
|
21
21
|
if (typeof app.onUnhandledRejection === 'function') {
|
|
22
22
|
window.addEventListener('unhandledrejection', app.onUnhandledRejection);
|
|
23
23
|
}
|
|
24
|
-
eventCenter.on('
|
|
24
|
+
eventCenter.on('__taroH5SetNavigationBarTitle', setMpaTitle);
|
|
25
25
|
RouterConfig.config = config;
|
|
26
26
|
const handler = new MultiPageHandler(config, history);
|
|
27
27
|
const launchParam = {
|
|
28
|
-
path: config.pageName,
|
|
28
|
+
path: config.pageName, // 多页面模式没新开一个页面相当于重启,所以直接使用当前页面路径
|
|
29
29
|
query: handler.getQuery(launchStampId),
|
|
30
30
|
scene: 0,
|
|
31
31
|
shareTicket: '',
|
|
@@ -68,12 +68,17 @@ function createMultiRouter(history, app, config, framework) {
|
|
|
68
68
|
handler.load(page, pageConfig);
|
|
69
69
|
(_f = app.onShow) === null || _f === void 0 ? void 0 : _f.call(app, launchParam);
|
|
70
70
|
window.addEventListener('visibilitychange', () => {
|
|
71
|
-
var _a, _b;
|
|
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 });
|
|
72
77
|
if (document.visibilityState === 'visible') {
|
|
73
|
-
(
|
|
78
|
+
(_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, param);
|
|
74
79
|
}
|
|
75
80
|
else {
|
|
76
|
-
(
|
|
81
|
+
(_c = app.onHide) === null || _c === void 0 ? void 0 : _c.call(app, param);
|
|
77
82
|
}
|
|
78
83
|
});
|
|
79
84
|
});
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { PageInstance } from '@tarojs/runtime';
|
|
2
|
-
import { PageConfig } from '@tarojs/taro';
|
|
3
|
-
import { History } from
|
|
4
|
-
import { MpaRouterConfig, Route } from '../../types/router';
|
|
5
|
-
|
|
1
|
+
import type { PageInstance } from '@tarojs/runtime';
|
|
2
|
+
import type { PageConfig } from '@tarojs/taro';
|
|
3
|
+
import type { History } from 'history';
|
|
4
|
+
import type { MpaRouterConfig, Route } from '../../types/router';
|
|
5
|
+
export default class MultiPageHandler {
|
|
6
6
|
history: History;
|
|
7
7
|
protected config: MpaRouterConfig;
|
|
8
8
|
constructor(config: MpaRouterConfig, history: History);
|
|
9
9
|
get appId(): string;
|
|
10
|
-
get router(): import("
|
|
10
|
+
get router(): import("../../types/router").Router;
|
|
11
11
|
get routerMode(): "hash" | "browser" | "multi";
|
|
12
12
|
get customRoutes(): Record<string, string | string[]>;
|
|
13
13
|
get tabBarList(): import("@tarojs/taro").TabBarItem[];
|
|
@@ -27,8 +27,7 @@ declare class MultiPageHandler {
|
|
|
27
27
|
onReady(page: PageInstance, onLoad?: boolean): void;
|
|
28
28
|
load(page: PageInstance, pageConfig?: Route): void;
|
|
29
29
|
getPageContainer(page?: PageInstance | null): HTMLElement | null;
|
|
30
|
-
getScrollingElement(page?: PageInstance | null):
|
|
30
|
+
getScrollingElement(page?: PageInstance | null): (Window & typeof globalThis) | HTMLElement;
|
|
31
31
|
bindPageEvents(page: PageInstance, config?: Partial<PageConfig>): void;
|
|
32
32
|
triggerRouterChange(): void;
|
|
33
33
|
}
|
|
34
|
-
export { MultiPageHandler as default };
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import PageHandler from
|
|
1
|
+
import type PageHandler from './page';
|
|
2
2
|
interface NavigationBarCache {
|
|
3
3
|
backgroundColor?: string;
|
|
4
4
|
fontColor?: string;
|
|
5
5
|
title?: string;
|
|
6
6
|
show?: boolean;
|
|
7
|
+
loading?: boolean;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
export default class NavigationBarHandler {
|
|
9
10
|
pageContext: PageHandler;
|
|
10
|
-
navigationBarElement:
|
|
11
|
+
navigationBarElement: HTMLElement;
|
|
11
12
|
cache: Record<string, NavigationBarCache>;
|
|
12
13
|
isLoadDdEntry: boolean;
|
|
13
14
|
constructor(pageContext: PageHandler);
|
|
@@ -16,11 +17,14 @@ declare class NavigationBarHandler {
|
|
|
16
17
|
get homeBtnElement(): Element | null;
|
|
17
18
|
get backBtnElement(): Element | null;
|
|
18
19
|
get titleElement(): Element | null;
|
|
20
|
+
get loadingElement(): Element | null;
|
|
19
21
|
init(): void;
|
|
20
22
|
setNavigationBarElement(): void;
|
|
21
23
|
load(): void;
|
|
22
24
|
setCacheValue(): void;
|
|
23
25
|
setFnBtnState(): void;
|
|
26
|
+
shiftLoadingState(show: boolean): void;
|
|
27
|
+
setNavigationLoading(show?: boolean): void;
|
|
24
28
|
setNavigationBarBackground(backgroundColor?: string): void;
|
|
25
29
|
setNavigationBarTextStyle(fontColor?: string): void;
|
|
26
30
|
setTitle(title?: any): void;
|
|
@@ -29,4 +33,4 @@ declare class NavigationBarHandler {
|
|
|
29
33
|
fnBtnToggleToNone(): void;
|
|
30
34
|
setNavigationBarVisible(show?: any): void;
|
|
31
35
|
}
|
|
32
|
-
export {
|
|
36
|
+
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { eventCenter } from '@tarojs/runtime';
|
|
2
2
|
import { reLaunch, navigateBack } from '../api.js';
|
|
3
|
-
import { loadNavigationBarStyle } from '../style.js';
|
|
4
3
|
import '../utils/index.js';
|
|
5
4
|
import stacks from './stack.js';
|
|
6
5
|
import { isDingTalk } from '../utils/navigate.js';
|
|
@@ -11,10 +10,12 @@ class NavigationBarHandler {
|
|
|
11
10
|
this.cache = {};
|
|
12
11
|
this.pageContext = pageContext;
|
|
13
12
|
this.init();
|
|
14
|
-
|
|
15
|
-
eventCenter.on('__taroH5SetNavigationTitle', (title) => {
|
|
13
|
+
eventCenter.on('__taroH5SetNavigationBarTitle', (title) => {
|
|
16
14
|
this.setTitle(title);
|
|
17
15
|
});
|
|
16
|
+
eventCenter.on('__taroH5setNavigationBarLoading', (loading) => {
|
|
17
|
+
this.setNavigationLoading(loading);
|
|
18
|
+
});
|
|
18
19
|
eventCenter.on('__taroH5setNavigationBarColor', ({ backgroundColor, frontColor }) => {
|
|
19
20
|
if (typeof backgroundColor === 'string')
|
|
20
21
|
this.setNavigationBarBackground(backgroundColor);
|
|
@@ -23,7 +24,7 @@ class NavigationBarHandler {
|
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
toHomeFn() {
|
|
26
|
-
reLaunch({ url: this.pageContext.
|
|
27
|
+
reLaunch({ url: this.pageContext.originHomePage });
|
|
27
28
|
}
|
|
28
29
|
backFn() {
|
|
29
30
|
navigateBack();
|
|
@@ -32,19 +33,24 @@ class NavigationBarHandler {
|
|
|
32
33
|
var _a;
|
|
33
34
|
if (!this.navigationBarElement)
|
|
34
35
|
return null;
|
|
35
|
-
return (_a = this.navigationBarElement.
|
|
36
|
+
return (_a = this.navigationBarElement.getElementsByClassName('taro-navigation-bar-home')) === null || _a === void 0 ? void 0 : _a[0];
|
|
36
37
|
}
|
|
37
38
|
get backBtnElement() {
|
|
38
39
|
var _a;
|
|
39
40
|
if (!this.navigationBarElement)
|
|
40
41
|
return null;
|
|
41
|
-
return (_a = this.navigationBarElement.
|
|
42
|
+
return (_a = this.navigationBarElement.getElementsByClassName('taro-navigation-bar-back')) === null || _a === void 0 ? void 0 : _a[0];
|
|
42
43
|
}
|
|
43
44
|
get titleElement() {
|
|
44
45
|
var _a;
|
|
45
46
|
if (!this.navigationBarElement)
|
|
46
47
|
return null;
|
|
47
|
-
return (_a = this.navigationBarElement.
|
|
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];
|
|
48
54
|
}
|
|
49
55
|
init() {
|
|
50
56
|
var _a, _b;
|
|
@@ -55,8 +61,7 @@ class NavigationBarHandler {
|
|
|
55
61
|
(_b = this.backBtnElement) === null || _b === void 0 ? void 0 : _b.addEventListener('click', this.backFn.bind(this));
|
|
56
62
|
}
|
|
57
63
|
setNavigationBarElement() {
|
|
58
|
-
|
|
59
|
-
this.navigationBarElement = (_a = document.getElementsByTagName('taro-navigation-bar-wrap')) === null || _a === void 0 ? void 0 : _a[0];
|
|
64
|
+
this.navigationBarElement = document.getElementById('taro-navigation-bar');
|
|
60
65
|
}
|
|
61
66
|
load() {
|
|
62
67
|
this.setCacheValue();
|
|
@@ -65,9 +70,10 @@ class NavigationBarHandler {
|
|
|
65
70
|
this.setFnBtnState();
|
|
66
71
|
this.setNavigationBarBackground();
|
|
67
72
|
this.setNavigationBarTextStyle();
|
|
73
|
+
this.setNavigationLoading();
|
|
68
74
|
}
|
|
69
75
|
setCacheValue() {
|
|
70
|
-
const currentPage = this.pageContext.
|
|
76
|
+
const currentPage = this.pageContext.originPathname;
|
|
71
77
|
if (typeof this.cache[currentPage] !== 'object') {
|
|
72
78
|
this.cache[currentPage] = {};
|
|
73
79
|
}
|
|
@@ -84,11 +90,46 @@ class NavigationBarHandler {
|
|
|
84
90
|
this.fnBtnToggleToHome();
|
|
85
91
|
}
|
|
86
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
|
+
}
|
|
87
128
|
setNavigationBarBackground(backgroundColor) {
|
|
88
129
|
var _a, _b, _c;
|
|
89
130
|
if (!this.navigationBarElement)
|
|
90
131
|
return;
|
|
91
|
-
const currentPage = this.pageContext.
|
|
132
|
+
const currentPage = this.pageContext.originPathname;
|
|
92
133
|
let color;
|
|
93
134
|
if (typeof backgroundColor === 'string') {
|
|
94
135
|
color = backgroundColor;
|
|
@@ -112,7 +153,7 @@ class NavigationBarHandler {
|
|
|
112
153
|
var _a, _b, _c;
|
|
113
154
|
if (!this.navigationBarElement)
|
|
114
155
|
return;
|
|
115
|
-
const currentPage = this.pageContext.
|
|
156
|
+
const currentPage = this.pageContext.originPathname;
|
|
116
157
|
let color;
|
|
117
158
|
if (typeof fontColor === 'string') {
|
|
118
159
|
color = fontColor;
|
|
@@ -134,7 +175,7 @@ class NavigationBarHandler {
|
|
|
134
175
|
}
|
|
135
176
|
setTitle(title) {
|
|
136
177
|
var _a, _b, _c;
|
|
137
|
-
const currentPage = this.pageContext.
|
|
178
|
+
const currentPage = this.pageContext.originPathname;
|
|
138
179
|
let proceedTitle;
|
|
139
180
|
if (typeof title === 'string') {
|
|
140
181
|
proceedTitle = title;
|
|
@@ -168,23 +209,25 @@ class NavigationBarHandler {
|
|
|
168
209
|
fnBtnToggleToHome() {
|
|
169
210
|
if (!this.navigationBarElement)
|
|
170
211
|
return;
|
|
171
|
-
this.navigationBarElement.classList.add('taro-navigation-bar-home');
|
|
172
|
-
this.navigationBarElement.classList.remove('taro-navigation-bar-back');
|
|
212
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-home-icon');
|
|
213
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-back-icon');
|
|
173
214
|
}
|
|
174
215
|
fnBtnToggleToBack() {
|
|
175
216
|
if (!this.navigationBarElement)
|
|
176
217
|
return;
|
|
177
|
-
this.navigationBarElement.classList.remove('taro-navigation-bar-home');
|
|
178
|
-
this.navigationBarElement.classList.add('taro-navigation-bar-back');
|
|
218
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-home-icon');
|
|
219
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-back-icon');
|
|
179
220
|
}
|
|
180
221
|
fnBtnToggleToNone() {
|
|
181
222
|
if (!this.navigationBarElement)
|
|
182
223
|
return;
|
|
183
|
-
this.navigationBarElement.classList.remove('taro-navigation-bar-home');
|
|
184
|
-
this.navigationBarElement.classList.remove('taro-navigation-bar-back');
|
|
224
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-home-icon');
|
|
225
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-back-icon');
|
|
185
226
|
}
|
|
186
227
|
setNavigationBarVisible(show) {
|
|
187
228
|
var _a, _b;
|
|
229
|
+
if (!this.navigationBarElement)
|
|
230
|
+
return;
|
|
188
231
|
let shouldShow;
|
|
189
232
|
if (typeof show === 'boolean') {
|
|
190
233
|
shouldShow = show;
|
package/dist/router/page.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import NavigationBarHandler from
|
|
2
|
-
import { PageInstance } from '@tarojs/runtime';
|
|
3
|
-
import { PageConfig, RouterAnimate } from '@tarojs/taro';
|
|
4
|
-
import { History } from
|
|
5
|
-
import { Route, SpaRouterConfig } from '../../types/router';
|
|
6
|
-
|
|
1
|
+
import NavigationBarHandler from './navigation-bar';
|
|
2
|
+
import type { PageInstance } from '@tarojs/runtime';
|
|
3
|
+
import type { PageConfig, RouterAnimate } from '@tarojs/taro';
|
|
4
|
+
import type { History } from 'history';
|
|
5
|
+
import type { Route, SpaRouterConfig } from '../../types/router';
|
|
6
|
+
export default class PageHandler {
|
|
7
7
|
history: History;
|
|
8
8
|
config: SpaRouterConfig;
|
|
9
9
|
protected readonly defaultAnimation: RouterAnimate;
|
|
@@ -13,10 +13,11 @@ declare class PageHandler {
|
|
|
13
13
|
protected lastUnloadPage: PageInstance | null;
|
|
14
14
|
protected navigationBarHandler: NavigationBarHandler;
|
|
15
15
|
homePage: string;
|
|
16
|
+
originHomePage: string;
|
|
16
17
|
constructor(config: SpaRouterConfig, history: History);
|
|
17
18
|
get currentPage(): string;
|
|
18
19
|
get appId(): string;
|
|
19
|
-
get router(): import("
|
|
20
|
+
get router(): import("../../types/router").Router;
|
|
20
21
|
get routerMode(): "hash" | "browser" | "multi";
|
|
21
22
|
get customRoutes(): Record<string, string | string[]>;
|
|
22
23
|
get routes(): Route[];
|
|
@@ -27,6 +28,7 @@ declare class PageHandler {
|
|
|
27
28
|
get animationDuration(): number;
|
|
28
29
|
set pathname(p: string);
|
|
29
30
|
get pathname(): string;
|
|
31
|
+
get originPathname(): string;
|
|
30
32
|
get basename(): string;
|
|
31
33
|
get pageConfig(): Route | undefined;
|
|
32
34
|
isTabBar(pathname: string): boolean;
|
|
@@ -42,11 +44,10 @@ declare class PageHandler {
|
|
|
42
44
|
load(page: PageInstance, pageConfig: Route | undefined, stampId: string, pageNo?: number): void;
|
|
43
45
|
unload(page?: PageInstance | null, delta?: number, top?: boolean): void;
|
|
44
46
|
show(page?: PageInstance | null, pageConfig?: Route, pageNo?: number): void;
|
|
45
|
-
hide(page?: PageInstance | null): void;
|
|
47
|
+
hide(page?: PageInstance | null, animation?: boolean): void;
|
|
46
48
|
addAnimation(pageEl?: HTMLElement | null, first?: boolean): void;
|
|
47
49
|
getPageContainer(page?: PageInstance | null): HTMLElement | null;
|
|
48
|
-
getScrollingElement(page?: PageInstance | null):
|
|
50
|
+
getScrollingElement(page?: PageInstance | null): (Window & typeof globalThis) | HTMLElement;
|
|
49
51
|
bindPageEvents(page: PageInstance, config?: Partial<PageConfig>): void;
|
|
50
52
|
triggerRouterChange(): void;
|
|
51
53
|
}
|
|
52
|
-
export { PageHandler as default };
|
package/dist/router/page.js
CHANGED
|
@@ -15,6 +15,7 @@ class PageHandler {
|
|
|
15
15
|
this.defaultAnimation = { duration: 300, delay: 50 };
|
|
16
16
|
this.config = config;
|
|
17
17
|
this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
|
|
18
|
+
this.originHomePage = this.config.entryPagePath || this.routes[0].path || this.basename;
|
|
18
19
|
this.mount();
|
|
19
20
|
this.navigationBarHandler = new NavigationBarHandler(this);
|
|
20
21
|
}
|
|
@@ -48,14 +49,14 @@ class PageHandler {
|
|
|
48
49
|
}
|
|
49
50
|
set pathname(p) { this.router.pathname = p; }
|
|
50
51
|
get pathname() { return this.router.pathname; }
|
|
52
|
+
// Note: 把 pathname 转换为原始路径,主要是处理 customRoutes 和 basename
|
|
53
|
+
get originPathname() { return routesAlias.getOrigin(addLeadingSlash(stripBasename(this.pathname, this.basename))); }
|
|
51
54
|
get basename() { return this.router.basename || ''; }
|
|
52
55
|
get pageConfig() {
|
|
53
|
-
const routePath = addLeadingSlash(stripBasename(this.pathname, this.basename));
|
|
54
56
|
const homePage = addLeadingSlash(this.homePage);
|
|
55
57
|
return this.routes.find(r => {
|
|
56
|
-
var _a;
|
|
57
58
|
const pagePath = addLeadingSlash(r.path);
|
|
58
|
-
return [pagePath, homePage].includes(
|
|
59
|
+
return [pagePath, homePage].includes(this.originPathname);
|
|
59
60
|
});
|
|
60
61
|
}
|
|
61
62
|
isTabBar(pathname) {
|
|
@@ -245,24 +246,35 @@ class PageHandler {
|
|
|
245
246
|
});
|
|
246
247
|
}
|
|
247
248
|
}
|
|
248
|
-
hide(page) {
|
|
249
|
-
var _a;
|
|
249
|
+
hide(page, animation = false) {
|
|
250
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
250
251
|
if (!page)
|
|
251
252
|
return;
|
|
252
253
|
// NOTE: 修复多页并发问题,此处可能因为路由跳转过快,执行时页面可能还没有创建成功
|
|
253
254
|
const pageEl = this.getPageContainer(page);
|
|
254
255
|
if (pageEl) {
|
|
255
|
-
if (
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
256
|
+
if (animation) {
|
|
257
|
+
if (this.hideTimer) {
|
|
258
|
+
clearTimeout(this.hideTimer);
|
|
259
|
+
this.hideTimer = null;
|
|
260
|
+
(_c = (_b = (_a = this.lastHidePage) === null || _a === void 0 ? void 0 : _a.classList) === null || _b === void 0 ? void 0 : _b.add) === null || _c === void 0 ? void 0 : _c.call(_b, 'taro_page_shade');
|
|
261
|
+
}
|
|
262
|
+
this.lastHidePage = pageEl;
|
|
263
|
+
this.hideTimer = setTimeout(() => {
|
|
264
|
+
this.hideTimer = null;
|
|
265
|
+
pageEl.classList.add('taro_page_shade');
|
|
266
|
+
}, this.animationDuration + this.animationDelay);
|
|
267
|
+
(_d = page.onHide) === null || _d === void 0 ? void 0 : _d.call(page);
|
|
259
268
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
269
|
+
else {
|
|
270
|
+
if (this.hideTimer) {
|
|
271
|
+
clearTimeout(this.hideTimer);
|
|
272
|
+
this.hideTimer = null;
|
|
273
|
+
(_g = (_f = (_e = this.lastHidePage) === null || _e === void 0 ? void 0 : _e.classList) === null || _f === void 0 ? void 0 : _f.add) === null || _g === void 0 ? void 0 : _g.call(_f, 'taro_page_shade');
|
|
274
|
+
}
|
|
263
275
|
pageEl.classList.add('taro_page_shade');
|
|
264
|
-
|
|
265
|
-
|
|
276
|
+
this.lastHidePage = pageEl;
|
|
277
|
+
}
|
|
266
278
|
}
|
|
267
279
|
else {
|
|
268
280
|
setTimeout(() => this.hide(page), 0);
|
package/dist/router/spa.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { AppInstance } from '@tarojs/runtime';
|
|
2
|
-
import { History } from
|
|
3
|
-
import { SpaRouterConfig } from '../../types/router';
|
|
4
|
-
declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig, framework?: string): () => void;
|
|
5
|
-
export { createRouter };
|
|
1
|
+
import type { AppInstance } from '@tarojs/runtime';
|
|
2
|
+
import type { History } from 'history';
|
|
3
|
+
import type { SpaRouterConfig } from '../../types/router';
|
|
4
|
+
export declare function createRouter(history: History, app: AppInstance, config: SpaRouterConfig, framework?: string): () => void;
|