Power_diagram.vue 5.0 KB

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