@tarojs/router 4.0.0-beta.2 → 4.0.0-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.js +21 -1
- package/dist/events/resize.js +12 -6
- package/dist/history.js +1 -1
- package/dist/index.cjs.d.ts +7 -2
- package/dist/index.cjs.js +370 -30
- package/dist/index.esm.d.ts +7 -2
- package/dist/index.esm.js +370 -32
- package/dist/index.js +4 -1
- package/dist/navigationBar.d.ts +2 -0
- package/dist/navigationBar.js +27 -0
- package/dist/router/mpa.js +13 -2
- package/dist/router/navigation-bar.d.ts +32 -0
- package/dist/router/navigation-bar.js +209 -0
- package/dist/router/page.d.ts +3 -1
- package/dist/router/page.js +6 -0
- package/dist/router/spa.js +12 -5
- package/dist/style.d.ts +5 -1
- package/dist/style.js +58 -1
- package/dist/utils/index.js +0 -1
- package/dist/utils/navigate.d.ts +7 -2
- package/dist/utils/navigate.js +22 -19
- package/package.json +5 -5
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import PageHandler from "./page.js";
|
|
2
|
+
interface NavigationBarCache {
|
|
3
|
+
backgroundColor?: string;
|
|
4
|
+
fontColor?: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
show?: boolean;
|
|
7
|
+
}
|
|
8
|
+
declare class NavigationBarHandler {
|
|
9
|
+
pageContext: PageHandler;
|
|
10
|
+
navigationBarElement: Element;
|
|
11
|
+
cache: Record<string, NavigationBarCache>;
|
|
12
|
+
isLoadDdEntry: boolean;
|
|
13
|
+
constructor(pageContext: PageHandler);
|
|
14
|
+
private toHomeFn;
|
|
15
|
+
private backFn;
|
|
16
|
+
get homeBtnElement(): Element | null;
|
|
17
|
+
get backBtnElement(): Element | null;
|
|
18
|
+
get titleElement(): Element | null;
|
|
19
|
+
init(): void;
|
|
20
|
+
setNavigationBarElement(): void;
|
|
21
|
+
load(): void;
|
|
22
|
+
setCacheValue(): void;
|
|
23
|
+
setFnBtnState(): void;
|
|
24
|
+
setNavigationBarBackground(backgroundColor?: string): void;
|
|
25
|
+
setNavigationBarTextStyle(fontColor?: string): void;
|
|
26
|
+
setTitle(title?: any): void;
|
|
27
|
+
fnBtnToggleToHome(): void;
|
|
28
|
+
fnBtnToggleToBack(): void;
|
|
29
|
+
fnBtnToggleToNone(): void;
|
|
30
|
+
setNavigationBarVisible(show?: any): void;
|
|
31
|
+
}
|
|
32
|
+
export { NavigationBarHandler as default };
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { eventCenter } from '@tarojs/runtime';
|
|
2
|
+
import { reLaunch, navigateBack } from '../api.js';
|
|
3
|
+
import { loadNavigationBarStyle } from '../style.js';
|
|
4
|
+
import '../utils/index.js';
|
|
5
|
+
import stacks from './stack.js';
|
|
6
|
+
import { isDingTalk } from '../utils/navigate.js';
|
|
7
|
+
|
|
8
|
+
class NavigationBarHandler {
|
|
9
|
+
constructor(pageContext) {
|
|
10
|
+
this.isLoadDdEntry = false;
|
|
11
|
+
this.cache = {};
|
|
12
|
+
this.pageContext = pageContext;
|
|
13
|
+
this.init();
|
|
14
|
+
loadNavigationBarStyle();
|
|
15
|
+
eventCenter.on('__taroH5SetNavigationTitle', (title) => {
|
|
16
|
+
this.setTitle(title);
|
|
17
|
+
});
|
|
18
|
+
eventCenter.on('__taroH5setNavigationBarColor', ({ backgroundColor, frontColor }) => {
|
|
19
|
+
if (typeof backgroundColor === 'string')
|
|
20
|
+
this.setNavigationBarBackground(backgroundColor);
|
|
21
|
+
if (typeof frontColor === 'string')
|
|
22
|
+
this.setNavigationBarTextStyle(frontColor);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
toHomeFn() {
|
|
26
|
+
reLaunch({ url: this.pageContext.homePage });
|
|
27
|
+
}
|
|
28
|
+
backFn() {
|
|
29
|
+
navigateBack();
|
|
30
|
+
}
|
|
31
|
+
get homeBtnElement() {
|
|
32
|
+
var _a;
|
|
33
|
+
if (!this.navigationBarElement)
|
|
34
|
+
return null;
|
|
35
|
+
return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-home')) === null || _a === void 0 ? void 0 : _a[0];
|
|
36
|
+
}
|
|
37
|
+
get backBtnElement() {
|
|
38
|
+
var _a;
|
|
39
|
+
if (!this.navigationBarElement)
|
|
40
|
+
return null;
|
|
41
|
+
return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-back')) === null || _a === void 0 ? void 0 : _a[0];
|
|
42
|
+
}
|
|
43
|
+
get titleElement() {
|
|
44
|
+
var _a;
|
|
45
|
+
if (!this.navigationBarElement)
|
|
46
|
+
return null;
|
|
47
|
+
return (_a = this.navigationBarElement.getElementsByTagName('taro-navigation-bar-title')) === null || _a === void 0 ? void 0 : _a[0];
|
|
48
|
+
}
|
|
49
|
+
init() {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
this.setNavigationBarElement();
|
|
52
|
+
if (!this.navigationBarElement)
|
|
53
|
+
return;
|
|
54
|
+
(_a = this.homeBtnElement) === null || _a === void 0 ? void 0 : _a.addEventListener('click', this.toHomeFn.bind(this));
|
|
55
|
+
(_b = this.backBtnElement) === null || _b === void 0 ? void 0 : _b.addEventListener('click', this.backFn.bind(this));
|
|
56
|
+
}
|
|
57
|
+
setNavigationBarElement() {
|
|
58
|
+
var _a;
|
|
59
|
+
this.navigationBarElement = (_a = document.getElementsByTagName('taro-navigation-bar-wrap')) === null || _a === void 0 ? void 0 : _a[0];
|
|
60
|
+
}
|
|
61
|
+
load() {
|
|
62
|
+
this.setCacheValue();
|
|
63
|
+
this.setTitle();
|
|
64
|
+
this.setNavigationBarVisible();
|
|
65
|
+
this.setFnBtnState();
|
|
66
|
+
this.setNavigationBarBackground();
|
|
67
|
+
this.setNavigationBarTextStyle();
|
|
68
|
+
}
|
|
69
|
+
setCacheValue() {
|
|
70
|
+
const currentPage = this.pageContext.currentPage;
|
|
71
|
+
if (typeof this.cache[currentPage] !== 'object') {
|
|
72
|
+
this.cache[currentPage] = {};
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
setFnBtnState() {
|
|
76
|
+
const currentRouter = this.pageContext.currentPage;
|
|
77
|
+
if (this.pageContext.isTabBar(currentRouter) || this.pageContext.homePage === currentRouter) {
|
|
78
|
+
this.fnBtnToggleToNone();
|
|
79
|
+
}
|
|
80
|
+
else if (stacks.length > 1) {
|
|
81
|
+
this.fnBtnToggleToBack();
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
this.fnBtnToggleToHome();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
setNavigationBarBackground(backgroundColor) {
|
|
88
|
+
var _a, _b, _c;
|
|
89
|
+
if (!this.navigationBarElement)
|
|
90
|
+
return;
|
|
91
|
+
const currentPage = this.pageContext.currentPage;
|
|
92
|
+
let color;
|
|
93
|
+
if (typeof backgroundColor === 'string') {
|
|
94
|
+
color = backgroundColor;
|
|
95
|
+
this.cache[currentPage] &&
|
|
96
|
+
(this.cache[currentPage].backgroundColor = color);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.backgroundColor;
|
|
100
|
+
if (typeof cacheValue === 'string') {
|
|
101
|
+
color = cacheValue;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarBackgroundColor) || '#000000';
|
|
105
|
+
this.cache[currentPage] &&
|
|
106
|
+
(this.cache[currentPage].backgroundColor = color);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
this.navigationBarElement.style.background = color;
|
|
110
|
+
}
|
|
111
|
+
setNavigationBarTextStyle(fontColor) {
|
|
112
|
+
var _a, _b, _c;
|
|
113
|
+
if (!this.navigationBarElement)
|
|
114
|
+
return;
|
|
115
|
+
const currentPage = this.pageContext.currentPage;
|
|
116
|
+
let color;
|
|
117
|
+
if (typeof fontColor === 'string') {
|
|
118
|
+
color = fontColor;
|
|
119
|
+
this.cache[currentPage] &&
|
|
120
|
+
(this.cache[currentPage].fontColor = color);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.fontColor;
|
|
124
|
+
if (typeof cacheValue === 'string') {
|
|
125
|
+
color = cacheValue;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
color = ((_c = (_b = this.pageContext.config) === null || _b === void 0 ? void 0 : _b.window) === null || _c === void 0 ? void 0 : _c.navigationBarTextStyle) || 'white';
|
|
129
|
+
this.cache[currentPage] &&
|
|
130
|
+
(this.cache[currentPage].fontColor = color);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
this.navigationBarElement.style.color = color;
|
|
134
|
+
}
|
|
135
|
+
setTitle(title) {
|
|
136
|
+
var _a, _b, _c;
|
|
137
|
+
const currentPage = this.pageContext.currentPage;
|
|
138
|
+
let proceedTitle;
|
|
139
|
+
if (typeof title === 'string') {
|
|
140
|
+
proceedTitle = title;
|
|
141
|
+
this.cache[currentPage] &&
|
|
142
|
+
(this.cache[currentPage].title = proceedTitle);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
const cacheValue = (_a = this.cache[currentPage]) === null || _a === void 0 ? void 0 : _a.title;
|
|
146
|
+
if (typeof cacheValue === 'string') {
|
|
147
|
+
proceedTitle = cacheValue;
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
proceedTitle = (_c = (_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationBarTitleText) !== null && _c !== void 0 ? _c : document.title;
|
|
151
|
+
this.cache[currentPage] &&
|
|
152
|
+
(this.cache[currentPage].title = proceedTitle);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
|
|
156
|
+
if (!this.isLoadDdEntry) {
|
|
157
|
+
this.isLoadDdEntry = true;
|
|
158
|
+
require('dingtalk-jsapi/platform');
|
|
159
|
+
}
|
|
160
|
+
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
161
|
+
setDingTitle({ proceedTitle });
|
|
162
|
+
}
|
|
163
|
+
document.title = proceedTitle;
|
|
164
|
+
if (!this.titleElement)
|
|
165
|
+
return;
|
|
166
|
+
this.titleElement.innerHTML = proceedTitle;
|
|
167
|
+
}
|
|
168
|
+
fnBtnToggleToHome() {
|
|
169
|
+
if (!this.navigationBarElement)
|
|
170
|
+
return;
|
|
171
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-home');
|
|
172
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-back');
|
|
173
|
+
}
|
|
174
|
+
fnBtnToggleToBack() {
|
|
175
|
+
if (!this.navigationBarElement)
|
|
176
|
+
return;
|
|
177
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-home');
|
|
178
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-back');
|
|
179
|
+
}
|
|
180
|
+
fnBtnToggleToNone() {
|
|
181
|
+
if (!this.navigationBarElement)
|
|
182
|
+
return;
|
|
183
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-home');
|
|
184
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-back');
|
|
185
|
+
}
|
|
186
|
+
setNavigationBarVisible(show) {
|
|
187
|
+
var _a, _b;
|
|
188
|
+
let shouldShow;
|
|
189
|
+
if (typeof show === 'boolean') {
|
|
190
|
+
shouldShow = show;
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
shouldShow = (_a = this.pageContext.config.window) === null || _a === void 0 ? void 0 : _a.navigationStyle;
|
|
194
|
+
if (typeof ((_b = this.pageContext.pageConfig) === null || _b === void 0 ? void 0 : _b.navigationStyle) === 'string') {
|
|
195
|
+
shouldShow = this.pageContext.pageConfig.navigationStyle;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (shouldShow === 'default') {
|
|
199
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-show');
|
|
200
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-hide');
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
this.navigationBarElement.classList.add('taro-navigation-bar-hide');
|
|
204
|
+
this.navigationBarElement.classList.remove('taro-navigation-bar-show');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export { NavigationBarHandler as default };
|
package/dist/router/page.d.ts
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
+
import NavigationBarHandler from "./navigation-bar.js";
|
|
1
2
|
import { PageInstance } from '@tarojs/runtime';
|
|
2
3
|
import { PageConfig, RouterAnimate } from '@tarojs/taro';
|
|
3
4
|
import { History } from "../history.js";
|
|
4
5
|
import { Route, SpaRouterConfig } from '../../types/router';
|
|
5
6
|
declare class PageHandler {
|
|
6
7
|
history: History;
|
|
7
|
-
|
|
8
|
+
config: SpaRouterConfig;
|
|
8
9
|
protected readonly defaultAnimation: RouterAnimate;
|
|
9
10
|
protected unloadTimer: ReturnType<typeof setTimeout> | null;
|
|
10
11
|
protected hideTimer: ReturnType<typeof setTimeout> | null;
|
|
11
12
|
protected lastHidePage: HTMLElement | null;
|
|
12
13
|
protected lastUnloadPage: PageInstance | null;
|
|
14
|
+
protected navigationBarHandler: NavigationBarHandler;
|
|
13
15
|
homePage: string;
|
|
14
16
|
constructor(config: SpaRouterConfig, history: History);
|
|
15
17
|
get currentPage(): string;
|
package/dist/router/page.js
CHANGED
|
@@ -5,6 +5,7 @@ import { bindPageScroll } from '../events/scroll.js';
|
|
|
5
5
|
import { setHistory, history } from '../history.js';
|
|
6
6
|
import { loadAnimateStyle, loadRouterStyle } from '../style.js';
|
|
7
7
|
import { routesAlias } from '../utils/index.js';
|
|
8
|
+
import NavigationBarHandler from './navigation-bar.js';
|
|
8
9
|
import stacks from './stack.js';
|
|
9
10
|
|
|
10
11
|
/* eslint-disable dot-notation */
|
|
@@ -15,6 +16,7 @@ class PageHandler {
|
|
|
15
16
|
this.config = config;
|
|
16
17
|
this.homePage = getHomePage(this.routes[0].path, this.basename, this.customRoutes, this.config.entryPagePath);
|
|
17
18
|
this.mount();
|
|
19
|
+
this.navigationBarHandler = new NavigationBarHandler(this);
|
|
18
20
|
}
|
|
19
21
|
get currentPage() {
|
|
20
22
|
const routePath = getCurrentPage(this.routerMode, this.basename);
|
|
@@ -158,6 +160,7 @@ class PageHandler {
|
|
|
158
160
|
this.isDefaultNavigationStyle() && pageEl.classList.add('taro_navigation_page');
|
|
159
161
|
this.addAnimation(pageEl, pageNo === 0);
|
|
160
162
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
163
|
+
this.navigationBarHandler.load();
|
|
161
164
|
this.bindPageEvents(page, pageConfig);
|
|
162
165
|
this.triggerRouterChange();
|
|
163
166
|
}
|
|
@@ -170,6 +173,7 @@ class PageHandler {
|
|
|
170
173
|
this.isDefaultNavigationStyle() && (pageEl === null || pageEl === void 0 ? void 0 : pageEl.classList.add('taro_navigation_page'));
|
|
171
174
|
this.addAnimation(pageEl, pageNo === 0);
|
|
172
175
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
176
|
+
this.navigationBarHandler.load();
|
|
173
177
|
this.onReady(page, true);
|
|
174
178
|
this.bindPageEvents(page, pageConfig);
|
|
175
179
|
this.triggerRouterChange();
|
|
@@ -224,6 +228,7 @@ class PageHandler {
|
|
|
224
228
|
pageEl.classList.remove('taro_page_shade');
|
|
225
229
|
this.addAnimation(pageEl, pageNo === 0);
|
|
226
230
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
231
|
+
this.navigationBarHandler.load();
|
|
227
232
|
this.bindPageEvents(page, pageConfig);
|
|
228
233
|
this.triggerRouterChange();
|
|
229
234
|
}
|
|
@@ -233,6 +238,7 @@ class PageHandler {
|
|
|
233
238
|
pageEl = this.getPageContainer(page);
|
|
234
239
|
this.addAnimation(pageEl, pageNo === 0);
|
|
235
240
|
(_a = page.onShow) === null || _a === void 0 ? void 0 : _a.call(page);
|
|
241
|
+
this.navigationBarHandler.load();
|
|
236
242
|
this.onReady(page, false);
|
|
237
243
|
this.bindPageEvents(page, pageConfig);
|
|
238
244
|
this.triggerRouterChange();
|
package/dist/router/spa.js
CHANGED
|
@@ -4,7 +4,6 @@ import { Action } from 'history';
|
|
|
4
4
|
import UniversalRouter from 'universal-router';
|
|
5
5
|
import { prependBasename } from '../history.js';
|
|
6
6
|
import { routesAlias } from '../utils/index.js';
|
|
7
|
-
import { setTitle } from '../utils/navigate.js';
|
|
8
7
|
import { RouterConfig } from './index.js';
|
|
9
8
|
import PageHandler from './page.js';
|
|
10
9
|
import stacks from './stack.js';
|
|
@@ -40,7 +39,7 @@ function createRouter(history, app, config, framework) {
|
|
|
40
39
|
(_a = app.onLaunch) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
41
40
|
app.onError && window.addEventListener('error', e => { var _a; return (_a = app.onError) === null || _a === void 0 ? void 0 : _a.call(app, e.message); });
|
|
42
41
|
const render = ({ location, action }) => __awaiter(this, void 0, void 0, function* () {
|
|
43
|
-
var _c, _d, _e, _f, _g, _h, _j, _k
|
|
42
|
+
var _c, _d, _e, _f, _g, _h, _j, _k;
|
|
44
43
|
handler.pathname = decodeURI(location.pathname);
|
|
45
44
|
if ((_c = window.__taroAppConfig) === null || _c === void 0 ? void 0 : _c.usingWindowScroll)
|
|
46
45
|
window.scrollTo(0, 0);
|
|
@@ -80,7 +79,6 @@ function createRouter(history, app, config, framework) {
|
|
|
80
79
|
let navigationBarTextStyle = ((_g = config === null || config === void 0 ? void 0 : config.window) === null || _g === void 0 ? void 0 : _g.navigationBarTextStyle) || 'white';
|
|
81
80
|
let navigationBarBackgroundColor = ((_h = config === null || config === void 0 ? void 0 : config.window) === null || _h === void 0 ? void 0 : _h.navigationBarBackgroundColor) || '#000000';
|
|
82
81
|
if (pageConfig) {
|
|
83
|
-
setTitle((_j = pageConfig.navigationBarTitleText) !== null && _j !== void 0 ? _j : document.title);
|
|
84
82
|
if (typeof pageConfig.enablePullDownRefresh === 'boolean') {
|
|
85
83
|
enablePullDownRefresh = pageConfig.enablePullDownRefresh;
|
|
86
84
|
}
|
|
@@ -97,7 +95,7 @@ function createRouter(history, app, config, framework) {
|
|
|
97
95
|
eventCenter.trigger('__taroSetNavigationStyle', navigationStyle, navigationBarTextStyle, navigationBarBackgroundColor);
|
|
98
96
|
const currentPage = Current.page;
|
|
99
97
|
const pathname = handler.pathname;
|
|
100
|
-
const methodName = (
|
|
98
|
+
const methodName = (_j = stacks.method) !== null && _j !== void 0 ? _j : '';
|
|
101
99
|
const cacheTabs = stacks.getTabs();
|
|
102
100
|
let shouldLoad = false;
|
|
103
101
|
stacks.method = '';
|
|
@@ -163,7 +161,7 @@ function createRouter(history, app, config, framework) {
|
|
|
163
161
|
shouldLoad = true;
|
|
164
162
|
}
|
|
165
163
|
if (shouldLoad || stacks.length < 1) {
|
|
166
|
-
const el = (
|
|
164
|
+
const el = (_k = element.default) !== null && _k !== void 0 ? _k : element;
|
|
167
165
|
const loadConfig = Object.assign({}, pageConfig);
|
|
168
166
|
const stacksIndex = stacks.length;
|
|
169
167
|
delete loadConfig['path'];
|
|
@@ -188,6 +186,15 @@ function createRouter(history, app, config, framework) {
|
|
|
188
186
|
}
|
|
189
187
|
render({ location: history.location, action: Action.Push });
|
|
190
188
|
(_b = app.onShow) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
|
|
189
|
+
window.addEventListener('visibilitychange', () => {
|
|
190
|
+
var _a, _b;
|
|
191
|
+
if (document.visibilityState === 'visible') {
|
|
192
|
+
(_a = app.onShow) === null || _a === void 0 ? void 0 : _a.call(app, launchParam);
|
|
193
|
+
}
|
|
194
|
+
else {
|
|
195
|
+
(_b = app.onHide) === null || _b === void 0 ? void 0 : _b.call(app, launchParam);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
191
198
|
return history.listen(render);
|
|
192
199
|
}
|
|
193
200
|
|
package/dist/style.d.ts
CHANGED
|
@@ -6,5 +6,9 @@ declare function loadAnimateStyle(ms?: number): void;
|
|
|
6
6
|
* 插入路由相关样式
|
|
7
7
|
*/
|
|
8
8
|
declare function loadRouterStyle(enableTabBar: boolean, enableWindowScroll: boolean): void;
|
|
9
|
+
/**
|
|
10
|
+
* 插入导航栏相关的样式
|
|
11
|
+
*/
|
|
12
|
+
declare function loadNavigationBarStyle(): void;
|
|
9
13
|
declare function addStyle(css: any): void;
|
|
10
|
-
export { loadAnimateStyle, loadRouterStyle, addStyle };
|
|
14
|
+
export { loadAnimateStyle, loadRouterStyle, loadNavigationBarStyle, addStyle };
|
package/dist/style.js
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
function loadAnimateStyle(ms = 300) {
|
|
5
5
|
const css = `
|
|
6
|
+
body {
|
|
7
|
+
overflow: hidden; // 防止 iOS 页面滚动
|
|
8
|
+
}
|
|
6
9
|
.taro_router > .taro_page {
|
|
7
10
|
position: absolute;
|
|
8
11
|
left: 0;
|
|
@@ -64,6 +67,60 @@ ${enableTabBar ? `
|
|
|
64
67
|
`;
|
|
65
68
|
addStyle(css);
|
|
66
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* 插入导航栏相关的样式
|
|
72
|
+
*/
|
|
73
|
+
function loadNavigationBarStyle() {
|
|
74
|
+
const css = `
|
|
75
|
+
.taro-navigation-bar-show {
|
|
76
|
+
background: white;
|
|
77
|
+
position: sticky;
|
|
78
|
+
z-index: 500;
|
|
79
|
+
top: 0;
|
|
80
|
+
padding-bottom: 8px;
|
|
81
|
+
padding-top: calc(env(safe-area-inset-top) + 8px);
|
|
82
|
+
display: flex;
|
|
83
|
+
justify-content: center;
|
|
84
|
+
align-items: center;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.taro-navigation-bar-hide {
|
|
88
|
+
display: none;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
taro-navigation-bar-title {
|
|
92
|
+
font-size: 24px;
|
|
93
|
+
height: 24px;
|
|
94
|
+
line-height: 24px;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.taro-navigation-bar-no-icon > taro-navigation-bar-home {
|
|
98
|
+
display: none;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.taro-navigation-bar-no-icon > taro-navigation-bar-back {
|
|
102
|
+
display: none;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
.taro-navigation-bar-home > taro-navigation-bar-home {
|
|
106
|
+
display: block;
|
|
107
|
+
left: 8px;
|
|
108
|
+
position: absolute;
|
|
109
|
+
width: 24px;
|
|
110
|
+
height: 24px;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.taro-navigation-bar-back > taro-navigation-bar-back {
|
|
114
|
+
display: block;
|
|
115
|
+
left: 8px;
|
|
116
|
+
position: absolute;
|
|
117
|
+
width: 24px;
|
|
118
|
+
height: 24px;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
`;
|
|
122
|
+
addStyle(css);
|
|
123
|
+
}
|
|
67
124
|
function addStyle(css) {
|
|
68
125
|
if (!css)
|
|
69
126
|
return;
|
|
@@ -72,4 +129,4 @@ function addStyle(css) {
|
|
|
72
129
|
document.getElementsByTagName('head')[0].appendChild(style);
|
|
73
130
|
}
|
|
74
131
|
|
|
75
|
-
export { addStyle, loadAnimateStyle, loadRouterStyle };
|
|
132
|
+
export { addStyle, loadAnimateStyle, loadNavigationBarStyle, loadRouterStyle };
|
package/dist/utils/index.js
CHANGED
package/dist/utils/navigate.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
declare const isWeixin: () => boolean;
|
|
2
2
|
declare const isDingTalk: () => boolean;
|
|
3
|
-
declare function
|
|
4
|
-
|
|
3
|
+
declare function setMpaTitle(title: string): void;
|
|
4
|
+
declare function setTitle(title: string): void;
|
|
5
|
+
declare function setNavigationBarStyle(option: {
|
|
6
|
+
backgroundColor: string;
|
|
7
|
+
frontColor: string;
|
|
8
|
+
}): void;
|
|
9
|
+
export { isWeixin, isDingTalk, setMpaTitle, setTitle, setNavigationBarStyle };
|
package/dist/utils/navigate.js
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { eventCenter } from '@tarojs/runtime';
|
|
2
2
|
|
|
3
|
-
let preTitle = document.title;
|
|
4
|
-
let isLoadDdEntry = false;
|
|
5
3
|
const isWeixin = () => !!navigator.userAgent.match(/\bMicroMessenger\b/ig);
|
|
6
4
|
const isDingTalk = () => !!navigator.userAgent.match(/\bDingTalk\b/ig);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
19
|
-
setDingTitle({ title });
|
|
5
|
+
let preTitle = document.title;
|
|
6
|
+
let isLoadDdEntry = false;
|
|
7
|
+
function setMpaTitle(title) {
|
|
8
|
+
if (preTitle === title)
|
|
9
|
+
return;
|
|
10
|
+
document.title = title;
|
|
11
|
+
preTitle = title;
|
|
12
|
+
if (process.env.SUPPORT_DINGTALK_NAVIGATE !== 'disabled' && isDingTalk()) {
|
|
13
|
+
if (!isLoadDdEntry) {
|
|
14
|
+
isLoadDdEntry = true;
|
|
15
|
+
require('dingtalk-jsapi/platform');
|
|
20
16
|
}
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
const setDingTitle = require('dingtalk-jsapi/api/biz/navigation/setTitle').default;
|
|
18
|
+
setDingTitle({ title });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function setTitle(title) {
|
|
22
|
+
eventCenter.trigger('__taroH5SetNavigationTitle', title);
|
|
23
|
+
}
|
|
24
|
+
function setNavigationBarStyle(option) {
|
|
25
|
+
eventCenter.trigger('__taroH5setNavigationBarColor', option);
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
export { isDingTalk, isWeixin, setTitle };
|
|
28
|
+
export { isDingTalk, isWeixin, setMpaTitle, setNavigationBarStyle, setTitle };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tarojs/router",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.21",
|
|
4
4
|
"description": "Taro-router",
|
|
5
5
|
"browser": "dist/index.js",
|
|
6
6
|
"main:h5": "dist/index.esm.js",
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"rollup-plugin-ts": "^3.0.2",
|
|
45
45
|
"ts-jest": "^29.0.5",
|
|
46
46
|
"typescript": "^4.7.4",
|
|
47
|
-
"@tarojs/
|
|
48
|
-
"@tarojs/
|
|
47
|
+
"@tarojs/taro": "4.0.0-beta.21",
|
|
48
|
+
"@tarojs/runtime": "4.0.0-beta.21"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@tarojs/
|
|
52
|
-
"@tarojs/
|
|
51
|
+
"@tarojs/runtime": "4.0.0-beta.21",
|
|
52
|
+
"@tarojs/taro": "4.0.0-beta.21"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"prebuild": "pnpm run clean",
|