index.html 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. <!-- HA 设备控制 -->
  9. <h3 style="margin-bottom: 20px; color: #2c3e50; border-bottom: 2px solid #eee; padding-bottom: 10px;">其他灯座控制</h3>
  10. <!-- 展厅桌面的灯座总开关 -->
  11. <div style="background: #f8f9fa; padding: 15px; border-radius: 8px; border: 1px solid #eee; margin-bottom: 15px;">
  12. <h4 style="margin-bottom: 15px; color: #555;">展厅桌面的灯座总开关</h4>
  13. <div class="control-row">
  14. <div class="control-group" style="display: flex; gap: 15px;">
  15. <button class="btn btn-secondary" style="flex: 1;" onclick="controlHALight('exhibition_desktop_switch', 'turn_on')">打开</button>
  16. <button class="btn" style="flex: 1; background-color: #34495e; color: white;" onclick="controlHALight('exhibition_desktop_switch', 'turn_off')">关闭</button>
  17. </div>
  18. </div>
  19. </div>
  20. <!-- 展厅桌面3D风扇投影 -->
  21. <div style="background: #f8f9fa; padding: 15px; border-radius: 8px; border: 1px solid #eee; margin-bottom: 15px;">
  22. <h4 style="margin-bottom: 15px; color: #555;">展厅桌面3D风扇投影</h4>
  23. <div class="control-row">
  24. <div class="control-group" style="display: flex; gap: 15px;">
  25. <button class="btn btn-secondary" style="flex: 1;" onclick="controlHALight('exhibition_3d_fan', 'turn_on')">打开</button>
  26. <button class="btn" style="flex: 1; background-color: #34495e; color: white;" onclick="controlHALight('exhibition_3d_fan', 'turn_off')">关闭</button>
  27. </div>
  28. </div>
  29. </div>
  30. <!-- 展台桌子灯带 -->
  31. <div style="background: #f8f9fa; padding: 15px; border-radius: 8px; border: 1px solid #eee; margin-bottom: 15px;">
  32. <h4 style="margin-bottom: 15px; color: #555;">展台桌子灯带</h4>
  33. <div class="control-row">
  34. <div class="control-group" style="display: flex; gap: 15px;">
  35. <button class="btn btn-secondary" style="flex: 1;" onclick="controlHALight('exhibition_stand_light_strip', 'turn_on')">打开</button>
  36. <button class="btn" style="flex: 1; background-color: #34495e; color: white;" onclick="controlHALight('exhibition_stand_light_strip', 'turn_off')">关闭</button>
  37. </div>
  38. </div>
  39. </div>
  40. <h3 style="margin-top: 30px; margin-bottom: 20px; color: #2c3e50; border-bottom: 2px solid #eee; padding-bottom: 10px;">展品灯带特效控制</h3>
  41. <div class="control-row">
  42. <div class="control-group">
  43. <label for="exhibitId">选择展品</label>
  44. <select id="exhibitId">
  45. {% if led_segments %}
  46. {% for segment in led_segments %}
  47. <option value="{{ segment.id }}">{{ segment.name }} (ID: {{ segment.id }})</option>
  48. {% endfor %}
  49. {% else %}
  50. <option value="0">未找到配置 (默认ID: 0)</option>
  51. {% endif %}
  52. </select>
  53. </div>
  54. <div class="control-group" style="flex: 2; display: flex; align-items: flex-end; gap: 10px;">
  55. <button class="btn btn-primary" onclick="startEffect()">启动灯效</button>
  56. <button class="btn btn-secondary" onclick="stopEffect()">停止灯效</button>
  57. <button class="btn btn-warning" onclick="getStatus()">刷新状态</button>
  58. </div>
  59. </div>
  60. <div class="status-display" id="ledStatusDisplay">
  61. <div id="statusContent">点击"刷新状态"查看当前LED状态</div>
  62. </div>
  63. <div style="margin-top: 20px; padding: 15px; background: #e3f2fd; border-radius: 8px; border-left: 4px solid #2196f3; color: #0d47a1;">
  64. <p><strong>📖 灯效说明:</strong> 指定展品将显示白色呼吸灯效,其他展品保持静止。10秒后,所有展品将随机播放波浪、闪烁或呼吸效果。</p>
  65. </div>
  66. </div>
  67. {% endblock %}
  68. {% block scripts %}
  69. <script>
  70. let currentStatus = null;
  71. document.addEventListener('DOMContentLoaded', function() {
  72. getStatus();
  73. });
  74. async function getStatus() {
  75. try {
  76. const response = await fetch('/api/led/status');
  77. const result = await response.json();
  78. if (result.success) {
  79. currentStatus = result.data;
  80. document.getElementById('statusContent').innerHTML = `
  81. <p><strong>运行状态:</strong> ${currentStatus.is_running ? '运行中' : '已停止'}</p>
  82. <p><strong>信息:</strong> ${currentStatus.message}</p>
  83. `;
  84. } else {
  85. document.getElementById('statusContent').innerHTML = `<span style="color:red">获取失败: ${result.message}</span>`;
  86. }
  87. } catch (error) {
  88. console.error(error);
  89. document.getElementById('statusContent').innerHTML = `<span style="color:red">网络错误</span>`;
  90. }
  91. }
  92. async function startEffect() {
  93. const exhibitId = parseInt(document.getElementById('exhibitId').value);
  94. if (isNaN(exhibitId) || exhibitId < 0) {
  95. showMessage('请输入有效的展品ID', 'error');
  96. return;
  97. }
  98. try {
  99. showLoading(true);
  100. const response = await fetch('/api/led/start', {
  101. method: 'POST',
  102. headers: { 'Content-Type': 'application/json' },
  103. body: JSON.stringify({ exhibit_id: exhibitId })
  104. });
  105. const result = await response.json();
  106. if (result.success) {
  107. showMessage(result.message);
  108. getStatus();
  109. } else {
  110. showMessage(result.message, 'error');
  111. }
  112. } catch (error) {
  113. showMessage('网络错误: ' + error.message, 'error');
  114. } finally {
  115. showLoading(false);
  116. }
  117. }
  118. async function stopEffect() {
  119. try {
  120. showLoading(true);
  121. const response = await fetch('/api/led/stop', { method: 'POST', headers: { 'Content-Type': 'application/json' } });
  122. const result = await response.json();
  123. if (result.success) {
  124. showMessage(result.message);
  125. getStatus();
  126. } else {
  127. showMessage(result.message, 'error');
  128. }
  129. } catch (error) {
  130. showMessage('网络错误: ' + error.message, 'error');
  131. } finally {
  132. showLoading(false);
  133. }
  134. }
  135. async function controlHALight(device, action) {
  136. let url = '';
  137. if (device === 'all') {
  138. url = `/api/ha/${action}_all`;
  139. } else {
  140. url = `/api/ha/${device}/${action}`;
  141. }
  142. try {
  143. showLoading(true);
  144. const response = await fetch(url, {
  145. method: 'POST',
  146. headers: { 'Content-Type': 'application/json' }
  147. });
  148. const result = await response.json();
  149. if (result.success) {
  150. showMessage(result.message);
  151. } else {
  152. showMessage(result.message, 'error');
  153. }
  154. } catch (error) {
  155. showMessage('网络错误: ' + error.message, 'error');
  156. } finally {
  157. showLoading(false);
  158. }
  159. }
  160. </script>
  161. {% endblock %}