index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. <!--
  2. * @Author: your name
  3. * @Date: 2025-01-13 13:56:55
  4. * @LastEditTime: 2025-01-16 10:01:41
  5. * @LastEditors: bogon
  6. * @Description: In User Settings Edit
  7. * @FilePath: /performance-test/src/views/overview/components/fault_all/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="zongFaultCsvData.length > 0">
  34. <FaultAll
  35. :faultTypes="
  36. zongFaultCsvData &&
  37. zongFaultCsvData[0] &&
  38. zongFaultCsvData[0].data.map((item) => item.fault_detail)
  39. "
  40. :faultCounts="
  41. zongFaultCsvData &&
  42. zongFaultCsvData[0] &&
  43. zongFaultCsvData[0].data.map((item) => item.count)
  44. "
  45. :faultDurations="
  46. zongFaultCsvData &&
  47. zongFaultCsvData[0] &&
  48. zongFaultCsvData[0].data.map((item) => item.fault_time_sum)
  49. "
  50. :zongFaultCsvData="zongFaultCsvData"
  51. ></FaultAll>
  52. <template v-for="(itemCsv, indCsv) in zongFaultCsvData">
  53. <el-table
  54. :key="indCsv + 'indCsv'"
  55. :data="filteredData(itemCsv)"
  56. border
  57. style="width: 100%"
  58. align="center"
  59. >
  60. <el-table-column prop="fault_detail" label="故障类型">
  61. </el-table-column>
  62. <el-table-column prop="count" sortable label="故障次数(次)">
  63. </el-table-column>
  64. <el-table-column
  65. prop="fault_time_sum"
  66. sortable
  67. label="故障时长(秒)"
  68. >
  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">提交评论</el-button>
  97. </el-col>
  98. </el-row>
  99. </div>
  100. <div class="right">
  101. <DicCard
  102. :batchCode="initBatchCode"
  103. :analysisTypeCode="'fault'"
  104. :commentDescriptionVos="commentDescriptionVos"
  105. >
  106. </DicCard>
  107. </div>
  108. </div>
  109. </template>
  110. <script>
  111. import DicCard from "@/views/overview/components/dicCard/index.vue";
  112. import FilterChart from "@/views/overview/components/filterChart/index.vue";
  113. import FaultAll from "@/views/performance/components/chartsCom/FaultAll.vue";
  114. import TinymceEditor from "@/components/Tinymce.vue";
  115. import { analysisDetail, queryAnalysisedEngine } from "@/api/performance";
  116. import Papa from "papaparse";
  117. import axios from "axios";
  118. export default {
  119. name: "fault_all",
  120. components: {
  121. DicCard,
  122. FilterChart,
  123. FaultAll,
  124. TinymceEditor,
  125. },
  126. props: {
  127. initBatchCode: {
  128. default: "",
  129. type: String,
  130. },
  131. analysisTypeCode: {
  132. default: "",
  133. type: String,
  134. },
  135. batchCodeList: {
  136. default: "",
  137. type: Array,
  138. },
  139. },
  140. data() {
  141. return {
  142. search: "",
  143. form: {
  144. value2: "",
  145. },
  146. windEngineGroupList: [], //批次风机列表
  147. fieldEngineCodes: [], //选中风机
  148. comment: "",
  149. options: [],
  150. zongFaultCsvHeader: [],
  151. zongFaultCsvData: [],
  152. fenFaultCsvHeader: [],
  153. fenFaultCsvData: [],
  154. commentDescriptionVos: [], //评论列表
  155. editableTabs: [],
  156. };
  157. },
  158. computed: {
  159. // 根据搜索关键字过滤数据
  160. filteredData() {
  161. return (itemCsv) => {
  162. // 如果有搜索关键词,则过滤数据
  163. if (this.search) {
  164. return itemCsv.data.filter((item) => {
  165. return item.fault_detail
  166. .toLowerCase()
  167. .includes(this.search.toLowerCase());
  168. });
  169. }
  170. // 没有搜索关键词时返回所有数据
  171. return itemCsv.data;
  172. };
  173. },
  174. filteredFenData() {
  175. return (itemCsv) => {
  176. // 如果有搜索关键词,则过滤数据
  177. if (this.searchFen) {
  178. return itemCsv.data.filter((item) => {
  179. return item.wind_turbine_name
  180. .toLowerCase()
  181. .includes(this.searchFen.toLowerCase());
  182. });
  183. }
  184. // 没有搜索关键词时返回所有数据
  185. return itemCsv.data;
  186. };
  187. },
  188. },
  189. watch: {
  190. initBatchCode(newVal) {
  191. if (newVal) {
  192. this.fetchData(); // 调用合并后的函数
  193. }
  194. },
  195. analysisTypeCode(newVal) {
  196. if (newVal) {
  197. this.fetchData(); // 调用合并后的函数
  198. }
  199. },
  200. },
  201. mounted() {
  202. if (this.initBatchCode && this.analysisTypeCode) {
  203. this.fetchData(); // 调用合并后的函数
  204. }
  205. },
  206. methods: {
  207. async handleComment() {
  208. try {
  209. await analysisCommentEdit({
  210. batchCode: this.initBatchCode,
  211. analysisTypeCode: this.analysisTypeCode,
  212. commentList: this.editableTabs.map((item) => {
  213. return {
  214. commentTypeCode: item.commentTypeCode,
  215. comment: item.commentTypeName === "分析评论" ? this.comment : "",
  216. };
  217. }),
  218. });
  219. this.$message({
  220. type: "success",
  221. message: "保存成功",
  222. });
  223. this.comment = "";
  224. this.getAnalysisDetail();
  225. } catch (e) {
  226. console.error(e);
  227. this.loading = false;
  228. }
  229. },
  230. onSubmit() {
  231. console.log("submit!");
  232. },
  233. // 封装的获取 CSV 数据方法
  234. fetchCsvData(analysisType, url) {
  235. axios
  236. .get(url, { responseType: "blob" }) // 确保数据以 blob 格式返回
  237. .then((response) => {
  238. const reader = new FileReader();
  239. reader.onload = (e) => {
  240. const csvText = e.target.result;
  241. Papa.parse(csvText, {
  242. header: true, // 使用 CSV 第一行作为键
  243. complete: (result) => {
  244. // 根据分析类型设置不同的数据
  245. if (analysisType === "fault") {
  246. if (Object.keys(result.data[0]).includes("fault_detail")) {
  247. //总图故障统计展示
  248. this.zongFaultCsvHeader.push(Object.keys(result.data[0]));
  249. this.zongFaultCsvData.push({
  250. data: result.data
  251. .filter((row) => Object.keys(row).length)
  252. .slice(0, result.data.length - 1),
  253. });
  254. } else {
  255. //分机型故障统计处理
  256. this.fenFaultCsvHeader.push(Object.keys(result.data[0]));
  257. this.fenFaultCsvData.push({
  258. data: result.data
  259. .filter((row) => Object.keys(row).length)
  260. .slice(0, result.data.length - 1),
  261. });
  262. }
  263. }
  264. },
  265. error: (error) => {
  266. console.error("CSV 解析错误:", error);
  267. },
  268. });
  269. };
  270. reader.readAsText(response.data); // 读取 blob 数据
  271. })
  272. .catch((error) => {
  273. console.error("无法获取 CSV 文件:", error);
  274. });
  275. },
  276. // 合并后的函数,处理数据请求
  277. async fetchData() {
  278. try {
  279. // 获取分析详情
  280. await this.getAnalysisDetail();
  281. // 获取风机列表
  282. await this.getWindEnfineList(this.initBatchCode, this.analysisTypeCode);
  283. } catch (err) {
  284. console.error("Failed to fetch data:", err);
  285. }
  286. },
  287. // 获取分析详情接口
  288. async getAnalysisDetail() {
  289. try {
  290. const result = await analysisDetail({
  291. batchCode: this.initBatchCode,
  292. analysisTypeCode: "fault",
  293. fieldEngineCodes:
  294. this.fieldEngineCodes.length === 0
  295. ? undefined
  296. : this.fieldEngineCodes,
  297. });
  298. if (
  299. result.data &&
  300. result.data[0] &&
  301. result.data[0].commentTypeRelations
  302. ) {
  303. this.editableTabs = result.data[0].commentTypeRelations;
  304. }
  305. //当前评论展示获取
  306. if (
  307. result.data &&
  308. result.data[0] &&
  309. result.data[0].commentDescriptionVos
  310. ) {
  311. this.commentDescriptionVos = result.data[0].commentDescriptionVos;
  312. }
  313. if (result.data && result.data[0] && result.data[0].generalFiles) {
  314. result.data[0].generalFiles.map((item) => {
  315. if (item.fileAddr) {
  316. this.zongFaultCsvHeader = [];
  317. this.zongFaultCsvData = [];
  318. this.fetchCsvData("fault", item.fileAddr);
  319. }
  320. });
  321. } else {
  322. this.zongFaultCsvHeader = [];
  323. this.zongFaultCsvData = [];
  324. }
  325. } catch (err) {
  326. console.error("Failed to fetch analysis details:", err);
  327. }
  328. },
  329. // 请求风机列表
  330. async getWindEnfineList(batchCode, analysisTypeCode) {
  331. // console.log("请求风机列表 分钟级");
  332. const resEngineList = await queryAnalysisedEngine({
  333. batchCode: batchCode,
  334. analysisTypeCode,
  335. });
  336. this.windEngineGroupList = resEngineList.data;
  337. },
  338. handleEditorInput(index, newVal) {
  339. // 更新对应的 comment 值
  340. // 如果该功能没有实现,可以删除这个方法
  341. },
  342. //获取选中风机list
  343. getEnfineList(data) {
  344. this.fieldEngineCodes = data;
  345. console.log(this.fieldEngineCodes, "this.fieldEngineCodes");
  346. },
  347. //下一条
  348. handleNext() {
  349. const index = this.batchCodeList.findIndex(
  350. (item) => item === this.initBatchCode
  351. );
  352. if (index === this.batchCodeList.length - 1) {
  353. this.$message.warning("已经是最后一个分析结果了");
  354. return;
  355. }
  356. this.$emit("setInitBathCode", this.batchCodeList[index + 1]);
  357. },
  358. //上一条
  359. handlePrevious() {
  360. const index = this.batchCodeList.findIndex(
  361. (item) => item === this.initBatchCode
  362. );
  363. if (index === 0) {
  364. this.$message.warning("没有上一条了");
  365. return;
  366. }
  367. this.$emit("setInitBathCode", this.batchCodeList[index - 1]);
  368. },
  369. onClick() {},
  370. },
  371. };
  372. </script>
  373. <style scoped lang="scss">
  374. .type-variable {
  375. display: flex;
  376. height: 90%;
  377. overflow: hidden;
  378. .left {
  379. width: 30%;
  380. height: 100%;
  381. overflow: auto;
  382. padding: 20px;
  383. flex: 1;
  384. }
  385. .right {
  386. width: 250px;
  387. height: 100%;
  388. overflow: hidden;
  389. }
  390. }
  391. </style>