8 changed files with 98 additions and 46 deletions
-
2package-lock.json
-
2package.json
-
22public/index.html
-
2public/lib/zepto.min.js
-
31public/main.js
-
6public/style.css
-
26public/test.html
-
37src/index.ts
@ -0,0 +1,22 @@ |
|||
<!DOCTYPE html> |
|||
<html lang="en"> |
|||
<head> |
|||
<meta charset="UTF-8" /> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
|||
<title>Document</title> |
|||
<link rel="stylesheet" href="style.css" /> |
|||
</head> |
|||
<body> |
|||
<div class="main"> |
|||
<div class="form"> |
|||
<label for="username">用户名</label> |
|||
<input type="text" id="username" /> |
|||
<label for="password">密码</label> |
|||
<input type="password" id="password" /> |
|||
<button type="submit" id="submit_user_pwd">确定</button> |
|||
</div> |
|||
</div> |
|||
<script src="lib/zepto.min.js"></script> |
|||
<script src="main.js"></script> |
|||
</body> |
|||
</html> |
2
public/lib/zepto.min.js
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,31 @@ |
|||
const ws = new WebSocket(`ws://${window.location.host}`); |
|||
|
|||
ws.onopen = () => { |
|||
console.log("Connected to server"); |
|||
ws.send("Hello from client!"); |
|||
}; |
|||
|
|||
ws.onmessage = event => { |
|||
console.log(`Message from server: ${event.data}`); |
|||
}; |
|||
|
|||
ws.onclose = () => { |
|||
console.log("Disconnected from server"); |
|||
}; |
|||
|
|||
$("#submit_user_pwd").on("click", () => { |
|||
const name = $("#username").val(); |
|||
const pwd = $("#password").val(); |
|||
$.ajax({ |
|||
type: "POST", |
|||
url: "/test", |
|||
data: JSON.stringify({ name, pwd }), |
|||
contentType: "application/json", |
|||
success: res => { |
|||
console.log("Success", res); |
|||
}, |
|||
error: err => { |
|||
console.error("Error", err); |
|||
}, |
|||
}); |
|||
}); |
@ -0,0 +1,6 @@ |
|||
.form { |
|||
display: flex; |
|||
flex-direction: column; |
|||
align-items: start; |
|||
gap: 8px; |
|||
} |
@ -1,26 +0,0 @@ |
|||
<!DOCTYPE html> |
|||
<html lang="en"> |
|||
<head> |
|||
<meta charset="UTF-8" /> |
|||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
|||
<title>Document</title> |
|||
</head> |
|||
<body> |
|||
<script> |
|||
const ws = new WebSocket("ws://localhost:3003"); |
|||
|
|||
ws.onopen = () => { |
|||
console.log("Connected to server"); |
|||
ws.send("Hello from client!"); |
|||
}; |
|||
|
|||
ws.onmessage = event => { |
|||
console.log(`Message from server: ${event.data}`); |
|||
}; |
|||
|
|||
ws.onclose = () => { |
|||
console.log("Disconnected from server"); |
|||
}; |
|||
</script> |
|||
</body> |
|||
</html> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue