DeviceTree.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <template>
  2. <!-- 设备树组件:左侧面板,包含设备分组树、Tab切换、角度保存等功能 -->
  3. <div class="device-tree">
  4. <!-- 顶部 Tab -->
  5. <div class="tree-tabs">
  6. <div v-for="tab in tabs" :key="tab.key" :class="['tab-item', { active: activeTab === tab.key }]"
  7. @click="activeTab = tab.key">
  8. {{ tab.label }}
  9. </div>
  10. </div>
  11. <!-- 角度栏 + 保存 -->
  12. <div class="tree-toolbar">
  13. <span class="toolbar-label">角度</span>
  14. <div class="save-btn" @click="handleSave">
  15. <div class="btn-item">保存</div>
  16. </div>
  17. </div>
  18. <!-- 设备树列表 -->
  19. <div class="tree-body">
  20. <div v-for="group in treeData" :key="group.id" class="tree-group">
  21. <div class="group-row" @click="toggleGroup(group.id)">
  22. <span :class="['expand-icon', { collapsed: !expandedMap[group.id] }]">
  23. <svg viewBox="0 0 10 10" width="10" height="10">
  24. <path d="M1 3.2 L5 7.2 L9 3.2" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"
  25. stroke-linejoin="round" />
  26. </svg>
  27. </span>
  28. <span class="group-icon">
  29. <SvgIcon class="icon-style2" size="18" name="jg-icon" />
  30. </span>
  31. <span class="group-title">{{ group.title }}</span>
  32. </div>
  33. <div v-show="expandedMap[group.id]" class="group-children">
  34. <div v-for="(device, index) in group.children" :key="device.id"
  35. :class="['device-row', { active: selectedId === device.id, 'is-last': index === group.children.length - 1 }]"
  36. @click="selectDevice(device)">
  37. <span class="tree-line"></span>
  38. <span class="device-icon">
  39. <SvgIcon class="icon-style2" size="18" name="video-icon" />
  40. </span>
  41. <span class="device-name" :title="device.name">{{ device.name }}</span>
  42. <div class="device-checks" @click.stop>
  43. <label
  44. v-for="(checked, cIndex) in device.checks"
  45. :key="cIndex"
  46. class="check-item"
  47. :data-tip="checkTips[cIndex]"
  48. >
  49. <input type="checkbox" :checked="checked"
  50. @change="toggleCheck(device, cIndex, ($event.target as HTMLInputElement).checked)" />
  51. <span class="check-box">
  52. <svg v-if="checked" viewBox="0 0 12 12" width="10" height="10">
  53. <path d="M2 6.2 L4.8 9 L10 3.2" fill="none" stroke="#fff" stroke-width="1.8" stroke-linecap="round"
  54. stroke-linejoin="round" />
  55. </svg>
  56. </span>
  57. </label>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. </div>
  63. </div>
  64. </template>
  65. <script setup lang="ts">
  66. import { onMounted, reactive, ref, watch } from 'vue'
  67. import { SvgIcon } from '/@/components/Icon';
  68. import { tabs } from '../hsqHome.data'
  69. /** 设备节点数据结构 */
  70. interface DeviceNode {
  71. id: string
  72. name: string
  73. /** 三个勾选状态:如显示/联动/告警等 */
  74. checks: [boolean, boolean, ]
  75. }
  76. let props=defineProps({
  77. treeData: {
  78. type: Array as any,
  79. default: () => [],
  80. },
  81. })
  82. /** 组件自定义事件 */
  83. const emit = defineEmits<{
  84. // (e: 'save', data: GroupNode[]): void
  85. (e: 'select', device: DeviceNode): void
  86. (e: 'checkChange', payload: any): void
  87. (e: 'tabChange', key: string): void
  88. }>()
  89. /** 多选框提示:第一个可见光取流,第二个红外取流 */
  90. const checkTips = ['可见光取流', '红外取流'] as const
  91. /** 当前激活的 Tab */
  92. const activeTab = ref('device')
  93. /** 当前选中的设备 ID */
  94. const selectedId = ref('d2')
  95. /** 设备分组展开/折叠状态映射 */
  96. const expandedMap = reactive<Record<string, boolean>>({
  97. g1: true,
  98. g2: true,
  99. })
  100. /** 切换设备分组的展开/折叠状态 */
  101. function toggleGroup(id: string) {
  102. expandedMap[id] = !expandedMap[id]
  103. }
  104. /** 选中设备,触发 select 事件 */
  105. function selectDevice(device: DeviceNode) {
  106. selectedId.value = device.id
  107. emit('select', device)
  108. }
  109. /** 切换设备勾选状态,触发 checkChange 事件 */
  110. function toggleCheck(device: DeviceNode, index: number, checked: boolean) {
  111. device.checks[index] = checked
  112. emit('checkChange', { device, index, checked })
  113. }
  114. /** 保存设备树数据,触发 save 事件 */
  115. function handleSave() {
  116. // emit('save', treeData.value)
  117. }
  118. /** 监听 Tab 切换,触发 tabChange 事件 */
  119. watch(activeTab, (key) => {
  120. emit('tabChange', key)
  121. })
  122. </script>
  123. <style lang="less" scoped>
  124. @import '/@/design/theme.less';
  125. // 设备树主容器
  126. .device-tree {
  127. --image-bg: url('@/assets/images/home-container/configurable/hsq/7-2.png');
  128. --dt-bg: #071528;
  129. --dt-bg-row: transparent;
  130. --dt-bg-active: rgba(22, 90, 150, 0.55);
  131. --dt-accent: #00b7ff;
  132. --dt-text: #e8f4ff;
  133. --dt-text-muted: #8aa0b8;
  134. --dt-border: rgba(40, 120, 180, 0.35);
  135. --dt-line: rgba(120, 150, 180, 0.55);
  136. height: 100%;
  137. display: flex;
  138. flex-direction: column;
  139. box-sizing: border-box;
  140. color: var(--dt-text);
  141. font-size: 13px;
  142. overflow: hidden;
  143. padding: 15px;
  144. box-sizing: border-box;
  145. }
  146. // 顶部 Tab 切换栏
  147. .tree-tabs {
  148. display: flex;
  149. align-items: stretch;
  150. height: 30px;
  151. flex-shrink: 0;
  152. border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  153. background: #15517b;
  154. margin-bottom: 10px;
  155. .tab-item {
  156. flex: 1;
  157. display: flex;
  158. align-items: center;
  159. justify-content: center;
  160. cursor: pointer;
  161. color: var(--dt-text-muted);
  162. position: relative;
  163. transition: color 0.2s;
  164. &:hover {
  165. color: #cfe9ff;
  166. }
  167. &.active {
  168. color: #fff;
  169. font-weight: 600;
  170. background-color: #1d73a8;
  171. &::after {
  172. content: '';
  173. position: absolute;
  174. left: 0%;
  175. right: 0%;
  176. bottom: 0;
  177. height: 2px;
  178. background: #36c7ff;
  179. border-radius: 1px;
  180. box-shadow: 0 0 6px rgba(0, 183, 255, 0.6);
  181. }
  182. }
  183. }
  184. }
  185. // 工具栏:角度标签 + 保存按钮
  186. .tree-toolbar {
  187. display: flex;
  188. align-items: center;
  189. justify-content: space-between;
  190. height: 28px;
  191. padding: 0 10px;
  192. flex-shrink: 0;
  193. border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  194. background: var(--image-bg) no-repeat;
  195. background-size: 100% 100%;
  196. .toolbar-label {
  197. color: var(--dt-text);
  198. font-size: 13px;
  199. }
  200. // 保存按钮
  201. .save-btn {
  202. min-width: 52px;
  203. height: 24px;
  204. padding: 2px;
  205. border: 1px solid #29e7db;
  206. border-radius: 3px;
  207. background: transparent;
  208. color: #fff;
  209. font-size: 12px;
  210. cursor: pointer;
  211. line-height: 24px;
  212. transition: background 0.2s, box-shadow 0.2s;
  213. .btn-item {
  214. display: flex;
  215. align-items: center;
  216. justify-content: center;
  217. width: 100%;
  218. height: 100%;
  219. background: linear-gradient(to bottom, rgba(41, 231, 219, 1) 0%, rgba(41, 231, 219, 0.5) 100%);
  220. }
  221. }
  222. }
  223. // 设备树列表主体(可滚动区域)
  224. .tree-body {
  225. flex: 1;
  226. overflow: auto;
  227. padding: 6px 0px;
  228. box-sizing: border-box;
  229. &::-webkit-scrollbar {
  230. width: 4px;
  231. }
  232. &::-webkit-scrollbar-thumb {
  233. background: rgba(0, 183, 255, 0.35);
  234. border-radius: 2px;
  235. }
  236. }
  237. // 设备分组行(煤场/采场等)
  238. .group-row {
  239. display: flex;
  240. align-items: center;
  241. height: 30px;
  242. padding: 0 10px 0 8px;
  243. cursor: pointer;
  244. user-select: none;
  245. &:hover {
  246. background: rgba(255, 255, 255, 0.03);
  247. }
  248. // 展开/折叠箭头图标
  249. .expand-icon {
  250. width: 14px;
  251. height: 14px;
  252. display: inline-flex;
  253. align-items: center;
  254. justify-content: center;
  255. color: #d8e6f5;
  256. margin-right: 4px;
  257. transition: transform 0.2s;
  258. &.collapsed {
  259. transform: rotate(-90deg);
  260. }
  261. }
  262. .group-icon {
  263. display: inline-flex;
  264. margin-right: 6px;
  265. }
  266. .group-title {
  267. font-size: 13px;
  268. color: var(--dt-text);
  269. }
  270. }
  271. // 分组子节点容器
  272. .group-children {
  273. position: relative;
  274. }
  275. // 单个设备行
  276. .device-row {
  277. position: relative;
  278. display: flex;
  279. align-items: center;
  280. height: 30px;
  281. padding: 0 10px 0 28px;
  282. cursor: pointer;
  283. background: var(--dt-bg-row);
  284. &:hover {
  285. background: rgba(255, 255, 255, 0.04);
  286. }
  287. &.active {
  288. background: var(--dt-bg-active);
  289. }
  290. /* 竖向虚线树连接线 */
  291. .tree-line {
  292. position: absolute;
  293. left: 14px;
  294. top: 0;
  295. bottom: 0;
  296. width: 0;
  297. border-left: 1px dashed var(--dt-line);
  298. &::after {
  299. content: '';
  300. position: absolute;
  301. left: 0;
  302. top: 15px;
  303. width: 10px;
  304. border-top: 1px dashed var(--dt-line);
  305. }
  306. }
  307. // 最后一个子节点只显示一半高度的连接线
  308. &.is-last .tree-line {
  309. bottom: 50%;
  310. }
  311. .device-icon {
  312. display: inline-flex;
  313. margin-right: 6px;
  314. flex-shrink: 0;
  315. }
  316. // 设备名称(溢出省略)
  317. .device-name {
  318. flex: 1;
  319. min-width: 0;
  320. overflow: hidden;
  321. text-overflow: ellipsis;
  322. white-space: nowrap;
  323. color: #d7e9fa;
  324. font-size: 12px;
  325. }
  326. // 设备勾选框容器
  327. .device-checks {
  328. display: flex;
  329. align-items: center;
  330. gap: 6px;
  331. margin-left: 8px;
  332. flex-shrink: 0;
  333. }
  334. }
  335. // 自定义勾选框样式
  336. .check-item {
  337. position: relative;
  338. display: inline-flex;
  339. cursor: pointer;
  340. margin: 0;
  341. input {
  342. display: none;
  343. }
  344. .check-box {
  345. width: 14px;
  346. height: 14px;
  347. box-sizing: border-box;
  348. border: 1px solid rgba(0, 183, 255, 0.75);
  349. border-radius: 2px;
  350. background: rgba(0, 30, 55, 0.85);
  351. display: inline-flex;
  352. align-items: center;
  353. justify-content: center;
  354. }
  355. input:checked+.check-box {
  356. background: var(--dt-accent);
  357. border-color: var(--dt-accent);
  358. }
  359. /* 悬停文字提示,风格对齐设备树(左侧弹出,避免被滚动容器裁切) */
  360. &::after {
  361. content: attr(data-tip);
  362. position: absolute;
  363. right: calc(100% + 8px);
  364. top: 50%;
  365. transform: translateY(-50%);
  366. padding: 3px 8px;
  367. white-space: nowrap;
  368. font-size: 12px;
  369. line-height: 1.4;
  370. color: #e8f4ff;
  371. background: rgba(7, 35, 58, 0.95);
  372. border: 1px solid rgba(0, 183, 255, 0.65);
  373. border-radius: 2px;
  374. box-shadow: 0 0 8px rgba(0, 183, 255, 0.35);
  375. pointer-events: none;
  376. opacity: 0;
  377. visibility: hidden;
  378. transition: opacity 0.15s ease;
  379. z-index: 20;
  380. }
  381. &::before {
  382. content: '';
  383. position: absolute;
  384. right: calc(100% - 2px);
  385. top: 50%;
  386. transform: translateY(-50%);
  387. border: 5px solid transparent;
  388. border-left-color: rgba(0, 183, 255, 0.65);
  389. pointer-events: none;
  390. opacity: 0;
  391. visibility: hidden;
  392. transition: opacity 0.15s ease;
  393. z-index: 20;
  394. }
  395. &:hover::after,
  396. &:hover::before {
  397. opacity: 1;
  398. visibility: visible;
  399. }
  400. }
  401. // 隐藏滚动条
  402. ::-webkit-scrollbar {
  403. display: none;
  404. }
  405. </style>