采用Ecode开发,复写组件方式实现
index.js
const{WeaUpload}=ecCom;classNewWeaUploadextendsReact.Component{hash=`${newDate().getTime()}_${Math.ceil(Math.random()*100000)}`;render(){const{uploadId}=this.props;constdrop_element=`weaUploadDragDrop_${uploadId}_${this.hash}`;constnewProps={...this.props,customOptions:{...this.props.customOptions,drop_element,}};//复写组件的时候,必须带上_noOverwrite参数,避免被复写的组件又被复写导致死循环return(<div id={drop_element}style={{width:'100%'}}><WeaUpload{...newProps}_noOverwrite={true}/></div>)}}//发布模块ecodeSDK.setCom('${appId}','NewWeaUpload',NewWeaUpload);register.js
constNewWeaUpload=(props,Com)=>{//此函数不允许写在复写方法内,会导致实例重复创建,也就是dimout不断执行constacParams={appId:'${appId}',//appId会自动识别name:'NewWeaUpload',//模块名称isPage:false,//是否是路由页面noCss:true,//是否禁止单独加载css,通常为了减少css数量,css默认前置加载props,}constNewCom=Com;returnwindow.ecCom?ecodeSDK.getAsyncCom(acParams):(<NewCom{...props}/>);}ecodeSDK.overwriteClassFnQueueMapSet('WeaUpload',{fn:(Com,newProps)=>{if(!window.location.hash.startsWith('#/main/workflow/req'))return;newProps.dragUpload=trueif(newProps._noOverwrite||!newProps.uploadId||!newProps.fieldid||!newProps.category||!newProps.showUpload||newProps.viewAttr==1)return;return{com:NewWeaUpload.bind(this,newProps,Com),props:newProps};}});