You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
274 lines
6.1 KiB
274 lines
6.1 KiB
<html>
|
|
<head>
|
|
<meta charset="utf-8" />
|
|
<title>WebSocket测试</title>
|
|
<style>
|
|
.div1
|
|
{
|
|
width:300px;
|
|
margin:auto;
|
|
}
|
|
.form-group {
|
|
display: flex;
|
|
align-items: center;
|
|
margin-bottom:10px;
|
|
}
|
|
label {
|
|
width: 100px;
|
|
text-align:right;
|
|
}
|
|
|
|
input {
|
|
width: calc(100% - 100px);
|
|
}
|
|
</style>
|
|
<script>
|
|
var webSocket = {};
|
|
//创建websockt
|
|
function CreateWebSocket() {
|
|
webSocket = new WebSocket("ws://127.0.0.1:9083");
|
|
webSocket.onopen = function(){
|
|
addlog("已经打开连接!");
|
|
};
|
|
webSocket.onmessage = function(event){
|
|
addlog('GET->'+event.data);
|
|
};
|
|
webSocket.onclose = function(){
|
|
addlog('和服务器断开连接');
|
|
};
|
|
};
|
|
|
|
//发送事件
|
|
function WebSocketSendMsg(testName) {
|
|
//获取text中的值
|
|
var id = document.getElementById("id").value;
|
|
var uid = document.getElementById("uid").value;
|
|
var pid = document.getElementById("pid").value;
|
|
var
|
|
Name = document.getElementById("firstName").value;
|
|
var lastName = document.getElementById("lastName").value;
|
|
var sex = document.getElementById("sex").value;
|
|
var birthday = document.getElementById("birthday").value;
|
|
var projectCode = document.getElementById("projectCode").value;
|
|
var projectName = document.getElementById("projectName").value;
|
|
|
|
var o={
|
|
id:'xx01',
|
|
command: testName,
|
|
data:{
|
|
id:id,
|
|
uid:uid,
|
|
pid:pid,
|
|
firstName:firstName,
|
|
lastName:lastName,
|
|
sex:sex,
|
|
birthday:birthday,
|
|
projectCode:projectCode,
|
|
projectName:projectName
|
|
}
|
|
}
|
|
|
|
addlog(JSON.stringify(o));
|
|
//发送到服务器
|
|
webSocket.send(JSON.stringify(o));
|
|
}
|
|
|
|
function configSet(){
|
|
var o={
|
|
id:'xxx',
|
|
command:'configSet',
|
|
data:{
|
|
titleText:'HM',
|
|
hotKey:'F4',
|
|
deviceId:'xxxxxxxxxx',
|
|
pluginName:'AAAAAA',
|
|
pluginContent:'BASE64*********',
|
|
postUrl:'http://xxx.xxx.xxx.xxx/xxx'
|
|
}
|
|
};
|
|
|
|
webSocket.send(JSON.stringify(o));
|
|
}
|
|
|
|
function configQuery() {
|
|
var o={
|
|
id:'xx02',
|
|
command: 'configQuery'
|
|
}
|
|
|
|
addlog(JSON.stringify(o));
|
|
//发送到服务器
|
|
webSocket.send(JSON.stringify(o));
|
|
};
|
|
|
|
function pdfOcr() {
|
|
var o = {
|
|
id: 'xxx',
|
|
command: 'pdfOcr',
|
|
data: {
|
|
fileId:'4615445250759CF22F1A49089D4B2C7A',
|
|
}
|
|
}
|
|
|
|
addlog(JSON.stringify(o));
|
|
//发送到服务器
|
|
webSocket.send(JSON.stringify(o));
|
|
};
|
|
|
|
function serialPortTest() {
|
|
var o = {
|
|
id: 'xxx',
|
|
command: 'serialPortTest',
|
|
data: {
|
|
portName: 'COM1',
|
|
baudRate: 9600,
|
|
parity: 0,
|
|
dataBits: 8,
|
|
stopBits: 0
|
|
}
|
|
}
|
|
|
|
addlog(JSON.stringify(o));
|
|
//发送到服务器
|
|
webSocket.send(JSON.stringify(o));
|
|
};
|
|
|
|
function serialPortWork() {
|
|
var o = {
|
|
id: 'xxx',
|
|
command: 'serialPortWork',
|
|
data: {
|
|
portName: 'COM1',
|
|
baudRate: 9600,
|
|
parity: 0,
|
|
dataBits: 8,
|
|
stopBits: 0,
|
|
wait: 2000
|
|
}
|
|
}
|
|
|
|
addlog(JSON.stringify(o));
|
|
//发送到服务器
|
|
webSocket.send(JSON.stringify(o));
|
|
};
|
|
|
|
function filesQuery() {
|
|
var o = {
|
|
id:'xxx',
|
|
command:'filesQuery',
|
|
data:{
|
|
beginDay:'2024-07-05',
|
|
endDay:'2024-09-25'
|
|
}
|
|
}
|
|
|
|
addlog(JSON.stringify(o));
|
|
//发送到服务器
|
|
webSocket.send(JSON.stringify(o));
|
|
};
|
|
|
|
|
|
function addlog(txt) {
|
|
var para = document.createElement("p");
|
|
var node = document.createTextNode(txt);
|
|
para.appendChild(node);
|
|
|
|
var element = document.getElementById("log");
|
|
element.appendChild(para);
|
|
}
|
|
|
|
function dcmScan(){
|
|
var o = {
|
|
id:'xxx',
|
|
command:'dcmScan',
|
|
data:{
|
|
beginDay:'2012-01-01'
|
|
}
|
|
}
|
|
|
|
addlog(JSON.stringify(o));
|
|
//发送到服务器
|
|
webSocket.send(JSON.stringify(o));
|
|
}
|
|
|
|
function dcmQuery(){
|
|
var o = {
|
|
id:'xxx',
|
|
command:'dcmQuery',
|
|
data:{
|
|
day:'2012-06-06'
|
|
}
|
|
}
|
|
|
|
addlog(JSON.stringify(o));
|
|
//发送到服务器
|
|
webSocket.send(JSON.stringify(o));
|
|
}
|
|
|
|
</script>
|
|
</head>
|
|
<body onload="CreateWebSocket()">
|
|
<div class="div1">
|
|
<h2>WebSocket DEMO</h2>
|
|
<div class="form-group">
|
|
<label for="id">ID:</label>
|
|
<input type="text" id="id" name="id" value="id001">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="uid">UID:</label>
|
|
<input type="text" id="uid" name="uid" value="uid001">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="pid">PID:</label>
|
|
<input type="text" id="pid" name="pid" value="pid001">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="firstName">FirstName:</label>
|
|
<input type="text" id="firstName" name="firstName" value="shihong">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="lastName">LastName:</label>
|
|
<input type="text" id="lastName" name="lastName" value="zhou">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="sex">Sex:</label>
|
|
<input type="text" id="sex" name="sex" value="1">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="birthday">Birthday:</label>
|
|
<input type="text" id="birthday" name="birthday" value="1990-01-01">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="projectCode">ProjectCode:</label>
|
|
<input type="text" id="projectCode" name="projectCode" value="pc001">
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="projectName">ProjectName:</label>
|
|
<input type="text" id="projectName" name="projectName" value="pn001">
|
|
</div>
|
|
|
|
<div style="text-align:center;">
|
|
<button onclick="CreateWebSocket()">连接</button>
|
|
<button onclick="configSet()">configSet</button>
|
|
<button onclick="configQuery()">configQuery</button>
|
|
<button onclick="serialPortTest()">SP-TEST</button>
|
|
<button onclick="serialPortWork()">SP-WORK</button>
|
|
|
|
|
|
<button onclick="filesQuery()">filesQuery</button>
|
|
<button onclick="pdfOcr()">pdfOcr</button>
|
|
<button onclick="serialPortWork()">SP-WORK</button>
|
|
<br/>
|
|
|
|
|
|
<button onclick="dcmScan()">dcmScan</button>
|
|
<button onclick="dcmQuery()">dcmQuery</button>
|
|
</div>
|
|
|
|
<div id="log">
|
|
|
|
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|