wangrong
2025-09-23 f19a0e925da02a08b88784a534b16ec6d833df4c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>路测控制面板</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      padding: 20px;
      margin: 0;
      box-sizing: border-box;
      background-color: #f8f8f8;
    }
 
    h2 {
      text-align: center;
      margin-bottom: 20px;
    }
 
    #status {
      font-size: 18px;
      margin-bottom: 20px;
      color: #333;
      text-align: center;
    }
 
    .controls {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 10px;
    }
 
    .input-group {
      display: flex;
      flex-direction: row;
      align-items: center;
      gap: 10px;
      flex-wrap: wrap;
      justify-content: center;
    }
 
    input[type="text"] {
      padding: 8px;
      font-size: 16px;
      border-radius: 4px;
      border: 1px solid #ccc;
      width: 120px;
    }
 
    button {
      padding: 10px 20px;
      font-size: 16px;
      border: none;
      background-color: #007bff;
      color: white;
      border-radius: 5px;
      cursor: pointer;
    }
 
    button:hover {
      background-color: #0056b3;
    }
 
    #result {
      margin-top: 20px;
      text-align: center;
      font-size: 16px;
      color: green;
    }
 
    @media (max-width: 600px) {
      h2 {
        font-size: 20px;
      }
 
      input[type="text"], button {
        width: 90%;
        font-size: 16px;
      }
 
      .input-group {
        flex-direction: column;
      }
    }
  </style>
</head>
<body>
 
  <h2>🚗 路测状态监控</h2>
 
  <div id="status">状态读取中...</div>
 
  <div class="controls">
    <div class="input-group">
      <label>路线代码:</label>
      <input type="text" id="routeCode" placeholder="如:line1">
      <label>楼层代码:</label>
      <input type="text" id="floorCode" placeholder="如:F1">
      <label>区域代码:</label>
      <input type="text" id="areaCode" placeholder="如:A">
    </div>
 
    <div class="input-group">
      <button onclick="startCollection()">开始</button>
      <button onclick="stopCollection()">停止</button>
    </div>
  </div>
 
  <div id="result"></div>
 
  <script>
    function updateStatus() {
      fetch('/status')
        .then(response => response.json())
        .then(data => {
          document.getElementById('status').textContent =
            `当前状态:${data.status.toUpperCase()}(check_line: ${data.check_line})`;
        })
        .catch(() => {
          document.getElementById('status').textContent = '❌ 无法获取状态';
        });
    }
 
    function startCollection() {
      const route = document.getElementById('routeCode').value.trim();
      const floor = document.getElementById('floorCode').value.trim();
      const area = document.getElementById('areaCode').value.trim();
      const resultDiv = document.getElementById('result');
      const regex = /^[a-zA-Z0-9]+$/;
 
      // 校验三个输入框是否都非空,并且只包含字母或数字
      if (!route || !floor || !area) {
        resultDiv.textContent = '❌ 所有字段都必须填写';
        resultDiv.style.color = 'red';
        return;
      }
 
      if (!regex.test(route) || !regex.test(floor) || !regex.test(area)) {
        resultDiv.textContent = '❌ 只允许输入字母或数字';
        resultDiv.style.color = 'red';
        return;
      }
 
      const checkLine = `${route}_${floor}_${area}`;
 
      fetch(`/start?check_line=${encodeURIComponent(checkLine)}`)
        .then(res => res.json())
        .then(data => {
          resultDiv.textContent = `✅ 开始接收: check_line=${data.check_line}`;
          resultDiv.style.color = 'green';
          updateStatus();
        })
        .catch(() => {
          resultDiv.textContent = '❌ 启动失败';
          resultDiv.style.color = 'red';
        });
    }
 
    function stopCollection() {
      fetch('/stop')
        .then(res => res.json())
        .then(() => {
          document.getElementById('result').textContent = `🛑 接收已停止`;
          updateStatus();
        })
        .catch(() => {
          document.getElementById('result').textContent = '❌ 停止失败';
        });
    }
 
    window.onload = updateStatus;
    setInterval(updateStatus, 5000);
  </script>
 
</body>
</html>