device_config.html 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. {% extends "base.html" %}
  2. {% block content %}
  3. <section class="device-info">
  4. <h2>设备信息</h2>
  5. {% if success is defined %}
  6. <script>
  7. // 创建弹窗元素
  8. const alertBox = document.createElement('div');
  9. alertBox.style.position = 'fixed';
  10. alertBox.style.top = '50%';
  11. alertBox.style.left = '50%';
  12. alertBox.style.transform = 'translate(-50%, -50%)';
  13. alertBox.style.padding = '20px';
  14. alertBox.style.borderRadius = '5px';
  15. alertBox.style.boxShadow = '0 2px 10px rgba(0,0,0,0.2)';
  16. alertBox.style.zIndex = '10000';
  17. alertBox.style.color = 'white';
  18. alertBox.style.fontWeight = 'bold';
  19. // 根据success值设置背景颜色
  20. alertBox.style.backgroundColor = "{{ 'green' if success else 'red' }}";
  21. // 设置弹窗内容
  22. alertBox.textContent = '{{ message }}';
  23. // 添加关闭按钮
  24. const closeBtn = document.createElement('button');
  25. closeBtn.textContent = '关闭';
  26. closeBtn.style.marginTop = '10px';
  27. closeBtn.style.padding = '5px 10px';
  28. closeBtn.style.border = 'none';
  29. closeBtn.style.borderRadius = '3px';
  30. closeBtn.style.backgroundColor = 'white';
  31. closeBtn.style.cursor = 'pointer';
  32. closeBtn.onclick = function() {
  33. document.body.removeChild(alertBox);
  34. };
  35. alertBox.appendChild(closeBtn);
  36. document.body.appendChild(alertBox);
  37. </script>
  38. {% endif %}
  39. <div class="info-grid">
  40. <div class="info-item">
  41. <span class="label">设备类型</span>
  42. <span class="value">{{ device.dev_type }}</span>
  43. </div>
  44. <div class="info-item">
  45. <span class="label">设备SN</span>
  46. <span class="value">{{ device.dev_sn }}</span>
  47. </div>
  48. <div class="info-item">
  49. <span class="label">固件版本</span>
  50. <span class="value">{{ device.firmware_ver }}</span>
  51. </div>
  52. <div class="info-item">
  53. <span class="label">在线状态</span>
  54. <span class="value" style="color: {% if device.online == '在线' %}green{% else %}red{% endif %};">{{ device.online }}</span>
  55. </div>
  56. </div>
  57. </section>
  58. <section class="device-configuration">
  59. <h2>参数配置</h2>
  60. <!-- WiFi配置表单 -->
  61. <div class="config-section">
  62. <h3>WiFi配置(例: wbjw/wbjw2025, e103-abc/12345678 )</h3>
  63. <form class="config-form" method="POST" action="{{ url_for('devices') }}">
  64. <input type="hidden" name="device_id" value="{{ device.id }}">
  65. <input type="hidden" name="dev_sn" value="{{ device.dev_sn }}">
  66. <input type="hidden" name="save_config" value="1">
  67. <input type="hidden" name="config_type" value="wifi">
  68. <div class="form-group">
  69. <label for="ssid">SSID</label>
  70. <input type="text" id="ssid" name="ssid" value="{{ device.wifi_ssid if 'wifi_ssid' in device else '' }}">
  71. </div>
  72. <div class="form-group">
  73. <label for="wifi_password">密码</label>
  74. <input type="password" id="wifi_password" name="wifi_password">
  75. </div>
  76. <button type="submit" class="save-config">保存WiFi配置</button>
  77. </form>
  78. </div>
  79. <!-- 云平台配置表单 -->
  80. <div class="config-section">
  81. <h3>云平台配置</h3>
  82. <form class="config-form" method="POST" action="{{ url_for('devices') }}">
  83. <input type="hidden" name="device_id" value="{{ device.id }}">
  84. <input type="hidden" name="dev_sn" value="{{ device.dev_sn }}">
  85. <input type="hidden" name="save_config" value="1">
  86. <input type="hidden" name="config_type" value="platform">
  87. <div class="form-group">
  88. <label>云平台选择</label>
  89. <div class="radio-group">
  90. {% for platform in platform_c %}
  91. <label>
  92. <input type="radio" name="cloud-platform"
  93. value="{{ platform.name }}"
  94. {{ 'checked' if 'cloud_platform' in device and device.cloud_platform == platform.name else '' }}>
  95. {{ platform.name }}
  96. </label>
  97. {% endfor %}
  98. </div>
  99. </div>
  100. <button type="submit" class="save-config">保存云平台配置</button>
  101. </form>
  102. </div>
  103. <!-- 网络类型配置表单 -->
  104. <div class="config-section">
  105. <h3>网络类型配置</h3>
  106. <form class="config-form" method="POST" action="{{ url_for('devices') }}">
  107. <input type="hidden" name="device_id" value="{{ device.id }}">
  108. <input type="hidden" name="dev_sn" value="{{ device.dev_sn }}">
  109. <input type="hidden" name="save_config" value="1">
  110. <input type="hidden" name="config_type" value="network">
  111. <div class="radio-group">
  112. <label>
  113. <input type="radio" name="network-type" value="WiFi"
  114. {{ 'checked' if 'network_type' in device and device.network_type == 'WiFi' else '' }}> WiFi
  115. </label>
  116. <label>
  117. <input type="radio" name="network-type" value="有线网"
  118. {{ 'checked' if 'network_type' in device and device.network_type == '有线网' else '' }}> 有线网
  119. </label>
  120. </div>
  121. <button type="submit" class="save-config">保存网络类型</button>
  122. </form>
  123. </div>
  124. <!-- 保存所有配置按钮 -->
  125. <div class="save-all-config-container">
  126. <button id="save-all-config" class="save-config">保存所有配置</button>
  127. </div>
  128. </section>
  129. <div class="back-btn-container">
  130. <a href="{{ url_for('devices') }}" class="back-btn">返回设备列表</a>
  131. </div>
  132. {% endblock %}
  133. {% block scripts %}
  134. <script>
  135. // 保存配置按钮效果
  136. document.querySelectorAll('.save-config').forEach(btn => {
  137. btn.addEventListener('click', function(e) {
  138. // 阻止默认提交行为,先显示提示再提交
  139. e.preventDefault();
  140. const form = this.closest('form');
  141. // alert('配置已保存');
  142. form.submit();
  143. });
  144. });
  145. // 保存所有配置按钮效果
  146. document.getElementById('save-all-config').addEventListener('click', function(e) {
  147. e.preventDefault();
  148. // 创建一个新表单,包含所有配置数据
  149. const allConfigForm = document.createElement('form');
  150. allConfigForm.method = 'POST';
  151. allConfigForm.action = "{{ url_for('devices') }}";
  152. // 添加设备ID
  153. const deviceIdInput = document.createElement('input');
  154. deviceIdInput.type = 'hidden';
  155. deviceIdInput.name = 'device_id';
  156. deviceIdInput.value = '{{ device.id }}';
  157. allConfigForm.appendChild(deviceIdInput);
  158. // 添加设备SN
  159. const deviceSnInput = document.createElement('input');
  160. deviceSnInput.type = 'hidden';
  161. deviceSnInput.name = 'dev_sn';
  162. deviceSnInput.value = '{{ device.dev_sn }}';
  163. allConfigForm.appendChild(deviceSnInput);
  164. // 添加保存配置标识
  165. const saveConfigInput = document.createElement('input');
  166. saveConfigInput.type = 'hidden';
  167. saveConfigInput.name = 'save_config';
  168. saveConfigInput.value = '1';
  169. allConfigForm.appendChild(saveConfigInput);
  170. // 添加配置类型为all
  171. const configTypeInput = document.createElement('input');
  172. configTypeInput.type = 'hidden';
  173. configTypeInput.name = 'config_type';
  174. configTypeInput.value = 'all';
  175. allConfigForm.appendChild(configTypeInput);
  176. // 收集WiFi配置
  177. const ssidInput = document.createElement('input');
  178. ssidInput.type = 'hidden';
  179. ssidInput.name = 'ssid';
  180. ssidInput.value = document.getElementById('ssid').value;
  181. allConfigForm.appendChild(ssidInput);
  182. const wifiPasswordInput = document.createElement('input');
  183. wifiPasswordInput.type = 'hidden';
  184. wifiPasswordInput.name = 'wifi_password';
  185. wifiPasswordInput.value = document.getElementById('wifi_password').value;
  186. allConfigForm.appendChild(wifiPasswordInput);
  187. // 收集云平台配置
  188. const cloudPlatformInput = document.createElement('input');
  189. cloudPlatformInput.type = 'hidden';
  190. cloudPlatformInput.name = 'cloud-platform';
  191. const selectedPlatform = document.querySelector('input[name="cloud-platform"]:checked');
  192. cloudPlatformInput.value = selectedPlatform ? selectedPlatform.value : '';
  193. allConfigForm.appendChild(cloudPlatformInput);
  194. // 收集网络类型配置
  195. const networkTypeInput = document.createElement('input');
  196. networkTypeInput.type = 'hidden';
  197. networkTypeInput.name = 'network-type';
  198. const selectedNetworkType = document.querySelector('input[name="network-type"]:checked');
  199. networkTypeInput.value = selectedNetworkType ? selectedNetworkType.value : '';
  200. allConfigForm.appendChild(networkTypeInput);
  201. // 提交表单
  202. document.body.appendChild(allConfigForm);
  203. allConfigForm.submit();
  204. });
  205. </script>
  206. {% endblock %}