index.js 1.57 KB
import React from 'react';
import yaSDK from 'yoho-activity-sdk';

import './index.scss';
export default class BottomButton extends React.Component {
    constructor(props) {
        super(props);
    }

    render() {
        const linkArr = this.props.links;
        const login = this.props.login || false;
        
        if (!linkArr || !linkArr.length) {
            return null;
        }
        
        let jump = e => {
            let $el = e.currentTarget;
            let url = $el.getAttribute('data-url');


            if (!url) {
                return;
            }
            
            if (yaSDK.env !== 'app') {
                const loginMatch = ['"islogin":"Y"', "'islogin':'Y'", 'islogin=Y'];
                const filterMatch = loginMatch.filter(mch => {
                    return url.indexOf(mch) > -1;
                });
                
                if (filterMatch.length && !login) {
                    return yaSDK.goLogin();
                }
            }
            
            yaSDK.link(e)
        };
        
        return (
            <div className="comp-bottom-btns-wrap">
                {
                    linkArr.map((link, idx) => {
                        return (
                            <span data-type='other' data-url={link.url} 
                               className="button-item" key={idx} onClick={jump}>
                                <img className="btn-item-bg" src={link.bg}/>
                            </span>
                        )
                    })
                }
       
            </div>
        )
    }
}