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 +++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 106 insertions(+), 63 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})

--
Gitblit v1.8.0