@ray-js/framework 1.3.22 → 1.3.23
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.md +9 -0
- package/lib/api/tabBar.js +0 -2
- package/lib/app/createApp.js +6 -7
- package/lib/app/createApp.jsx +18 -0
- package/lib/app/createAppInstance.js +3 -3
- package/lib/app/createAppInstance.jsx +12 -0
- package/lib/app/index.js +1 -1
- package/lib/app/index.jsx +6 -0
- package/lib/components/AppWrapper/index.d.ts +1 -1
- package/lib/components/AppWrapper/index.js +24 -47
- package/lib/components/AppWrapper/index.jsx +29 -0
- package/lib/components/Application/index.d.ts +2 -2
- package/lib/components/Application/index.js +63 -90
- package/lib/components/Application/index.jsx +59 -0
- package/lib/components/PageWrapper/index.d.ts +2 -2
- package/lib/components/PageWrapper/index.js +113 -144
- package/lib/components/PageWrapper/index.jsx +116 -0
- package/lib/components/TabBar/index.d.ts +2 -2
- package/lib/components/TabBar/index.js +59 -93
- package/lib/components/TabBar/index.jsx +55 -0
- package/lib/runtime/index.js +2 -1
- package/lib/runtime/responsive.js +8 -10
- package/lib/store/appStore.js +5 -8
- package/lib/utils/normalizeBasename.js +0 -5
- package/lib/utils/withPublicPath.js +0 -2
- package/package.json +10 -10
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Copyright © 2014-2022 Tuya.inc
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/lib/api/tabBar.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { appStoreEmitter, actions } from '../store/appStore';
|
|
2
2
|
export function showTabBar(options) {
|
|
3
3
|
var _options$success, _options$complete;
|
|
4
|
-
|
|
5
4
|
appStoreEmitter.emit(actions.toggleTabBar, {
|
|
6
5
|
visible: true,
|
|
7
6
|
animation: options.animation
|
|
@@ -11,7 +10,6 @@ export function showTabBar(options) {
|
|
|
11
10
|
}
|
|
12
11
|
export function hideTabBar(options) {
|
|
13
12
|
var _options$success2, _options$complete2;
|
|
14
|
-
|
|
15
13
|
appStoreEmitter.emit(actions.toggleTabBar, {
|
|
16
14
|
visible: false,
|
|
17
15
|
animation: options.animation
|
package/lib/app/createApp.js
CHANGED
|
@@ -7,15 +7,14 @@ import { Application } from '../components/Application';
|
|
|
7
7
|
import { normalizeBasename } from '../utils';
|
|
8
8
|
export function createApp(options) {
|
|
9
9
|
var _cfg$globalConfig;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var root = document.createElement('div');
|
|
10
|
+
const cfg = _objectSpread({}, options);
|
|
11
|
+
const root = document.createElement('div');
|
|
14
12
|
root.id = 'root';
|
|
15
|
-
document.body.appendChild(root);
|
|
16
|
-
|
|
13
|
+
document.body.appendChild(root);
|
|
14
|
+
// 入口初始化 格式数据
|
|
17
15
|
set(cfg, 'globalConfig.basename', normalizeBasename((_cfg$globalConfig = cfg.globalConfig) === null || _cfg$globalConfig === void 0 ? void 0 : _cfg$globalConfig.basename));
|
|
18
|
-
set(cfg, 'tabBar', normalizeTabBar(cfg.tabBar, cfg.routes));
|
|
16
|
+
set(cfg, 'tabBar', normalizeTabBar(cfg.tabBar, cfg.routes));
|
|
19
17
|
|
|
18
|
+
// 作为 web 构建的启动入口文件
|
|
20
19
|
ReactDOM.render( /*#__PURE__*/React.createElement(Application, cfg), root);
|
|
21
20
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import set from 'lodash.set';
|
|
4
|
+
import { normalizeTabBar } from '@ray-js/framework-shared';
|
|
5
|
+
import { Application } from '../components/Application';
|
|
6
|
+
import { normalizeBasename } from '../utils';
|
|
7
|
+
export function createApp(options) {
|
|
8
|
+
var _a;
|
|
9
|
+
const cfg = Object.assign({}, options);
|
|
10
|
+
const root = document.createElement('div');
|
|
11
|
+
root.id = 'root';
|
|
12
|
+
document.body.appendChild(root);
|
|
13
|
+
// 入口初始化 格式数据
|
|
14
|
+
set(cfg, 'globalConfig.basename', normalizeBasename((_a = cfg.globalConfig) === null || _a === void 0 ? void 0 : _a.basename));
|
|
15
|
+
set(cfg, 'tabBar', normalizeTabBar(cfg.tabBar, cfg.routes));
|
|
16
|
+
// 作为 web 构建的启动入口文件
|
|
17
|
+
ReactDOM.render(<Application {...cfg}/>, root);
|
|
18
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { getCurrent } from '@ray-js/runtime';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* 创建抽象的 App Instance 对标到小程序,提供给 getApp() 进行使用
|
|
4
5
|
* @param appThis
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
7
|
export function createAppInstance(appThis) {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const current = getCurrent();
|
|
9
|
+
// App 实例仅且注册一次
|
|
10
10
|
if (!current.app) {
|
|
11
11
|
current.app = appThis;
|
|
12
12
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { getCurrent } from '@ray-js/runtime';
|
|
2
|
+
/**
|
|
3
|
+
* 创建抽象的 App Instance 对标到小程序,提供给 getApp() 进行使用
|
|
4
|
+
* @param appThis
|
|
5
|
+
*/
|
|
6
|
+
export function createAppInstance(appThis) {
|
|
7
|
+
const current = getCurrent();
|
|
8
|
+
// App 实例仅且注册一次
|
|
9
|
+
if (!current.app) {
|
|
10
|
+
current.app = appThis;
|
|
11
|
+
}
|
|
12
|
+
}
|
package/lib/app/index.js
CHANGED
|
@@ -1,53 +1,30 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
-
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
1
|
import React from 'react';
|
|
6
2
|
import styles from './index.module.less';
|
|
7
3
|
import { getApp } from '../../app';
|
|
8
4
|
import location from '@ray-js/location';
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
_createClass(AppWrapper, [{
|
|
21
|
-
key: "componentDidMount",
|
|
22
|
-
value: function componentDidMount() {
|
|
23
|
-
var app = getApp();
|
|
24
|
-
|
|
25
|
-
if (typeof app.onLaunch === 'function') {
|
|
26
|
-
app.onLaunch({
|
|
27
|
-
path: location.pathname,
|
|
28
|
-
query: location.query,
|
|
29
|
-
params: location.params
|
|
30
|
-
});
|
|
31
|
-
} // 初次展现
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (typeof app.onShow === 'function') {
|
|
35
|
-
app.onShow({
|
|
36
|
-
path: location.pathname,
|
|
37
|
-
query: location.query,
|
|
38
|
-
params: location.params
|
|
39
|
-
});
|
|
40
|
-
}
|
|
5
|
+
export class AppWrapper extends React.Component {
|
|
6
|
+
componentDidMount() {
|
|
7
|
+
const app = getApp();
|
|
8
|
+
if (typeof app.onLaunch === 'function') {
|
|
9
|
+
app.onLaunch({
|
|
10
|
+
path: location.pathname,
|
|
11
|
+
query: location.query,
|
|
12
|
+
params: location.params
|
|
13
|
+
});
|
|
41
14
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
15
|
+
// 初次展现
|
|
16
|
+
if (typeof app.onShow === 'function') {
|
|
17
|
+
app.onShow({
|
|
18
|
+
path: location.pathname,
|
|
19
|
+
query: location.query,
|
|
20
|
+
params: location.params
|
|
21
|
+
});
|
|
49
22
|
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
23
|
+
}
|
|
24
|
+
render() {
|
|
25
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
26
|
+
id: "Application",
|
|
27
|
+
className: styles.application
|
|
28
|
+
}, this.props.children);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styles from './index.module.less';
|
|
3
|
+
import { getApp } from '../../app';
|
|
4
|
+
import location from '@ray-js/location';
|
|
5
|
+
export class AppWrapper extends React.Component {
|
|
6
|
+
componentDidMount() {
|
|
7
|
+
const app = getApp();
|
|
8
|
+
if (typeof app.onLaunch === 'function') {
|
|
9
|
+
app.onLaunch({
|
|
10
|
+
path: location.pathname,
|
|
11
|
+
query: location.query,
|
|
12
|
+
params: location.params,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
// 初次展现
|
|
16
|
+
if (typeof app.onShow === 'function') {
|
|
17
|
+
app.onShow({
|
|
18
|
+
path: location.pathname,
|
|
19
|
+
query: location.query,
|
|
20
|
+
params: location.params,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
render() {
|
|
25
|
+
return (<div id='Application' className={styles.application}>
|
|
26
|
+
{this.props.children}
|
|
27
|
+
</div>);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../../runtime';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import * as types from '@ray-js/types';
|
|
4
|
-
export
|
|
4
|
+
export type ApplicationProps = {
|
|
5
5
|
globalConfig: types.GlobalConfig & types.WebGlobalConfig;
|
|
6
6
|
routes: types.Routes;
|
|
7
7
|
tabBar: types.TabBar;
|
|
@@ -15,5 +15,5 @@ export declare class Application extends React.Component<ApplicationProps, {
|
|
|
15
15
|
constructor(props: Readonly<ApplicationProps>);
|
|
16
16
|
componentDidMount(): void;
|
|
17
17
|
getGlobalConfig: (path: string | string[], defaultValue?: any) => any;
|
|
18
|
-
render(): JSX.Element | null;
|
|
18
|
+
render(): React.JSX.Element | null;
|
|
19
19
|
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
4
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
-
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
6
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
7
1
|
import '../../runtime';
|
|
8
2
|
import React from 'react';
|
|
9
3
|
import { createRouter } from '@ray-js/router';
|
|
@@ -12,94 +6,73 @@ import { get } from '../../utils';
|
|
|
12
6
|
import { AppWrapper } from '../AppWrapper';
|
|
13
7
|
import { PageWrapper } from '../PageWrapper';
|
|
14
8
|
import { TabBar } from '../TabBar';
|
|
15
|
-
|
|
16
|
-
var isClassComponent = function (Component) {
|
|
9
|
+
const isClassComponent = Component => {
|
|
17
10
|
return Component.prototype && typeof Component.prototype.render === 'function';
|
|
18
11
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
function Application(props) {
|
|
26
|
-
var _this;
|
|
27
|
-
|
|
28
|
-
_classCallCheck(this, Application);
|
|
29
|
-
|
|
30
|
-
_this = _super.call(this, props);
|
|
31
|
-
|
|
32
|
-
_defineProperty(_assertThisInitialized(_this), "getGlobalConfig", function (path, defaultValue) {
|
|
33
|
-
var _this$props$globalCon = _this.props.globalConfig,
|
|
34
|
-
globalConfig = _this$props$globalCon === void 0 ? {} : _this$props$globalCon;
|
|
35
|
-
var value = get(globalConfig, path, defaultValue);
|
|
36
|
-
return value;
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
_this.state = {};
|
|
40
|
-
|
|
41
|
-
var title = _this.getGlobalConfig(['window', 'navigationBarTitleText'], 'Ray App');
|
|
42
|
-
|
|
12
|
+
export class Application extends React.Component {
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(props);
|
|
15
|
+
this.state = {};
|
|
16
|
+
const title = this.getGlobalConfig(['window', 'navigationBarTitleText'], 'Ray App');
|
|
43
17
|
document.title = title;
|
|
44
|
-
return _this;
|
|
45
18
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
_this2.setState({
|
|
66
|
-
component: component,
|
|
67
|
-
matchedPage: props.page
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}, {
|
|
73
|
-
key: "render",
|
|
74
|
-
value: function render() {
|
|
75
|
-
var _this$props2 = this.props,
|
|
76
|
-
App = _this$props2.app,
|
|
77
|
-
tabBar = _this$props2.tabBar;
|
|
78
|
-
var basename = this.getGlobalConfig('basename', '/') || '/';
|
|
79
|
-
var _this$state = this.state,
|
|
80
|
-
PageComponent = _this$state.component,
|
|
81
|
-
matchedPage = _this$state.matchedPage; // 空页面暂不渲染,否则 appEvent 无法应用到页面内部
|
|
82
|
-
|
|
83
|
-
if (!matchedPage) {
|
|
84
|
-
return null;
|
|
19
|
+
componentDidMount() {
|
|
20
|
+
const {
|
|
21
|
+
routes,
|
|
22
|
+
pages,
|
|
23
|
+
tabBar
|
|
24
|
+
} = this.props;
|
|
25
|
+
const basename = this.getGlobalConfig('basename', '/') || '/';
|
|
26
|
+
const bgColor = this.getGlobalConfig(['window', 'backgroundColor'], '#fff');
|
|
27
|
+
document.body.style.backgroundColor = bgColor;
|
|
28
|
+
createRouter({
|
|
29
|
+
basename,
|
|
30
|
+
routes,
|
|
31
|
+
pages,
|
|
32
|
+
tabBar,
|
|
33
|
+
onChange: (component, props) => {
|
|
34
|
+
this.setState({
|
|
35
|
+
component,
|
|
36
|
+
matchedPage: props.page
|
|
37
|
+
});
|
|
85
38
|
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
getGlobalConfig = (path, defaultValue) => {
|
|
42
|
+
const {
|
|
43
|
+
globalConfig = {}
|
|
44
|
+
} = this.props;
|
|
45
|
+
const value = get(globalConfig, path, defaultValue);
|
|
46
|
+
return value;
|
|
47
|
+
};
|
|
48
|
+
render() {
|
|
49
|
+
const {
|
|
50
|
+
app: App,
|
|
51
|
+
tabBar
|
|
52
|
+
} = this.props;
|
|
53
|
+
const basename = this.getGlobalConfig('basename', '/') || '/';
|
|
54
|
+
const {
|
|
55
|
+
component: PageComponent,
|
|
56
|
+
matchedPage
|
|
57
|
+
} = this.state;
|
|
86
58
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
createAppInstance(appThis);
|
|
91
|
-
}
|
|
92
|
-
}, /*#__PURE__*/React.createElement(PageWrapper, {
|
|
93
|
-
isClassType: isClassType,
|
|
94
|
-
page: matchedPage,
|
|
95
|
-
key: matchedPage.route,
|
|
96
|
-
getGlobalConfig: this.getGlobalConfig
|
|
97
|
-
}, /*#__PURE__*/React.createElement(PageComponent, null)), matchedPage.isTabBar && /*#__PURE__*/React.createElement(TabBar, {
|
|
98
|
-
basename: basename,
|
|
99
|
-
config: tabBar
|
|
100
|
-
})));
|
|
59
|
+
// 空页面暂不渲染,否则 appEvent 无法应用到页面内部
|
|
60
|
+
if (!matchedPage) {
|
|
61
|
+
return null;
|
|
101
62
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
63
|
+
const isClassType = isClassComponent(PageComponent);
|
|
64
|
+
return /*#__PURE__*/React.createElement(AppWrapper, null, /*#__PURE__*/React.createElement(App, {
|
|
65
|
+
ref: appThis => {
|
|
66
|
+
createAppInstance(appThis);
|
|
67
|
+
}
|
|
68
|
+
}, /*#__PURE__*/React.createElement(PageWrapper, {
|
|
69
|
+
isClassType: isClassType,
|
|
70
|
+
page: matchedPage,
|
|
71
|
+
key: matchedPage.route,
|
|
72
|
+
getGlobalConfig: this.getGlobalConfig
|
|
73
|
+
}, /*#__PURE__*/React.createElement(PageComponent, null)), matchedPage.isTabBar && /*#__PURE__*/React.createElement(TabBar, {
|
|
74
|
+
basename: basename,
|
|
75
|
+
config: tabBar
|
|
76
|
+
})));
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import '../../runtime';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { createRouter } from '@ray-js/router';
|
|
4
|
+
import { createAppInstance } from '../../app/createAppInstance';
|
|
5
|
+
import { get } from '../../utils';
|
|
6
|
+
import { AppWrapper } from '../AppWrapper';
|
|
7
|
+
import { PageWrapper } from '../PageWrapper';
|
|
8
|
+
import { TabBar } from '../TabBar';
|
|
9
|
+
const isClassComponent = (Component) => {
|
|
10
|
+
return Component.prototype && typeof Component.prototype.render === 'function';
|
|
11
|
+
};
|
|
12
|
+
export class Application extends React.Component {
|
|
13
|
+
constructor(props) {
|
|
14
|
+
super(props);
|
|
15
|
+
this.getGlobalConfig = (path, defaultValue) => {
|
|
16
|
+
const { globalConfig = {} } = this.props;
|
|
17
|
+
const value = get(globalConfig, path, defaultValue);
|
|
18
|
+
return value;
|
|
19
|
+
};
|
|
20
|
+
this.state = {};
|
|
21
|
+
const title = this.getGlobalConfig(['window', 'navigationBarTitleText'], 'Ray App');
|
|
22
|
+
document.title = title;
|
|
23
|
+
}
|
|
24
|
+
componentDidMount() {
|
|
25
|
+
const { routes, pages, tabBar } = this.props;
|
|
26
|
+
const basename = this.getGlobalConfig('basename', '/') || '/';
|
|
27
|
+
const bgColor = this.getGlobalConfig(['window', 'backgroundColor'], '#fff');
|
|
28
|
+
document.body.style.backgroundColor = bgColor;
|
|
29
|
+
createRouter({
|
|
30
|
+
basename,
|
|
31
|
+
routes,
|
|
32
|
+
pages,
|
|
33
|
+
tabBar,
|
|
34
|
+
onChange: (component, props) => {
|
|
35
|
+
this.setState({ component, matchedPage: props.page });
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
render() {
|
|
40
|
+
const { app: App, tabBar } = this.props;
|
|
41
|
+
const basename = this.getGlobalConfig('basename', '/') || '/';
|
|
42
|
+
const { component: PageComponent, matchedPage } = this.state;
|
|
43
|
+
// 空页面暂不渲染,否则 appEvent 无法应用到页面内部
|
|
44
|
+
if (!matchedPage) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const isClassType = isClassComponent(PageComponent);
|
|
48
|
+
return (<AppWrapper>
|
|
49
|
+
<App ref={(appThis) => {
|
|
50
|
+
createAppInstance(appThis);
|
|
51
|
+
}}>
|
|
52
|
+
<PageWrapper isClassType={isClassType} page={matchedPage} key={matchedPage.route} getGlobalConfig={this.getGlobalConfig}>
|
|
53
|
+
<PageComponent />
|
|
54
|
+
</PageWrapper>
|
|
55
|
+
{matchedPage.isTabBar && <TabBar basename={basename} config={tabBar}/>}
|
|
56
|
+
</App>
|
|
57
|
+
</AppWrapper>);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { PageInstance } from '@ray-js/runtime';
|
|
3
3
|
import { Page, PageConfig } from '@ray-js/types';
|
|
4
4
|
import './index.module.less';
|
|
5
|
-
|
|
5
|
+
type PageWrapperProps = {
|
|
6
6
|
isClassType: boolean;
|
|
7
7
|
page: Page;
|
|
8
8
|
getGlobalConfig: (path: string | string[], defaultValue?: any) => any;
|
|
@@ -20,6 +20,6 @@ export declare class PageWrapper extends React.Component<PageWrapperProps, any>
|
|
|
20
20
|
handlePageScroll: () => void;
|
|
21
21
|
checkReachBottom: () => void;
|
|
22
22
|
getPageConfig: (field: keyof PageConfig | string[], defaultValue?: any) => any;
|
|
23
|
-
render(): JSX.Element;
|
|
23
|
+
render(): React.JSX.Element;
|
|
24
24
|
}
|
|
25
25
|
export {};
|
|
@@ -1,162 +1,131 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
4
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
-
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
6
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
7
|
-
import "core-js/modules/es.object.to-string.js";
|
|
8
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
9
|
-
import "core-js/modules/es.object.keys.js";
|
|
10
1
|
import React from 'react';
|
|
11
2
|
import { lifecycle, PageInstance, PageInstanceContext } from '@ray-js/runtime';
|
|
12
3
|
import { pageLifecycles } from '@ray-js/types';
|
|
13
4
|
import { get } from '../../utils';
|
|
14
5
|
import './index.module.less';
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
6
|
+
export class PageWrapper extends React.Component {
|
|
7
|
+
$reachBottomDistance = 50;
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super(props);
|
|
10
|
+
this.$instance = new PageInstance();
|
|
11
|
+
lifecycle.addInstance(this.$instance);
|
|
12
|
+
this.getGlobalConfig = this.props.getGlobalConfig;
|
|
13
|
+
}
|
|
14
|
+
componentDidMount() {
|
|
15
|
+
const title = this.getPageConfig('navigationBarTitleText', '');
|
|
16
|
+
document.title = title;
|
|
17
|
+
window.addEventListener('scroll', this.handlePageScroll);
|
|
18
|
+
window.addEventListener('resize', this.handlePageResize);
|
|
19
|
+
const backgroundColor = this.getPageConfig('backgroundColor');
|
|
20
|
+
if (backgroundColor) {
|
|
21
|
+
document.body.style.backgroundColor = backgroundColor;
|
|
22
|
+
}
|
|
26
23
|
|
|
27
|
-
|
|
24
|
+
// 获取页面触底的距离
|
|
25
|
+
this.$reachBottomDistance = this.getPageConfig('onReachBottomDistance', this.getGlobalConfig(['window', 'onReachBottomDistance'], 50) // 全局配置
|
|
26
|
+
);
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
name: pageLifecycles.onResize,
|
|
35
|
-
args: {
|
|
36
|
-
windowWidth: windowWidth,
|
|
37
|
-
windowHeight: windowHeight
|
|
38
|
-
}
|
|
39
|
-
});
|
|
28
|
+
// FIXME: 应用实例化未完成,didMount 从内至外执行
|
|
29
|
+
// 此时触发 onShow onReady 获取不到 getApp 实例,组件内也存在这样的情况
|
|
30
|
+
lifecycle.emit({
|
|
31
|
+
uniqueId: this.$instance.uniqueId,
|
|
32
|
+
name: pageLifecycles.onShow
|
|
40
33
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
scrollTop: window.scrollY
|
|
45
|
-
};
|
|
46
|
-
lifecycle.emit({
|
|
47
|
-
uniqueId: _this.$instance.uniqueId,
|
|
48
|
-
name: pageLifecycles.onPageScroll,
|
|
49
|
-
args: event
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
_this.checkReachBottom();
|
|
34
|
+
lifecycle.emit({
|
|
35
|
+
uniqueId: this.$instance.uniqueId,
|
|
36
|
+
name: pageLifecycles.onReady
|
|
53
37
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
});
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
_this.$isReachBottom = isCurrentReachBottom;
|
|
38
|
+
}
|
|
39
|
+
componentWillUnmount() {
|
|
40
|
+
window.removeEventListener('scroll', this.handlePageScroll);
|
|
41
|
+
window.removeEventListener('resize', this.handlePageResize);
|
|
42
|
+
|
|
43
|
+
// FIXME: 目前是 SPA 的页面直接切换,卸载前直接调用事件
|
|
44
|
+
lifecycle.emit({
|
|
45
|
+
uniqueId: this.$instance.uniqueId,
|
|
46
|
+
name: pageLifecycles.onHide
|
|
68
47
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
var pageConfig = page.config;
|
|
73
|
-
return get(pageConfig, field, defaultValue);
|
|
48
|
+
lifecycle.emit({
|
|
49
|
+
uniqueId: this.$instance.uniqueId,
|
|
50
|
+
name: pageLifecycles.onUnload
|
|
74
51
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
lifecycle.addInstance(_this.$instance);
|
|
78
|
-
_this.getGlobalConfig = _this.props.getGlobalConfig;
|
|
79
|
-
return _this;
|
|
52
|
+
lifecycle.removeInstance(this.$instance);
|
|
53
|
+
// TODO: 实现 onPullDownRefresh 生命周期
|
|
80
54
|
}
|
|
81
55
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}, {
|
|
110
|
-
key: "componentWillUnmount",
|
|
111
|
-
value: function componentWillUnmount() {
|
|
112
|
-
window.removeEventListener('scroll', this.handlePageScroll);
|
|
113
|
-
window.removeEventListener('resize', this.handlePageResize); // FIXME: 目前是 SPA 的页面直接切换,卸载前直接调用事件
|
|
114
|
-
|
|
115
|
-
lifecycle.emit({
|
|
116
|
-
uniqueId: this.$instance.uniqueId,
|
|
117
|
-
name: pageLifecycles.onHide
|
|
118
|
-
});
|
|
56
|
+
handlePageResize = () => {
|
|
57
|
+
const windowWidth = document.documentElement.clientWidth;
|
|
58
|
+
const windowHeight = document.documentElement.clientHeight;
|
|
59
|
+
lifecycle.emit({
|
|
60
|
+
uniqueId: this.$instance.uniqueId,
|
|
61
|
+
name: pageLifecycles.onResize,
|
|
62
|
+
args: {
|
|
63
|
+
windowWidth,
|
|
64
|
+
windowHeight
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
handlePageScroll = () => {
|
|
69
|
+
const event = {
|
|
70
|
+
scrollTop: window.scrollY
|
|
71
|
+
};
|
|
72
|
+
lifecycle.emit({
|
|
73
|
+
uniqueId: this.$instance.uniqueId,
|
|
74
|
+
name: pageLifecycles.onPageScroll,
|
|
75
|
+
args: event
|
|
76
|
+
});
|
|
77
|
+
this.checkReachBottom();
|
|
78
|
+
};
|
|
79
|
+
checkReachBottom = () => {
|
|
80
|
+
const isCurrentReachBottom = document.body.scrollHeight - (window.innerHeight + window.scrollY) <= this.$reachBottomDistance;
|
|
81
|
+
if (!this.$isReachBottom && isCurrentReachBottom) {
|
|
82
|
+
this.$isReachBottom = true;
|
|
119
83
|
lifecycle.emit({
|
|
120
84
|
uniqueId: this.$instance.uniqueId,
|
|
121
|
-
name: pageLifecycles.
|
|
85
|
+
name: pageLifecycles.onReachBottom
|
|
122
86
|
});
|
|
123
|
-
|
|
87
|
+
return;
|
|
124
88
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
89
|
+
this.$isReachBottom = isCurrentReachBottom;
|
|
90
|
+
};
|
|
91
|
+
getPageConfig = (field, defaultValue) => {
|
|
92
|
+
const {
|
|
93
|
+
page
|
|
94
|
+
} = this.props;
|
|
95
|
+
const pageConfig = page.config;
|
|
96
|
+
return get(pageConfig, field, defaultValue);
|
|
97
|
+
};
|
|
98
|
+
render() {
|
|
99
|
+
const {
|
|
100
|
+
page,
|
|
101
|
+
children,
|
|
102
|
+
isClassType
|
|
103
|
+
} = this.props;
|
|
104
|
+
const $instance = this.$instance;
|
|
105
|
+
const globalBackgroundColor = this.getGlobalConfig(['window', 'backgroundColor'], '#fff');
|
|
106
|
+
const backgroundColor = this.getPageConfig('backgroundColor', globalBackgroundColor);
|
|
107
|
+
document.body.style.backgroundColor = backgroundColor;
|
|
108
|
+
return /*#__PURE__*/React.createElement(PageInstanceContext.Provider, {
|
|
109
|
+
value: {
|
|
110
|
+
$instance,
|
|
111
|
+
pageConfig: page.config
|
|
112
|
+
}
|
|
113
|
+
}, /*#__PURE__*/React.createElement("v-page", {
|
|
114
|
+
"data-route": page.route
|
|
115
|
+
}, isClassType ?
|
|
116
|
+
/*#__PURE__*/
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
React.cloneElement(children, {
|
|
119
|
+
ref(ins) {
|
|
120
|
+
if (ins) {
|
|
121
|
+
// 实现 class 生命周期用法的挂载
|
|
122
|
+
Object.keys(pageLifecycles).forEach(event => {
|
|
123
|
+
if (typeof ins[event] === 'function') {
|
|
124
|
+
$instance.registerLifecycle(event, ins, ins[event]);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
156
127
|
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return PageWrapper;
|
|
162
|
-
}(React.Component);
|
|
128
|
+
}
|
|
129
|
+
}) : children));
|
|
130
|
+
}
|
|
131
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { lifecycle, PageInstance, PageInstanceContext } from '@ray-js/runtime';
|
|
3
|
+
import { pageLifecycles } from '@ray-js/types';
|
|
4
|
+
import { get } from '../../utils';
|
|
5
|
+
import './index.module.less';
|
|
6
|
+
export class PageWrapper extends React.Component {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
this.$reachBottomDistance = 50;
|
|
10
|
+
this.handlePageResize = () => {
|
|
11
|
+
const windowWidth = document.documentElement.clientWidth;
|
|
12
|
+
const windowHeight = document.documentElement.clientHeight;
|
|
13
|
+
lifecycle.emit({
|
|
14
|
+
uniqueId: this.$instance.uniqueId,
|
|
15
|
+
name: pageLifecycles.onResize,
|
|
16
|
+
args: { windowWidth, windowHeight },
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
this.handlePageScroll = () => {
|
|
20
|
+
const event = { scrollTop: window.scrollY };
|
|
21
|
+
lifecycle.emit({
|
|
22
|
+
uniqueId: this.$instance.uniqueId,
|
|
23
|
+
name: pageLifecycles.onPageScroll,
|
|
24
|
+
args: event,
|
|
25
|
+
});
|
|
26
|
+
this.checkReachBottom();
|
|
27
|
+
};
|
|
28
|
+
this.checkReachBottom = () => {
|
|
29
|
+
const isCurrentReachBottom = document.body.scrollHeight - (window.innerHeight + window.scrollY) <=
|
|
30
|
+
this.$reachBottomDistance;
|
|
31
|
+
if (!this.$isReachBottom && isCurrentReachBottom) {
|
|
32
|
+
this.$isReachBottom = true;
|
|
33
|
+
lifecycle.emit({
|
|
34
|
+
uniqueId: this.$instance.uniqueId,
|
|
35
|
+
name: pageLifecycles.onReachBottom,
|
|
36
|
+
});
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
this.$isReachBottom = isCurrentReachBottom;
|
|
40
|
+
};
|
|
41
|
+
this.getPageConfig = (field, defaultValue) => {
|
|
42
|
+
const { page } = this.props;
|
|
43
|
+
const pageConfig = page.config;
|
|
44
|
+
return get(pageConfig, field, defaultValue);
|
|
45
|
+
};
|
|
46
|
+
this.$instance = new PageInstance();
|
|
47
|
+
lifecycle.addInstance(this.$instance);
|
|
48
|
+
this.getGlobalConfig = this.props.getGlobalConfig;
|
|
49
|
+
}
|
|
50
|
+
componentDidMount() {
|
|
51
|
+
const title = this.getPageConfig('navigationBarTitleText', '');
|
|
52
|
+
document.title = title;
|
|
53
|
+
window.addEventListener('scroll', this.handlePageScroll);
|
|
54
|
+
window.addEventListener('resize', this.handlePageResize);
|
|
55
|
+
const backgroundColor = this.getPageConfig('backgroundColor');
|
|
56
|
+
if (backgroundColor) {
|
|
57
|
+
document.body.style.backgroundColor = backgroundColor;
|
|
58
|
+
}
|
|
59
|
+
// 获取页面触底的距离
|
|
60
|
+
this.$reachBottomDistance = this.getPageConfig('onReachBottomDistance', this.getGlobalConfig(['window', 'onReachBottomDistance'], 50) // 全局配置
|
|
61
|
+
);
|
|
62
|
+
// FIXME: 应用实例化未完成,didMount 从内至外执行
|
|
63
|
+
// 此时触发 onShow onReady 获取不到 getApp 实例,组件内也存在这样的情况
|
|
64
|
+
lifecycle.emit({
|
|
65
|
+
uniqueId: this.$instance.uniqueId,
|
|
66
|
+
name: pageLifecycles.onShow,
|
|
67
|
+
});
|
|
68
|
+
lifecycle.emit({
|
|
69
|
+
uniqueId: this.$instance.uniqueId,
|
|
70
|
+
name: pageLifecycles.onReady,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
componentWillUnmount() {
|
|
74
|
+
window.removeEventListener('scroll', this.handlePageScroll);
|
|
75
|
+
window.removeEventListener('resize', this.handlePageResize);
|
|
76
|
+
// FIXME: 目前是 SPA 的页面直接切换,卸载前直接调用事件
|
|
77
|
+
lifecycle.emit({
|
|
78
|
+
uniqueId: this.$instance.uniqueId,
|
|
79
|
+
name: pageLifecycles.onHide,
|
|
80
|
+
});
|
|
81
|
+
lifecycle.emit({
|
|
82
|
+
uniqueId: this.$instance.uniqueId,
|
|
83
|
+
name: pageLifecycles.onUnload,
|
|
84
|
+
});
|
|
85
|
+
lifecycle.removeInstance(this.$instance);
|
|
86
|
+
// TODO: 实现 onPullDownRefresh 生命周期
|
|
87
|
+
}
|
|
88
|
+
render() {
|
|
89
|
+
const { page, children, isClassType } = this.props;
|
|
90
|
+
const $instance = this.$instance;
|
|
91
|
+
const globalBackgroundColor = this.getGlobalConfig(['window', 'backgroundColor'], '#fff');
|
|
92
|
+
const backgroundColor = this.getPageConfig('backgroundColor', globalBackgroundColor);
|
|
93
|
+
document.body.style.backgroundColor = backgroundColor;
|
|
94
|
+
return (<PageInstanceContext.Provider value={{ $instance, pageConfig: page.config }}>
|
|
95
|
+
<v-page data-route={page.route}>
|
|
96
|
+
{isClassType
|
|
97
|
+
? // @ts-ignore
|
|
98
|
+
React.cloneElement(children, {
|
|
99
|
+
ref(ins) {
|
|
100
|
+
if (ins) {
|
|
101
|
+
// 实现 class 生命周期用法的挂载
|
|
102
|
+
Object.keys(pageLifecycles).forEach((event) => {
|
|
103
|
+
if (typeof ins[event] === 'function') {
|
|
104
|
+
$instance.registerLifecycle(event, ins, ins[event]);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
})
|
|
110
|
+
: children}
|
|
111
|
+
{/* TODO: 如果需要转场动画,需要在 PageWrapper 中渲染 */}
|
|
112
|
+
{/* {page?.isTabBar && <TabBar config={tabBarConfig} />} */}
|
|
113
|
+
</v-page>
|
|
114
|
+
</PageInstanceContext.Provider>);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TabBar as ITabBar } from '@ray-js/types';
|
|
3
3
|
import { renderOptions } from '../../store/appStore';
|
|
4
|
-
|
|
4
|
+
type TabBarProps = {
|
|
5
5
|
config: ITabBar;
|
|
6
6
|
basename?: string;
|
|
7
7
|
};
|
|
@@ -20,6 +20,6 @@ export declare class TabBar extends React.Component<TabBarProps, {
|
|
|
20
20
|
};
|
|
21
21
|
componentDidMount(): void;
|
|
22
22
|
componentWillUnmount(): void;
|
|
23
|
-
render(): JSX.Element;
|
|
23
|
+
render(): React.JSX.Element;
|
|
24
24
|
}
|
|
25
25
|
export {};
|
|
@@ -1,102 +1,68 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
4
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
-
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
6
|
-
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
7
|
-
import "core-js/modules/es.array.concat.js";
|
|
8
|
-
import "core-js/modules/es.array.map.js";
|
|
9
1
|
import clsx from 'clsx';
|
|
10
2
|
import React from 'react';
|
|
11
3
|
import router from '@ray-js/router';
|
|
12
4
|
import { events, appStoreEmitter, renderOptions } from '../../store/appStore';
|
|
13
5
|
import { withPublicPath } from '../../utils';
|
|
14
6
|
import styles from './index.module.less';
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
26
|
-
args[_key] = arguments[_key];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
30
|
-
|
|
31
|
-
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
32
|
-
currentRoute: router.scheduler.currentRoute,
|
|
33
|
-
renderOptions: renderOptions
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
return _this;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
_createClass(TabBar, [{
|
|
40
|
-
key: "componentDidMount",
|
|
41
|
-
value: function componentDidMount() {
|
|
42
|
-
var _this2 = this;
|
|
43
|
-
|
|
44
|
-
this.unChangeHandle = router.scheduler.on('routeChange', function (route) {
|
|
45
|
-
_this2.setState({
|
|
46
|
-
currentRoute: route
|
|
47
|
-
});
|
|
7
|
+
export class TabBar extends React.Component {
|
|
8
|
+
state = {
|
|
9
|
+
currentRoute: router.scheduler.currentRoute,
|
|
10
|
+
renderOptions: renderOptions
|
|
11
|
+
};
|
|
12
|
+
componentDidMount() {
|
|
13
|
+
this.unChangeHandle = router.scheduler.on('routeChange', route => {
|
|
14
|
+
this.setState({
|
|
15
|
+
currentRoute: route
|
|
48
16
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
17
|
+
});
|
|
18
|
+
this.unAppStoreChange = appStoreEmitter.on(events.tabBarChange, state => {
|
|
19
|
+
this.setState({
|
|
20
|
+
renderOptions: state
|
|
53
21
|
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
componentWillUnmount() {
|
|
25
|
+
var _this$unChangeHandle, _this$unAppStoreChang;
|
|
26
|
+
(_this$unChangeHandle = this.unChangeHandle) === null || _this$unChangeHandle === void 0 ? void 0 : _this$unChangeHandle.call(this);
|
|
27
|
+
(_this$unAppStoreChang = this.unAppStoreChange) === null || _this$unAppStoreChang === void 0 ? void 0 : _this$unAppStoreChang.call(this);
|
|
28
|
+
}
|
|
29
|
+
render() {
|
|
30
|
+
const {
|
|
31
|
+
config
|
|
32
|
+
} = this.props;
|
|
33
|
+
const {
|
|
34
|
+
currentRoute,
|
|
35
|
+
renderOptions
|
|
36
|
+
} = this.state;
|
|
37
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
38
|
+
"data-route": currentRoute,
|
|
39
|
+
className: clsx(styles.wrapper, {
|
|
40
|
+
[styles.hidden]: !renderOptions.tabBarVisible && !renderOptions.tabBarAnimation,
|
|
41
|
+
[styles.showIn]: renderOptions.tabBarVisible && renderOptions.tabBarAnimation,
|
|
42
|
+
[styles.hideOut]: !renderOptions.tabBarVisible && renderOptions.tabBarAnimation
|
|
43
|
+
})
|
|
44
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
45
|
+
className: styles.tabBar
|
|
46
|
+
}, config.list.map((item, index) => {
|
|
47
|
+
const fullRoute = item.route;
|
|
48
|
+
const isActive = currentRoute === fullRoute;
|
|
49
|
+
// console.log('>>>>>>>> currentRoute: %s, item: %s', currentRoute, item.route)
|
|
72
50
|
return /*#__PURE__*/React.createElement("div", {
|
|
73
|
-
"data-route":
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}), /*#__PURE__*/React.createElement("span", {
|
|
92
|
-
className: styles.text,
|
|
93
|
-
style: {
|
|
94
|
-
color: isActive ? config.selectedColor : config.textColor
|
|
95
|
-
}
|
|
96
|
-
}, item.text));
|
|
97
|
-
})));
|
|
98
|
-
}
|
|
99
|
-
}]);
|
|
100
|
-
|
|
101
|
-
return TabBar;
|
|
102
|
-
}(React.Component);
|
|
51
|
+
"data-full-route": fullRoute,
|
|
52
|
+
key: item.pagePath + index,
|
|
53
|
+
className: styles.item,
|
|
54
|
+
onClick: () => {
|
|
55
|
+
router.push(item.route);
|
|
56
|
+
}
|
|
57
|
+
}, item.icon && /*#__PURE__*/React.createElement("img", {
|
|
58
|
+
className: styles.icon,
|
|
59
|
+
src: `${withPublicPath(isActive ? item.activeIcon : item.icon)}`
|
|
60
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
61
|
+
className: styles.text,
|
|
62
|
+
style: {
|
|
63
|
+
color: isActive ? config.selectedColor : config.textColor
|
|
64
|
+
}
|
|
65
|
+
}, item.text));
|
|
66
|
+
})));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import clsx from 'clsx';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import router from '@ray-js/router';
|
|
4
|
+
import { events, appStoreEmitter, renderOptions } from '../../store/appStore';
|
|
5
|
+
import { withPublicPath } from '../../utils';
|
|
6
|
+
import styles from './index.module.less';
|
|
7
|
+
export class TabBar extends React.Component {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.state = {
|
|
11
|
+
currentRoute: router.scheduler.currentRoute,
|
|
12
|
+
renderOptions: renderOptions,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
componentDidMount() {
|
|
16
|
+
this.unChangeHandle = router.scheduler.on('routeChange', (route) => {
|
|
17
|
+
this.setState({
|
|
18
|
+
currentRoute: route,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
this.unAppStoreChange = appStoreEmitter.on(events.tabBarChange, (state) => {
|
|
22
|
+
this.setState({ renderOptions: state });
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
componentWillUnmount() {
|
|
26
|
+
var _a, _b;
|
|
27
|
+
(_a = this.unChangeHandle) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
28
|
+
(_b = this.unAppStoreChange) === null || _b === void 0 ? void 0 : _b.call(this);
|
|
29
|
+
}
|
|
30
|
+
render() {
|
|
31
|
+
const { config } = this.props;
|
|
32
|
+
const { currentRoute, renderOptions } = this.state;
|
|
33
|
+
return (<div data-route={currentRoute} className={clsx(styles.wrapper, {
|
|
34
|
+
[styles.hidden]: !renderOptions.tabBarVisible && !renderOptions.tabBarAnimation,
|
|
35
|
+
[styles.showIn]: renderOptions.tabBarVisible && renderOptions.tabBarAnimation,
|
|
36
|
+
[styles.hideOut]: !renderOptions.tabBarVisible && renderOptions.tabBarAnimation,
|
|
37
|
+
})}>
|
|
38
|
+
<div className={styles.tabBar}>
|
|
39
|
+
{config.list.map((item, index) => {
|
|
40
|
+
const fullRoute = item.route;
|
|
41
|
+
const isActive = currentRoute === fullRoute;
|
|
42
|
+
// console.log('>>>>>>>> currentRoute: %s, item: %s', currentRoute, item.route)
|
|
43
|
+
return (<div data-full-route={fullRoute} key={item.pagePath + index} className={styles.item} onClick={() => {
|
|
44
|
+
router.push(item.route);
|
|
45
|
+
}}>
|
|
46
|
+
{item.icon && (<img className={styles.icon} src={`${withPublicPath(isActive ? item.activeIcon : item.icon)}`}/>)}
|
|
47
|
+
<span className={styles.text} style={{ color: isActive ? config.selectedColor : config.textColor }}>
|
|
48
|
+
{item.text}
|
|
49
|
+
</span>
|
|
50
|
+
</div>);
|
|
51
|
+
})}
|
|
52
|
+
</div>
|
|
53
|
+
</div>);
|
|
54
|
+
}
|
|
55
|
+
}
|
package/lib/runtime/index.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
var htmlRoot = document.querySelector('html');
|
|
1
|
+
const htmlRoot = document.querySelector('html');
|
|
3
2
|
export function responsive() {
|
|
4
3
|
function setRem() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
htmlRoot.style.fontSize =
|
|
8
|
-
|
|
4
|
+
let clientWidth = htmlRoot.clientWidth;
|
|
5
|
+
// clientWidth = Math.min(clientWidth, 640); // PC 模式下限定最大值
|
|
6
|
+
htmlRoot.style.fontSize = `${clientWidth / 7.5}px`;
|
|
7
|
+
const div = document.createElement('div');
|
|
9
8
|
div.style.width = '7.5rem';
|
|
10
9
|
document.body.appendChild(div);
|
|
11
|
-
htmlRoot.style.fontSize =
|
|
10
|
+
htmlRoot.style.fontSize = `${parseFloat(htmlRoot.style.fontSize) * clientWidth / div.clientWidth}px`;
|
|
12
11
|
document.body.removeChild(div);
|
|
13
|
-
document.body.style.fontSize =
|
|
12
|
+
document.body.style.fontSize = `16px`;
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
var b = null;
|
|
14
|
+
let b = null;
|
|
17
15
|
window.addEventListener('resize', function () {
|
|
18
16
|
clearTimeout(b);
|
|
19
17
|
b = setTimeout(setRem, 100);
|
package/lib/store/appStore.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import "core-js/modules/es.object.assign.js";
|
|
2
1
|
import { Emitter } from '@ray-js/framework-shared';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
2
|
+
export const appStoreEmitter = new Emitter();
|
|
3
|
+
export const renderOptions = {
|
|
5
4
|
tabBarVisible: true,
|
|
6
5
|
tabBarAnimation: false
|
|
7
6
|
};
|
|
8
|
-
export
|
|
7
|
+
export const actions = {
|
|
9
8
|
toggleTabBar: 'toggleTabBar',
|
|
10
9
|
onChange: 'onChange'
|
|
11
10
|
};
|
|
12
|
-
export
|
|
11
|
+
export const events = {
|
|
13
12
|
tabBarChange: 'tabBarChange'
|
|
14
13
|
};
|
|
15
|
-
|
|
16
|
-
var update = function (eventName, nextState) {
|
|
14
|
+
const update = (eventName, nextState) => {
|
|
17
15
|
Object.assign(renderOptions, nextState);
|
|
18
16
|
appStoreEmitter.emit(eventName, renderOptions);
|
|
19
17
|
};
|
|
20
|
-
|
|
21
18
|
appStoreEmitter.on(actions.toggleTabBar, function (next) {
|
|
22
19
|
if (next.visible !== renderOptions.tabBarVisible) update(events.tabBarChange, {
|
|
23
20
|
tabBarVisible: next.visible,
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
2
|
-
import "core-js/modules/es.regexp.test.js";
|
|
3
1
|
import slash from 'slash';
|
|
4
2
|
export function normalizeBasename(p) {
|
|
5
3
|
var _p;
|
|
6
|
-
|
|
7
4
|
p = slash((_p = p) !== null && _p !== void 0 ? _p : '/');
|
|
8
|
-
|
|
9
5
|
if (!/^\//.test(p)) {
|
|
10
6
|
p = '/' + p;
|
|
11
7
|
}
|
|
12
|
-
|
|
13
8
|
return p;
|
|
14
9
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/framework",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.23",
|
|
4
4
|
"description": "Ray Core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ray"
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"watch": "tsc -p ./tsconfig.build.json --module esnext --outDir lib --watch"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@ray-js/framework-mp": "1.3.
|
|
24
|
-
"@ray-js/framework-shared": "1.3.
|
|
25
|
-
"@ray-js/library": "1.3.
|
|
26
|
-
"@ray-js/location": "1.3.
|
|
27
|
-
"@ray-js/router": "1.3.
|
|
28
|
-
"@ray-js/runtime": "1.3.
|
|
23
|
+
"@ray-js/framework-mp": "1.3.23",
|
|
24
|
+
"@ray-js/framework-shared": "1.3.23",
|
|
25
|
+
"@ray-js/library": "1.3.23",
|
|
26
|
+
"@ray-js/location": "1.3.23",
|
|
27
|
+
"@ray-js/router": "1.3.23",
|
|
28
|
+
"@ray-js/runtime": "1.3.23",
|
|
29
29
|
"clsx": "^1.1.1",
|
|
30
30
|
"hoist-non-react-statics": "^3.3.2",
|
|
31
31
|
"lodash.get": "^4.4.2",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
"tiny-invariant": "^1.1.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@ray-js/cli": "1.3.
|
|
38
|
-
"@ray-js/types": "1.3.
|
|
37
|
+
"@ray-js/cli": "1.3.23",
|
|
38
|
+
"@ray-js/types": "1.3.23"
|
|
39
39
|
},
|
|
40
40
|
"maintainers": [
|
|
41
41
|
{
|
|
@@ -43,6 +43,6 @@
|
|
|
43
43
|
"email": "tuyafe@tuya.com"
|
|
44
44
|
}
|
|
45
45
|
],
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "04708bb394d817a7a522fcde178f19f170d5d364",
|
|
47
47
|
"repository": {}
|
|
48
48
|
}
|