| | |
| | | triggerExcelout = (btn) => { |
| | | let viewParam = this.props.getexceloutparam() |
| | | let name = `${viewParam.menuName}${moment().format('YYYYMMDDHHmmss')}.xlsx` |
| | | // let pageSize = 100 |
| | | let pageSize = 100 |
| | | |
| | | this.setState({loadingUuid: btn.uuid}) |
| | | |
| | |
| | | } else { |
| | | this.execError({ErrCode: 'N', message: '导出按钮设置错误!'}, btn) |
| | | } |
| | | } else if (btn.intertype === 'outer' && btn.innerFunc) { // 分页,且两步请求 |
| | | this.getExcelOutDoubleData(btn, viewParam, 1, pageSize, [], name) |
| | | } else { // 分页,一步请求 |
| | | this.getExcelOutData(btn, viewParam, 1, pageSize, [], name) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 两步分页请求 |
| | | */ |
| | | getExcelOutDoubleData = (btn, viewParam, pageIndex, pageSize, data, name) => { |
| | | let param = this.getExcelCustomParam(viewParam.orderBy, viewParam.search, true, pageIndex, pageSize) |
| | | param.func = btn.innerFunc |
| | | |
| | | Api.genericInterface(param).then(res => { |
| | | if (res.status) { |
| | | delete res.ErrCode |
| | | delete res.ErrMesg |
| | | delete res.message |
| | | delete res.status |
| | | |
| | | if (btn.sysInterface === 'true') { |
| | | res.rduri = window.GLOB.mainSystemApi || window.GLOB.subSystemApi |
| | | } else { |
| | | res.rduri = btn.interface |
| | | } |
| | | |
| | | if (btn.outerFunc) { |
| | | res.func = btn.outerFunc |
| | | } |
| | | |
| | | res.appkey = window.GLOB.appkey || '' // 外部请求时,统一添加appkey |
| | | |
| | | Api.genericInterface(res).then(result => { |
| | | if (result.status) { |
| | | if (!result.data) { |
| | | this.execError({ErrCode: 'N', message: '未获取到数据信息!'}, btn) |
| | | } else if (result.data.length >= pageSize) { |
| | | data = data.concat(result.data) |
| | | pageIndex++ |
| | | this.getExcelOutDoubleData(btn, viewParam, pageIndex, pageSize, data, name) |
| | | } else { |
| | | data = data.concat(result.data) |
| | | this.exportExcel(data, btn, name) |
| | | } |
| | | } else { |
| | | this.execError(result, btn) |
| | | } |
| | | }) |
| | | } else { |
| | | this.execError(res, btn) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * @description 一步分页请求 |
| | | */ |
| | | getExcelOutData = (btn, viewParam, pageIndex, pageSize, data, name) => { |
| | | let param = null |
| | | if (btn.intertype === 'inner' && !btn.innerFunc) { // 使用系统函数 |
| | | if (!viewParam.arr_field) { |
| | | this.execError({ErrCode: 'N', message: '未设置显示列!'}, btn) |
| | | return |
| | | } |
| | | |
| | | param = this.getExcelDefaultParam(viewParam.arr_field, viewParam.orderBy, viewParam.search, true, pageIndex, pageSize) |
| | | |
| | | |
| | | } else if (btn.intertype === 'inner' && btn.innerFunc) { // 使用内部函数 |
| | | param = this.getExcelCustomParam(viewParam.orderBy, viewParam.search, true, pageIndex, pageSize) |
| | | param.func = btn.innerFunc |
| | | |
| | | } else if (btn.intertype === 'outer' && !btn.innerFunc) { // 使用外部函数 |
| | | param = this.getExcelCustomParam(viewParam.orderBy, viewParam.search, true, pageIndex, pageSize) |
| | | if (btn.sysInterface === 'true') { |
| | | param.rduri = window.GLOB.mainSystemApi || window.GLOB.subSystemApi |
| | | } else { |
| | | param.rduri = btn.interface |
| | | } |
| | | |
| | | param.appkey = window.GLOB.appkey || '' |
| | | |
| | | if (btn.outerFunc) { |
| | | param.func = btn.outerFunc |
| | | } |
| | | } |
| | | |
| | | Api.genericInterface(param).then(result => { |
| | | if (result.status) { |
| | | if (!result.data) { |
| | | this.execError({ErrCode: 'N', message: '未获取到数据信息!'}, btn) |
| | | } else if (result.data.length >= pageSize) { |
| | | data = data.concat(result.data) |
| | | pageIndex++ |
| | | this.getExcelOutData(btn, viewParam, pageIndex, pageSize, data, name) |
| | | } else { |
| | | data = data.concat(result.data) |
| | | this.exportExcel(data, btn, name) |
| | | } |
| | | } else { |
| | | this.execError(result, btn) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * @description Excel 生成 |
| | | */ |
| | | exportExcel = (data, btn, name) => { |
| | | const { logcolumns } = this.props |
| | | if (data && data.length > 0) { |
| | |
| | | let _header = [] |
| | | let _topRow = {} |
| | | let colwidth = [] |
| | | |
| | | let hidecolumns = [] |
| | | logcolumns.forEach(col => { |
| | | if (col.Hide === 'true') { |
| | | hidecolumns.push(col.field) |
| | | } |
| | | }) |
| | | |
| | | 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}) |
| | | }) |
| | | } |
| | | |
| | | logcolumns.forEach(col => { |
| | | if (col.Hide === 'true') return |
| | | |
| | | if (!data[0].hasOwnProperty(col.field)) return |
| | | if (_topRow[col.field]) return |
| | | |
| | | _header.push(col.field) |
| | | _topRow[col.field] = col.label |
| | | |
| | | let _colwidth = Math.floor(col.Width / 6) |
| | | |
| | | if (!_colwidth || _colwidth < 10) { |
| | | _colwidth = 10 |
| | | if (!_colwidth || _colwidth < 5) { |
| | | _colwidth = 5 |
| | | } |
| | | |
| | | colwidth.push({width: _colwidth}) |
| | | }) |
| | | |
| | | 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}) |
| | | }) |
| | | |
| | | let table = [] |
| | |
| | | table.push(_row) |
| | | }) |
| | | |
| | | // const ws = XLSX.utils.aoa_to_sheet(data) |
| | | const ws = XLSX.utils.json_to_sheet(table, {header: _header, skipHeader: true}) |
| | | |
| | | ws['!cols'] = colwidth |
| | |
| | | ..._search |
| | | } |
| | | |
| | | if (this.props.BID) { |
| | | param.BID = this.props.BID |
| | | } |
| | | |
| | | if (pagination) { |
| | | param.PageIndex = pageIndex |
| | | param.PageSize = pageSize |
| | |
| | | arr_field: arr_field, |
| | | appkey: window.GLOB.appkey || '' |
| | | } |
| | | |
| | | if (this.props.BID) { |
| | | param.BID = this.props.BID |
| | | } |
| | | |
| | | let _dataresource = setting.dataresource |
| | | |