CylinderOfTower.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <template>
  2. <div class="chartsContent">
  3. <el-card shadow="never" v-if="type === 'Waveformdiagram'">
  4. <div slot="header" class="clearfix">
  5. <h4 style="color: black; font-size: 16px; font-weight: 700">
  6. 塔筒振动波形图
  7. </h4>
  8. <div style="font-size: 12px; color: #666">
  9. 测点路径:江西大唐国际新能源有限公司\、金华山风电场\01#风机\塔筒振动
  10. </div>
  11. <div style="font-size: 12px; color: #666">
  12. 采样频率(Hz):2560 有效值(m/s2):8.32 叶轮转速(r/min):15.3
  13. 采样时间:2024//3/10 12:34:33
  14. </div>
  15. </div>
  16. <div class="line-chart" ref="chart"></div>
  17. </el-card>
  18. <el-card shadow="never" v-else-if="type === 'spectrogram'">
  19. <div slot="header" class="clearfix">
  20. <h4 style="color: black; font-size: 16px; font-weight: 700">
  21. 塔筒振动频谱图
  22. </h4>
  23. </div>
  24. <div class="line-chart" ref="chart"></div>
  25. </el-card>
  26. </div>
  27. </template>
  28. <script>
  29. import * as echarts from "echarts"; // 导入 echarts 库
  30. import screenfull from "screenfull";
  31. export default {
  32. props: {
  33. type: {
  34. default: "",
  35. },
  36. },
  37. data() {
  38. return {
  39. currentIndex: 0, // 默认索引
  40. tableData: [], // 数据
  41. originalChartStyle: {}, // 用于存储原始样式
  42. };
  43. },
  44. mounted() {
  45. this.initializeChart();
  46. // 监听键盘事件
  47. window.addEventListener("keydown", this.handleKeyDown);
  48. },
  49. destroyed() {
  50. // 移除键盘事件监听
  51. window.removeEventListener("keydown", this.handleKeyDown);
  52. },
  53. methods: {
  54. // 初始化图表
  55. initializeChart() {
  56. const chartDom = this.$refs.chart;
  57. this.chartInstance = echarts.init(chartDom);
  58. const defaultData = [
  59. Math.floor(Math.random() * 300),
  60. Math.floor(Math.random() * 300),
  61. Math.floor(Math.random() * 300),
  62. ];
  63. const defaultLabels = ["2024/1/1", "2024/1/2", "2024/1/3"];
  64. this.updateChart(defaultData, defaultLabels);
  65. // 保存初始样式
  66. this.originalChartStyle = {
  67. width: chartDom.style.width,
  68. height: chartDom.style.height,
  69. backgroundColor: chartDom.style.backgroundColor,
  70. };
  71. },
  72. // 更新图表数据
  73. updateChart(data, labels) {
  74. const defaultData = Array.from({ length: 5000 }, () =>
  75. Math.floor(Math.random() * 300)
  76. );
  77. const defaultLabels = Array.from(
  78. { length: 5000 },
  79. (_, index) => `2024/1/${index + 1}`
  80. );
  81. const option = {
  82. toolbox: {
  83. feature: {
  84. dataZoom: { yAxisIndex: "none" },
  85. restore: {},
  86. saveAsImage: {},
  87. myCustomTool: {
  88. show: true,
  89. title: "上一条",
  90. icon: `image://${require("@/assets/analyse/08.png")}`,
  91. onclick: () => this.previousRow(),
  92. },
  93. myCustomTool2: {
  94. show: true,
  95. title: "下一条",
  96. icon: `image://${require("@/assets/analyse/09.png")}`,
  97. onclick: () => this.nextRow(),
  98. },
  99. myCustomTool3: {
  100. show: true,
  101. title: "全屏",
  102. icon: `image://${require("@/assets/analyse/fullScreen.png")}`,
  103. onclick: () => this.fullScreen(),
  104. },
  105. myCustomTool4: {
  106. show: true,
  107. title: "退出全屏",
  108. icon: `image://${require("@/assets/analyse/exitFullScreen.png")}`, // 替换为你自己的图标路径
  109. onclick: () => this.exitFullScreen(),
  110. },
  111. },
  112. },
  113. xAxis: {
  114. type: "category",
  115. boundaryGap: false,
  116. data: defaultLabels,
  117. },
  118. yAxis: {
  119. type: "value",
  120. boundaryGap: [0, "100%"],
  121. },
  122. tooltip: {
  123. trigger: "axis",
  124. position: function (pt) {
  125. return [pt[0], "10%"];
  126. },
  127. },
  128. series: [
  129. {
  130. name: "",
  131. type: "line",
  132. symbol: "none",
  133. sampling: "lttb",
  134. itemStyle: {
  135. normal: {
  136. color: "#3070B7",
  137. lineStyle: {
  138. color: "#3070B7",
  139. width: 1,
  140. },
  141. },
  142. },
  143. data: defaultData,
  144. },
  145. ],
  146. };
  147. this.chartInstance.setOption(option);
  148. },
  149. previousRow() {
  150. let newIndex =
  151. this.currentIndex > 0
  152. ? this.currentIndex - 1
  153. : this.tableData.length - 1;
  154. this.$emit("update:currentIndex", newIndex);
  155. },
  156. nextRow() {
  157. console.log("下一条");
  158. let newIndex =
  159. this.currentIndex < this.tableData.length - 1
  160. ? this.currentIndex + 1
  161. : 0;
  162. this.$emit("update:currentIndex", newIndex);
  163. },
  164. toggleFullScreen() {
  165. const chartDom = this.$refs.chart;
  166. if (screenfull.isEnabled) {
  167. screenfull.toggle(chartDom);
  168. }
  169. },
  170. fullScreen() {
  171. const chartDom = this.$refs.chart;
  172. if (screenfull.isEnabled) {
  173. // 设置全屏样式
  174. chartDom.style.position = "absolute";
  175. chartDom.style.top = 0;
  176. chartDom.style.left = 0;
  177. chartDom.style.width = "100vw";
  178. chartDom.style.height = "100vh";
  179. chartDom.style.backgroundColor = "#ffffff";
  180. // 进入全屏
  181. screenfull.request(chartDom);
  182. this.chartInstance.resize();
  183. // 监听全屏变化
  184. screenfull.on("change", this.handleFullScreenChange);
  185. }
  186. },
  187. exitFullScreen() {
  188. const chartDom = this.$refs.chart;
  189. if (screenfull.isEnabled) {
  190. screenfull.exit();
  191. // 监听全屏变化
  192. screenfull.on("change", this.handleFullScreenChange);
  193. }
  194. },
  195. // 处理全屏变化的回调
  196. handleFullScreenChange() {
  197. const chartDom = this.$refs.chart;
  198. if (!screenfull.isFullscreen) {
  199. // 退出全屏时恢复样式
  200. chartDom.style.position = this.originalChartStyle.position || "";
  201. chartDom.style.top = this.originalChartStyle.top || "";
  202. chartDom.style.left = this.originalChartStyle.left || "";
  203. chartDom.style.width = this.originalChartStyle.width || "100%";
  204. chartDom.style.height = this.originalChartStyle.height || "250px";
  205. chartDom.style.backgroundColor =
  206. this.originalChartStyle.backgroundColor || "#fff";
  207. // 调整图表尺寸
  208. this.chartInstance.resize();
  209. // 可选:移除事件监听(如果不再需要)
  210. screenfull.off("change", this.handleFullScreenChange);
  211. }
  212. },
  213. },
  214. };
  215. </script>
  216. <style lang="scss" scoped>
  217. ::v-deep .el-card__body {
  218. width: 100%;
  219. height: 250px;
  220. position: relative;
  221. }
  222. .line-chart {
  223. width: 100%;
  224. height: 250px;
  225. background-color: #fff;
  226. position: relative;
  227. }
  228. .eigenvalue {
  229. position: absolute;
  230. top: 0;
  231. right: 0;
  232. font-size: 10px;
  233. width: 100px;
  234. border: 1px solid black;
  235. padding: 5px;
  236. background: #fff;
  237. z-index: 99;
  238. h5 {
  239. line-height: 16px;
  240. height: 16px;
  241. }
  242. }
  243. </style>