index.html 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. {% extends "base.html" %}
  2. {% block title %}展厅灯光控制{% endblock %}
  3. {% block content %}
  4. <div class="module-header">
  5. <h2>💡 展厅灯光控制 (HA)</h2>
  6. </div>
  7. <div class="sub-section">
  8. <!-- 1. 玄关顶灯 -->
  9. <div style="background: #f8f9fa; padding: 15px; border-radius: 8px; border: 1px solid #eee; margin-bottom: 15px;">
  10. <h4 style="margin-bottom: 15px; color: #555;">一楼大门玄关顶灯</h4>
  11. <div class="control-row">
  12. <div class="control-group" style="display: flex; gap: 15px;">
  13. <button class="btn btn-secondary" style="flex: 1;" onclick="controlHALight('entrance_lights', 'turn_on')">打开</button>
  14. <button class="btn" style="flex: 1; background-color: #34495e; color: white;" onclick="controlHALight('entrance_lights', 'turn_off')">关闭</button>
  15. </div>
  16. </div>
  17. </div>
  18. <!-- 2. 玄关射灯 -->
  19. <div style="background: #f8f9fa; padding: 15px; border-radius: 8px; border: 1px solid #eee; margin-bottom: 15px;">
  20. <h4 style="margin-bottom: 15px; color: #555;">一楼大门玄关射灯</h4>
  21. <div class="control-row">
  22. <div class="control-group" style="display: flex; gap: 15px;">
  23. <button class="btn btn-secondary" style="flex: 1;" onclick="controlHALight('exhibition_spotlight', 'turn_on')">打开</button>
  24. <button class="btn" style="flex: 1; background-color: #34495e; color: white;" onclick="controlHALight('exhibition_spotlight', 'turn_off')">关闭</button>
  25. </div>
  26. </div>
  27. </div>
  28. <!-- 3. 展厅顶灯 -->
  29. <div style="background: #f8f9fa; padding: 15px; border-radius: 8px; border: 1px solid #eee; margin-bottom: 15px;">
  30. <h4 style="margin-bottom: 15px; color: #555;">一楼展厅顶灯 (等级控制)</h4>
  31. <div class="control-row">
  32. <div class="control-group" style="display: flex; gap: 10px; align-items: center;">
  33. <span style="font-weight: bold; min-width: 30px;" id="ceilingLightLevelVal">0</span>
  34. <input type="range" id="ceilingLightLevel" min="0" max="3" value="0" step="1"
  35. style="flex: 1; height: 30px;"
  36. onchange="controlHALightLevel(this.value)"
  37. oninput="document.getElementById('ceilingLightLevelVal').textContent = this.value">
  38. </div>
  39. <div style="display: flex; justify-content: space-between; font-size: 12px; color: #666; margin-top: 5px; padding: 0 5px;">
  40. <span>0 (全关)</span>
  41. <span>1 (单灯)</span>
  42. <span>2 (双灯)</span>
  43. <span>3 (全开)</span>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. {% endblock %}
  49. {% block scripts %}
  50. <script>
  51. async function controlHALight(device, action) {
  52. let url = '';
  53. if (device === 'all') {
  54. url = `/api/ha/${action}_all`;
  55. } else {
  56. url = `/api/ha/${device}/${action}`;
  57. }
  58. try {
  59. showLoading(true);
  60. const response = await fetch(url, {
  61. method: 'POST',
  62. headers: { 'Content-Type': 'application/json' }
  63. });
  64. const result = await response.json();
  65. if (result.success) {
  66. showMessage(result.message);
  67. } else {
  68. showMessage(result.message, 'error');
  69. }
  70. } catch (error) {
  71. showMessage('网络错误: ' + error.message, 'error');
  72. } finally {
  73. showLoading(false);
  74. }
  75. }
  76. async function controlHALightLevel(level) {
  77. try {
  78. showLoading(true);
  79. const response = await fetch('/api/ha/exhibition_ceiling_lights/set_level', {
  80. method: 'POST',
  81. headers: { 'Content-Type': 'application/json' },
  82. body: JSON.stringify({ level: parseInt(level) })
  83. });
  84. const result = await response.json();
  85. if (result.success) {
  86. showMessage(result.message);
  87. } else {
  88. showMessage(result.message, 'error');
  89. }
  90. } catch (error) {
  91. showMessage('网络错误: ' + error.message, 'error');
  92. } finally {
  93. showLoading(false);
  94. }
  95. }
  96. </script>
  97. {% endblock %}