index.html 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. {% extends "base.html" %}
  2. {% block title %}办公楼大门控制{% endblock %}
  3. {% block content %}
  4. <div class="module-header">
  5. <h2>🚪 办公楼大门控制</h2>
  6. </div>
  7. <div class="sub-section">
  8. <div style="background: #f8f9fa; padding: 20px; border-radius: 10px; border: 1px solid #eee; margin-bottom: 20px;">
  9. <h4 style="margin-bottom: 15px; color: #2ecc71;">🔓 远程开门</h4>
  10. <div class="control-row">
  11. <div class="control-group" style="flex: 2;">
  12. <p style="color: #666; margin-bottom: 0; display: flex; align-items: center; height: 100%;">控制办公楼大门 (ID: 1)</p>
  13. </div>
  14. <div class="control-group" style="flex: 0 0 auto;">
  15. <button class="btn btn-primary" onclick="remoteOpenDoor()">远程开门</button>
  16. </div>
  17. </div>
  18. </div>
  19. <div style="background: #f8f9fa; padding: 20px; border-radius: 10px; border: 1px solid #eee;">
  20. <h4 style="margin-bottom: 15px; color: #e74c3c;">⚙️ 模式设置</h4>
  21. <div class="control-row">
  22. <div class="control-group">
  23. <label for="doorControlWay">控制模式</label>
  24. <select id="doorControlWay">
  25. <option value="0">在线 (普通模式)</option>
  26. <option value="1">常开 (保持开启)</option>
  27. <option value="2">常闭 (保持关闭)</option>
  28. </select>
  29. </div>
  30. <div class="control-group" style="flex: 0 0 auto;">
  31. <button class="btn btn-warning" onclick="setDoorMode()">应用设置</button>
  32. </div>
  33. </div>
  34. </div>
  35. </div>
  36. {% endblock %}
  37. {% block scripts %}
  38. <script>
  39. async function remoteOpenDoor() {
  40. const doorId = 1;
  41. const payload = { door_id: doorId };
  42. try {
  43. showLoading(true);
  44. const response = await fetch('/api/door/open', {
  45. method: 'POST',
  46. headers: { 'Content-Type': 'application/json' },
  47. body: JSON.stringify(payload)
  48. });
  49. const result = await response.json();
  50. if (result.success) {
  51. showMessage(result.message);
  52. } else {
  53. showMessage(result.message, 'error');
  54. }
  55. } catch (error) {
  56. showMessage('网络错误: ' + error.message, 'error');
  57. } finally {
  58. showLoading(false);
  59. }
  60. }
  61. async function setDoorMode() {
  62. const controlWay = parseInt(document.getElementById('doorControlWay').value);
  63. const payload = { control_way: controlWay };
  64. const modeName = controlWay === 0 ? '在线' : (controlWay === 1 ? '常开' : '常闭');
  65. if (!confirm(`确定要将门禁设置为"${modeName}"模式吗?`)) return;
  66. try {
  67. showLoading(true);
  68. const response = await fetch('/api/door/control', {
  69. method: 'POST',
  70. headers: { 'Content-Type': 'application/json' },
  71. body: JSON.stringify(payload)
  72. });
  73. const result = await response.json();
  74. if (result.success) {
  75. showMessage(result.message);
  76. } else {
  77. showMessage(result.message, 'error');
  78. }
  79. } catch (error) {
  80. showMessage('网络错误: ' + error.message, 'error');
  81. } finally {
  82. showLoading(false);
  83. }
  84. }
  85. </script>
  86. {% endblock %}