index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  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" v-if="isShowTinymceEditorCom">
  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. isShowTinymceEditorCom: {
  151. default: true,
  152. type: Boolean,
  153. },
  154. analysisTypeCode: {
  155. default: "",
  156. type: String,
  157. },
  158. batchCodeList: {
  159. default: "",
  160. type: Array,
  161. },
  162. isShow: {
  163. default: false,
  164. type: Boolean,
  165. },
  166. },
  167. data() {
  168. return {
  169. searchFen: "",
  170. form: {
  171. value2: "",
  172. },
  173. isShowDescription: false,
  174. commentDescriptionVos: [], //评论列表
  175. windEngineGroupList: [], //批次风机列表
  176. fieldEngineCodes: [], //选中风机
  177. comment: "",
  178. options: [],
  179. zongFaultCsvHeader: [],
  180. zongFaultCsvData: [],
  181. fenFaultCsvData: [],
  182. fenFaultCsvHeader: [],
  183. editableTabs: [],
  184. };
  185. },
  186. computed: {
  187. // 根据搜索关键字过滤数据
  188. filteredData() {
  189. return (itemCsv) => {
  190. // 如果有搜索关键词,则过滤数据
  191. if (this.search) {
  192. return itemCsv.data.filter((item) => {
  193. return item.wind_turbine_name
  194. .toLowerCase()
  195. .includes(this.search.toLowerCase());
  196. });
  197. }
  198. // 没有搜索关键词时返回所有数据
  199. return itemCsv.data;
  200. };
  201. },
  202. filteredFenData() {
  203. return (itemCsv) => {
  204. // 如果有搜索关键词,则过滤数据
  205. if (this.searchFen) {
  206. return itemCsv.data.filter((item) => {
  207. return item.wind_turbine_name
  208. .toLowerCase()
  209. .includes(this.searchFen.toLowerCase());
  210. });
  211. }
  212. // 没有搜索关键词时返回所有数据
  213. return itemCsv.data;
  214. };
  215. },
  216. },
  217. watch: {
  218. initBatchCode(newVal) {
  219. if (newVal) {
  220. this.fetchData(); // 调用合并后的函数
  221. }
  222. },
  223. analysisTypeCode(newVal) {
  224. if (newVal) {
  225. this.fetchData(); // 调用合并后的函数
  226. }
  227. },
  228. isShow() {
  229. if (this.isShow) {
  230. if (!this.isShowDescription) {
  231. this.$message({
  232. message: "当前分析模型暂无分析,不能进行评论操作",
  233. type: "warning",
  234. });
  235. this.$emit("setIsShow");
  236. }
  237. }
  238. },
  239. },
  240. mounted() {
  241. if (this.initBatchCode && this.analysisTypeCode) {
  242. this.fetchData(); // 调用合并后的函数
  243. }
  244. },
  245. methods: {
  246. handleClose() {
  247. //关闭评论弹框
  248. this.$emit("setIsShow");
  249. },
  250. onSubmit() {
  251. console.log("submit!");
  252. },
  253. async handleComment() {
  254. try {
  255. await analysisCommentEdit({
  256. batchCode: this.initBatchCode,
  257. analysisTypeCode: this.analysisTypeCode,
  258. commentList: this.editableTabs.map((item) => {
  259. return {
  260. commentTypeCode: item.commentTypeCode,
  261. comment: item.commentTypeName === "分析评论" ? this.comment : "",
  262. };
  263. }),
  264. });
  265. this.$message({
  266. type: "success",
  267. message: "保存成功",
  268. });
  269. this.comment = "";
  270. this.getAnalysisDetail();
  271. this.$emit("setIsShow");
  272. } catch (e) {
  273. console.error(e);
  274. this.loading = false;
  275. }
  276. },
  277. // 封装的获取 CSV 数据方法
  278. fetchCsvData(analysisType, url) {
  279. axios
  280. .get(url, { responseType: "blob" }) // 确保数据以 blob 格式返回
  281. .then((response) => {
  282. const reader = new FileReader();
  283. reader.onload = (e) => {
  284. const csvText = e.target.result;
  285. Papa.parse(csvText, {
  286. header: true, // 使用 CSV 第一行作为键
  287. complete: (result) => {
  288. // 根据分析模型设置不同的数据
  289. if (analysisType === "fault") {
  290. if (
  291. Object.keys(result.data[0]).includes("wind_turbine_name")
  292. ) {
  293. //分机型故障统计处理
  294. this.fenFaultCsvHeader.push(Object.keys(result.data[0]));
  295. this.fenFaultCsvData.push({
  296. data: result.data
  297. .filter((row) => Object.keys(row).length)
  298. .slice(0, result.data.length - 1),
  299. });
  300. }
  301. }
  302. },
  303. error: (error) => {
  304. console.error("CSV 解析错误:", error);
  305. },
  306. });
  307. };
  308. reader.readAsText(response.data); // 读取 blob 数据
  309. })
  310. .catch((error) => {
  311. console.error("无法获取 CSV 文件:", error);
  312. });
  313. },
  314. // 合并后的函数,处理数据请求
  315. async fetchData() {
  316. try {
  317. // 获取分析详情
  318. await this.getAnalysisDetail();
  319. // 获取风机列表
  320. await this.getWindEnfineList(this.initBatchCode, this.analysisTypeCode);
  321. } catch (err) {
  322. console.error("Failed to fetch data:", err);
  323. }
  324. },
  325. // 获取分析详情接口
  326. async getAnalysisDetail() {
  327. try {
  328. const result = await analysisDetail({
  329. batchCode: this.initBatchCode,
  330. analysisTypeCode: "fault",
  331. fieldEngineCodes:
  332. this.fieldEngineCodes.length === 0
  333. ? undefined
  334. : this.fieldEngineCodes.join(","),
  335. });
  336. if (result.data.length > 0) {
  337. this.isShowDescription = true;
  338. }
  339. if (
  340. result.data &&
  341. result.data[0] &&
  342. result.data[0].commentTypeRelations
  343. ) {
  344. this.editableTabs = result.data[0].commentTypeRelations;
  345. }
  346. //当前评论展示获取
  347. if (
  348. result.data &&
  349. result.data[0] &&
  350. result.data[0].commentDescriptionVos
  351. ) {
  352. this.commentDescriptionVos = result.data[0].commentDescriptionVos;
  353. }
  354. if (result.data && result.data[0] && result.data[0].generalFiles) {
  355. result.data[0].generalFiles.map((item) => {
  356. if (item.fileAddr) {
  357. this.fenFaultCsvHeader = [];
  358. this.fenFaultCsvData = [];
  359. this.fetchCsvData("fault", item.fileAddr);
  360. }
  361. });
  362. } else {
  363. this.fenFaultCsvHeader = [];
  364. this.fenFaultCsvData = [];
  365. }
  366. } catch (err) {
  367. console.error("Failed to fetch analysis details:", err);
  368. }
  369. },
  370. // 请求风机列表
  371. async getWindEnfineList(batchCode, analysisTypeCode) {
  372. // console.log("请求风机列表 分钟级");
  373. const resEngineList = await queryAnalysisedEngine({
  374. batchCode: batchCode,
  375. analysisTypeCode,
  376. });
  377. this.windEngineGroupList = resEngineList.data;
  378. },
  379. handleEditorInput(index, newVal) {
  380. // 更新对应的 comment 值
  381. // 如果该功能没有实现,可以删除这个方法
  382. },
  383. //获取选中风机list
  384. getEnfineList(data) {
  385. this.fieldEngineCodes = data;
  386. this.getAnalysisDetail();
  387. },
  388. //下一条
  389. handleNext() {
  390. const index = this.batchCodeList.findIndex(
  391. (item) => item === this.initBatchCode
  392. );
  393. if (index === this.batchCodeList.length - 1) {
  394. this.$message.warning("已经是最后一个分析结果了");
  395. return;
  396. }
  397. this.$emit("setInitBathCode", this.batchCodeList[index + 1]);
  398. },
  399. //上一条
  400. handlePrevious() {
  401. const index = this.batchCodeList.findIndex(
  402. (item) => item === this.initBatchCode
  403. );
  404. if (index === 0) {
  405. this.$message.warning("没有上一条了");
  406. return;
  407. }
  408. this.$emit("setInitBathCode", this.batchCodeList[index - 1]);
  409. },
  410. onClick() {},
  411. },
  412. };
  413. </script>
  414. <style scoped lang="scss">
  415. .type-variable {
  416. display: flex;
  417. height: 90%;
  418. overflow: hidden;
  419. .left {
  420. width: 30%;
  421. height: 100%;
  422. overflow: auto;
  423. padding: 20px;
  424. flex: 1;
  425. /* 滚动条整体样式 */
  426. &::-webkit-scrollbar {
  427. width: 6px; /* 滚动条宽度 */
  428. }
  429. /* 滚动条轨道 */
  430. &::-webkit-scrollbar-track {
  431. background: #f5f7fa;
  432. border-radius: 3px;
  433. }
  434. /* 滚动条滑块 */
  435. &::-webkit-scrollbar-thumb {
  436. background: #c0c4cc;
  437. border-radius: 3px;
  438. }
  439. /* 滚动条滑块悬停时 */
  440. &::-webkit-scrollbar-thumb:hover {
  441. background: #909399;
  442. }
  443. }
  444. .right {
  445. width: 250px;
  446. height: 100%;
  447. overflow: hidden;
  448. }
  449. }
  450. .el-dialog__wrapper {
  451. position: relative !important;
  452. }
  453. ::v-deep .el-dialog {
  454. position: fixed !important;
  455. z-index: 999 !important;
  456. top: 50%;
  457. left: 50%;
  458. transform: translate(0, -50%);
  459. }
  460. </style>