index.vue 13 KB

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