DeviceTree.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <div id="DeviceTree" style="width: 100%;height: 100%; background-color: #FFFFFF; overflow: auto">
  3. <el-container>
  4. <el-header>设备列表</el-header>
  5. <el-main style="background-color: #ffffff;">
  6. <div class="device-tree-main-box">
  7. <el-tree ref="gdTree" :props="defaultProps" :load="loadNode" lazy @node-click="handleNodeClick"@node-contextmenu="handleContextMenu" node-key="id" style="min-width: 100%; display:inline-block !important;">
  8. <span class="custom-tree-node" slot-scope="{ node, data }" style="width: 100%">
  9. <span v-if="node.data.type === 0 && node.data.online" title="在线设备" class="device-online iconfont icon-jiedianleizhukongzhongxin2"></span>
  10. <span v-if="node.data.type === 0 && !node.data.online " title="离线设备" class="device-offline iconfont icon-jiedianleizhukongzhongxin2"></span>
  11. <span v-if="node.data.type === 2 && node.data.online" title="目录" class="device-online iconfont icon-jiedianleilianjipingtai"></span>
  12. <span v-if="node.data.type === 2 && !node.data.online" title="目录" class="device-offline iconfont icon-jiedianleilianjipingtai"></span>
  13. <span v-if="node.data.type === 3 && node.data.online " title="在线通道" class="device-online iconfont icon-shebeileijiankongdian"></span>
  14. <span v-if="node.data.type === 3 && !node.data.online" title="在线通道" class="device-offline iconfont icon-shebeileijiankongdian"></span>
  15. <span v-if="node.data.type === 4 && node.data.online " title="在线通道-球机" class="device-online iconfont icon-shebeileiqiuji"></span>
  16. <span v-if="node.data.type === 4 && !node.data.online" title="在线通道-球机" class="device-offline iconfont icon-shebeileiqiuji"></span>
  17. <span v-if="node.data.type === 5 && node.data.online " title="在线通道-半球" class="device-online iconfont icon-shebeileibanqiu"></span>
  18. <span v-if="node.data.type === 5 && !node.data.online" title="在线通道-半球" class="device-offline iconfont icon-shebeileibanqiu"></span>
  19. <span v-if="node.data.type === 6 && node.data.online " title="在线通道-枪机" class="device-online iconfont icon-shebeileiqiangjitongdao"></span>
  20. <span v-if="node.data.type === 6 && !node.data.online" title="在线通道-枪机" class="device-offline iconfont icon-shebeileiqiangjitongdao"></span>
  21. <span v-if="node.data.online" style="padding-left: 1px" class="device-online">{{ node.label }}</span>
  22. <span v-if="!node.data.online" style="padding-left: 1px" class="device-offline">{{ node.label }}</span>
  23. <span>
  24. <i v-if="node.data.hasGPS && node.data.online" style="color: #9d9d9d" class="device-online iconfont icon-dizhi"></i>
  25. <i v-if="node.data.hasGPS && !node.data.online" style="color: #9d9d9d" class="device-offline iconfont icon-dizhi"></i>
  26. </span>
  27. </span>
  28. </el-tree>
  29. </div>
  30. </el-main>
  31. </el-container>
  32. </div>
  33. </template>
  34. <script>
  35. import DeviceService from "../service/DeviceService.js";
  36. export default {
  37. name: 'DeviceTree',
  38. data() {
  39. return {
  40. deviceService: new DeviceService(),
  41. defaultProps: {
  42. children: 'children',
  43. label: 'name',
  44. isLeaf: 'isLeaf'
  45. }
  46. };
  47. },
  48. props: ['device', 'onlyCatalog', 'clickEvent', 'contextMenuEvent'],
  49. methods: {
  50. handleNodeClick(data,node,element) {
  51. let deviceNode = this.$refs.gdTree.getNode(data.userData.deviceId)
  52. if(typeof (this.clickEvent) == "function") {
  53. this.clickEvent(deviceNode.data.userData, data.userData, data.type === 2)
  54. }
  55. },
  56. handleContextMenu(event,data,node,element) {
  57. console.log("右键点击事件")
  58. let deviceNode = this.$refs.gdTree.getNode(data.userData.deviceId)
  59. if(typeof (this.contextMenuEvent) == "function") {
  60. this.contextMenuEvent(deviceNode.data.userData, event, data.userData, data.type === 2)
  61. }
  62. },
  63. loadNode: function(node, resolve){
  64. console.log(this.device)
  65. if (node.level === 0) {
  66. if (this.device) {
  67. let node = {
  68. name: this.device.name || this.device.deviceId,
  69. isLeaf: false,
  70. id: this.device.deviceId,
  71. type: this.device.online,
  72. online: this.device.online === 1,
  73. userData: this.device
  74. }
  75. resolve([node])
  76. }else {
  77. this.deviceService.getAllDeviceList((data)=>{
  78. console.log(data)
  79. if (data.length > 0) {
  80. let nodeList = []
  81. for (let i = 0; i < data.length; i++) {
  82. console.log(data[i].name)
  83. let node = {
  84. name: data[i].name || data[i].deviceId,
  85. isLeaf: false,
  86. id: data[i].deviceId,
  87. type: data[i].online,
  88. online: data[i].online === 1,
  89. userData: data[i]
  90. }
  91. nodeList.push(node);
  92. }
  93. resolve(nodeList)
  94. }else {
  95. resolve([])
  96. }
  97. }, (list)=>{
  98. console.log("设备加载完成")
  99. }, (error)=>{
  100. })
  101. }
  102. }else {
  103. let channelArray = []
  104. this.deviceService.getTree(node.data.userData.deviceId, node.data.id, this.onlyCatalog, catalogData =>{
  105. console.log(catalogData)
  106. channelArray = channelArray.concat(catalogData)
  107. this.channelDataHandler(channelArray, resolve)
  108. },(endCatalogData) => {
  109. })
  110. }
  111. },
  112. channelDataHandler: function (data, resolve) {
  113. if (data.length > 0) {
  114. let nodeList = []
  115. for (let i = 0; i <data.length; i++) {
  116. let item = data[i];
  117. let type = 3;
  118. if (item.id.length <= 10) {
  119. type = 2;
  120. }else {
  121. if (item.id.length > 14) {
  122. let channelType = item.id.substring(10, 13)
  123. console.log("channelType: " + channelType)
  124. if (channelType === '215' || channelType === '216') {
  125. type = 2;
  126. }
  127. console.log(type)
  128. if (item.basicData.ptztype === 1 ) { // 1-球机;2-半球;3-固定枪机;4-遥控枪机
  129. type = 4;
  130. }else if (item.basicData.ptztype === 2) {
  131. type = 5;
  132. }else if (item.basicData.ptztype === 3 || item.basicData.ptztype === 4) {
  133. type = 6;
  134. }
  135. }else {
  136. if (item.basicData.subCount > 0 || item.basicData.parental === 1) {
  137. type = 2;
  138. }
  139. }
  140. }
  141. let node = {
  142. name: item.name || item.basicData.channelId,
  143. isLeaf: type !== 2,
  144. id: item.id,
  145. deviceId: item.deviceId,
  146. type: type,
  147. online: item.basicData.status === 1,
  148. hasGPS: item.basicData.longitude*item.basicData.latitude !== 0,
  149. userData: item.basicData
  150. }
  151. nodeList.push(node);
  152. }
  153. resolve(nodeList)
  154. }else {
  155. resolve([])
  156. }
  157. },
  158. reset: function (){
  159. this.$forceUpdate();
  160. }
  161. },
  162. destroyed() {
  163. // if (this.jessibuca) {
  164. // this.jessibuca.destroy();
  165. // }
  166. // this.playing = false;
  167. // this.loaded = false;
  168. // this.performance = "";
  169. },
  170. }
  171. </script>
  172. <style>
  173. .device-tree-main-box{
  174. text-align: left;
  175. }
  176. .device-online{
  177. color: #252525;
  178. }
  179. .device-offline{
  180. color: #727272;
  181. }
  182. </style>