CircuitPreview.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <template>
  2. <div style="overflow: auto; position: relative">
  3. <div class="svg-contain">
  4. <svg
  5. version="1.1"
  6. xmlns="http://www.w3.org/2000/svg"
  7. xmlns:xlink="http://www.w3.org/1999/xlink"
  8. style="background-color: #000000"
  9. viewBox="0 0 1920 1080"
  10. width="100%"
  11. height="100%"
  12. >
  13. <defs />
  14. <g
  15. style="cursor: pointer"
  16. v-for="(item, index) in svgLists"
  17. :key="item"
  18. :id="item.id"
  19. @mousedown="
  20. MousedownSvg(
  21. item.id,
  22. index,
  23. item.svgPositionX,
  24. item.svgPositionY,
  25. $event
  26. )
  27. "
  28. :title="item.title"
  29. :type="item.type"
  30. :transform="
  31. 'translate(' +
  32. item.svgPositionX +
  33. ',' +
  34. item.svgPositionY +
  35. ')' +
  36. 'rotate(' +
  37. item.angle +
  38. ')'
  39. "
  40. >
  41. <SvgComponents
  42. :svg_color="item.svgColor"
  43. :svgtype="item.type"
  44. :stroke-width="item.width"
  45. :text="item.svgText"
  46. :font-size="item.fontSize"
  47. :height="item.height"
  48. :svgInfoData="svgInfoData"
  49. ></SvgComponents>
  50. </g>
  51. </svg>
  52. </div>
  53. <div class="btns-content">
  54. <a-button type="primary" @click="testF">模拟硬件</a-button>
  55. <a-button type="primary" @click="testG">取消模拟硬件</a-button>
  56. </div>
  57. </div>
  58. </template>
  59. <script>
  60. import SvgComponents from "@/components/SvgComponents.vue";
  61. export default {
  62. components: { SvgComponents },
  63. data() {
  64. return {
  65. svgLists: [],
  66. svgInfoData: [],
  67. analogDataTimer: "", //模拟数据定时器
  68. userInfo: "",
  69. editable: false,
  70. };
  71. },
  72. mounted() {},
  73. methods: {
  74. testF() {
  75. //找出所有断路器
  76. let anyCircuitBreakerList = this.svgLists.filter(
  77. (f) => f.type == "CircuitBreakerSvg"
  78. );
  79. //找出所有的电线开关
  80. let anyWireBreakList = this.svgLists.filter(
  81. (f) => f.type == "WireConnectionSvg" || f.type == "WireBreakOffSvg"
  82. );
  83. //查找所有表格值
  84. let anyTable = this.svgLists.filter((f) => f.type == "TableSvg")[0];
  85. let anyTableList;
  86. if (anyTable == "undefined" || anyTable == null) {
  87. anyTableList = [];
  88. } else {
  89. anyTableList = anyTable.tableData.map((m) => m.cols);
  90. }
  91. this.analogDataTimer = setInterval(function () {
  92. anyCircuitBreakerList.forEach((anyCircuitBreaker) => {
  93. //生成一个随机数
  94. let random = Math.round(Math.random() * 10);
  95. if (random < 5) {
  96. anyCircuitBreaker.svgColor = "#00FF00";
  97. } else {
  98. anyCircuitBreaker.svgColor = "#FF0000";
  99. }
  100. });
  101. anyWireBreakList.forEach((anyWireBreak) => {
  102. //生成一个随机数
  103. let random = Math.round(Math.random() * 10);
  104. if (random < 5) {
  105. anyWireBreak.type = "WireConnectionSvg";
  106. anyWireBreak.svgColor = "#FF0000";
  107. } else {
  108. anyWireBreak.type = "WireBreakOffSvg";
  109. anyWireBreak.svgColor = "#00FF00";
  110. }
  111. });
  112. anyTableList.forEach((anyTables) => {
  113. anyTables.forEach((anyTable) => {
  114. if (
  115. anyTable.type == "ff85bc7f-3b69-454f-8cf8-21c9f1903dd6" ||
  116. anyTable.id == "f8271273-d07d-4033-8b6c-6b52c04fe3e5" ||
  117. anyTable.id == "dc5931bc-7e8e-47f4-b28e-5bc42fb207da" ||
  118. anyTable.id == "560f5404-6539-422f-8fb9-77bac641e72b"
  119. ) {
  120. //生成一个随机数
  121. let random = Math.round(Math.random() * 100);
  122. anyTable.val = random;
  123. }
  124. });
  125. });
  126. }, 2000);
  127. },
  128. testG() {
  129. clearInterval(this.analogDataTimer);
  130. },
  131. },
  132. created() {
  133. let _this = this;
  134. _this.svgLists = JSON.parse(localStorage.getItem("svginfo"));
  135. //请求接口获取组件
  136. this.$axios
  137. .get(window.PLATFROM_CONFIG.Interface)
  138. .then(function (response) {
  139. _this.svgInfoData = response.data;
  140. console.log(response.data);
  141. })
  142. .catch(function (error) {
  143. console.log(error);
  144. });
  145. },
  146. };
  147. </script>
  148. <style scoped lang="less">
  149. .svg-contain {
  150. position: fixed;
  151. left: 0;
  152. right: 0;
  153. top: 0;
  154. bottom: 0;
  155. }
  156. .btns-content {
  157. position: fixed;
  158. left: 10px;
  159. bottom: 10px;
  160. button {
  161. margin-right: 10px;
  162. }
  163. }
  164. </style>