android 菜鸟面单打印_关于菜鸟的圆通电子面单打印

1

2

3

Print Test

4

5

6

7 /*div#ctlDiv {height:750px;width:50%;float:left;border-style:solid;border-color:red;border-width:0px;}*/

8 div#pdfDiv{height:750px;width:49%;border-style:solid;border-color:red;border-width:0px;}

9

10

11

12 varsocket;13

14 window.οnlοad= functionload()15 {16

17 document.getElementById("pdfDiv").style.visibility="hidden";18 }19

20 functionsetStatusLabel(msg)21 {22 vareStatus=document.getElementById("connectionStatus");23 eStatus.innerHTML=msg;24 }25

26 functiondoConnect(callback)27 {28 varserviceUrl=document.getElementById("serviceUrl").value;29

30 socket= newWebSocket(serviceUrl);31

32 //监听消息

33 socket.onmessage= function(event)34 {35 console.log('Client received a message',event);36 document.getElementById("pdfDiv").style.visibility="hidden";37 //parse json

38 varobj=eval('('+event.data+')');39

40 if(obj&&(obj.previewURL||obj.previewImage))41 {42 varurl;43 if(obj&&obj.previewURL) {44 url=obj.previewURL;45 }else if(obj&&obj.previewImage) {46 url=obj.previewImage;47 }48 varpdf=document.getElementById('pdf');49 if(pdf) {50 pdf.setAttribute('src', url);51 document.getElementById("pdfDiv").style.visibility="visible";52 }53 }54 varresultElement=document.getElementById("resultMessage");55 resultElement.value=resultElement.value+event.data+ "\n";56 resultElement.scrollTop=resultElement.scrollHeight;57 };58

59 socket.onopen= function(event)60 {61 if(callback!= null) {62 callback();63 }64 setStatusLabel("已连接");65 }66

67 socket.οnerrοr= function(error)68 {69 console.log("Failed to connect CN print at" +serviceUrl, error);70 setStatusLabel("连接错误");71 }72

73 //监听Socket的关闭

74 socket.onclose= function(event)75 {76 console.log('Client notified socket has closed',event);77 setStatusLabel("连接关闭");78 };79 }80

81 functionsendCommand()82 {83 if(typeofsocket== "undefined" ||socket.readyState==WebSocket.CLOSED) {84 doConnect(sendCommand);85 return;86 }87

88 if(socket.readyState!=WebSocket.OPEN) {89 alert("无效连接:" +socket.readyState);90 return;91 }92

93 varmsg=document.getElementById('printmessage').value;94 varrepeatCount=document.getElementById('repeatCount').value;95 varisPreview=document.getElementById('isPreview').checked;96 vartime= newDate().getTime();97

98 for(varindex= 0; index

101 if(obj["task"])102 {103 //taskID

104 obj["task"]["taskID"]=time.toString()+ "_TASK_" +index;105

106 //preview

107 obj["task"]["preview"]=isPreview;108 }109

110 varnewMsg=JSON.stringify(obj);111 socket.send(newMsg);112 }113 }114

115 functionclearResult()116 {117 varresultElement=document.getElementById("resultMessage");118 resultElement.value= "";119 }120

121

122

123

124

125

126

127

128

129 重复发送请求:   

130 预览模式131

132

133 未知

134

135

136 {137 "cmd": "print",138 "requestID": "123458976",139 "version": "1.0",140 "task": {141 "taskID": "7293666",142 "preview": false,143 "printer": "",144 "notifyMode": "allInOne",145 "previewType": "html",146 "documents": [147 {148 "documentID": "0123456789",149 "contents": [150 {$list}//数据是在这里哦接收的,你不需要改什么,如果你觉得这不是你想要的,你也可以借鉴一下方法151 ]152 }153 ]154 }155 }156

157

158

159

160

161

162

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值