assetssDetail.vue 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  1. <!--
  2. * @Author: your name
  3. * @Date: 2024-05-27 09:25:45
  4. * @LastEditTime: 2024-09-29 15:49:05
  5. * @LastEditors: bogon
  6. * @Description: In User Settings Edit
  7. * @FilePath: /performance-test/src/views/performance/assetssDetail.vue
  8. -->
  9. <template>
  10. <div class="global-variable" v-loading="loading">
  11. <!-- <LineCharts></LineCharts> -->
  12. <!-- 通过json文件绘制新的图表 -->
  13. <!-- <CreateNewChart></CreateNewChart> -->
  14. <el-row type="flex" justify="space-between">
  15. <el-col :span="8">
  16. <el-button
  17. type="text"
  18. style="font-size: 20px"
  19. icon="el-icon-arrow-left"
  20. @click="() => $router.push('/home/performance/assetssMag')"
  21. >
  22. 返回
  23. </el-button>
  24. </el-col>
  25. <el-col :span="8">
  26. <h2 style="text-align: center">分析历史记录总览</h2>
  27. </el-col>
  28. <el-col :span="8">
  29. <div style="text-align: end; font-size: 16px">
  30. 分析时间:{{
  31. generalFiles.length > 0
  32. ? generalFiles[0].createTime
  33. : diagramRelations.length > 0
  34. ? diagramRelations[0].createTime
  35. : "/"
  36. }}
  37. </div>
  38. </el-col>
  39. </el-row>
  40. <el-card class="box-card analysisType">
  41. <el-form
  42. :model="formInfo"
  43. :rules="rules"
  44. ref="ruleForm"
  45. label-width="100px"
  46. inline
  47. class="demo-ruleForm"
  48. >
  49. <el-row type="flex" justify="space-between">
  50. <el-col :span="8">
  51. <el-form-item label="分析类型" prop="analysisTypeCode">
  52. <el-select
  53. v-model="formInfo.analysisTypeCode"
  54. size="small"
  55. @change="handleAnalysisType"
  56. >
  57. <el-option
  58. v-for="(item, indAns) in analysisTypeList"
  59. :key="item.analysisTypeCode + indAns"
  60. :label="item.analysisTypeName"
  61. :value="item.analysisTypeCode"
  62. ></el-option>
  63. </el-select>
  64. </el-form-item>
  65. </el-col>
  66. <el-col :span="8">
  67. <el-form-item label="机组名称" prop="fieldEngineCode">
  68. <el-select v-model="formInfo.fieldEngineCode" size="small">
  69. <el-option
  70. v-for="(item, indWind) in windEngineGroupList"
  71. :key="item.engineCode + indWind"
  72. :label="item.engineName"
  73. :value="item.engineCode"
  74. ></el-option>
  75. </el-select>
  76. </el-form-item>
  77. </el-col>
  78. <el-col :span="8">
  79. <el-form-item
  80. class="searchFrom"
  81. style="display: flex; justify-content: end"
  82. >
  83. <el-button type="primary" @click="onSubmit" size="small">
  84. 查询
  85. </el-button>
  86. <el-button @click="reset('ruleForm')" size="small">
  87. 重置
  88. </el-button>
  89. <el-button
  90. type="primary"
  91. @click="downLoadAllTypeFile"
  92. size="small"
  93. >
  94. 一键下载分析结果图
  95. </el-button>
  96. </el-form-item>
  97. </el-col>
  98. </el-row>
  99. </el-form>
  100. </el-card>
  101. <el-empty :image-size="200" v-if="flage"></el-empty>
  102. <div v-else>
  103. <el-table
  104. class="box-card"
  105. v-if="
  106. this.formInfo.analysisTypeCode === 'yaw_error' &&
  107. this.csvData.length > 0
  108. "
  109. :data="csvData"
  110. border
  111. max-height="550"
  112. style="width: 100%"
  113. align="center"
  114. >
  115. <el-table-column prop="engine_name" label="风机名称"> </el-table-column>
  116. <el-table-column prop="yaw_error1" label="误差值"> </el-table-column>
  117. </el-table>
  118. <div v-else>
  119. <el-card class="box-card analysisType" v-if="generalFiles.length > 0">
  120. <div slot="header" class="clearfix">
  121. <span style="font-weight: 700; font-size: 16px">
  122. 分析总图{{ fileCheckResult1 }}
  123. </span>
  124. </div>
  125. <el-row class="assetssConent">
  126. <template
  127. v-if="
  128. formInfo.analysisTypeCode === 'power_curve' &&
  129. (generalFilesData.length > 0 || powerHtmlZongData.length > 0)
  130. "
  131. >
  132. <template
  133. v-if="
  134. generalFilesData[0] !== null && generalFilesData.length !== 0
  135. "
  136. >
  137. <template
  138. v-for="(powerCurveDom, ind) in generalFilesData"
  139. :style="{ marginTop: '50px' }"
  140. >
  141. <el-col :span="12">
  142. <div class="left">
  143. <el-button
  144. @click="
  145. downLoadCsv(
  146. powerCurveDom && powerCurveDom.powerCurveTableData
  147. )
  148. "
  149. >导出表格数据</el-button
  150. >
  151. <el-table
  152. :data="
  153. powerCurveDom && powerCurveDom.powerCurveTableData
  154. "
  155. border
  156. max-height="500"
  157. style="width: 100%"
  158. align="center"
  159. >
  160. <el-table-column prop="enginName" label="风机名称">
  161. </el-table-column>
  162. <el-table-column prop="engineTypeName" label="风机机型">
  163. </el-table-column>
  164. <el-table-column prop="xData" label="风速">
  165. </el-table-column>
  166. <el-table-column prop="yData" label="实际功率">
  167. </el-table-column>
  168. <el-table-column
  169. prop="contractPowerCurve"
  170. label="合同功率"
  171. >
  172. </el-table-column>
  173. </el-table>
  174. </div>
  175. </el-col>
  176. <el-col :span="12">
  177. <div class="right">
  178. <PlotlyCharts
  179. :lineMarkerData="powerCurveDom.chartsData"
  180. :comType="'generalDrawing'"
  181. :inds="`zong${ind}`"
  182. ></PlotlyCharts>
  183. </div>
  184. </el-col>
  185. </template>
  186. </template>
  187. <template v-if="powerHtmlZongData.length > 0">
  188. <el-col
  189. v-for="(file, index) in powerHtmlZongData"
  190. :key="index + file.fileAddr + file.createTime"
  191. :span="24"
  192. class="col_content"
  193. :style="{
  194. marginTop: '50px',
  195. display:
  196. getFileType(file.fileAddr) === 'html' ? 'block' : 'none',
  197. }"
  198. >
  199. <iframe
  200. v-if="getFileType(file.fileAddr) === 'html'"
  201. :src="file.fileAddr"
  202. :ref="'iframe' + index"
  203. frameborder="0"
  204. @load="iframeLoad(index + powerHtmlZongData.length)"
  205. width="100%"
  206. height="100%"
  207. ></iframe>
  208. </el-col>
  209. </template>
  210. </template>
  211. <template v-else>
  212. <el-col
  213. v-for="(file, index) in generalFiles"
  214. :key="index + file.fileAddr + file.createTime"
  215. :span="24"
  216. class="col_content"
  217. :style="{
  218. display:
  219. getFileType(file.fileAddr) === 'html' ? 'block' : 'none',
  220. }"
  221. >
  222. <iframe
  223. v-if="getFileType(file.fileAddr) === 'html'"
  224. :src="file.fileAddr"
  225. :ref="'iframe' + index"
  226. frameborder="0"
  227. @load="iframeLoad(index + generalFiles.length)"
  228. width="100%"
  229. height="100%"
  230. ></iframe>
  231. </el-col>
  232. </template>
  233. </el-row>
  234. </el-card>
  235. <el-card
  236. class="box-card analysisType"
  237. v-if="diagramRelations.length > 0"
  238. >
  239. <div slot="header" class="clearfix">
  240. <span style="font-weight: 700; font-size: 16px">
  241. 分析分图 {{ fileCheckResult1 }}
  242. </span>
  243. </div>
  244. <el-row class="assetssConent">
  245. <template
  246. v-if="
  247. formInfo.analysisTypeCode === 'power_curve' &&
  248. generalFiles.length > 0
  249. "
  250. >
  251. <template
  252. v-if="graphFilesData[0] !== null && graphFilesData.length !== 0"
  253. >
  254. <template v-for="(powerCurveDom, ind) in graphFilesData">
  255. <el-col :span="12">
  256. <div class="left">
  257. <!-- <el-button
  258. @click="
  259. downLoadCsv(
  260. powerCurveDom && powerCurveDom.powerCurveTableData
  261. )
  262. "
  263. >导出表格数据</el-button
  264. > -->
  265. <el-table
  266. :data="
  267. powerCurveDom && powerCurveDom.powerCurveTableData
  268. "
  269. border
  270. max-height="500"
  271. style="width: 100%"
  272. align="center"
  273. >
  274. <el-table-column prop="enginName" label="风机名称">
  275. </el-table-column>
  276. <el-table-column prop="engineTypeName" label="风机机型">
  277. </el-table-column>
  278. <el-table-column prop="xData" label="风速">
  279. </el-table-column>
  280. <el-table-column prop="yData" label="实际功率">
  281. </el-table-column>
  282. <el-table-column
  283. prop="contractPowerCurve"
  284. label="合同功率"
  285. >
  286. </el-table-column>
  287. </el-table>
  288. </div>
  289. </el-col>
  290. <el-col
  291. v-if="formInfo.analysisTypeCode === 'power_curve'"
  292. :span="12"
  293. >
  294. <div class="right">
  295. <PlotlyCharts
  296. :lineMarkerData="powerCurveDom.chartsData"
  297. :comType="'graph'"
  298. :inds="`fen${ind}`"
  299. ></PlotlyCharts>
  300. </div>
  301. </el-col>
  302. </template>
  303. </template>
  304. <template v-if="powerHtmlFenData.length > 0">
  305. <el-col
  306. v-for="(file, index) in powerHtmlFenData"
  307. :key="index + file.fileAddr + file.createTime"
  308. :span="24"
  309. class="col_content"
  310. :style="{
  311. display:
  312. getFileType(file.fileAddr) === 'html' ? 'block' : 'none',
  313. }"
  314. >
  315. <iframe
  316. v-if="getFileType(file.fileAddr) === 'html'"
  317. :src="file.fileAddr"
  318. :ref="'iframe' + index"
  319. frameborder="0"
  320. @load="iframeLoad(index + powerHtmlFenData.length)"
  321. width="100%"
  322. height="100%"
  323. ></iframe>
  324. </el-col>
  325. </template>
  326. </template>
  327. <template v-else>
  328. <el-col
  329. v-for="(file, index) in diagramRelations"
  330. :key="index + file.fileAddr + file.createTime"
  331. :span="24"
  332. :style="{
  333. display:
  334. getFileType(file.fileAddr) === 'html' ? 'block' : 'none',
  335. }"
  336. class="col_content"
  337. >
  338. <iframe
  339. v-if="getFileType(file.fileAddr) === 'html'"
  340. :src="file.fileAddr"
  341. :ref="'iframe' + index + diagramRelations.length"
  342. frameborder="0"
  343. width="100%"
  344. height="100%"
  345. @load="iframeLoad(index + diagramRelations.length)"
  346. ></iframe>
  347. </el-col>
  348. </template>
  349. </el-row>
  350. </el-card>
  351. </div>
  352. <el-card
  353. class="box-card"
  354. v-for="o in commentDescriptionVos"
  355. :key="o.commentTypeName"
  356. >
  357. <div slot="header" class="clearfix">
  358. <span style="font-weight: 700; font-size: 16px">{{
  359. o.commentTypeName
  360. }}</span>
  361. </div>
  362. <div class="text item">
  363. <div v-html="o.comment"></div>
  364. </div>
  365. </el-card>
  366. </div>
  367. </div>
  368. </template>
  369. <script>
  370. import {
  371. analysisDetail,
  372. queryAnalysisedType,
  373. queryAnalysisedEngine,
  374. queryAnalysisTypeConfig,
  375. queryDownloadFile,
  376. downloadFile,
  377. } from "@/api/performance";
  378. import CreateNewChart from "./createNewChart.vue";
  379. import DetailCharts from "./components/DetailCharts.vue";
  380. // import JsonMarkerCharts from "./components/JsonMarkerCharts.vue";
  381. import PlotlyCharts from "./components/PlotlyCharts.vue";
  382. import LineCharts from "./components/chartsCom/lineChart.vue";
  383. import { downLoadCsvFile } from "@/utils/common";
  384. import { saveAs } from "file-saver";
  385. import JSZip from "jszip";
  386. import Papa from "papaparse";
  387. import axios from "axios";
  388. export default {
  389. components: {
  390. DetailCharts,
  391. // JsonMarkerCharts,
  392. CreateNewChart,
  393. PlotlyCharts,
  394. LineCharts,
  395. },
  396. data() {
  397. return {
  398. loadings: [],
  399. loading: false,
  400. fileCheckResult: null,
  401. fileCheckResult1: null,
  402. analysisTypeList: [],
  403. windEngineGroupList: [],
  404. generalFiles: [], //总图数组
  405. diagramRelations: [], //分图数组
  406. commentDescriptionVos: [],
  407. formInfo: {
  408. fieldEngineCode: null,
  409. analysisTypeCode: null,
  410. },
  411. csvData: [], // 解析后的数据
  412. csvHeaders: [], // CSV 表头
  413. rules: {},
  414. flage: false,
  415. csvData: [], // 解析后的数据
  416. csvHeaders: [], // CSV 表头
  417. generalFilesData: [],
  418. graphChartData: {},
  419. graphFilesData: [],
  420. powerHtmlZongData: [],
  421. powerHtmlFenData: [],
  422. };
  423. },
  424. created() {
  425. //获取分析 分析类型、机组编号 列表
  426. this.getWindCodeList();
  427. },
  428. mounted() {
  429. this.initializeLoading();
  430. // this.chartsTypeConfig();
  431. },
  432. methods: {
  433. //一键下载所有文件
  434. async downLoadAllTypeFile() {
  435. const result = await queryDownloadFile({
  436. fieldCode: this.$route.query.fieldCode,
  437. batchCode: this.$route.query.batchCode,
  438. });
  439. if (result.code === 200) {
  440. this.downLoadSingleType(result.data);
  441. } else {
  442. this.$message({ type: "error", message: result.msg });
  443. }
  444. },
  445. // 下载单个类型的文件
  446. // async downLoadSingleType(data) {
  447. // if (data && data !== null) {
  448. // let totalFiles = data.length;
  449. // let completedFiles = 0;
  450. // // 检查通知支持情况
  451. // if (!("Notification" in window)) {
  452. // alert("This browser does not support desktop notifications.");
  453. // } else if (Notification.permission !== "granted") {
  454. // Notification.requestPermission();
  455. // }
  456. // this.loading = true;
  457. // for (let i = 0; i < data.length; i++) {
  458. // try {
  459. // const formData = new FormData();
  460. // formData.append("batchCode", this.$route.query.batchCode);
  461. // formData.append("analysisTypeCode", data[i]);
  462. // formData.append("fieldCode", this.$route.query.fieldCode);
  463. // // 获取 Blob 对象并提供进度回调
  464. // await downloadFile(formData, (percentCompleted) => {
  465. // // 更新通知
  466. // if (Notification.permission === "granted") {
  467. // new Notification(`Downloading file ${data[i]}`, {
  468. // body: `Progress: ${percentCompleted}%`,
  469. // });
  470. // }
  471. // }).then((blob) => {
  472. // if (blob instanceof Blob) {
  473. // // 使用 FileSaver.js 直接保存文件,自动弹出保存对话框
  474. // saveAs(blob, `file_${data[i]}.pdf`);
  475. // // 更新下载进度
  476. // completedFiles += 1;
  477. // this.loading = false;
  478. // this.$notify({
  479. // title: "提示",
  480. // message: `已完成 ${completedFiles}/${totalFiles} 文件`,
  481. // });
  482. // } else {
  483. // throw new Error(`返回的数据不是 Blob 对象`);
  484. // }
  485. // });
  486. // } catch (error) {
  487. // console.error(`下载文件 ${data[i]} 时发生错误:`, error);
  488. // this.loading = false;
  489. // return;
  490. // }
  491. // }
  492. // // 完成所有文件下载后的通知
  493. // if (Notification.permission === "granted") {
  494. // new Notification("所有文件已下载", {
  495. // body: `${completedFiles}/${totalFiles} 文件已成功下载`,
  496. // });
  497. // }
  498. // }
  499. // },
  500. async downLoadSingleType(data) {
  501. if (data && data !== null) {
  502. let totalFiles = data.length;
  503. let completedFiles = 0;
  504. if (!("Notification" in window)) {
  505. alert("This browser does not support desktop notifications.");
  506. } else if (Notification.permission !== "granted") {
  507. Notification.requestPermission();
  508. }
  509. this.loading = true;
  510. const zip = new JSZip();
  511. for (let i = 0; i < data.length; i++) {
  512. try {
  513. const formData = new FormData();
  514. formData.append("batchCode", this.$route.query.batchCode);
  515. formData.append("analysisTypeCode", data[i]);
  516. formData.append("fieldCode", this.$route.query.fieldCode);
  517. // 获取 Blob 对象并提供进度回调
  518. await downloadFile(formData, (percentCompleted) => {
  519. // 创建或更新通知
  520. // if (Notification.permission === "granted") {
  521. // new Notification(`Downloading file ${data[i]}`, {
  522. // body: `Progress: ${percentCompleted}%`,
  523. // });
  524. // }
  525. }).then((blob) => {
  526. if (blob instanceof Blob) {
  527. zip.file(`file_${data[i]}.zip`, blob);
  528. // console.log(`文件 ${data[i]} 加入到 ZIP 成功`);
  529. completedFiles += 1;
  530. this.loading = false;
  531. this.$notify({
  532. title: "提示",
  533. message: `已完成 ${completedFiles}/${totalFiles} 文件`,
  534. // duration: 0,
  535. });
  536. // console.log(`已完成 ${completedFiles}/${totalFiles} 文件`);
  537. } else {
  538. throw new Error(`返回的数据不是 Blob 对象`);
  539. }
  540. });
  541. } catch (error) {
  542. console.error(`下载文件 ${data[i]} 时发生错误:`, error);
  543. this.loading = false;
  544. return;
  545. }
  546. }
  547. // 生成 ZIP 文件并下载
  548. zip
  549. .generateAsync({ type: "blob" })
  550. .then((content) => {
  551. saveAs(content, "Downloaded_Files.zip");
  552. // console.log("所有文件已打包并下载成功");
  553. })
  554. .catch((error) => {
  555. console.error("生成 ZIP 文件时发生错误:", error);
  556. });
  557. }
  558. },
  559. async handleAnalysisType(e) {
  560. this.csvData = []; // 解析后的数据
  561. this.csvHeaders = [];
  562. const resEngineList = await queryAnalysisedEngine({
  563. batchCode: this.$route.query.batchCode,
  564. analysisTypeCode: e,
  565. });
  566. this.windEngineGroupList = resEngineList.data;
  567. this.formInfo.fieldEngineCode =
  568. resEngineList.data !== null && resEngineList.data.length > 0
  569. ? resEngineList.data[0].engineCode
  570. : null;
  571. this.getDetailInfo();
  572. },
  573. //分析类型图表样式
  574. async chartsTypeConfig() {
  575. const result = await queryAnalysisTypeConfig();
  576. },
  577. iframeLoad(index) {
  578. this.$set(this.loadings, index, false);
  579. },
  580. initializeLoading() {
  581. // 计算总的文件数量,包括分析总图和分析分图
  582. const totalFiles =
  583. this.generalFiles.length + this.diagramRelations.length;
  584. // 初始化 loadings 数组,全部设置为 true,表示加载状态
  585. this.loadings = new Array(totalFiles).fill(true);
  586. },
  587. // 查询
  588. onSubmit() {
  589. this.getDetailInfo();
  590. },
  591. // 重置
  592. reset(formName) {
  593. this.$refs[formName].resetFields();
  594. this.getWindCodeList();
  595. },
  596. async getDetailInfo() {
  597. const formData = new FormData();
  598. formData.append("batchCode", this.$route.query.batchCode);
  599. formData.append("analysisTypeCode", this.formInfo.analysisTypeCode);
  600. formData.append("fieldEngineCode", this.formInfo.fieldEngineCode);
  601. this.loading = true;
  602. //获取详情信息
  603. try {
  604. const response = await analysisDetail(formData);
  605. if (response.data.length === 0 || response.data === null) {
  606. this.flage = true;
  607. } else {
  608. this.flage = false;
  609. }
  610. this.generalFiles = [];
  611. this.generalFiles =
  612. (response.data &&
  613. response.data.length > 0 &&
  614. response.data[0].generalFiles) ||
  615. [];
  616. this.diagramRelations = [];
  617. this.diagramRelations =
  618. (response.data &&
  619. response.data.length > 0 &&
  620. response.data[0].diagramRelations) ||
  621. [];
  622. this.commentDescriptionVos =
  623. (response.data &&
  624. response.data.length > 0 &&
  625. response.data[0].commentDescriptionVos) ||
  626. [];
  627. if (this.formInfo.analysisTypeCode === "yaw_error") {
  628. this.getCsvData(response.data[0].generalFiles[0].fileAddr);
  629. }
  630. this.initializeLoading();
  631. //有功功率的数据处理
  632. // 有功功率的数据处理
  633. if (this.formInfo.analysisTypeCode === "power_curve") {
  634. try {
  635. const generalFiles = response.data[0]?.generalFiles || [];
  636. this.powerHtmlZongData = [];
  637. this.powerHtmlFenData = [];
  638. this.generalFilesData = [];
  639. this.graphFilesData = [];
  640. const generalFilesData = await this.filterJsonData(
  641. generalFiles,
  642. "总图"
  643. );
  644. //分图数据
  645. const graphChartData = await this.filterJsonData(
  646. response.data[0].diagramRelations,
  647. "分图"
  648. );
  649. // 过滤掉 null 或没有 chartsData 的项
  650. this.generalFilesData = generalFilesData.filter(
  651. (item) => item && item.chartsData
  652. );
  653. this.graphFilesData = graphChartData.filter(
  654. (item) => item && item.chartsData
  655. );
  656. // // 这是处理分图数据的逻辑如果有数据,处理并设置图表数据
  657. // if (
  658. // this.generalFilesData.length > 0 &&
  659. // this.generalFilesData[0]?.chartsData?.data
  660. // ) {
  661. // //总图数据
  662. // const grapgFilterData =
  663. // this.generalFilesData[0].chartsData.data.filter(
  664. // (item) =>
  665. // item.enginName === "合同功率曲线" ||
  666. // item.enginName === this.formInfo.fieldEngineCode
  667. // );
  668. // //分图数据
  669. // this.graphChartData = {
  670. // oldData: this.generalFilesData[0].chartsData.data,
  671. // ...this.generalFilesData[0].chartsData,
  672. // data: grapgFilterData,
  673. // formInfoFieldEngineCode: this.formInfo.fieldEngineCode,
  674. // };
  675. // } else {
  676. // // 如果没有数据,设置为 null 或其他默认值
  677. // this.graphChartData = null;
  678. // }
  679. } catch (error) {
  680. console.error("Error processing power curve data:", error);
  681. this.graphChartData = null; // 处理错误时设置默认值
  682. } finally {
  683. this.loading = false; // 确保在所有情况下都设置 loading 状态
  684. }
  685. } else {
  686. this.loading = false;
  687. }
  688. } catch (error) {
  689. console.error(error);
  690. this.loading = false;
  691. }
  692. },
  693. //有功功率数据处理
  694. async filterJsonData(generalFiles, type) {
  695. return Promise.all(
  696. generalFiles.map(async (item, ind) => {
  697. const types = this.getFileType(item.fileAddr);
  698. if (types !== "html" && types !== "image") {
  699. //就是json 数据
  700. try {
  701. const resultChartsData = await axios.get(item.fileAddr);
  702. // 更新表格数据
  703. if (type === "总图") {
  704. return {
  705. chartsData: {
  706. ...resultChartsData.data,
  707. },
  708. powerCurveTableData: this.creatPowerCurveTableData(
  709. resultChartsData.data
  710. ).filter((val) => val !== undefined),
  711. };
  712. } else if (type === "分图") {
  713. return {
  714. chartsData: {
  715. ...resultChartsData.data,
  716. formInfoFieldEngineCode: this.formInfo.fieldEngineCode,
  717. },
  718. powerCurveTableData: this.creatPowerCurveTableData(
  719. resultChartsData.data
  720. )
  721. .filter((val) => val !== undefined)
  722. .filter(
  723. (item) =>
  724. item?.enginName === this.formInfo.fieldEngineCode ||
  725. item?.enginCode === this.formInfo.fieldEngineCode
  726. ),
  727. };
  728. }
  729. } catch (error) {
  730. console.error("Error fetching chart data:", error);
  731. return null; // 如果有错误,返回 null
  732. }
  733. } else {
  734. if (type === "总图") {
  735. this.powerHtmlZongData.push(item);
  736. } else if (type === "分图") {
  737. this.powerHtmlFenData.push(item);
  738. }
  739. //html 展示
  740. return null; // 返回 null 以确保没有 undefined
  741. }
  742. })
  743. );
  744. },
  745. creatPowerCurveTableData(data) {
  746. // 风机名称\风机机型\风速\合同功率\实际功率
  747. // xData--风速
  748. // yData--实际功率
  749. // 合同功率曲线[...]---合同功率
  750. // enginName--风机名称
  751. // engineTypeName--风机机型
  752. const contractPowerCurve =
  753. data && data.data.filter((item) => item.enginName === "合同功率曲线");
  754. const powerCurveTableData =
  755. data &&
  756. data.data.map((item, ind) => {
  757. if (item.enginName !== "合同功率曲线") {
  758. const childData = item.xData.map((child, childInd) => {
  759. // 检查是否所有需要的数据都存在
  760. if (
  761. item.yData[childInd] !== undefined &&
  762. contractPowerCurve[0].yData[childInd] !== undefined
  763. ) {
  764. return {
  765. xData: child,
  766. yData:
  767. item.yData[childInd] !== null ? item.yData[childInd] : 0.0,
  768. contractPowerCurve: contractPowerCurve[0].yData[childInd],
  769. enginName: item.enginName,
  770. enginCode: item.enginCode,
  771. engineTypeName: data.engineTypeName,
  772. };
  773. }
  774. });
  775. return childData;
  776. }
  777. });
  778. return powerCurveTableData.flat();
  779. },
  780. getCsvData(url) {
  781. // 使用 axios 获取 CSV 文件
  782. axios
  783. .get(url, { responseType: "blob" }) // 确保数据以 blob 格式返回
  784. .then((response) => {
  785. const reader = new FileReader();
  786. reader.onload = (e) => {
  787. const csvText = e.target.result;
  788. Papa.parse(csvText, {
  789. header: true, // 使用 CSV 第一行作为键
  790. complete: (result) => {
  791. this.csvHeaders = Object.keys(result.data[0]);
  792. this.csvData = result.data.filter(
  793. (row) => Object.keys(row).length
  794. ); // 过滤空行
  795. },
  796. error: (error) => {
  797. console.error("CSV 解析错误:", error);
  798. },
  799. });
  800. };
  801. reader.readAsText(response.data); // 读取 blob 数据
  802. })
  803. .catch((error) => {
  804. console.error("无法获取 CSV 文件:", error);
  805. });
  806. },
  807. downLoadCsv(tableDatas) {
  808. const headers = ["风机名称", "风机机型", "风速", "实际功率", "合同功率"]; // CSV 文件的标题
  809. const data = tableDatas.map((item) => {
  810. return [
  811. item.enginName,
  812. item.engineTypeName,
  813. item.xData,
  814. item.yData,
  815. item.contractPowerCurve,
  816. ];
  817. });
  818. // 将标题和数据组合成 CSV 格式
  819. const csvContent = [
  820. headers.join(","),
  821. ...data.map((row) => row.join(",")),
  822. ].join("\n");
  823. const fileName = this.windEngineGroupList.filter(
  824. (item) => item.engineCode === this.formInfo.fieldEngineCode
  825. );
  826. downLoadCsvFile(csvContent, "风机有功功率数据");
  827. // downLoadCsvFile(csvContent, fileName[0].engineName);
  828. },
  829. async getWindCodeList() {
  830. this.loading = true;
  831. try {
  832. const resAnalysisedType = await queryAnalysisedType({
  833. batchCode: this.$route.query.batchCode,
  834. });
  835. if (resAnalysisedType.data && resAnalysisedType.data.length > 0) {
  836. const resEngineList = await queryAnalysisedEngine({
  837. batchCode: this.$route.query.batchCode,
  838. analysisTypeCode: resAnalysisedType.data[0].analysisTypeCode,
  839. });
  840. this.analysisTypeList = resAnalysisedType.data;
  841. this.windEngineGroupList = resEngineList.data;
  842. this.formInfo.fieldEngineCode =
  843. resEngineList.data !== null && resEngineList.data.length > 0
  844. ? resEngineList.data[0].engineCode
  845. : null;
  846. this.formInfo.analysisTypeCode =
  847. resAnalysisedType.data.length > 0
  848. ? resAnalysisedType.data[0].analysisTypeCode
  849. : "";
  850. this.loading = false;
  851. }
  852. this.getDetailInfo();
  853. } catch (error) {
  854. this.loading = false;
  855. console.error(error);
  856. }
  857. },
  858. // getSpan(index, type) {
  859. // let isLastElement = false;
  860. // if (type === "generalFiles") {
  861. // isLastElement = index === this.generalFiles.length - 1;
  862. // } else if (type === "diagramRelations") {
  863. // isLastElement = index === this.diagramRelations.length - 1;
  864. // }
  865. // const isOddPosition = (index + 1) % 2 !== 0;
  866. // if (isLastElement && isOddPosition) {
  867. // return 24;
  868. // }
  869. // return 12;
  870. // },
  871. getFileType(url) {
  872. // 使用 URL 对象解析 URL
  873. // 获取路径名部分
  874. let pathname = url.split("/").pop();
  875. // 截取路径名,去除加密乱码字符部分
  876. const index = pathname.indexOf(".html");
  877. if (index !== -1) {
  878. pathname = pathname.slice(0, index + 5); // '.html' 的长度是 5
  879. } else {
  880. pathname = pathname.slice(0, pathname.indexOf(".png") + 4); // '.png' 的长度是 4
  881. }
  882. // 正则表达式匹配图片扩展名
  883. const imageExtensions = /\.(png|jpg|jpeg|gif|bmp|svg)$/i;
  884. // 正则表达式匹配 HTML 扩展名
  885. const htmlExtensions = /\.html?$/i;
  886. if (imageExtensions.test(pathname)) {
  887. return "image";
  888. } else if (htmlExtensions.test(pathname)) {
  889. return "html";
  890. } else {
  891. return "unknown";
  892. }
  893. },
  894. },
  895. };
  896. </script>
  897. <style scoped lang="scss">
  898. .box-card {
  899. margin-top: 20px;
  900. }
  901. .imageDetail {
  902. padding: 80px 100px;
  903. }
  904. .analysisType {
  905. .assetssConent {
  906. height: 550px !important;
  907. .el-col-12 {
  908. height: 100%;
  909. }
  910. .el-col-24 {
  911. height: 100%;
  912. }
  913. iframe {
  914. width: 100%;
  915. height: 100%;
  916. }
  917. img {
  918. width: 100%;
  919. height: auto;
  920. margin: 0 auto;
  921. }
  922. }
  923. }
  924. ::v-deep .gjp .el-skeleton {
  925. width: 90% !important;
  926. height: 90% !important;
  927. margin: 0 auto !important;
  928. }
  929. </style>