From f0602b981659c6d1ff18e8dba4ca1ce89c5f5610 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 22 三月 2020 21:18:34 +0800
Subject: [PATCH] 2020-03-22

---
 src/tabviews/zshare/actionList/index.jsx        |  169 ++++++++++++++++++++++++++---------------
 src/templates/zshare/verifycardprint/index.jsx  |   62 ++++++++-------
 src/templates/zshare/verifycardprint/index.scss |    7 +
 3 files changed, 147 insertions(+), 91 deletions(-)

diff --git a/src/tabviews/zshare/actionList/index.jsx b/src/tabviews/zshare/actionList/index.jsx
index 942dd60..ad64acb 100644
--- a/src/tabviews/zshare/actionList/index.jsx
+++ b/src/tabviews/zshare/actionList/index.jsx
@@ -225,60 +225,10 @@
       formdata[_data.key] = _data.value
     })
 
-    // btn.verify.printFunc = `
-    //   let _data = data[0]
-    //   _data = JSON.parse(_data)
-
-    //   let socket = new WebSocket(_data.wsaddr)
-      
-    //   // 鎵撳紑Socket
-    //   socket.onopen = () => {
-    //     notification.success({
-    //       top: 92,
-    //       message: '鎵撳嵃璇锋眰宸插彂鍑恒��',
-    //       duration: 2
-    //     })
-    //     socket.send(JSON.stringify(_data.data))
-    //   }
-    //   // 鐩戝惉娑堟伅
-    //   socket.onmessage = (event) => {
-    //     let data = ''
-
-    //     if (event.data) {
-    //       try {
-    //         data = JSON.parse(event.data)
-    //       } catch {
-    //         notification.warning({
-    //           top: 92,
-    //           message: event.data,
-    //           duration: 10
-    //         })
-    //         data = ''
-    //       }
-    //     }
-
-    //     if (data && data.message && !data.status) {
-    //       notification.warning({
-    //         top: 92,
-    //         message: data.message,
-    //         duration: 10
-    //       })
-    //     }
-    //   }
-
-    //   socket.onerror = () => {
-    //     notification.warning({
-    //       top: 92,
-    //       message: '鏃犳硶杩炴帴鍒�:' + _data.wsaddr,
-    //       duration: 10
-    //     })
-    //   }
-    // `
-
     if (
       !btn.verify ||
       (btn.verify.printMode === 'normal' && (!btn.verify.Template || !btn.verify.linkUrl)) ||
-      (btn.verify.printMode === 'custom' && !btn.verify.printFunc)
+      (btn.verify.printMode === 'custom' && (!btn.verify.printFunc || !btn.verify.linkUrl))
     ) {
       notification.warning({
         top: 92,
@@ -412,15 +362,109 @@
     })
   }
 
-  execCustomPrint = (btn, printdata) => {
+  execCustomPrint = (item, printlist) => {
     this.setState({loadingUuid: ''})
 
-    try {
-      // eslint-disable-next-line
-      let func = new Function('data', 'notification', btn.verify.printFunc)  // 鏈�鍚庝竴涓弬鏁板綋鍑芥暟浣撴潵鎵ц锛屽墠闈㈢殑鍙傛暟褰撴垚鍑芥暟浣撶殑鍙傛暟銆�
-      func(printdata, notification)
-    } catch (e) {
-      console.warn(e)
+    if (!socket || socket.readyState !== 1 || socket.url !== 'ws://' + item.verify.linkUrl) {
+      socket = new WebSocket('ws://' + item.verify.linkUrl)
+    } else {
+      if (!item.printer) {
+        let request  = {
+          requestID: '',
+          version: '',
+          cmd: 'getPrinters'
+        }
+        socket.send(JSON.stringify(request))
+      } else {
+        this.setState({loadingUuid: ''})
+        try {
+          // eslint-disable-next-line
+          let func = new Function('socket', 'data', 'printer', 'notification', item.verify.printFunc)
+          func(socket, printlist, item.printer, notification)
+        } catch (e) {
+          console.warn(e)
+          notification.warning({
+            top: 92,
+            message: '鑷畾涔夊嚱鏁版墽琛岄敊璇紒',
+            duration: 10
+          })
+        }
+      }
+    }
+    // 鎵撳紑Socket
+    socket.onopen = () =>{
+      if (!item.printer) {
+        let request  = {
+          requestID: '',
+          version: '',
+          cmd: 'getPrinters'
+        }
+        socket.send(JSON.stringify(request))
+      } else {
+        this.setState({loadingUuid: ''})
+        try {
+          // eslint-disable-next-line
+          let func = new Function('socket', 'data', 'printer', 'notification', item.verify.printFunc)
+          func(socket, printlist, item.printer, notification)
+        } catch (e) {
+          console.warn(e)
+          notification.warning({
+            top: 92,
+            message: '鑷畾涔夊嚱鏁版墽琛岄敊璇紒',
+            duration: 10
+          })
+        }
+      }
+    }
+    // 鐩戝惉娑堟伅
+    socket.onmessage = (event) => {
+      let data = ''
+
+      if (event.data) {
+        try {
+          data = JSON.parse(event.data)
+        } catch {
+          data = ''
+          notification.warning({
+            top: 92,
+            message: event.data,
+            duration: 10
+          })
+          this.setState({loadingUuid: ''})
+        }
+      }
+
+      if (data && data.cmd === 'getPrinters' && data.status) {
+        this.setState({loadingUuid: ''})
+        try {
+          // eslint-disable-next-line
+          let func = new Function('socket', 'data', 'printer', 'notification', item.verify.printFunc)
+          func(socket, printlist, data.defaultPrinter, notification)
+        } catch (e) {
+          console.warn(e)
+          notification.warning({
+            top: 92,
+            message: '鑷畾涔夊嚱鏁版墽琛岄敊璇紒',
+            duration: 10
+          })
+        }
+      } else if (data && data.message && !data.status) {
+        notification.warning({
+          top: 92,
+          message: data.message,
+          duration: 10
+        })
+        this.setState({loadingUuid: ''})
+      }
+    }
+
+    socket.onerror = () => {
+      notification.warning({
+        top: 92,
+        message: '鏃犳硶杩炴帴鍒�:' + item.verify.linkUrl,
+        duration: 10
+      })
+      this.setState({loadingUuid: ''})
     }
   }
 
@@ -489,8 +533,7 @@
             result.forEach(res => {
               if (res.status) {
                 if (btn.verify.printMode === 'custom') {
-                  // _list.push(res.data)
-                  _list.push('{"status": true,"message": "","ErrCode": "","ErrMesg": "", "wsaddr": "ws://127.0.0.1:13529","wstype": "local/server","data": [{"cmd": "print","requestID": "202003091036391803ACEAAE08DF7454599AEA243D8959F","version": "1.0","task": {"taskID": "202003091036391803ACEAAE08DF7454599AEA243D8959F","preview": false,"printer": "Microsoft Print To PDF", "documents": [{"documentID": "05512003090002A243D8959F","contents": [{"data": {"Bill": "05512003090002","ReturnProduct": ""},"templateURL": "http://css.positecgroup.com/template/warespaceprint01/2020010810525789956968_U000000001.srt","ectype": "jdpop"}]}]}}	]}')
+                  _list.push(res)
                 } else {
                   res.data.forEach(_item => {
                     _list.push({data: _item, count: res.printCount})
@@ -590,7 +633,7 @@
         return Api.genericInterface(_callbackparam)
       } else if (response.status) {
         if (btn.verify.printMode === 'custom') {
-          _list.push(response.data)
+          _list.push(response)
         } else {
           response.data.forEach(_item => {
             _list.push({data: _item, count: response.printCount})
@@ -612,7 +655,7 @@
 
       if (response.status) {
         if (btn.verify.printMode === 'custom') {
-          _list.push(response.data)
+          _list.push(response)
         } else {
           response.data.forEach(_item => {
             _list.push({data: _item, count: response.printCount})
@@ -641,7 +684,7 @@
     Api.genericInterface(param).then(res => {
       if (res.status) {
         if (btn.verify.printMode === 'custom') {
-          _list.push(res.data)
+          _list.push(res)
         } else {
           res.data.forEach(_item => {
             _list.push({data: _item, count: res.printCount})
diff --git a/src/templates/zshare/verifycardprint/index.jsx b/src/templates/zshare/verifycardprint/index.jsx
index 5847ad1..c5e21b4 100644
--- a/src/templates/zshare/verifycardprint/index.jsx
+++ b/src/templates/zshare/verifycardprint/index.jsx
@@ -15,6 +15,7 @@
 import './index.scss'
 
 const { TabPane } = Tabs
+let _printFunc = null
 
 class VerifyCard extends Component {
   static propTpyes = {
@@ -43,8 +44,10 @@
       },
       linkType: _verify.linkType || 'system',
       printMode: _verify.printMode || 'normal',
-      printFunc: _verify.printFunc || '// Function(data, notification) // data-鎵撳嵃鏁版嵁鍒楄〃锛宯otification-淇℃伅鎻愮ず鎺т欢',
+      printFunc: _verify.printFunc || '// Function(socket, data, printer, notification) socket-WebSocket 瀵硅薄锛宒ata-鎵撳嵃鏁版嵁鍒楄〃锛宲rinter-鎵撳嵃鏈猴紝notification-淇℃伅鎻愮ず鎺т欢'
     })
+
+    _printFunc = _verify.printFunc || ''
   }
 
   componentDidMount() {
@@ -162,7 +165,7 @@
     return new Promise((resolve, reject) => {
       this.props.form.validateFieldsAndScroll((err, values) => {
         if (!err) {
-          let _verify = {...verify, ...values}
+          let _verify = {...verify, ...values, printFunc: _printFunc}
 
           resolve(_verify)
         } else {
@@ -231,6 +234,31 @@
                     )}
                   </Form.Item>
                 </Col>
+                <Col span={8}>
+                  <Form.Item label={'閾炬帴绫诲瀷'}>
+                    {getFieldDecorator('linkType', {
+                      initialValue: linkType || 'system'
+                    })(
+                      <Radio.Group onChange={this.changeLinkType}>
+                        <Radio value="system">绯荤粺</Radio>
+                        <Radio value="custom">鑷畾涔�</Radio>
+                      </Radio.Group>
+                    )}
+                  </Form.Item>
+                </Col>
+                <Col span={8}>
+                  <Form.Item label={'閾炬帴鍦板潃'}>
+                    {getFieldDecorator('linkUrl', {
+                      initialValue: verify.linkUrl || '127.0.0.1:13529',
+                      rules: [
+                        {
+                          required: true,
+                          message: this.props.dict['form.required.input'] + '閾炬帴鍦板潃!'
+                        }
+                      ]
+                    })(<Input placeholder="" autoComplete="off" disabled={linkType === 'system'} />)}
+                  </Form.Item>
+                </Col>
                 {printMode === 'custom' ? <Col span={24}>
                   <Form.Item label={'澶勭悊鍑芥暟'} className="printFunc">
                     {getFieldDecorator('printFunc', {
@@ -251,35 +279,13 @@
                           lineWrapping: true
                         }}
                         onBeforeChange={() => {}}
+                        onBlur={(editor) => {
+                          _printFunc = editor.getValue()
+                        }}
                       />
-                    )}
+                    )} 
                   </Form.Item>
                 </Col> : null}
-                {printMode === 'normal' ? <Col span={8}>
-                  <Form.Item label={'閾炬帴绫诲瀷'}>
-                    {getFieldDecorator('linkType', {
-                      initialValue: linkType || 'system'
-                    })(
-                      <Radio.Group onChange={this.changeLinkType}>
-                        <Radio value="system">绯荤粺</Radio>
-                        <Radio value="custom">鑷畾涔�</Radio>
-                      </Radio.Group>
-                    )}
-                  </Form.Item>
-                </Col> : null}
-                {printMode === 'normal' ? <Col span={8}>
-                  <Form.Item label={'閾炬帴鍦板潃'}>
-                    {getFieldDecorator('linkUrl', {
-                      initialValue: verify.linkUrl || '127.0.0.1:13529',
-                      rules: [
-                        {
-                          required: true,
-                          message: this.props.dict['form.required.input'] + '閾炬帴鍦板潃!'
-                        }
-                      ]
-                    })(<Input placeholder="" autoComplete="off" disabled={linkType === 'system'} />)}
-                  </Form.Item>
-                </Col> : null }
                 {printMode === 'normal' ? <Col span={8}>
                   <Form.Item label={'鎵撳嵃妯℃澘'}>
                     {getFieldDecorator('Template', {
diff --git a/src/templates/zshare/verifycardprint/index.scss b/src/templates/zshare/verifycardprint/index.scss
index fc537bc..7b8abf6 100644
--- a/src/templates/zshare/verifycardprint/index.scss
+++ b/src/templates/zshare/verifycardprint/index.scss
@@ -4,6 +4,9 @@
   }
   .ant-tabs-content {
     min-height: 40vh;
+    .ant-form-item {
+      margin-bottom: 10px;
+    }
   }
   .ant-input-disabled {
     color: rgba(0, 0, 0, 0.65);
@@ -36,5 +39,9 @@
   .code-mirror-area {
     font-size : 14px;
     line-height : 25px;
+
+    .CodeMirror {
+      height: calc(100vh - 360px);
+    }
   }
 }
\ No newline at end of file

--
Gitblit v1.8.0