PlotOfFit.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <template>
  2. <div class="chartsContent">
  3. <el-card shadow="never" v-if="type === 'LeafRootOutline'">
  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#风机 2024/3/1 11:00:00
  10. </div>
  11. </div>
  12. <div class="line-chart" ref="chart"></div>
  13. </el-card>
  14. <el-card shadow="never" v-else-if="type === 'LeafRootRelativeOutline'">
  15. <div slot="header" class="clearfix">
  16. <h4 style="color: black; font-size: 16px; font-weight: 700">
  17. 叶根相对平均轮廓拟合图
  18. </h4>
  19. <div style="font-size: 12px; color: #666">
  20. 江西大唐国际新能源有限公司\金华山风电场\01#风机 2024/3/1 11:00:00
  21. </div>
  22. </div>
  23. <div class="line-chart" ref="chart"></div>
  24. </el-card>
  25. <el-card shadow="never" v-else-if="type === 'LeafTipProfile'">
  26. <div slot="header" class="clearfix">
  27. <h4 style="color: black; font-size: 16px; font-weight: 700">
  28. 叶尖轮廓拟合图
  29. </h4>
  30. <div style="font-size: 12px; color: #666">
  31. 江西大唐国际新能源有限公司\金华山风电场\01#风机 2024/3/1 11:00:00
  32. </div>
  33. </div>
  34. <div class="line-chart" ref="chart"></div>
  35. </el-card>
  36. <el-card shadow="never" v-else-if="type === 'LeafTipRelativeProfile'">
  37. <div slot="header" class="clearfix">
  38. <h4 style="color: black; font-size: 16px; font-weight: 700">
  39. 叶尖相对平均轮廓拟合图
  40. </h4>
  41. <div style="font-size: 12px; color: #666">
  42. 江西大唐国际新能源有限公司\金华山风电场\01#风机 2024/3/1 11:00:00
  43. </div>
  44. </div>
  45. <div class="line-chart" ref="chart"></div>
  46. </el-card>
  47. </div>
  48. </template>
  49. <script>
  50. import * as echarts from "echarts"; // 导入 echarts 库
  51. import screenfull from "screenfull";
  52. export default {
  53. props: {
  54. type: {
  55. default: "",
  56. },
  57. },
  58. data() {
  59. return {
  60. currentIndex: 0, // 默认索引
  61. tableData: [], // 数据
  62. originalChartStyle: {}, // 用于存储原始样式
  63. };
  64. },
  65. mounted() {
  66. this.initializeChart();
  67. // 监听键盘事件
  68. window.addEventListener("keydown", this.handleKeyDown);
  69. },
  70. destroyed() {
  71. // 移除键盘事件监听
  72. window.removeEventListener("keydown", this.handleKeyDown);
  73. },
  74. methods: {
  75. // 初始化图表
  76. initializeChart() {
  77. const chartDom = this.$refs.chart;
  78. this.chartInstance = echarts.init(chartDom);
  79. const defaultData = [
  80. Math.floor(Math.random() * 300),
  81. Math.floor(Math.random() * 300),
  82. Math.floor(Math.random() * 300),
  83. ];
  84. const defaultLabels = ["2024/1/1", "2024/1/2", "2024/1/3"];
  85. this.updateChart(defaultData, defaultLabels);
  86. // 保存初始样式
  87. this.originalChartStyle = {
  88. width: chartDom.style.width,
  89. height: chartDom.style.height,
  90. backgroundColor: chartDom.style.backgroundColor,
  91. };
  92. },
  93. // 更新图表数据
  94. updateChart(data, labels) {
  95. const defaultData = Array.from({ length: 5000 }, () =>
  96. Math.floor(Math.random() * 300)
  97. );
  98. const defaultLabels = Array.from(
  99. { length: 5000 },
  100. (_, index) => `2024/1/${index + 1}`
  101. );
  102. const option = {
  103. color: ["#9CC5AF", "#C9866B", "#709EA6", "#344453", "#B34138"],
  104. // title: [
  105. // {
  106. // text: "",
  107. // left: "center",
  108. // // subtext: '纯属虚构'
  109. // },
  110. // {
  111. // text: "",
  112. // // subtext:'实线',
  113. // textStyle: {
  114. // color: "#c23531",
  115. // // }
  116. // },
  117. // right: 35,
  118. // top: 275,
  119. // // subtext: '纯属虚构'
  120. // },
  121. // {
  122. // text: "",
  123. // right: 3,
  124. // top: 280,
  125. // textStyle: {
  126. // color: "#c23531",
  127. // fontSize: 12,
  128. // },
  129. // },
  130. // {
  131. // text: "",
  132. // textStyle: {
  133. // color: "#2f4554",
  134. // },
  135. // right: 35,
  136. // top: 295,
  137. // // subtext: '纯属虚构'
  138. // },
  139. // {
  140. // text: "",
  141. // textStyle: {
  142. // // fontSize:12,
  143. // color: "#d48265",
  144. // },
  145. // right: 0,
  146. // top: 219,
  147. // // subtext: '纯属虚构'
  148. // },
  149. // {
  150. // text: "",
  151. // textStyle: {
  152. // color: "#61a0a8",
  153. // },
  154. // right: 35,
  155. // top: 410,
  156. // // subtext: '纯属虚构'
  157. // },
  158. // {
  159. // top: 510,
  160. // left: 50,
  161. // subtextStyle: {
  162. // fontWeight: "bold",
  163. // },
  164. // },
  165. // ],
  166. toolbox: {
  167. feature: {
  168. dataZoom: { yAxisIndex: "none" },
  169. restore: {},
  170. saveAsImage: {},
  171. myCustomTool: {
  172. show: true,
  173. title: "上一条",
  174. icon: `image://${require("@/assets/analyse/08.png")}`,
  175. onclick: () => this.previousRow(),
  176. },
  177. myCustomTool2: {
  178. show: true,
  179. title: "下一条",
  180. icon: `image://${require("@/assets/analyse/09.png")}`,
  181. onclick: () => this.nextRow(),
  182. },
  183. myCustomTool3: {
  184. show: true,
  185. title: "全屏",
  186. icon: `image://${require("@/assets/analyse/fullScreen.png")}`,
  187. onclick: () => this.fullScreen(),
  188. },
  189. myCustomTool4: {
  190. show: true,
  191. title: "退出全屏",
  192. icon: `image://${require("@/assets/analyse/exitFullScreen.png")}`, // 替换为你自己的图标路径
  193. onclick: () => this.exitFullScreen(),
  194. },
  195. },
  196. },
  197. xAxis: {
  198. type: "category",
  199. boundaryGap: false,
  200. data: [
  201. 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
  202. 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011,
  203. 2012, 2013, 2014, 2015, 2016,
  204. ],
  205. },
  206. yAxis: {
  207. type: "value",
  208. boundaryGap: [0, "100%"],
  209. },
  210. tooltip: {
  211. trigger: "axis",
  212. position: function (pt) {
  213. return [pt[0], "10%"];
  214. },
  215. },
  216. series: [
  217. {
  218. name: "叶片1根部轮廓",
  219. type: "line",
  220. showSymbol: false,
  221. data: [
  222. 1.63, 1.9, 2.16, 2.55, 2.7, 2.69, 2.65, 2.87, 2.9, 3.1, 3.47,
  223. 3.89, 4.54, 5.33, 5.95, 6.44, 6.94, 7.45, 7.61, 8.44, 9.35, 9.58,
  224. 10.06, 10.6, 10.94, 11.49, 11.03, 11.11,
  225. ],
  226. },
  227. {
  228. name: "叶片2根部轮廓",
  229. type: "line",
  230. showSymbol: false,
  231. lineStyle: {
  232. // type: "dashed",
  233. },
  234. data: [
  235. 12.84, 13.03, 13.05, 13.89, 13.72, 12.97, 13.21, 14.02, 14.54,
  236. 15.07, 14.94, 14.55, 13.84, 12.7, 12.06, 11.93, 11.6, 10.84,
  237. 10.26, 10.18, 10.21, 9.86, 10.1, 9.96, 10.25, 11.1, 11.08, 10.7,
  238. ],
  239. },
  240. {
  241. name: "叶片3根部轮廓",
  242. showSymbol: false,
  243. lineStyle: {
  244. // type: "dotted",
  245. },
  246. type: "line",
  247. data: [
  248. 7.38, 7.73, 7.46, 7.85, 7.68, 7.45, 6.94, 6.7, 5.98, 6.25, 6.28,
  249. 5.74, 5.51, 5.35, 5.25, 5.03, 4.83, 4.57, 4.58, 4.33, 4.6, 4.42,
  250. 4.38, 3.95, 3.82, 3.7, 3.75, 3.71,
  251. ],
  252. },
  253. {
  254. name: "平均轮廓",
  255. showSymbol: false,
  256. type: "line",
  257. data: [
  258. "-",
  259. "-",
  260. 23.55,
  261. 21.24,
  262. 21.26,
  263. 21.32,
  264. 20.88,
  265. 20.23,
  266. 21.2,
  267. 20.36,
  268. 18.28,
  269. 18.93,
  270. 18.85,
  271. 19.19,
  272. 18.79,
  273. 18.1,
  274. 18.06,
  275. 17.88,
  276. 17.38,
  277. 17.06,
  278. 16.04,
  279. 15.98,
  280. 15.17,
  281. 15.17,
  282. 15.16,
  283. 14.77,
  284. 14.91,
  285. 14.76,
  286. ],
  287. },
  288. ],
  289. };
  290. this.chartInstance.setOption(option);
  291. },
  292. previousRow() {
  293. let newIndex =
  294. this.currentIndex > 0
  295. ? this.currentIndex - 1
  296. : this.tableData.length - 1;
  297. this.$emit("update:currentIndex", newIndex);
  298. },
  299. nextRow() {
  300. console.log("下一条");
  301. let newIndex =
  302. this.currentIndex < this.tableData.length - 1
  303. ? this.currentIndex + 1
  304. : 0;
  305. this.$emit("update:currentIndex", newIndex);
  306. },
  307. toggleFullScreen() {
  308. const chartDom = this.$refs.chart;
  309. if (screenfull.isEnabled) {
  310. screenfull.toggle(chartDom);
  311. }
  312. },
  313. fullScreen() {
  314. const chartDom = this.$refs.chart;
  315. if (screenfull.isEnabled) {
  316. // 设置全屏样式
  317. chartDom.style.position = "absolute";
  318. chartDom.style.top = 0;
  319. chartDom.style.left = 0;
  320. chartDom.style.width = "100vw";
  321. chartDom.style.height = "100vh";
  322. chartDom.style.backgroundColor = "#ffffff";
  323. // 进入全屏
  324. screenfull.request(chartDom);
  325. this.chartInstance.resize();
  326. // 监听全屏变化
  327. screenfull.on("change", this.handleFullScreenChange);
  328. }
  329. },
  330. exitFullScreen() {
  331. const chartDom = this.$refs.chart;
  332. if (screenfull.isEnabled) {
  333. screenfull.exit();
  334. // 监听全屏变化
  335. screenfull.on("change", this.handleFullScreenChange);
  336. }
  337. },
  338. // 处理全屏变化的回调
  339. handleFullScreenChange() {
  340. const chartDom = this.$refs.chart;
  341. if (!screenfull.isFullscreen) {
  342. // 退出全屏时恢复样式
  343. chartDom.style.position = this.originalChartStyle.position || "";
  344. chartDom.style.top = this.originalChartStyle.top || "";
  345. chartDom.style.left = this.originalChartStyle.left || "";
  346. chartDom.style.width = this.originalChartStyle.width || "100%";
  347. chartDom.style.height = this.originalChartStyle.height || "250px";
  348. chartDom.style.backgroundColor =
  349. this.originalChartStyle.backgroundColor || "#fff";
  350. // 调整图表尺寸
  351. this.chartInstance.resize();
  352. // 可选:移除事件监听(如果不再需要)
  353. screenfull.off("change", this.handleFullScreenChange);
  354. }
  355. },
  356. },
  357. };
  358. </script>
  359. <style lang="scss" scoped>
  360. ::v-deep .el-card__body {
  361. width: 100%;
  362. height: 250px;
  363. position: relative;
  364. }
  365. .line-chart {
  366. width: 100%;
  367. height: 250px;
  368. background-color: #fff;
  369. position: relative;
  370. }
  371. .eigenvalue {
  372. position: absolute;
  373. top: 0;
  374. right: 0;
  375. font-size: 10px;
  376. width: 100px;
  377. border: 1px solid black;
  378. padding: 5px;
  379. background: #fff;
  380. z-index: 99;
  381. h5 {
  382. line-height: 16px;
  383. height: 16px;
  384. }
  385. }
  386. </style>