index.js 2.28 KB
Newer Older
wangshuo committed
1 2
import React, {Component} from 'react'
import './index.scss';
FE committed
3
import {withRouter} from 'react-router-dom'
FE committed
4
import {browser,getParam} from "@/utils";
xuzhenghua committed
5

wangshuo committed
6 7 8 9
class HeaderBar extends Component {
    constructor(props) {
        super(props);
    }
xuzhenghua committed
10

wangshuo committed
11
    goBack = () => {
zhanghaozhe committed
12 13
        const {state, hash} = this.props.location
        if(hash.includes('goback')){
zhanghaozhe committed
14
            return window.history.go(-1)
zhanghaozhe committed
15
        }
FE committed
16 17 18
        if(browser.isWeixin && getParam('code') && getParam('state')){
            window.history.go(-2)
        }
zhanghaozhe committed
19
        if(state.records && state.records.length > 1){
20
            window.history.go(-1);
21 22
        }else if(state.from && state.from.pathname) {
            location.replace(`${state.from.pathname}${state.from.search}`)
23 24 25
        }else{
            window.location.href = window.location.origin
        }
wangshuo committed
26
    }
FE committed
27

28 29
    toLink = () => {
        const { toHref } = this.props;
30
        // console.log(toHref);
31
        location.replace(toHref)
FE committed
32 33
    }

wangshuo committed
34
    goShop = () => {
FE committed
35
        this.props.history.push('/shopcart')
wangshuo committed
36
    }
xuzhenghua committed
37

wangshuo committed
38
    render() {
xuzhenghua committed
39
        const { toHref, home } = this.props;
wangshuo committed
40 41
        return (
            <div className="detail-header" style={{...this.props.style}}>
xuzhenghua committed
42
                {
43
                    !toHref && this.props.arrow &&
xuzhenghua committed
44 45
                    <i className='iconfont iconiconfront-68' onClick={this.goBack}></i>
                }
FE committed
46
                {
47
                    toHref && typeof toHref === 'function' &&
FE committed
48
                    <i className='iconfont iconiconfront-68' onClick={toHref}></i>
49 50 51 52
                }
                {
                    toHref && typeof toHref === 'string' &&
                    <i className='iconfont iconiconfront-68' onClick={this.toLink}></i>
FE committed
53
                }
wangshuo committed
54
                <span className='herder'>{this.props.title}</span>
xuzhenghua committed
55 56 57 58 59 60 61 62
                {
                    this.props.cart &&
                    <i className='iconfont icongouwuche-xianxing' onClick={this.goShop}></i>
                }
                {
                    this.props.delete &&
                    <i className='iconfont iconiconfront-56' onClick={this.props.toDelete}></i>
                }
xuzhenghua committed
63 64 65 66
                {
                    home && 
                    <i className="iconfont iconshouye-xianxing"></i>
                }
wangshuo committed
67 68 69
            </div>
        );
    }
xuzhenghua committed
70 71
};

FE committed
72
export default  withRouter(HeaderBar);