// index.html
* {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
// 排除input与textarea
[contenteditable="true"], input, textarea {
-webkit-user-select: auto!important;
-khtml-user-select: auto!important;
-moz-user-select: auto!important;
-ms-user-select: auto!important;
-o-user-select: auto!important;
user-select: auto!important;
}
iPhoneX底部样式兼容,包括页面主体内容的在安全区域及fix定位下bottom: 0的兼容。参考:iPhone X兼容
h5中拨号,采用window.open(‘tel:15000000000‘),在iOS中不能使用。原因:iOS中不兼容window.open方法,通过window.location.href = ‘tel:15000000000‘来实现拨号操作
const isIos = function() {
const isIphone = navigator.userAgent.includes(‘iPhone‘)
const isIpad = navigator.userAgent.includes(‘iPad‘)
return isIphone || isIpad
}
if (isIos) {
window.location.href = ‘tel:15000000000‘
} else {
window.open(‘tel:15000000000‘)
}
<input
id=‘phone‘
type=‘tel‘
maxLength=‘11‘
placeholder=‘请输入‘
onChange={({ target: { value } }) => handlePhone(value)}
onBlur={() => inputOnBlur()}
/>
const check = () => {
setTimeout(() => {
const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0
window.scrollTo(0, Math.max(scrollHeight - 1, 0))
}, 100)
}
const inputOnBlur = () => {
document.getElementById(‘phone‘).setAttribute(‘onblur‘, check())
setTimeout(() => {
window.scrollTo(0, document.body.scrollTop + 1)
document.body.scrollTop >= 1 && window.scrollTo(0, document.body.scrollTop - 1)
}, 100)
}
npm install react-live-route --save
// routes.js
export const routes = [
{
path: ‘/‘,
exact: true,
component: () => <Redirect to=‘/list‘ />
},
/*
{
path: ‘/list‘,
exact: true,
component: () => <DirectListPage />
},
*/
{
path: ‘/create‘,
exact: true,
component: () => (
<PermissionWrap>
<DirectCreatePage />
</PermissionWrap>
)
}
]
// 需要处理的路由列表
export const keepRouter = [
{
path: ‘/list‘,
component: DirectListPage
},
{
path: ‘/demand/list‘,
component: DemandListPage
}
]
// APP.js
import NotLiveRoute from ‘react-live-route‘
import { routes, keepRouter } from ‘./pages/routes‘
const LiveRoute = withRouter(NotLiveRoute)
<HashRouter>
<>
<Switch>
{routes.map((item, index) => {
return (
<Route
key={index}
path={item.path}
exact
render={props => {
if (canDirectLogin === true) {
return <item.component {...props} />
} else if (canDirectLogin === false) {
return <ForbiddenPage />
} else {
return <Loading.Full />
}
}}
/>
)
})}
</Switch>
{keepRouter.map((item, index) => {
return (
<LiveRoute
key={index}
path={item.path}
alwaysLive
component={item.component}
name={item.path}
/>
)
}
)}
</>
</HashRouter>
// 最终的重定向方法
// 去除重定向地址中的#,同时添加参数connect_redirect
redirectWXAuth = () => {
const { goToPage } = this.state
const url = (goToPage + ‘‘).replace(‘#‘, ‘‘)
const redirectUrl = encodeURIComponent(
`${process.env.REDIRECT_HOST}/login?goto_page=${encodeURIComponent(url)}&bindCode=1`
)
const wechatAuthUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${process.env.WXAPPID}&redirect_uri=${redirectUrl}&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect`
window.location.replace(wechatAuthUrl)
}
原文:https://www.cnblogs.com/sk-3/p/13499677.html