From 6afdec0062dacbded57e166230eb22cc55ced0c1 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 08 五月 2021 14:30:21 +0800
Subject: [PATCH] 2021-05-08

---
 src/views/billprint/index.jsx |   92 +++++++++++++++++++++++++++++++++-------------
 1 files changed, 66 insertions(+), 26 deletions(-)

diff --git a/src/views/billprint/index.jsx b/src/views/billprint/index.jsx
index cb4e936..6adefcc 100644
--- a/src/views/billprint/index.jsx
+++ b/src/views/billprint/index.jsx
@@ -21,11 +21,14 @@
 const PropCard = asyncComponent(() => import('@/tabviews/custom/components/card/prop-card'))
 const TableCard = asyncComponent(() => import('@/tabviews/custom/components/card/table-card'))
 const NormalTable = asyncComponent(() => import('@/tabviews/custom/components/table/normal-table'))
+const BraftEditor = asyncComponent(() => import('@/tabviews/custom/components/editor/braft-editor'))
+const SandBox = asyncComponent(() => import('@/tabviews/custom/components/code/sand-box'))
 
 class BillPrint extends Component {
   state = {
-    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
+    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     loadingview: true,
+    printing: false,
     pages: null,
     BID: '',
     data: '',
@@ -118,31 +121,36 @@
           A4: {
             vertical: 980,
             horizontal: 1200,
-            verticaldefault: 1.45789,
-            verticalwithout: 1.41428,
-            horizontaldefault: 0.685,
-            horizontalwithout: 0.705,
+            verticaldefault: 1.455,
+            verticalwithout: 1.411,
+            horizontaldefault: 0.679,
+            horizontalwithout: 0.701,
           },
           A3: {
             vertical: 1200,
             horizontal: 1600,
-            verticaldefault: 1.44404,
-            verticalwithout: 1.41414,
-            horizontaldefault: 0.6923,
-            horizontalwithout: 0.707,
+            verticaldefault: 1.441,
+            verticalwithout: 1.410,
+            horizontaldefault: 0.688,
+            horizontalwithout: 0.703,
           },
           A5: {
             vertical: 700,
             horizontal: 1000,
-            verticaldefault: 1.482,
-            verticalwithout: 1.417,
-            horizontaldefault: 0.6736,
-            horizontalwithout: 0.7047,
+            verticaldefault: 1.478,
+            verticalwithout: 1.413,
+            horizontaldefault: 0.669,
+            horizontalwithout: 0.700,
           }
         }
 
         config.width = pageParam[config.pageSize][config.pageLayout]
         config.style.height = Math.floor(config.width * pageParam[config.pageSize][config.pageLayout + config.pagePadding])
+
+        if (config.printCustom === 'true' && config.printWidth && config.printHeight) {
+          config.width = config.printWidth
+          config.style.height = config.printHeight
+        }
 
         let params = []
         let _pars = []
@@ -152,9 +160,13 @@
           if (component.action) component.action = []
           if (component.search) component.search = []
           component.data = [] // 鍒濆鍖栨暟鎹负绌�
+
+          if (['propcard', 'brafteditor', 'sandbox'].includes(component.subtype) && component.wrap.datatype === 'static') {
+            component.format = ''
+          }
     
           if (!component.setting) return component // 涓嶄娇鐢ㄧ郴缁熷嚱鏁版椂
-          if (!component.format || (component.subtype === 'propcard' && component.wrap.datatype === 'static')) return component // 娌℃湁鍔ㄦ�佹暟鎹�  鏁版嵁鏍煎紡 array 鎴� object
+          if (!component.format) return component  // 娌℃湁鍔ㄦ�佹暟鎹�  鏁版嵁鏍煎紡 array 鎴� object
           if (component.setting.interType !== 'system') { // 涓嶄娇鐢ㄧ郴缁熷嚱鏁版椂
             component.setting.sync = 'false'
             return component
@@ -189,6 +201,12 @@
           } else {
             component.setting.dataresource = component.setting.dataresource.replace(/@\$|\$@/ig, '')
             _customScript = _customScript.replace(/@\$|\$@/ig, '')
+          }
+
+          // 澶栬仈鏁版嵁搴撴浛鎹�
+          if (window.GLOB.externalDatabase !== null) {
+            component.setting.dataresource = component.setting.dataresource.replace(/@db@/ig, window.GLOB.externalDatabase)
+            _customScript = _customScript.replace(/@db@/ig, window.GLOB.externalDatabase)
           }
     
           component.setting.customScript = _customScript // 鏁寸悊鍚庤嚜瀹氫箟鑴氭湰
@@ -349,7 +367,7 @@
       let _results = results.filter(Boolean)
 
       let comps = components.map(item => {
-        if (item.subtype === 'propcard' && item.wrap.datatype === 'static') return item
+        if (!item.format) return item
 
         _results.forEach(res => {
           if (res.componentId === item.uuid && res.data) {
@@ -406,7 +424,8 @@
               }
               page.push(item)
             }
-          } else {
+          } else if (!item.added) {
+            _item.added = true
             page.push(item)
           }
 
@@ -451,7 +470,8 @@
                 }
                 page.push(item)
               }
-            } else {
+            } else if (!item.added) {
+              _item.added = true
               page.push(item)
             }
   
@@ -474,14 +494,20 @@
   }
 
   print = () => {
-    const { config } = this.state
+    const { config, printing } = this.state
+
+    if (printing) return
+
     let jubuData = document.getElementById('bill-print').innerHTML
+
+    this.setState({printing: true})
     
     try {
       let iframe = document.createElement('IFRAME')
       let linkList = document.getElementsByTagName('link')     // 鑾峰彇鐖剁獥鍙ink鏍囩瀵硅薄鍒楄〃
       let styleList = document.getElementsByTagName('style')   // 鑾峰彇鐖剁獥鍙tyle鏍囩瀵硅薄鍒楄〃
 
+      iframe.style.marginTop = '600px'
       document.body.appendChild(iframe)
       let doc = iframe.contentWindow.document
       
@@ -501,14 +527,16 @@
       doc.write(`</body></html>`)
       doc.close()
 
-      iframe.contentWindow.focus()
-      iframe.contentWindow.print()
-
-      document.body.removeChild(iframe)
-
       setTimeout(() => {
-        window.close()
-      }, 2000)
+        iframe.contentWindow.focus()
+        iframe.contentWindow.print()
+
+        document.body.removeChild(iframe)
+
+        setTimeout(() => {
+          window.close()
+        }, 2000)
+      }, 500)
     } catch (e) {
       notification.warning({
         top: 92,
@@ -556,6 +584,18 @@
             <NormalTable config={item} initdata={item.data} mainSearch={[]} menuType="" />
           </Col>
         )
+      } else if (item.type === 'editor') {
+        return (
+          <Col span={item.width} key={item.uuid}>
+            <BraftEditor config={item} initdata={item.data} mainSearch={[]} menuType="" />
+          </Col>
+        )
+      } else if (item.type === 'code') {
+        return (
+          <Col span={item.width} key={item.uuid}>
+            <SandBox config={item} initdata={item.data} mainSearch={[]} menuType="" />
+          </Col>
+        )
       } else {
         return null
       }
@@ -569,7 +609,7 @@
       <div className="bill-print-wrap" >
         {loadingview && <Spin size="large" />}
         {pages ? <div id="bill-print">
-          {pages.map((components, index) => (<div className="print-page" key={index} style={{...config.style, overflow: 'hidden'}}><Row>{this.getComponents(components)}</Row></div>))}
+          {pages.map((components, index) => (<div className="print-page" key={index} style={{...config.style, overflow: 'hidden', boxSizing: 'border-box'}}><Row>{this.getComponents(components)}</Row></div>))}
         </div> : null}
         {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
         {pages && !loadingview && !viewlost ? <div className="print-button"><Button icon="printer" size="large" shape="circle" onClick={this.print}></Button></div> : null}

--
Gitblit v1.8.0