import * as React from 'react' import { LofterTitle } from '../lofterTitle' import log from '../utils/lofter-log' import { BaseComponent } from '../base-component' import { imgResize } from '../utils/imgResize' import { showMessage } from '../common/toast/toast'; import { isUpAppVersion, ios } from 'nw-detect'; import LazyLoad from 'react-lazy-load' import debounce from 'lodash.debounce'; import { get, post } from '../utils/request' import { getDeviceId } from '../utils/lofter-log' import { Props, State } from './type' import * as Styled from './index.style' const AVATAR_TYPE = 0, DRESSING_TYPE = 4, MUSICVIP_TYPE = 5 export class NewuserGiftPacks extends React.Component { static defaultProps = new Props(); state = new State() getGiftList = async (day: number) => { const mockUrl = 'https://nei.hz.netease.com/api/apimock-v2/c6da9202198a943efec7f11c8a937f16/newweb/giftPacks/secondDay.json' const url = day === 2 ? '//www.lofter.com/newweb/giftPacks/secondDay.json' : '//www.lofter.com/newweb/giftPacks/thirdDay.json' const res = await get(url) if (res.code === 0) { this.setState({ giftList: res.data }) } } receiveGift = debounce(async (type: number) => { const { giftList } = this.state const mockUrl = 'https://nei.hz.netease.com/api/apimock-v2/c6da9202198a943efec7f11c8a937f16/newweb/giftPacks/receive.json' const url = '//www.lofter.com/newweb/giftPacks/receive.json' post(url, { type }).then(res => { if (res.code !== 0) { return showMessage(res.msg) } if (res.data.res) { showMessage(`${type === 5 ? '领取成功!兑换方式请查看私信。' : '领取成功!'}`) const temp = giftList switch (type) { case 0: log.capture('newusergift-2', { category: 'newusergift', action: 101, scene: 'newusergift', v: '1.0.0', activityId: 'newusergif' }); temp.avatarBox.status = 1 break case 4: log.capture('newusergift-7', { category: 'newusergift', action: 101, scene: 'newusergift', v: '1.0.0', activityId: 'newusergif' }); temp.dressingSuit.status = 1 break case 5: log.capture('newusergift-8', { category: 'newusergift', action: 101, scene: 'newusergift', v: '1.0.0', activityId: 'newusergif' }); temp.musicVip.status = 1 break } this.setState({ giftList: temp }) } else { showMessage('领取失败') } }) }, 1000, { leading: true, tailing: false, }) getBind = async () => { const mockUrl = 'https://nei.hz.netease.com/api/apimock-v2/c6da9202198a943efec7f11c8a937f16/newweb/phoneAccount/getBind.json' const url = '//www.lofter.com/newweb/phoneAccount/getBind.json' const res = await get(url) if (res.code === 0) { if (!res.data?.bindPhone && !res.data?.verifyPhone) { return window.location.href = 'https://www.lofter.com/front/homesite/gift-packs/bind-phone' } return this.receiveGift(MUSICVIP_TYPE) } } initData = () => { this.getGiftList(this.props.day); } pageReload = () => { if (ios()) { const persistHandler = (event: any) => { if (event.persisted || performance.getEntriesByType("navigation")[0].type === 'back_forward') { this.initData() } return () => { window.removeEventListener('pageshow', persistHandler); } } window.addEventListener('pageshow', persistHandler); } else { document.addEventListener('visibilitychange', this.initData) return () => { document.removeEventListener('visibilitychange', this.initData) } } } componentDidMount() { this.pageReload(); this.initData(); } componentDidUpdate(preProps: any) { if (this.props.day !== preProps.day) { this.getGiftList(this.props.day); } } render() { let { style, marginTop, title, dressingImage, musicImage, avatarImage } = this.props let { giftList } = this.state return (
{ title && } { giftList && giftList.musicVip && (
{giftList.musicVip.name}
{giftList.musicVip.tip}
) } { giftList && giftList.dressingSuit && (
{giftList.dressingSuit.name}
快去试试装扮套装吧~
) } { giftList && giftList.avatarBox && (
{giftList.avatarBox.name}
在下萌新一枚~
) }
) } }