From f830c733cbc071f023c9a9a4e1571b7c81d672bf Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 12 十一月 2020 11:47:33 +0800 Subject: [PATCH] 2020-11-12 --- src/views/billprint/index.jsx | 207 +++++++++++++++++++++++++++++++++++---------------- 1 files changed, 141 insertions(+), 66 deletions(-) diff --git a/src/views/billprint/index.jsx b/src/views/billprint/index.jsx index 0dfa6b2..9565445 100644 --- a/src/views/billprint/index.jsx +++ b/src/views/billprint/index.jsx @@ -1,7 +1,6 @@ import React, { Component } from 'react' import { is, fromJS } from 'immutable' -import { connect } from 'react-redux' -import { Col, Row, Spin, notification } from 'antd' +import { Col, Row, Spin, notification, Button } from 'antd' import moment from 'moment' import Api from '@/api' @@ -9,6 +8,7 @@ import zhCN from '@/locales/zh-CN/main.js' import enUS from '@/locales/en-US/main.js' import options from '@/store/options.js' +import UtilsDM from '@/utils/utils-datamanage.js' import NotFount from '@/components/404' import asyncComponent from '@/utils/asyncComponent' @@ -23,6 +23,8 @@ class BillPrint extends Component { state = { dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS, + loadingview: true, + dataManager: false, BID: '', data: '', tempId: '', @@ -32,10 +34,10 @@ UNSAFE_componentWillMount() { try { let param = JSON.parse(window.decodeURIComponent(window.atob(this.props.match.params.param))) - this.setState({ BID: param.id || '', tempId: param.tempId, + dataManager: param.dataManager }, () => { this.getMenuParam() }) @@ -62,39 +64,33 @@ } getMenuParam = () => { - const { tempId, BID } = this.state + const { tempId, BID, dataManager } = this.state - let param = { - func: 's_PrintTemplateMGetData', - Type: 'Y', - PrintTempNO: tempId + let _param = { + func: 'sPC_Get_LongParam', + MenuID: tempId } if (window.GLOB.mainSystemApi) { // 浠庡崟鐐圭櫥褰曟湇鍔″櫒鍙栨墦鍗伴厤缃俊鎭� - param.rduri = window.GLOB.mainSystemApi + _param.rduri = window.GLOB.mainSystemApi } - Api.getLocalConfig(param).then(result => { + Api.getLocalConfig(_param).then(result => { if (result.status) { let config = '' try { - config = JSON.parse(window.decodeURIComponent(window.atob(result.ConfigParam))) + config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam))) } catch (e) { console.warn('Parse Failure') config = '' } - setTimeout(() => { // 寤舵椂鍔犺浇鐘舵�� - this.setState({ - loadingview: false - }) - }, 1500) - // 椤甸潰閰嶇疆瑙f瀽閿欒鏃舵彁绀� if (!config) { this.setState({ - viewlost: true + viewlost: true, + loadingview: false }) return } @@ -103,15 +99,17 @@ if (!config.enabled) { this.setState({ viewlost: true, + loadingview: false, lostmsg: this.state.dict['main.view.unenabled'] }) return } let params = [] + let _pars = [] + + config.components = config.components.filter(item => !['tabs', 'search'].includes(item.type) && item.subtype !== 'tablecard') config.components = config.components.map(component => { - if (['tabs', 'search'].includes(component.type)) return null - if (component.action) component.action = [] if (component.search) component.search = [] @@ -143,7 +141,7 @@ component.setting.dataresource = '(' + component.setting.dataresource + ') tb' } - if (this.props.dataManager) { // 鏁版嵁鏉冮檺 + if (dataManager) { // 鏁版嵁鏉冮檺 component.setting.dataresource = component.setting.dataresource.replace(/\$@/ig, '/*') component.setting.dataresource = component.setting.dataresource.replace(/@\$/ig, '*/') _customScript = _customScript.replace(/\$@/ig, '/*') @@ -163,19 +161,35 @@ // pageable 鏄惁鍒嗛〉锛岀粍浠跺睘鎬э紝涓嶅垎椤电殑缁勪欢鎵嶅彲浠ョ粺涓�鏌ヨ if (component.dataName && component.setting.sync === 'true') { let param = this.getDefaultParam(component) - params.push(param) + _pars.push(param) } else { - component.setting.sync = 'false' + let arr_field = component.columns.map(col => col.field).join(',') + let param = UtilsDM.getQueryDataParams(component.setting, arr_field, [], component.setting.order || '', 1, 1000, BID, '', dataManager) + + param.componentId = component.uuid + + params.push(param) } + component.setting.sync = 'true' return component }) + _pars = this.getFormatParam(_pars) + + if (_pars) { + _pars.componentId = 'union' + params.unshift(_pars) + } + this.setState({ - setting: config.setting, config }, () => { - this.loadmaindata(params) + if (params.length === 0) { + this.setState({loadingview: false}) + } else { + this.loadmaindata(params) + } }) } else { notification.warning({ @@ -221,11 +235,8 @@ } } - /** - * @description 涓昏〃鏁版嵁鍔犺浇 - */ - loadmaindata = (params) => { - if (!params || params.length === 0) return + getFormatParam = (params) => { + if (!params || params.length === 0) return '' let LText_field = [] let LText = params.map((item, index) => { let _sql = item.sql @@ -254,36 +265,109 @@ param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') param.secretkey = Utils.encrypt(param.LText, param.timestamp) - Api.getLocalConfig(param).then(result => { - if (result.status) { - delete result.status - delete result.message - delete result.ErrMesg - delete result.ErrCode + return param + } - this.setState({ - data: result, - loading: false + /** + * @description 涓昏〃鏁版嵁鍔犺浇 + */ + loadmaindata = (params) => { + let deffers = params.map(item => { + let componentId = item.componentId + delete item.componentId + return new Promise(resolve => { + Api.getLocalConfig(item).then(res => { + if (!res.status) { + notification.warning({ + top: 92, + message: res.message, + duration: 5 + }) + resolve(false) + } else { + res.componentId = componentId + resolve(res) + } }) - } else { - this.setState({ - data: '', - loading: false - }) - notification.error({ - top: 92, - message: result.message, - duration: 10 - }) + }) + }) + + Promise.all(deffers).then(results => { + let _results = results.filter(Boolean) + + this.setState({loadingview: false}) + + if (_results.length === results.length) { + console.log(_results) } + + // delete result.ErrCode + // delete result.ErrMesg + // delete result.message + // delete result.status }) } - getComponents = () => { - const { dataManager } = this.props - const { config, BID, data } = this.state + print = () => { + let bdhtml = window.document.body.innerHTML + let jubuData = document.getElementById('bill-print').innerHTML + window.document.body.innerHTML = jubuData + // document.getElementsByTagName('body')[0].style.zoom = 0.7 - if (!config || !config.components) return + try { + if (window.ActiveXObject) { + let hkeyRoot + let hkeyPath + let hkeyKey + // eslint-disable-next-line + let RegWsh = new ActiveXObject('WScript.Shell') + + hkeyRoot = 'HKEY_CURRENT_USER' + hkeyPath = '\\Software\\Microsoft\\Internet Explorer\\PageSetup\\' + + // 璁剧疆椤电湁/鑴氱殑瀛椾綋鏍峰紡 + hkeyKey = 'font' + RegWsh.RegWrite(hkeyRoot + hkeyPath + hkeyKey, 'font-size: 12px; font-family: 榛戜綋; line-height: 24px') + + // 璁剧疆椤电湁 + hkeyKey = 'header' + RegWsh.RegWrite(hkeyRoot + hkeyPath + hkeyKey, '鎵撳嵃缂栧彿') + + // 璁剧疆椤佃剼 + hkeyKey = 'footer' + RegWsh.RegWrite(hkeyRoot + hkeyPath + hkeyKey, '&b绗� &p 椤�/鍏� &P 椤�') + + // 璁剧疆椤佃竟璺�(0.6 瑕佷箻浠� 2.5涓哄疄闄呮墦鍗扮殑灏哄) + hkeyKey = 'margin_bottom' + RegWsh.RegWrite(hkeyRoot + hkeyPath + hkeyKey, '0.6') + + hkeyKey = 'margin_left' + RegWsh.RegWrite(hkeyRoot + hkeyPath + hkeyKey, '0.6') + + hkeyKey = 'margin_right' + RegWsh.RegWrite(hkeyRoot + hkeyPath + hkeyKey, '0.6') + + hkeyKey = 'margin_top' + RegWsh.RegWrite(hkeyRoot + hkeyPath + hkeyKey, '0.6') + + window.print() + } else { + window.print() + } + } catch (e) { + notification.warning({ + top: 92, + message: '鎵撳嵃寮傚父锛�', + duration: 5 + }) + } + + window.document.body.innerHTML = bdhtml + window.location.reload() + } + + getComponents = () => { + const { config, BID, data, dataManager } = this.state return config.components.map(item => { if (!item) return null @@ -322,23 +406,14 @@ const { loadingview, viewlost, config } = this.state return ( - <div className="custom-page-wrap" id={this.state.ContainerId} style={config ? config.style : null}> + <div className="bill-print-wrap" > {loadingview && <Spin size="large" />} - <Row>{this.getComponents()}</Row> + {config ? <div id="bill-print" style={config.style}><Row>{this.getComponents()}</Row></div> : null} {viewlost ? <NotFount msg={this.state.lostmsg} /> : null} + {!loadingview && !viewlost ? <div className="print-button"><Button onClick={this.print}>鎵撳嵃</Button></div> : null} </div> ) } } -const mapStateToProps = (state) => { - return { - dataManager: state.dataManager - } -} - -const mapDispatchToProps = () => { - return {} -} - -export default connect(mapStateToProps, mapDispatchToProps)(BillPrint) \ No newline at end of file +export default BillPrint \ No newline at end of file -- Gitblit v1.8.0