| | |
| | | class ExcelOutButton extends Component { |
| | | static propTpyes = { |
| | | BID: PropTypes.string, // 主表ID |
| | | BData: PropTypes.any, // 主表数据 |
| | | show: PropTypes.any, // 显示样式 |
| | | Tab: PropTypes.any, // 如果当前元素为标签时,tab为标签信息 |
| | | MenuID: PropTypes.string, // 菜单ID |
| | | btn: PropTypes.object, // 按钮 |
| | | columns: PropTypes.array, // 字段列 |
| | | setting: PropTypes.any, // 页面通用设置 |
| | | ContainerId: PropTypes.any, // tab页面ID,用于弹窗控制 |
| | | updateStatus: PropTypes.func, // 按钮状态更新 |
| | | getexceloutparam: PropTypes.func, // 获取表格中参数 |
| | | triggerBtn: PropTypes.any, |
| | |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '导出按钮配置错误!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | | } else if (!btn.verify || !btn.verify.columns || btn.verify.columns.length === 0) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '请设置导出列!', |
| | | duration: 5 |
| | | }) |
| | | return |
| | |
| | | * @description Excel 生成 |
| | | */ |
| | | exportExcel = (data) => { |
| | | const { columns, btn } = this.props |
| | | const { btn } = this.props |
| | | if (data && data.length > 0) { |
| | | try { |
| | | let _header = [] |
| | | let _topRow = {} |
| | | let colwidth = [] |
| | | |
| | | let hidecolumns = [] |
| | | btn.verify.columns.forEach(col => { |
| | | if (!data[0].hasOwnProperty(col.Column)) return |
| | | if (_topRow[col.Column]) return |
| | | |
| | | let verifyColumn = {} // 记录验证信息中的Excel列配置 |
| | | if (btn.verify && btn.verify.columns && btn.verify.columns.length > 0) { |
| | | btn.verify.columns.forEach(col => { |
| | | if (col.export === 'false') { |
| | | hidecolumns.push(col.Column) |
| | | return |
| | | } |
| | | verifyColumn[col.Column] = col |
| | | }) |
| | | } |
| | | _header.push(col.Column) |
| | | _topRow[col.Column] = col.Text |
| | | |
| | | columns.forEach(col => { |
| | | if (col.Hide === 'true' || hidecolumns.includes(col.field)) { |
| | | hidecolumns.push(col.field) |
| | | return |
| | | } |
| | | if (!data[0].hasOwnProperty(col.field)) return |
| | | if (_topRow[col.field]) return |
| | | |
| | | if (verifyColumn[col.field]) { // 优先使用验证信息中的列设置 |
| | | _header.push(col.field) |
| | | _topRow[col.field] = verifyColumn[col.field].Text |
| | | |
| | | colwidth.push({width: verifyColumn[col.field].Width}) |
| | | } else { |
| | | _header.push(col.field) |
| | | _topRow[col.field] = col.label |
| | | |
| | | let _colwidth = Math.floor(col.Width / 6) |
| | | |
| | | if (!_colwidth || _colwidth < 5) { |
| | | _colwidth = 5 |
| | | } |
| | | |
| | | colwidth.push({width: _colwidth}) |
| | | } |
| | | }) |
| | | |
| | | if (btn.verify && btn.verify.columns && btn.verify.columns.length > 0) { |
| | | btn.verify.columns.forEach(col => { |
| | | if (hidecolumns.includes(col.Column)) return |
| | | if (!data[0].hasOwnProperty(col.Column)) return |
| | | if (_topRow[col.Column]) return |
| | | |
| | | _header.push(col.Column) |
| | | _topRow[col.Column] = col.Text |
| | | |
| | | colwidth.push({width: col.Width}) |
| | | }) |
| | | } |
| | | |
| | | Object.keys(data[0]).forEach(key => { |
| | | if (hidecolumns.includes(key)) return |
| | | if (_topRow[key]) return |
| | | |
| | | _header.push(key) |
| | | _topRow[key] = key |
| | | |
| | | colwidth.push({width: 12}) |
| | | colwidth.push({width: col.Width}) |
| | | }) |
| | | |
| | | let table = [] |
| | |
| | | } |
| | | |
| | | render() { |
| | | const { btn } = this.props |
| | | const { btn, show } = this.props |
| | | const { loading } = this.state |
| | | |
| | | return ( |
| | | <div className="mk-btn-wrap"> |
| | | <Button |
| | | {!show ? <Button |
| | | className={'mk-btn mk-' + btn.class} |
| | | icon={btn.icon} |
| | | onClick={() => {this.actionTrigger()}} |
| | | loading={loading} |
| | | >{btn.label}</Button> |
| | | >{btn.label}</Button> : null} |
| | | {show === 'icon' ? <Button |
| | | className="export-icon" |
| | | icon="download" |
| | | onClick={() => {this.actionTrigger()}} |
| | | loading={loading} |
| | | title={btn.label} |
| | | ></Button> : null} |
| | | </div> |
| | | ) |
| | | } |