index.html 4.7 KB

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