tk2312-web/src/arap/public/ReferLoader/index.js

42 lines
1001 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*zSUoWKMuZerEXLsc4aAHfpzRg5lzN2RmctWmdBaiPTc=*/
import { Component } from 'react';
import createScript from '../components/uapRefer';
import './index.less';
/**
* 参照加载组件
*/
export default class ReferLoader extends Component {
constructor(props) {
super(props);
this.state = {};
}
componentWillReceiveProps(nextProps) {
// 参照类型改变时清空已有参照否则会走react更新的生命周期不会走构造函数
if (this.props.tag !== nextProps.tag) {
this.setState({
[nextProps.tag]: null
});
}
}
render() {
let props = this.props;
let state = this.state;
let refer = null;
if (!state[props.tag]) {
createScript.call(this, props.refcode, props.tag);
} else {
refer = state[props.tag] ? state[props.tag](props) : <div />;
}
return (
<div className="refer-wrapper">
{props.showStar ? <span className="required-star">*</span> : null}
{refer}
</div>
);
}
}
/*zSUoWKMuZerEXLsc4aAHfpzRg5lzN2RmctWmdBaiPTc=*/