device_detail.html 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. {% extends 'base.html' %}
  2. {% block content %}
  3. <section class="device-detail">
  4. <h2>设备详情</h2>
  5. <div class="device-info-card" id="deviceInfoCard">
  6. <div class="info-row">
  7. <span class="info-label">设备类型:</span>
  8. <span class="info-value" id="deviceType">{{ device.dev_type }}</span>
  9. </div>
  10. <div class="info-row">
  11. <span class="info-label">设备SN:</span>
  12. <span class="info-value" id="deviceSn">{{ device.dev_sn }}</span>
  13. </div>
  14. <div class="info-row">
  15. <span class="info-label">固件版本:</span>
  16. <span class="info-value" id="app_version">{{ device.app_version }}</span>
  17. </div>
  18. <div class="info-row">
  19. <span class="info-label">重置次数:</span>
  20. <span class="info-value" id="reset_times">{{ device.reset_times }}</span>
  21. </div>
  22. <div class="info-row">
  23. <span class="info-label">在线状态:</span>
  24. <span class="info-value" id="deviceOnline" style="color: {% if device.online == '在线' %}green{% else %}red{% endif %};">{{ device.online }}</span>
  25. </div>
  26. <div class="info-row">
  27. <span class="info-label">WiFi:</span>
  28. <span class="info-value" id="deviceWifi">{{ device.wifi_ssid }}/{{ device.wifi_password }}</span>
  29. </div>
  30. <div class="info-row">
  31. <span class="info-label">云平台:</span>
  32. <span class="info-value" id="deviceCloudPlatform">{{ device.cloud_platform }}</span>
  33. </div>
  34. <div class="info-row">
  35. <span class="info-label">网络类型:</span>
  36. <span class="info-value" id="deviceNetworkType">{{ device.network_type }}</span>
  37. </div>
  38. <div class="info-row">
  39. <span class="info-label">IP地址:</span>
  40. <span class="info-value" id="deviceIp">{{ device.ip }}</span>
  41. </div>
  42. <div class="info-row">
  43. <span class="info-label">统计信息:</span>
  44. </div>
  45. <div class="info-row">
  46. <span class="info-label">&nbsp;&nbsp;&nbsp;&nbsp;剩余资源:</span>
  47. <span class="info-value" id="deviceFreeFiFo">{{ device.free_fifo }}</span>
  48. </div>
  49. <div class="info-row">
  50. <span class="info-label">&nbsp;&nbsp;&nbsp;&nbsp;运行时间:</span>
  51. <span class="info-value" id="deviceRunTime">{{ device.run_time }}秒</span>
  52. </div>
  53. <div class="info-row">
  54. <span class="info-label">&nbsp;&nbsp;&nbsp;&nbsp;总条数:</span>
  55. <span class="info-value" id="deviceTotalCnt">{{ device.receive_sum }}条</span>
  56. </div>
  57. <div class="info-row">
  58. <span class="info-label">&nbsp;&nbsp;&nbsp;&nbsp;正常条数:</span>
  59. <span class="info-value" id="deviceNormalCnt">{{ device.send_sum }}条</span>
  60. </div>
  61. <div class="info-row">
  62. <span class="info-label">&nbsp;&nbsp;&nbsp;&nbsp;异常条数:</span>
  63. <span class="info-value" id="deviceAbnormalCnt">{{ device.abnormal_sum }}条</span>
  64. </div>
  65. <div class="info-row">
  66. <span class="info-label">&nbsp;&nbsp;&nbsp;&nbsp;成功率:</span>
  67. <span class="info-value" id="deviceSuccessRate">{{ device.success_rate }} &#37 </span>
  68. </div>
  69. <div class="info-row">
  70. <span class="info-label">&nbsp;&nbsp;&nbsp;&nbsp;速度:</span>
  71. <span class="info-value" id="deviceSpeed">{{ device.speed }} 条/秒</span>
  72. </div>
  73. <div class="info-row">
  74. <span class="info-label">最后更新时间:</span>
  75. <span class="info-value" id="lastUpdateTime">{{ datetime.now().strftime('%Y-%m-%d %H:%M:%S') }}</span>
  76. </div>
  77. </div>
  78. </section>
  79. <div class="back-btn-container">
  80. <a href="{{ url_for('devices') }}" class="back-btn">返回设备列表</a>
  81. </div>
  82. {% endblock %}
  83. {% block scripts %}
  84. <script>
  85. // 获取设备ID
  86. const dev_sn = "{{ device.dev_sn }}";
  87. // 刷新设备详情数据
  88. function refreshDeviceDetail() {
  89. fetch(`/api/device_detail/${dev_sn}`)
  90. .then(response => {
  91. if (!response.ok) {
  92. throw new Error('网络响应错误');
  93. }
  94. return response.json();
  95. })
  96. .then(data => {
  97. // 更新页面上的设备信息
  98. document.getElementById('deviceType').textContent = data.dev_type;
  99. document.getElementById('deviceSn').textContent = data.dev_sn;
  100. document.getElementById('app_version').textContent = data.app_version;
  101. document.getElementById('reset_times').textContent = data.reset_times;
  102. document.getElementById('deviceOnline').textContent = data.online;
  103. // 检查data中是否存在wifi_ssid和wifi_password
  104. const ssid = data.wifi_ssid ? data.wifi_ssid.replace(/[\s\n\t]/g, '*') : 'ssid未知';
  105. const password = data.wifi_password ? data.wifi_password.replace(/[\s\n\t]/g, '*') : '密码未知';
  106. document.getElementById('deviceWifi').textContent = `${ssid}/${password}`;
  107. document.getElementById('deviceIp').textContent = data.ip;
  108. document.getElementById('deviceFreeFiFo').textContent = data.free_fifo;
  109. document.getElementById('deviceRunTime').textContent = data.run_time_str;
  110. document.getElementById('deviceTotalCnt').textContent = data.receive_sum.toString().replace( /\B(?=(\d{3})+(?!\d))/g, ",") + '条';
  111. document.getElementById('deviceNormalCnt').textContent = data.send_sum.toString().replace( /\B(?=(\d{3})+(?!\d))/g, ",") + '条';
  112. document.getElementById('deviceAbnormalCnt').textContent = data.abnormal_sum.toString().replace( /\B(?=(\d{3})+(?!\d))/g, ",") + '条';
  113. document.getElementById('deviceSuccessRate').textContent = data.success_rate.toFixed(2) + ' %';
  114. document.getElementById('deviceSpeed').textContent = data.speed.toFixed(2) + ' 条/秒';
  115. // 动态更新可能存在的字段
  116. const cloudPlatformElem = document.getElementById('deviceCloudPlatform');
  117. if (cloudPlatformElem && data.cloud_platform) {
  118. cloudPlatformElem.textContent = data.cloud_platform;
  119. }
  120. const networkTypeElem = document.getElementById('deviceNetworkType');
  121. if (networkTypeElem && data.network_type) {
  122. networkTypeElem.textContent = data.network_type;
  123. }
  124. // 更新最后更新时间
  125. document.getElementById('lastUpdateTime').textContent =
  126. new Date().toLocaleString('zh-CN', {
  127. year: 'numeric',
  128. month: '2-digit',
  129. day: '2-digit',
  130. hour: '2-digit',
  131. minute: '2-digit',
  132. second: '2-digit'
  133. });
  134. })
  135. .catch(error => {
  136. console.error('获取设备详情失败:', error);
  137. });
  138. }
  139. // 初始加载
  140. refreshDeviceDetail();
  141. // 设置定时器,每秒刷新一次
  142. setInterval(refreshDeviceDetail, 1000);
  143. </script>
  144. {% endblock %}