import * as React from 'react' import debounce from 'lodash.debounce' import smoothscroll from 'smoothscroll-polyfill' import log from '../utils/lofter-log' import { Props, State, } from './type' import { get } from '../utils/request'; import { showMessage } from '../common/toast/toast' import { TemplateActivityContext } from '../common/template-context' import { oneTemplateActivityRequest } from '../utils/one-request' import * as Styled from './index.style' smoothscroll.polyfill() export class TemplateActivityContainer extends React.Component { static defaultProps = new Props() state = new State() debounceFetch = debounce(this.getActivityInfo.bind(this), 400) componentDidMount() { this.getActivityInfo() document.getElementById('app').style.minHeight = '100vh' } componentDidUpdate(prevProps) { if (prevProps.activityId !== this.props.activityId) { this.debounceFetch() } } async getActivityInfo() { if (!this.props.activityId) return const { contextValue } = this.state let res = await oneTemplateActivityRequest(this.props.activityId).oneFetch() if (res.code === 200) { log.capture('act-1', { category: 'actmould', action: 100, scene: 'actmould', actid: this.props.activityId.trim(), v: 'H5' }) this.setState({ contextValue: { activityInfo: res.data, isLoading: false, getActivityInfo: this.getActivityInfo.bind(this) } }) } else { this.setState({ contextValue: { ...contextValue, activityInfo: undefined, isLoading: false, getActivityInfo: this.getActivityInfo.bind(this) } }) showMessage({ text: res.msg }) } } render() { const { children, style, isEdit,backgroundImage } = this.props const isEmpty = Array.isArray(children) ? children.length === 0 : !children return (
{ if (node) { node.style.setProperty("z-index", "auto", "important"); } }} > {backgroundImage && } { isEmpty ? ( 模板活动容器,模板活动组件相关请添加至该容器下 ) : this.props.activityId ? this.state.contextValue.isLoading && isEdit ? ( 活动模板信息加载中... ) : children : ( 请填入活动ID ) }
) } }