导语
项目中添加按钮的两种方式
编辑
方案1 if判断
``` const buttonTableList = []; if (status == '116237257909008888811254') { buttonTableList.push({ title: '发布', type: 'primary', buttonKey: 'H701100000001', onClick: () => { this.publishPopup(); }, }); } if (status == '116233111696128888077445') { buttonTableList.push({ title: '关闭', type: 'primary', buttonKey: 'H701100000003', onClick: () => { this.closePopup(); }, }); } buttonTableList.push( { title: '新增', type: 'primary', buttonKey: 'H701100000002',
onClick: () => { openTab(this.props, `/management/frameList/add`); }, } // { // title: '发布', // type: 'primary', // onClick: () => { // this.publishPopup(); // }, // }, );
方案2 switch
switch (row.status) { case PARTNERS_TOBESIGN_STATUS: //待签约1 return [ viewDetail, row.freezeStatus != '116291061459328888765442' && row.canContract == '1596682955895718561276' ? handleBySigning : '', row.freezeStatus != '116291061459328888765442' ? ownerChange : '', row.freezeStatus != '116291061459328888765442' ? specialRelease : '', ]; case PARTNERS_CNECELED_STATUS: //已取消 return [viewDetail, row.freezeStatus != '116291061459328888765442' ? del : '']; case PARTNERS_EFFECTIVE_STATUS: //合作中 return [ viewDetail, row.freezeStatus != '116291061459328888765442' ? modify : '', row.freezeStatus != '116291061459328888765442' ? handleTransferApply : '', row.freezeStatus != '116291061459328888765442' ? ownerChange : '', ]; case PARTNERS_FREEZEING_STATUS: //冻结中 return [viewDetail]; case PARTNERS_SPECIALRELEASE_STATUS: //特殊放行 return [ viewDetail, row.freezeStatus != '116291061459328888765442' ? handleBySigning : '', ]; default: return [viewDetail]; }
总结
两种方式 都是按照不同的判断生成对应的按钮 我是歌谣 微信公众号关注前端小歌谣
-