| | |
| | | import moment from 'moment' |
| | | import { is, fromJS } from 'immutable' |
| | | import { Button, Modal, notification, message } from 'antd' |
| | | import * as XLSX from 'xlsx' |
| | | import * as XLSX from 'sheetjs-style' |
| | | |
| | | import Utils from '@/utils/utils.js' |
| | | import options from '@/store/options.js' |
| | |
| | | static propTpyes = { |
| | | BID: PropTypes.string, // 主表ID |
| | | BData: PropTypes.any, // 主表数据 |
| | | Tab: PropTypes.any, // 如果当前元素为标签时,tab为标签信息 |
| | | btn: PropTypes.object, // 按钮 |
| | | setting: PropTypes.any, // 页面通用设置 |
| | | updateStatus: PropTypes.func, // 按钮状态更新 |
| | |
| | | |
| | | componentDidMount () { |
| | | MKEmitter.addListener('triggerBtnId', this.actionTrigger) |
| | | MKEmitter.addListener('returnModuleParam', this.triggerExcelout) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | |
| | | return |
| | | } |
| | | MKEmitter.removeListener('triggerBtnId', this.actionTrigger) |
| | | MKEmitter.removeListener('returnModuleParam', this.triggerExcelout) |
| | | } |
| | | |
| | | /** |
| | |
| | | * @description 触发按钮操作 |
| | | */ |
| | | actionTrigger = (triggerId, record, type) => { |
| | | const { setting, Tab, BID, btn } = this.props |
| | | const { setting, BID, btn } = this.props |
| | | const { loading, disabled } = this.state |
| | | |
| | | if (loading || disabled) return |
| | | if (triggerId && btn.uuid !== triggerId) return |
| | | |
| | | if (((Tab && Tab.supMenu) || setting.supModule) && !BID) { |
| | | if (setting.supModule && !BID) { |
| | | notification.warning({ |
| | | top: 92, |
| | | message: '需要上级主键值!', |
| | |
| | | return |
| | | } |
| | | |
| | | MKEmitter.emit('queryModuleParam', btn.$menuId, btn.uuid) |
| | | MKEmitter.emit('queryModuleParam', btn.$menuId, this.triggerExcelout) |
| | | if (window.GLOB.systemType === 'production') { |
| | | MKEmitter.emit('queryTrigger', {menuId: btn.uuid, name: '导出Excel'}) |
| | | } |
| | |
| | | /** |
| | | * @description Excel 导出 |
| | | */ |
| | | triggerExcelout = (menuId, btnId, viewParam) => { |
| | | triggerExcelout = (viewParam) => { |
| | | const { btn } = this.props |
| | | |
| | | if (btn.$menuId !== menuId || btn.uuid !== btnId || !viewParam) return |
| | | |
| | | let name = `${viewParam.menuName}${moment().format('YYYYMMDDHHmmss')}.xlsx` |
| | | let pageSize = 1000 |
| | |
| | | }) |
| | | viewParam.arr_field = viewParam.arr_field.join(',') |
| | | |
| | | viewParam.orderBy = btn.verify.order || viewParam.orderBy |
| | | viewParam.orderBy = btn.verify.order || '' |
| | | } |
| | | } |
| | | if (btn.intertype === 'system' && btn.verify.enable === 'true') { |
| | |
| | | if (window.GLOB.mkHS) { |
| | | if (btn.sysInterface === 'true' && options.cloudServiceApi) { |
| | | param.rduri = options.cloudServiceApi |
| | | param.userid = sessionStorage.getItem('CloudUserID') || '' |
| | | param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' |
| | | } else if (btn.sysInterface !== 'true') { |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | param.rduri = btn.proInterface |
| | |
| | | } |
| | | } |
| | | } else { |
| | | if (btn.sysInterface === 'true' && window.GLOB.mainSystemApi) { |
| | | param.rduri = window.GLOB.mainSystemApi |
| | | } else if (btn.sysInterface !== 'true') { |
| | | if (btn.sysInterface === 'true') { |
| | | if (window.GLOB.mainSystemApi) { |
| | | param.rduri = window.GLOB.mainSystemApi |
| | | } |
| | | } else if (btn.sysInterface === 'external') { |
| | | if (window.GLOB.systemType === 'production') { |
| | | param.$token = btn.exProInterface || '' |
| | | } else { |
| | | param.$token = btn.exInterface || '' |
| | | } |
| | | } else { |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | param.rduri = btn.proInterface |
| | | } else { |
| | | param.rduri = btn.interface |
| | | } |
| | | let host = window.GLOB.baseurl.replace(/http(s):\/\//, '') |
| | | if (param.rduri.indexOf(host) === -1 && /\/dostars/.test(param.rduri)) { |
| | | param.$login = true |
| | | } |
| | | } |
| | | } |
| | |
| | | if (window.GLOB.mkHS) { |
| | | if (btn.sysInterface === 'true' && options.cloudServiceApi) { |
| | | res.rduri = options.cloudServiceApi |
| | | res.userid = sessionStorage.getItem('CloudUserID') || '' |
| | | res.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' |
| | | } else if (btn.sysInterface !== 'true') { |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | res.rduri = btn.proInterface |
| | |
| | | } |
| | | } |
| | | } else { |
| | | if (btn.sysInterface === 'true' && window.GLOB.mainSystemApi) { |
| | | res.rduri = window.GLOB.mainSystemApi |
| | | } else if (btn.sysInterface !== 'true') { |
| | | if (btn.sysInterface === 'true') { |
| | | if (window.GLOB.mainSystemApi) { |
| | | res.rduri = window.GLOB.mainSystemApi |
| | | } |
| | | } else if (btn.sysInterface === 'external') { |
| | | if (window.GLOB.systemType === 'production') { |
| | | res.$token = btn.exProInterface || '' |
| | | } else { |
| | | res.$token = btn.exInterface || '' |
| | | } |
| | | } else { |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | res.rduri = btn.proInterface |
| | | } else { |
| | | res.rduri = btn.interface |
| | | } |
| | | let host = window.GLOB.baseurl.replace(/http(s):\/\//, '') |
| | | if (res.rduri.indexOf(host) === -1 && /\/dostars/.test(res.rduri)) { |
| | | res.$login = true |
| | | } |
| | | } |
| | | } |
| | |
| | | if (window.GLOB.mkHS) { |
| | | if (btn.sysInterface === 'true' && options.cloudServiceApi) { |
| | | res.rduri = options.cloudServiceApi |
| | | res.userid = sessionStorage.getItem('CloudUserID') || '' |
| | | res.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' |
| | | } else if (btn.sysInterface !== 'true') { |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | res.rduri = btn.proInterface |
| | |
| | | } |
| | | } |
| | | } else { |
| | | if (btn.sysInterface === 'true' && window.GLOB.mainSystemApi) { |
| | | res.rduri = window.GLOB.mainSystemApi |
| | | } else if (btn.sysInterface !== 'true') { |
| | | if (btn.sysInterface === 'true') { |
| | | if (window.GLOB.mainSystemApi) { |
| | | res.rduri = window.GLOB.mainSystemApi |
| | | } |
| | | } else if (btn.sysInterface === 'external') { |
| | | if (window.GLOB.systemType === 'production') { |
| | | res.$token = btn.exProInterface || '' |
| | | } else { |
| | | res.$token = btn.exInterface || '' |
| | | } |
| | | } else { |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | res.rduri = btn.proInterface |
| | | } else { |
| | | res.rduri = btn.interface |
| | | } |
| | | let host = window.GLOB.baseurl.replace(/http(s):\/\//, '') |
| | | if (res.rduri.indexOf(host) === -1 && /\/dostars/.test(res.rduri)) { |
| | | res.$login = true |
| | | } |
| | | } |
| | | } |
| | |
| | | if (window.GLOB.mkHS) { |
| | | if (btn.sysInterface === 'true' && options.cloudServiceApi) { |
| | | param.rduri = options.cloudServiceApi |
| | | param.userid = sessionStorage.getItem('CloudUserID') || '' |
| | | param.LoginUID = sessionStorage.getItem('CloudLoginUID') || '' |
| | | } else if (btn.sysInterface !== 'true') { |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | param.rduri = btn.proInterface |
| | |
| | | } |
| | | } |
| | | } else { |
| | | if (btn.sysInterface === 'true' && window.GLOB.mainSystemApi) { |
| | | param.rduri = window.GLOB.mainSystemApi |
| | | } else if (btn.sysInterface !== 'true') { |
| | | if (btn.sysInterface === 'true') { |
| | | if (window.GLOB.mainSystemApi) { |
| | | param.rduri = window.GLOB.mainSystemApi |
| | | } |
| | | } else if (btn.sysInterface === 'external') { |
| | | if (window.GLOB.systemType === 'production') { |
| | | param.$token = btn.exProInterface || '' |
| | | } else { |
| | | param.$token = btn.exInterface || '' |
| | | } |
| | | } else { |
| | | if (window.GLOB.systemType === 'production' && btn.proInterface) { |
| | | param.rduri = btn.proInterface |
| | | } else { |
| | | param.rduri = btn.interface |
| | | } |
| | | |
| | | let host = window.GLOB.baseurl.replace(/http(s):\/\//, '') |
| | | if (param.rduri.indexOf(host) === -1 && /\/dostars/.test(param.rduri)) { |
| | | param.$login = true |
| | | } |
| | | } |
| | | } |
| | |
| | | exportExcel = (data) => { |
| | | const { btn } = this.props |
| | | |
| | | let columns = btn.verify.columns.filter(col => col.output !== 'false') |
| | | let imgCol = false |
| | | let columns = btn.verify.columns.filter(col => { |
| | | if (col.output === 'false') return false |
| | | |
| | | if (col.type === 'image') { |
| | | imgCol = true |
| | | } |
| | | |
| | | if (col.type === 'number' && (col.decimal || col.decimal === 0) ) { |
| | | col.round = Math.pow(10, col.decimal) |
| | | } |
| | | |
| | | return col |
| | | }) |
| | | |
| | | try { |
| | | let imgCol = columns.filter(col => col.type === 'image')[0] |
| | | |
| | | if (imgCol) { |
| | | const column = columns.map(item => { |
| | | let col = { |
| | |
| | | item.$Index = index + 1 + '' |
| | | |
| | | columns.forEach((col, i) => { |
| | | if (item[col.Column] && col.abs === 'true') { |
| | | _row[col.Column] = Math.abs(item[col.Column]) |
| | | } else { |
| | | _row[col.Column] = item[col.Column] |
| | | let val = item[col.Column] |
| | | if (typeof(val) === 'number') { |
| | | if (col.abs === 'true') { |
| | | val = Math.abs(val) |
| | | } |
| | | if (col.round) { |
| | | val = Math.round(val * col.round) / col.round |
| | | val = val.toFixed(col.decimal) |
| | | } |
| | | } |
| | | |
| | | _row[col.Column] = val |
| | | }) |
| | | |
| | | table.push(_row) |
| | |
| | | } else { |
| | | this.execSuccess({ErrCode: 'S', ErrMesg: '导出成功!'}) |
| | | } |
| | | |
| | | } else { |
| | | let _header = [] |
| | | let _topRow = {} |
| | | let colwidth = [] |
| | | let abses = [] |
| | | |
| | | columns.forEach(col => { |
| | | if (_topRow[col.Column]) return |
| | | |
| | | let requires = [] |
| | | |
| | | columns.forEach((col, i) => { |
| | | _header.push(col.Column) |
| | | _topRow[col.Column] = col.Text |
| | | |
| | | if (col.abs === 'true') { |
| | | abses.push(col.Column) |
| | | } |
| | | |
| | | colwidth.push({width: col.Width || 20}) |
| | | if (col.required === 'true') { |
| | | requires.push(i) |
| | | } |
| | | }) |
| | | |
| | | let table = [] |
| | |
| | | |
| | | item.$Index = index + 1 + '' |
| | | |
| | | _header.forEach(field => { |
| | | if (item[field] && abses.includes(field)) { |
| | | _row[field] = Math.abs(item[field]) |
| | | } else { |
| | | _row[field] = item[field] |
| | | columns.forEach((col, i) => { |
| | | let val = item[col.Column] |
| | | |
| | | if (typeof(val) === 'number') { |
| | | if (col.abs === 'true') { |
| | | val = Math.abs(val) |
| | | } |
| | | if (col.round) { |
| | | val = Math.round(val * col.round) / col.round |
| | | val = val.toFixed(col.decimal) |
| | | } |
| | | } |
| | | |
| | | _row[col.Column] = val |
| | | }) |
| | | |
| | | table.push(_row) |
| | | }) |
| | | |
| | | const ws = XLSX.utils.json_to_sheet(table, {header: _header, skipHeader: true}) |
| | | |
| | | |
| | | ws['!cols'] = colwidth |
| | | |
| | | if (requires.length) { |
| | | let cols = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| | | requires.forEach(col => { |
| | | if (cols[col]) { |
| | | ws[cols[col] + '1'].s = {font: { color: { rgb: 'F5222D' } }} |
| | | } |
| | | }) |
| | | } |
| | | // ws["A1"].s = {fill: { bgColor: { rgb: "FFFFAA" }}, font: { color: { rgb: "1890FF" } }} |
| | | |
| | | const wb = XLSX.utils.book_new() |
| | | XLSX.utils.book_append_sheet(wb, ws, 'Sheet1') |
| | |
| | | let customScript = setting.customScript || '' |
| | | let _dataresource = setting.dataresource || '' |
| | | let queryType = setting.queryType |
| | | let transaction = setting.transaction |
| | | |
| | | if (btn.verify.dataType === 'custom') { |
| | | defaultSql = btn.verify.defaultSql || 'true' |
| | | _dataresource = btn.verify.dataresource || '' |
| | | queryType = btn.verify.queryType |
| | | transaction = btn.verify.transaction |
| | | |
| | | if (/\s/.test(_dataresource)) { |
| | | _dataresource = '(' + _dataresource + ') tb' |
| | |
| | | |
| | | if (window.GLOB.mkHS) { // 云端数据验证 |
| | | param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) |
| | | } |
| | | |
| | | if (transaction === 'true') { |
| | | param.func = 'sPC_Get_TableData_try' |
| | | } |
| | | |
| | | return param |