<h2>登录认证</h2>
<div class="form-group">
<label for="username">用户名:</label>
- <input type="text" id="username" placeholder="请输入用户名">
+ <input type="text" id="username" value="admin" placeholder="请输入用户名">
</div>
<div class="form-group">
<label for="password">密码:</label>
- <input type="password" id="password" placeholder="请输入密码">
+ <input type="password" id="password" value="admin123" placeholder="请输入密码">
</div>
<button id="login-button">登录</button>
<button id="logout-button" disabled>登出</button>
background-color: #27ae60;
}
.btn-danger {
- background-color: #e74c3c;
+background-color: #e74c3c;
}
.btn-danger:hover {
background-color: #c0392b;
- }
+}
/* 添加WebSocket连接状态按钮样式 */
.btn-connected {
background-color: #27ae60;
<h2>GET请求测试</h2>
<div class="form-group">
<label for="get-url">URL:</label>
- <input type="text" id="get-url" value="http://localhost:8000/api/get" placeholder="输入GET请求URL">
+ <input type="text" id="get-url" value="http://localhost/api/pcs_info" placeholder="输入GET请求URL">
</div>
<div class="button-group">
<button id="get-request-button" class="btn">发送GET请求</button>
<h2>WebSocket测试</h2>
<div class="form-group">
<label for="websocket-url">WebSocket URL:</label>
- <input type="text" id="websocket-url" value="ws://localhost:8000/ws/" placeholder="输入WebSocket URL">
+ <input type="text" id="websocket-url" value="ws://localhost/ws/" placeholder="输入WebSocket URL">
</div>
<div class="button-group">
<button id="connect-websocket-button" class="btn btn-primary btn-disconnected">连接</button>
</div>
<div id="responseMessage"></div>
<script>
+ // 添加页面加载时自动设置GET请求URL和WebSocket URL的host部分
+ document.addEventListener('DOMContentLoaded', function() {
+ // 获取当前页面的host
+ const currentHost = window.location.host;
+
+ // 设置GET请求URL
+ const getUrlInput = document.getElementById('get-url');
+ if (getUrlInput) {
+ // 保留原URL的路径部分,只替换host
+ const originalUrl = getUrlInput.value;
+ const urlParts = originalUrl.split('/');
+ // 重建URL,使用当前页面的host
+ const newUrl = urlParts[0] + '//' + currentHost + '/' + urlParts.slice(3).join('/');
+ getUrlInput.value = newUrl;
+ }
+
+ // 设置WebSocket URL
+ const websocketUrlInput = document.getElementById('websocket-url');
+ if (websocketUrlInput) {
+ // 保留原URL的路径部分,只替换host
+ const originalWsUrl = websocketUrlInput.value;
+ const wsUrlParts = originalWsUrl.split('/');
+ // 重建URL,使用当前页面的host
+ const newWsUrl = wsUrlParts[0] + '//' + currentHost + '/' + wsUrlParts.slice(3).join('/');
+ websocketUrlInput.value = newWsUrl;
+ }
+ });
+
document.getElementById('myForm').addEventListener('submit', function(e) {
//处理上传文件成功后的响应处理,避免直接跳转到新页面
const getPcsParamsButton = document.getElementById("get-pcs-params-button");
const pcsParamsInfoLoading = document.getElementById("pcs-params-info-loading");
const pcsParamsInfoResponse = document.getElementById("pcs-params-info-response");
-
// 检查DOM元素是否存在
if (!getPcsParamsButton || !pcsParamsInfoLoading || !pcsParamsInfoResponse) {
console.error("获取PCS参数信息所需的DOM元素不存在");