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

42 lines
1001 B
JavaScript
Raw Normal View History

2025-04-09 14:13:40 +08:00
/*Rr06URj+uwmytLHxccewIFYi8Ss3NmKmWKs4Kbig6fU=*/
import { Component } from 'react';
import createScript from '../components/uapRefer';
import './index.less';
2025-03-09 11:34:19 +08:00
/**
* 参照加载组件
*/
export default class ReferLoader extends Component {
constructor(props) {
super(props);
this.state = {};
}
2025-03-09 11:34:19 +08:00
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>
);
}
2025-03-09 11:34:19 +08:00
}
2025-04-09 14:13:40 +08:00
/*Rr06URj+uwmytLHxccewIFYi8Ss3NmKmWKs4Kbig6fU=*/