react-app-shell
Version:
react打包脚本和example, 这里的版本请忽略
87 lines (73 loc) • 2.06 kB
JavaScript
import React, {Component} from 'react';
import queryString from 'query-string';
import {localStore, tools} from '../../utils';
class BasicLayout extends Component {
constructor(props) {
super(props);
this.urlParams = queryString.parse(window.location.search);
}
componentDidMount() {
if (tools.isIOS() && !document.body.focusin) {
document.body.addEventListener('focusin', this.handleIOSFocusIn);
document.body.addEventListener('focusout', this.handleIOSKeyboard);
}
}
componentWillUnmount() {
if (tools.isIOS() && document.body.focusin) {
document.body.removeEventListener('focusin', this.handleIOSFocusIn);
document.body.removeEventListener('focusout', this.handleIOSKeyboard);
}
if (this.time) {
clearTimeout(this.time);
}
}
/**
* 解决IOS软键盘呼出之后, 按钮事件失效
*/
handleIOSKeyboard = () => {
let scrollTop = parseInt(document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop, 10); // 获取滚动条值当前值
this.time = setTimeout(() => {
window.scrollTo(0, scrollTop);
}, 100);
};
handleIOSFocusIn = () => {
if (this.time) {
clearTimeout(this.time);
}
}
/**
* 设置推荐码
*/
setRecommend = () => {
const {rf} = this.urlParams;
if (rf) {
localStore.set('rf', rf);
}
};
/**
* 通过history跳转
* @param url
* @returns {Function}
*/
handleHistoryPush = (url) => {
return () => {
this.props.history.replace(url);
};
};
/**
* 通过修改href跳转
*/
handleHrefChange = (url) => {
return () => {
window.location.href = url;
};
};
render() {
return (
<div>
{this.props.children}
</div>
);
}
}
export default BasicLayout;