DeviceTree.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <template>
  2. <div id="DeviceTree" style="width: 100%; height: 100%; background-color: #ffffff; overflow: auto">
  3. <div style="line-height: 3vh; margin-bottom: 10px; font-size: 17px;" class="pl-5 mt-2">设备列表</div>
  4. <el-tree
  5. ref="treeRef"
  6. :props="defaultProps"
  7. :current-node-key="selectchannelId"
  8. :default-expanded-keys="expandIds"
  9. :highlight-current="true"
  10. @node-click="handleNodeClick"
  11. :load="loadNode"
  12. lazy
  13. node-key="id"
  14. style="min-width: 100%; display: inline-block !important"
  15. >
  16. <template #default="{ node, data }">
  17. <span class="custom-tree-node" style="width: 100%">
  18. <span
  19. v-if="data.type === 0 && data.online"
  20. title="在线设备"
  21. class="device-online iconfont icon-jiedianleizhukongzhongxin2"
  22. ></span>
  23. <span
  24. v-if="data.type === 0 && !data.online"
  25. title="离线设备"
  26. class="device-offline iconfont icon-jiedianleizhukongzhongxin2"
  27. ></span>
  28. <span
  29. v-if="data.type === 3 && data.online"
  30. title="在线通道"
  31. class="device-online iconfont icon-shebeileijiankongdian"
  32. ></span>
  33. <span
  34. v-if="data.type === 3 && !data.online"
  35. title="离线通道"
  36. class="device-offline iconfont icon-shebeileijiankongdian"
  37. ></span>
  38. <span
  39. v-if="data.type === 4 && data.online"
  40. title="在线通道-球机"
  41. class="device-online iconfont icon-shebeileiqiuji"
  42. ></span>
  43. <span
  44. v-if="data.type === 4 && !data.online"
  45. title="离线通道-球机"
  46. class="device-offline iconfont icon-shebeileiqiuji"
  47. ></span>
  48. <span
  49. v-if="data.type === 5 && data.online"
  50. title="在线通道-半球"
  51. class="device-online iconfont icon-shebeileibanqiu"
  52. ></span>
  53. <span
  54. v-if="data.type === 5 && !data.online"
  55. title="离线通道-半球"
  56. class="device-offline iconfont icon-shebeileibanqiu"
  57. ></span>
  58. <span
  59. v-if="data.type === 6 && data.online"
  60. title="在线通道-枪机"
  61. class="device-online iconfont icon-shebeileiqiangjitongdao"
  62. ></span>
  63. <span
  64. v-if="data.type === 6 && !data.online"
  65. title="离线通道-枪机"
  66. class="device-offline iconfont icon-shebeileiqiangjitongdao"
  67. ></span>
  68. <span v-if="data.online" style="padding-left: 1px" class="device-online">{{ node.label }}</span>
  69. <span v-if="!data.online" style="padding-left: 1px" class="device-offline">{{ node.label }}</span>
  70. </span>
  71. </template>
  72. </el-tree>
  73. </div>
  74. </template>
  75. <script setup>
  76. import { ref, reactive, onMounted, onUnmounted } from 'vue'
  77. import { listSipDeviceChannel } from '@/api/pms/video/sipdevice'
  78. import { listDeviceShort } from '@/api/pms/video/device'
  79. // 使用组合式API
  80. const { t } = useI18n()
  81. // 定义 props
  82. const props = defineProps({
  83. onlyCatalog: {
  84. type: Boolean,
  85. default: false
  86. },
  87. clickEvent: {
  88. type: Function,
  89. default: null
  90. }
  91. })
  92. // 定义 emits
  93. const emit = defineEmits([])
  94. // refs
  95. const treeRef = ref(null)
  96. // 数据状态
  97. const total = ref(0)
  98. const channelList = ref([])
  99. const DeviceData = ref([])
  100. const expandIds = ref([])
  101. const selectData = ref({})
  102. const selectchannelId = ref('')
  103. // 默认属性
  104. const defaultProps = reactive({
  105. children: 'children',
  106. label: 'name',
  107. isLeaf: 'isLeaf',
  108. })
  109. // 查询参数
  110. const queryParams = reactive({
  111. pageNum: 1,
  112. pageSize: 100,
  113. status: 3,
  114. deviceType: 3,
  115. })
  116. // 生命周期钩子
  117. onMounted(() => {
  118. selectchannelId.value = ''
  119. expandIds.value = ['0']
  120. })
  121. onUnmounted(() => {
  122. // 组件销毁时的操作
  123. })
  124. // 节点点击事件
  125. const handleNodeClick = (data, node, element) => {
  126. selectData.value = node.data
  127. selectchannelId.value = node.data.value
  128. if (node.level !== 0) {
  129. const deviceNode = treeRef.value.getNode(data.userData.channelSipId)
  130. if (typeof props.clickEvent === 'function' && node.level > 1) {
  131. props.clickEvent(deviceNode.data.userData)
  132. }
  133. }
  134. }
  135. // 加载节点
  136. const loadNode = (node, resolve) => {
  137. if (node.level === 0) {
  138. listDeviceShort(queryParams).then((response) => {
  139. const data = response
  140. if (data.length > 0) {
  141. let nodeList = []
  142. for (let i = 0; i < data.length; i++) {
  143. let node = {
  144. name: data[i].deviceName,
  145. isLeaf: false,
  146. id: data[i].serialNumber,
  147. type: 0,
  148. online: data[i].status === 3,
  149. userData: data[i],
  150. }
  151. nodeList.push(node)
  152. }
  153. resolve(nodeList)
  154. } else {
  155. resolve([])
  156. }
  157. })
  158. } else {
  159. let channelArray = []
  160. listSipDeviceChannel(node.data.userData.serialNumber).then((res) => {
  161. if (res != null) {
  162. channelArray = channelArray.concat(res)
  163. channelDataHandler(channelArray, resolve)
  164. } else {
  165. resolve([])
  166. }
  167. })
  168. }
  169. }
  170. // 通道数据处理
  171. const channelDataHandler = (data, resolve) => {
  172. if (data.length > 0) {
  173. let nodeList = []
  174. for (let i = 0; i < data.length; i++) {
  175. let item = data[i]
  176. let channelType = item.id.substring(10, 13)
  177. console.log('channelType: ' + channelType)
  178. let type = 3
  179. if (item.id.length <= 10) {
  180. type = 2
  181. } else {
  182. if (item.id.length > 14) {
  183. let channelType = item.id.substring(10, 13)
  184. // 111-DVR编码;112-视频服务器编码;118-网络视频录像机(NVR)编码;131-摄像机编码;132-网络摄像机(IPC)编码
  185. if (channelType !== '111' && channelType !== '112' && channelType !== '118' && channelType !== '131' && channelType !== '132') {
  186. type = -1
  187. // 1-球机;2-半球;3-固定枪机;4-遥控枪机
  188. } else if (item.basicData.ptztype === 1) {
  189. type = 4
  190. } else if (item.basicData.ptztype === 2) {
  191. type = 5
  192. } else if (item.basicData.ptztype === 3 || item.basicData.ptztype === 4) {
  193. type = 6
  194. }
  195. } else {
  196. if (item.basicData.subCount > 0 || item.basicData.parental === 1) {
  197. type = 2
  198. }
  199. }
  200. }
  201. let node = {
  202. name: item.name || item.id,
  203. isLeaf: true,
  204. id: item.id,
  205. deviceId: item.deviceId,
  206. type: type,
  207. online: item.status === 3,
  208. userData: item.basicData,
  209. }
  210. if (channelType === '111' || channelType === '112' || channelType === '118' || channelType === '131' || channelType === '132') {
  211. nodeList.push(node)
  212. }
  213. }
  214. resolve(nodeList)
  215. } else {
  216. resolve([])
  217. }
  218. }
  219. // 重置
  220. const reset = () => {
  221. // Vue 3 中不再需要 $forceUpdate
  222. }
  223. // 暴露方法给父组件
  224. defineExpose({
  225. treeRef,
  226. handleNodeClick,
  227. loadNode,
  228. channelDataHandler,
  229. reset
  230. })
  231. </script>
  232. <style scoped>
  233. .device-tree-main-box {
  234. text-align: left;
  235. }
  236. .device-online {
  237. color: #252525;
  238. }
  239. .device-offline {
  240. color: #727272;
  241. }
  242. </style>