DetectorTable.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <div class="detector-monitor-table">
  3. <div class="table-header">
  4. <div class="header-left">
  5. <span v-for="tick in timeTicks" :key="tick" class="tick-item">{{ tick }}</span>
  6. </div>
  7. <div class="header-right">
  8. <div class="th-cell">编号</div>
  9. <div class="th-cell">名称</div>
  10. <div class="th-cell">流量</div>
  11. <div class="th-cell">占有率</div>
  12. </div>
  13. </div>
  14. <div class="table-body">
  15. <div class="table-row" v-for="item in tableData" :key="item.id">
  16. <div class="row-left">
  17. <!-- 留白:未来放每个检测器的时序曲线 -->
  18. </div>
  19. <div class="row-right">
  20. <div class="td-cell id-cell">{{ item.id }}</div>
  21. <div class="td-cell name-cell">{{ item.name }}</div>
  22. <div class="td-cell num-cell flow">{{ item.flow }}</div>
  23. <div class="td-cell num-cell occ">{{ item.occupancy }}</div>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import { apiGetDetectorMonitorData } from '@/api';
  31. export default {
  32. name: "DetectorMonitorTable",
  33. props: {
  34. intersectionId: { type: String, default: '' },
  35. pollIntervalMs: { type: Number, default: 5000 },
  36. },
  37. data() {
  38. return {
  39. timeTicks: [180, 150, 120, 90, 60, 30],
  40. tableData: [],
  41. };
  42. },
  43. mounted() {
  44. // pollTimer 直接挂在实例上(不进 data 避免无谓的响应式开销)
  45. this.pollTimer = null;
  46. this.fetchData();
  47. this.pollTimer = setInterval(this.fetchData, this.pollIntervalMs);
  48. },
  49. beforeDestroy() {
  50. if (this.pollTimer) {
  51. clearInterval(this.pollTimer);
  52. this.pollTimer = null;
  53. }
  54. },
  55. methods: {
  56. async fetchData() {
  57. try {
  58. const res = await apiGetDetectorMonitorData(this.intersectionId);
  59. if (res) {
  60. if (Array.isArray(res.tableData)) this.tableData = res.tableData;
  61. if (Array.isArray(res.timeTicks)) this.timeTicks = res.timeTicks;
  62. }
  63. } catch (e) {
  64. console.warn('[DetectorTable] fetchData failed:', e);
  65. }
  66. },
  67. },
  68. };
  69. </script>
  70. <style scoped>
  71. .detector-monitor-table {
  72. width: 100%;
  73. height: 100%;
  74. padding: clamp(2px, 0.5cqw, 4px);
  75. background: rgba(5, 22, 45, 0.9);
  76. color: #fff;
  77. font-family: inherit;
  78. box-sizing: border-box;
  79. display: flex;
  80. flex-direction: column;
  81. /* 容器不够宽时,由根节点接管横向滚动;纵向滚动仍由 .table-body 内部处理 */
  82. overflow-x: auto;
  83. overflow-y: hidden;
  84. container-type: inline-size;
  85. }
  86. .detector-monitor-table::-webkit-scrollbar { height: 6px; }
  87. .detector-monitor-table::-webkit-scrollbar-thumb {
  88. background: rgba(30, 77, 142, 0.6);
  89. border-radius: 3px;
  90. }
  91. .detector-monitor-table::-webkit-scrollbar-track { background: transparent; }
  92. /* ---------------- 表头 ---------------- */
  93. .table-header {
  94. display: flex;
  95. height: clamp(26px, 7cqw, 34px);
  96. background: linear-gradient(180deg, rgba(58, 127, 209, 0.28) 0%, rgba(58, 127, 209, 0.12) 100%);
  97. border: 1px solid rgba(127, 182, 255, 0.4);
  98. border-radius: 3px;
  99. flex-shrink: 0;
  100. /* 与 .table-row 同一最小宽度,保证横向滚动时表头与表体对齐 */
  101. min-width: 460px;
  102. }
  103. .header-left {
  104. flex: 1;
  105. display: flex;
  106. justify-content: space-between;
  107. align-items: center;
  108. padding: 0 clamp(6px, 2cqw, 16px);
  109. border-right: 1px solid rgba(127, 182, 255, 0.35);
  110. min-width: 180px;
  111. }
  112. .tick-item {
  113. font-size: clamp(10px, 2.4cqw, 13px);
  114. font-weight: 600;
  115. color: rgba(127, 182, 255, 0.9);
  116. font-family: 'Consolas', 'Courier New', monospace;
  117. letter-spacing: 0.5px;
  118. }
  119. .header-right {
  120. display: flex;
  121. width: clamp(280px, 55%, 360px);
  122. flex-shrink: 0;
  123. }
  124. .th-cell {
  125. flex: 1;
  126. display: flex;
  127. align-items: center;
  128. justify-content: center;
  129. font-size: clamp(10px, 2.4cqw, 13px);
  130. font-weight: 600;
  131. color: rgba(127, 182, 255, 0.95);
  132. border-right: 1px solid rgba(127, 182, 255, 0.25);
  133. min-width: 0;
  134. padding: 0 clamp(2px, 0.5cqw, 4px);
  135. white-space: nowrap;
  136. overflow: hidden;
  137. text-overflow: ellipsis;
  138. }
  139. .th-cell:last-child {
  140. border-right: none;
  141. }
  142. /* "名称" 列(第 2 列)需要承载最长文本,给它两倍宽度 */
  143. .header-right .th-cell:nth-child(2) {
  144. flex: 2;
  145. }
  146. /* ---------------- 表体 ---------------- */
  147. .table-body {
  148. flex: 1;
  149. display: flex;
  150. flex-direction: column;
  151. margin-top: 4px;
  152. overflow-y: auto;
  153. overflow-x: visible; /* 横向溢出由 .detector-monitor-table 接管 */
  154. /* 与 .table-header 同一最小宽度,让 row 与 header 一起被外层水平滚动 */
  155. min-width: 460px;
  156. }
  157. .table-body::-webkit-scrollbar {
  158. width: 6px;
  159. }
  160. .table-body::-webkit-scrollbar-thumb {
  161. background: rgba(30, 77, 142, 0.6);
  162. border-radius: 3px;
  163. }
  164. .table-body::-webkit-scrollbar-track {
  165. background: transparent;
  166. }
  167. /* flex:1 0 28px → 容器够大则平分多余高度填满(不留白),不够时锁 28px 触发滚动 */
  168. .table-row {
  169. display: flex;
  170. flex: 1 0 28px;
  171. min-height: 28px;
  172. border-bottom: 1px dashed rgba(30, 77, 142, 0.45);
  173. transition: background 0.15s;
  174. }
  175. .table-row:last-child {
  176. border-bottom: none;
  177. }
  178. .table-row:hover {
  179. background: rgba(58, 127, 209, 0.12);
  180. }
  181. .row-left {
  182. flex: 1;
  183. border-right: 1px solid rgba(30, 77, 142, 0.3);
  184. min-width: 180px;
  185. /* 时序图区域占位(180s ~ 30s 时间窗),后续可挂折线/柱图 */
  186. }
  187. .row-right {
  188. display: flex;
  189. width: clamp(280px, 55%, 360px);
  190. flex-shrink: 0;
  191. }
  192. .td-cell {
  193. flex: 1;
  194. display: flex;
  195. align-items: center;
  196. justify-content: center;
  197. font-size: clamp(11px, 2.4cqw, 14px);
  198. border-right: 1px solid rgba(30, 77, 142, 0.3);
  199. min-width: 0;
  200. padding: 0 clamp(2px, 0.5cqw, 4px);
  201. white-space: nowrap;
  202. overflow: hidden;
  203. text-overflow: ellipsis;
  204. }
  205. .td-cell:last-child {
  206. border-right: none;
  207. }
  208. .id-cell {
  209. color: rgba(127, 182, 255, 0.95);
  210. font-family: 'Consolas', 'Courier New', monospace;
  211. font-weight: 600;
  212. }
  213. /* 名称列内容最长(如"北进口 第3车道"),给它两倍宽度 */
  214. .name-cell {
  215. flex: 2;
  216. color: rgba(255, 255, 255, 0.95);
  217. font-weight: 500;
  218. }
  219. .num-cell {
  220. font-family: 'Consolas', 'Courier New', monospace;
  221. font-weight: 600;
  222. }
  223. .num-cell.flow {
  224. color: #7fe3a8;
  225. }
  226. .num-cell.occ {
  227. color: #ffc857;
  228. }
  229. </style>