index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <!--
  2. * @Author: your name
  3. * @Date: 2025-01-10 09:24:14
  4. * @LastEditTime: 2025-01-21 14:50:01
  5. * @LastEditors: bogon
  6. * @Description: In User Settings Edit
  7. * @FilePath: /performance-test/src/views/overview/components/yaw_error/index.vue
  8. -->
  9. <template>
  10. <div class="type-variable">
  11. <!-- 静态偏航误差分析 -->
  12. <div class="left">
  13. <FilterChart
  14. :windList="windEngineGroupList"
  15. @getEnfineList="getEnfineList"
  16. @handlePrevious="handlePrevious"
  17. @handleNext="handleNext"
  18. ></FilterChart>
  19. <el-alert type="info" :closable="false">
  20. <template v-slot:title>
  21. <div style="display: flex; align-items: center">
  22. <i
  23. class="el-icon-info"
  24. style="font-size: 20px; margin-right: 5px"
  25. ></i>
  26. <h3>分析说明:</h3>
  27. </div>
  28. </template>
  29. <div style="font-size: 12px; margin-top: 10px">
  30. 静态偏航误差过大,导致风轮不能精准对风,会造成发电损失,例如10°的静态偏航误差导致2.6%的发电损失,且风速较低的风场往往出现更多的发电损失;此外静态偏航误差过大,不仅会影响机组的功率输出,还会引起叶片气动弹性波动,增加机组的额外载荷。因此,定期检测机组的静态偏航误差,并及时校正,对于改善机组发电性能和机组运行安全都有很重要的意义。
  31. </div>
  32. </el-alert>
  33. <div class="titleCharts">分析分图 :</div>
  34. <div v-if="zongFaultCsvData.length > 0">
  35. <FaultAll
  36. :faultTypes="
  37. zongFaultCsvData &&
  38. zongFaultCsvData[0] &&
  39. zongFaultCsvData[0].data.map((item) => item.engine_name)
  40. "
  41. :faultCounts="
  42. zongFaultCsvData &&
  43. zongFaultCsvData[0] &&
  44. zongFaultCsvData[0].data.map((item) => item.count)
  45. "
  46. :faultDurations="
  47. zongFaultCsvData &&
  48. zongFaultCsvData[0] &&
  49. zongFaultCsvData[0].data.map((item) => item.fault_time_sum)
  50. "
  51. :zongFaultCsvData="zongFaultCsvData"
  52. ></FaultAll>
  53. </div>
  54. <el-empty description="暂无分析记录" v-else></el-empty>
  55. <div class="titleCharts">分析总图 :</div>
  56. <div v-if="zongFaultCsvData.length > 0">
  57. <template v-for="(itemCsv, indCsv) in zongFaultCsvData">
  58. <el-table
  59. :key="indCsv + 'indCsv'"
  60. :data="filteredData(itemCsv)"
  61. border
  62. style="width: 100%"
  63. max-height="500"
  64. align="center"
  65. >
  66. <el-table-column prop="engine_name" label="风机名称">
  67. </el-table-column>
  68. <el-table-column prop="yaw_error1" label="误差值">
  69. </el-table-column>
  70. <el-table-column align="right">
  71. <template slot="header" slot-scope="scope">
  72. <el-input
  73. v-model="search"
  74. size="mini"
  75. placeholder="输入风机名称关键字搜索"
  76. />
  77. </template>
  78. </el-table-column>
  79. </el-table>
  80. </template>
  81. </div>
  82. <el-empty description="暂无分析记录" v-else></el-empty>
  83. <el-tabs value="first">
  84. <el-tab-pane label="意见描述" name="first">
  85. <TinymceEditor
  86. ref="editor"
  87. v-model="comment"
  88. @input="handleEditorInput($event)"
  89. @onClick="onClick"
  90. >
  91. </TinymceEditor>
  92. </el-tab-pane>
  93. </el-tabs>
  94. <el-row type="flex" class="row-bg" justify="end">
  95. <el-col :span="2" style="margin: 20px">
  96. <el-button type="primary" size="small" @click="handleComment"
  97. >提交评论</el-button
  98. >
  99. </el-col>
  100. </el-row>
  101. </div>
  102. <div class="right">
  103. <DicCard
  104. :batchCode="initBatchCode"
  105. :analysisTypeCode="analysisTypeCode"
  106. :commentDescriptionVos="commentDescriptionVos"
  107. >
  108. </DicCard>
  109. </div>
  110. </div>
  111. </template>
  112. <script>
  113. import DicCard from "@/views/overview/components/dicCard/index.vue";
  114. import FilterChart from "@/views/overview/components/filterChart/index.vue";
  115. import FaultAll from "@/views/performance/components/chartsCom/FaultAll.vue";
  116. import TinymceEditor from "@/components/Tinymce.vue";
  117. import {
  118. analysisDetail,
  119. queryAnalysisedEngine,
  120. analysisCommentEdit,
  121. } from "@/api/performance";
  122. import Papa from "papaparse";
  123. import axios from "axios";
  124. export default {
  125. name: "yaw_error",
  126. components: {
  127. DicCard,
  128. FilterChart,
  129. FaultAll,
  130. TinymceEditor,
  131. },
  132. props: {
  133. initBatchCode: {
  134. default: "",
  135. type: String,
  136. },
  137. analysisTypeCode: {
  138. default: "",
  139. type: String,
  140. },
  141. batchCodeList: {
  142. default: "",
  143. type: Array,
  144. },
  145. },
  146. data() {
  147. return {
  148. search: "",
  149. form: {
  150. value2: "",
  151. },
  152. windEngineGroupList: [], //批次风机列表
  153. fieldEngineCodes: [], //选中风机
  154. comment: "",
  155. options: [],
  156. zongFaultCsvHeader: [],
  157. zongFaultCsvData: [],
  158. fenFaultCsvHeader: [],
  159. fenFaultCsvData: [],
  160. commentDescriptionVos: [], //评论列表
  161. editableTabs: [],
  162. };
  163. },
  164. computed: {
  165. // 根据搜索关键字过滤数据
  166. filteredData() {
  167. return (itemCsv) => {
  168. // 如果有搜索关键词,则过滤数据
  169. if (this.search) {
  170. return itemCsv.data.filter((item) => {
  171. return item.engine_name
  172. .toLowerCase()
  173. .includes(this.search.toLowerCase());
  174. });
  175. }
  176. // 没有搜索关键词时返回所有数据
  177. return itemCsv.data;
  178. };
  179. },
  180. filteredFenData() {
  181. return (itemCsv) => {
  182. // 如果有搜索关键词,则过滤数据
  183. if (this.searchFen) {
  184. return itemCsv.data.filter((item) => {
  185. return item.wind_turbine_name
  186. .toLowerCase()
  187. .includes(this.searchFen.toLowerCase());
  188. });
  189. }
  190. // 没有搜索关键词时返回所有数据
  191. return itemCsv.data;
  192. };
  193. },
  194. },
  195. watch: {
  196. initBatchCode(newVal) {
  197. if (newVal) {
  198. this.fetchData(); // 调用合并后的函数
  199. }
  200. },
  201. analysisTypeCode(newVal) {
  202. if (newVal) {
  203. this.fetchData(); // 调用合并后的函数
  204. }
  205. },
  206. },
  207. mounted() {
  208. if (this.initBatchCode && this.analysisTypeCode) {
  209. this.fetchData(); // 调用合并后的函数
  210. }
  211. },
  212. methods: {
  213. async handleComment() {
  214. try {
  215. await analysisCommentEdit({
  216. batchCode: this.initBatchCode,
  217. analysisTypeCode: this.analysisTypeCode,
  218. commentList: this.editableTabs.map((item) => {
  219. return {
  220. commentTypeCode: item.commentTypeCode,
  221. comment: item.commentTypeName === "分析评论" ? this.comment : "",
  222. };
  223. }),
  224. });
  225. this.$message({
  226. type: "success",
  227. message: "保存成功",
  228. });
  229. this.comment = "";
  230. this.getAnalysisDetail();
  231. } catch (e) {
  232. console.error(e);
  233. this.loading = false;
  234. }
  235. },
  236. onSubmit() {
  237. console.log("submit!");
  238. },
  239. // 封装的获取 CSV 数据方法
  240. fetchCsvData(analysisType, url) {
  241. axios
  242. .get(url, { responseType: "blob" }) // 确保数据以 blob 格式返回
  243. .then((response) => {
  244. const reader = new FileReader();
  245. reader.onload = (e) => {
  246. const csvText = e.target.result;
  247. Papa.parse(csvText, {
  248. header: true, // 使用 CSV 第一行作为键
  249. complete: (result) => {
  250. // 根据分析类型设置不同的数据
  251. if (analysisType === "yaw_error") {
  252. if (Object.keys(result.data[0]).includes("engine_name")) {
  253. //总图
  254. this.zongFaultCsvHeader.push(Object.keys(result.data[0]));
  255. this.zongFaultCsvData.push({
  256. data: result.data
  257. .filter((row) => Object.keys(row).length)
  258. .slice(0, result.data.length - 1),
  259. });
  260. } else {
  261. //分
  262. this.fenFaultCsvHeader.push(Object.keys(result.data[0]));
  263. this.fenFaultCsvData.push({
  264. data: result.data
  265. .filter((row) => Object.keys(row).length)
  266. .slice(0, result.data.length - 1),
  267. });
  268. }
  269. }
  270. },
  271. error: (error) => {
  272. console.error("CSV 解析错误:", error);
  273. },
  274. });
  275. };
  276. reader.readAsText(response.data); // 读取 blob 数据
  277. })
  278. .catch((error) => {
  279. console.error("无法获取 CSV 文件:", error);
  280. });
  281. },
  282. // 合并后的函数,处理数据请求
  283. async fetchData() {
  284. try {
  285. // 获取分析详情
  286. await this.getAnalysisDetail();
  287. // 获取风机列表
  288. await this.getWindEnfineList(this.initBatchCode, this.analysisTypeCode);
  289. } catch (err) {
  290. console.error("Failed to fetch data:", err);
  291. }
  292. },
  293. // 获取分析详情接口
  294. async getAnalysisDetail() {
  295. try {
  296. const result = await analysisDetail({
  297. batchCode: this.initBatchCode,
  298. analysisTypeCode: this.analysisTypeCode,
  299. fieldEngineCodes:
  300. this.fieldEngineCodes.length === 0
  301. ? undefined
  302. : this.fieldEngineCodes.join(","),
  303. });
  304. if (
  305. result.data &&
  306. result.data[0] &&
  307. result.data[0].commentTypeRelations
  308. ) {
  309. this.editableTabs = result.data[0].commentTypeRelations;
  310. }
  311. //当前评论展示获取
  312. if (
  313. result.data &&
  314. result.data[0] &&
  315. result.data[0].commentDescriptionVos
  316. ) {
  317. this.commentDescriptionVos = result.data[0].commentDescriptionVos;
  318. }
  319. if (result.data && result.data[0] && result.data[0].generalFiles) {
  320. result.data[0].generalFiles.map((item) => {
  321. if (item.fileAddr) {
  322. this.zongFaultCsvHeader = [];
  323. this.zongFaultCsvData = [];
  324. this.fetchCsvData("yaw_error", item.fileAddr);
  325. }
  326. });
  327. } else {
  328. this.zongFaultCsvHeader = [];
  329. this.zongFaultCsvData = [];
  330. }
  331. if (result.data && result.data[0] && result.data[0].diagramRelations) {
  332. result.data[0].diagramRelations.map((item) => {
  333. if (item.fileAddr) {
  334. this.fenFaultCsvHeader = [];
  335. this.fenFaultCsvData = [];
  336. this.fetchCsvData("yaw_error", item.fileAddr);
  337. }
  338. });
  339. } else {
  340. this.fenFaultCsvHeader = [];
  341. this.fenFaultCsvData = [];
  342. }
  343. } catch (err) {
  344. console.error("Failed to fetch analysis details:", err);
  345. }
  346. },
  347. // 请求风机列表
  348. async getWindEnfineList(batchCode, analysisTypeCode) {
  349. // console.log("请求风机列表 分钟级");
  350. const resEngineList = await queryAnalysisedEngine({
  351. batchCode: batchCode,
  352. analysisTypeCode,
  353. });
  354. this.windEngineGroupList = resEngineList.data;
  355. },
  356. handleEditorInput(index, newVal) {
  357. // 更新对应的 comment 值
  358. // 如果该功能没有实现,可以删除这个方法
  359. },
  360. //获取选中风机list
  361. getEnfineList(data) {
  362. this.fieldEngineCodes = data;
  363. this.getAnalysisDetail();
  364. },
  365. //下一条
  366. handleNext() {
  367. const index = this.batchCodeList.findIndex(
  368. (item) => item === this.initBatchCode
  369. );
  370. if (index === this.batchCodeList.length - 1) {
  371. this.$message.warning("已经是最后一个分析结果了");
  372. return;
  373. }
  374. this.$emit("setInitBathCode", this.batchCodeList[index + 1]);
  375. },
  376. //上一条
  377. handlePrevious() {
  378. const index = this.batchCodeList.findIndex(
  379. (item) => item === this.initBatchCode
  380. );
  381. if (index === 0) {
  382. this.$message.warning("没有上一条了");
  383. return;
  384. }
  385. this.$emit("setInitBathCode", this.batchCodeList[index - 1]);
  386. },
  387. onClick() {},
  388. },
  389. };
  390. </script>
  391. <style scoped lang="scss">
  392. .type-variable {
  393. display: flex;
  394. height: 90%;
  395. overflow: hidden;
  396. .left {
  397. width: 30%;
  398. height: 100%;
  399. overflow: auto;
  400. padding: 20px;
  401. flex: 1;
  402. /* 滚动条整体样式 */
  403. &::-webkit-scrollbar {
  404. width: 6px; /* 滚动条宽度 */
  405. }
  406. /* 滚动条轨道 */
  407. &::-webkit-scrollbar-track {
  408. background: #f5f7fa;
  409. border-radius: 3px;
  410. }
  411. /* 滚动条滑块 */
  412. &::-webkit-scrollbar-thumb {
  413. background: #c0c4cc;
  414. border-radius: 3px;
  415. }
  416. /* 滚动条滑块悬停时 */
  417. &::-webkit-scrollbar-thumb:hover {
  418. background: #909399;
  419. }
  420. }
  421. .right {
  422. width: 250px;
  423. height: 100%;
  424. overflow: hidden;
  425. }
  426. }
  427. .titleCharts {
  428. font-size: 16px;
  429. font-weight: 500;
  430. margin-top: 20px;
  431. }
  432. </style>