InfoVtkmodel.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <div class="vtkmodel1" id="infomodel"></div>
  3. </template>
  4. <script setup>
  5. import { ref, onMounted, reactive} from "vue";
  6. import { RouterView, RouterLink } from "vue-router";
  7. import { request, uploadFile } from "@/utils/request";
  8. import { vtkmodel } from "@/control/vtkModel.js";
  9. import { throttle } from "@kitware/vtk.js/macros";
  10. import vtkSphereSource from "@kitware/vtk.js/Filters/Sources/SphereSource";
  11. import vtkActor from "@kitware/vtk.js/Rendering/Core/Actor";
  12. import vtkMapper from "@kitware/vtk.js/Rendering/Core/Mapper";
  13. import vtkLineSource from "@kitware/vtk.js/Filters/Sources/LineSource";
  14. import vtkPointSource from "@kitware/vtk.js/Filters/Sources/PointSource";
  15. import emitter from "@/utils/emitter";
  16. import { message } from '@/utils/message';
  17. onBeforeMount(()=>{
  18. })
  19. onMounted(() => {
  20. const rootContainer = document.getElementById("infomodel");
  21. // rootContainer.style.position = "relative";
  22. // rootContainer.style.width = "100%";
  23. // rootContainer.style.height = "100%";
  24. vtkmodel.initMode(rootContainer);
  25. readNodeAndPipe();
  26. vtkmodel.clearJgAddMode();
  27. emitter.emit('accident');
  28. });
  29. const nodes = ref([]); //节点数据
  30. const pipes = ref([]); //管道数据
  31. const delNodes = ref([]); //无效节点
  32. const validNodes = ref([]); //有效节点
  33. const checkNodes = ref([]); //监测点
  34. async function readNodeAndPipe() {
  35. const params = {
  36. transCode: "D00000",
  37. count: 1000,
  38. page: 1,
  39. };
  40. await request(params)
  41. .then((res) => {
  42. if (res.returnCode == "000000000") {
  43. nodes.value = res.rows;
  44. readePipe();
  45. } else {
  46. message({
  47. message: res.returnMsg,
  48. type: "error",
  49. });
  50. }
  51. })
  52. .catch((err) => {});
  53. }
  54. async function readePipe() {
  55. const params = {
  56. transCode: "D00001",
  57. count: 1000,
  58. page: 1,
  59. };
  60. await request(params)
  61. .then((res) => {
  62. if (res.returnCode == "000000000") {
  63. pipes.value = res.rows;
  64. lineShow();
  65. } else {
  66. message({
  67. message: res.returnMsg,
  68. type: "error",
  69. });
  70. }
  71. })
  72. .catch((err) => {});
  73. }
  74. // 查询监测点
  75. async function readCheckNode(){
  76. const params = {
  77. transCode: 'D10004',
  78. }
  79. request(params)
  80. .then((res) => {
  81. checkNodes.value= res.rows;
  82. vtkmodel.initCheckNodes(checkNodes.value);
  83. })
  84. .catch((err) => {
  85. })
  86. }
  87. // 查询传感器
  88. async function readSensor(){
  89. const params = {
  90. transCode: 'D10010',
  91. type: 'Fire'
  92. }
  93. request(params)
  94. .then((res) => {
  95. console.log("readSensor",res);
  96. res.rows.forEach(element => {
  97. vtkmodel.addSensor(element.pid,element.site)
  98. });
  99. })
  100. .catch((err) => {
  101. })
  102. }
  103. /**
  104. * 在管道中已存在的点才可以使用
  105. */
  106. function nodeIsValid(node) {
  107. let isValid = false;
  108. pipes.value.forEach((pipe) => {
  109. if (node.id == pipe.snId || node.id == pipe.enId) {
  110. isValid = true;
  111. return isValid;
  112. }
  113. });
  114. return isValid;
  115. }
  116. function lineShow() {
  117. console.log("模板加载..");
  118. //判断NODE 是否在管道中使用
  119. nodes.value.forEach((node) => {
  120. if (!nodeIsValid(node)) {
  121. delNodes.value.push(node);
  122. } else {
  123. validNodes.value.push(node);
  124. }
  125. });
  126. vtkmodel.modelInit(validNodes.value, pipes.value);
  127. readCheckNode();
  128. readSensor();
  129. // vtkmodel.selectNodes();
  130. // vtkmodel.selectByNodeId(178);
  131. // vtkmodel.selectPipes();
  132. // vtkmodel.selectByPipeId(253);
  133. }
  134. </script>
  135. <style scoped>
  136. .vtk {
  137. position: absolute;
  138. z-index: 150;
  139. top: 70px;
  140. }
  141. span {
  142. position: absolute;
  143. top: 2px;
  144. }
  145. </style>
  146. <style>
  147. .vtkmodel1 canvas{
  148. /* background-color: rgba(51,51,51,0.7); */
  149. /* background-color:#B5C7F0 ; */
  150. background-image: url(../../src/assets/img/BJ.png)!important;
  151. background-size: 100% 100%;
  152. background-repeat: no-repeat;
  153. }
  154. </style>