import * as React from 'react'; import SDKView from '../components/common/SDKView'; import Loading from '@beisen/loading'; import { taker, getApiUrl, getToUserId, getBSGlobal } from '../helper'; import {HonourIframeProps, HonourIframeState} from './propsSetting'; export default class HonourIframe extends React.Component { state = { isFetching: true, url: '', code: '', id: 0 } componentDidMount() { this.setIframeUrl(this.props) } componentWillReceiveProps(nextProps: HonourIframeProps) { if (nextProps.code != this.props.code){ this.setIframeUrl(nextProps) } } setIframeUrl = (props: HonourIframeProps) => { const { code } = props; const indexIframe = code.indexOf('__ISIFRAME'); const iframeCode = code.substring(0, indexIframe); this.setState({ isFetching: true },()=>{ this.getIframeUrl(iframeCode).then((clickChannelData: any) => { if (clickChannelData) { this.setState({ isFetching: false, url: `//${getBSGlobal('titaHost')}${clickChannelData.IFrameHref}`, code: clickChannelData.Code || '', id: clickChannelData.RelatedApp || 0, }) } }) }) } getIframeUrl = async (code: string) => { const url = getApiUrl(`proxy/GetUPaaSCoreGateway/TalentHonor/GetAppItems?code=Tabs&toUserId=${getToUserId()}`); const ChannelRes = await taker(url); if (ChannelRes && ChannelRes.Code === 200 && ChannelRes.OperationObject) { const clickChannelData = ChannelRes.OperationObject.find((item: any) => item.Code == code) || {}; return clickChannelData; } return null } render() { const { isFetching, url, code, id } = this.state return isFetching? :
} }