Commit cb2f3a7d by zhanghaozhe

国际手机号

parent 7ec178ee
...@@ -37,6 +37,10 @@ class App extends Component { ...@@ -37,6 +37,10 @@ class App extends Component {
...this.props.location ...this.props.location
} }
records = []
firstLoad = true
componentDidMount() { componentDidMount() {
// 友盟统计 // 友盟统计
const script = document.createElement('script'); const script = document.createElement('script');
...@@ -44,7 +48,7 @@ class App extends Component { ...@@ -44,7 +48,7 @@ class App extends Component {
script.language = 'JavaScript'; script.language = 'JavaScript';
document.body.appendChild(script); document.body.appendChild(script);
this.setNavigationRecord(this.props.location) this.setNavigationRecord(this.props.location, this.props.history.action)
//平台信息 //平台信息
...@@ -58,10 +62,9 @@ class App extends Component { ...@@ -58,10 +62,9 @@ class App extends Component {
const routeMatchRule = /binding-tel|forgot|set-password/ const routeMatchRule = /binding-tel|forgot|set-password/
const {history} = this.props const {history} = this.props
history.listen((location) => { history.listen((location, action) => {
console.log(this.props.location); this.firstLoad = false
console.log(location); this.setNavigationRecord(location, action)
this.setNavigationRecord(location)
if (cookie.get('uid') && this.props.user.hasError) { if (cookie.get('uid') && this.props.user.hasError) {
this.getUser() this.getUser()
} }
...@@ -77,18 +80,23 @@ class App extends Component { ...@@ -77,18 +80,23 @@ class App extends Component {
} }
setNavigationRecord = (location) => { setNavigationRecord = (location, action) => {
let {location: _location} = this.props const {pathname, search, hash} = location
let {state: _state = {}} = _location let isLastRecord = location.pathname === this.records.length && this.records[this.records.length - 1].pathname
let {state = {}} = location switch (action) {
location.state = { case 'POP':
...state, ...{ this.firstLoad ? this.records.push({pathname, search, hash}) : this.records.pop()
record: _state.record ? break
[..._state.record, {pathname: location.pathname, search: location.search, hash: location.hash}] : case 'REPLACE':
[{pathname: location.pathname, search: '', hash: ''}] this.records[this.records.length - 1] = {pathname, search, hash}
} break
default:
!isLastRecord && this.records.push({pathname, search, hash})
} }
// console.log(location.state.record);
location.state && location.state.records
? (location.state.records = this.records)
: (location.state = {records: this.records})
} }
getUser = () => { getUser = () => {
...@@ -127,15 +135,33 @@ class App extends Component { ...@@ -127,15 +135,33 @@ class App extends Component {
} }
componentDidUpdate() { componentDidUpdate() {
const {location} = this.props
this.previousLocation = location.pathname.startsWith('/passport') ? this.setPreviousLocation()
this.previousLocation.pathname === '/' ? location : this.previousLocation : location
if (!this.props.user.hasError && getParam('redirect')) { if (!this.props.user.hasError && getParam('redirect')) {
window.location.href = getParam('redirect') window.location.href = getParam('redirect')
} }
} }
setPreviousLocation = () => {
const {location, history: {action}} = this.props
if (location.pathname.startsWith('/passport')) {
let index = this.records.findIndex(item => item.pathname.startsWith('/passport'))
this.previousLocation = index > 0
? this.records[index - 1]
: this.records.length
? this.records[this.records.length - 1]
: null
} else {
if (action === 'POP' || action === 'REPLACE') {
let index = this.records.findIndex(item => item.pathname.startsWith('/passport'))
this.previousLocation = index > 0 ? this.records[index - 1] : this.records[this.records.length - 1]
} else {
this.previousLocation = location
}
}
}
transformUser = res => { transformUser = res => {
let payload let payload
......
...@@ -13,8 +13,7 @@ class HeaderBar extends Component { ...@@ -13,8 +13,7 @@ class HeaderBar extends Component {
if(browser.isWeixin && getParam('code') && getParam('state')){ if(browser.isWeixin && getParam('code') && getParam('state')){
window.history.go(-2) window.history.go(-2)
} }
if(state.record && state.record.length > 1){ if(state.records && state.records.length > 1){
console.log(state.record.length);
window.history.go(-1); window.history.go(-1);
}else{ }else{
window.location.href = window.location.origin window.location.href = window.location.origin
......
...@@ -75,7 +75,7 @@ class Passport extends Component { ...@@ -75,7 +75,7 @@ class Passport extends Component {
if (history.action === 'POP' && history.length <= 3) { if (history.action === 'POP' && history.length <= 3) {
history.push('/') history.push('/')
} else { } else {
const { from } = location.state || {from: {pathname: '/', search: ''}}; const from = location.state && location.state.from || {from: {pathname: '/', search: ''}};
const redirectURI = getParam('redirect') const redirectURI = getParam('redirect')
redirectURI ? (window.location.href = redirectURI) : history.replace(from); redirectURI ? (window.location.href = redirectURI) : history.replace(from);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment