index.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. <template>
  2. <div class="home" v-loading="loading">
  3. <div class="second">
  4. <div class="topPanel">
  5. <!-- 原始数据 -->
  6. <div class="tPanel">
  7. <el-table size="mini" :data="originalList">
  8. <el-table-column prop="dataName" label="数据" align="center">
  9. <template slot-scope="scope">
  10. <el-tooltip
  11. class="item"
  12. effect="dark"
  13. :content="scope.row.dataName"
  14. placement="top"
  15. >
  16. <!-- @click="handleFile(scope.row.id, null)" -->
  17. <span class="file">{{ scope.row.dataName }}</span>
  18. </el-tooltip>
  19. </template>
  20. </el-table-column>
  21. </el-table>
  22. </div>
  23. <!-- 去噪 -->
  24. <div class="tPanel">
  25. <el-table size="mini" :data="denoisingList">
  26. <el-table-column
  27. prop="processedDataName"
  28. label="处理前数据"
  29. align="center"
  30. >
  31. <template slot-scope="scope">
  32. <el-tooltip
  33. class="item"
  34. effect="dark"
  35. :content="scope.row.processedDataName"
  36. placement="top"
  37. >
  38. <span class="beforeFile">{{
  39. scope.row.processedDataName
  40. }}</span>
  41. </el-tooltip>
  42. </template>
  43. </el-table-column>
  44. <el-table-column
  45. prop="resultDataName"
  46. label="处理后数据"
  47. align="center"
  48. >
  49. <template slot-scope="scope">
  50. <el-tooltip
  51. class="item"
  52. effect="dark"
  53. :content="scope.row.resultDataName"
  54. placement="top"
  55. >
  56. <span class="file" @click="handleFile(scope.row, 2)">{{
  57. scope.row.resultDataName
  58. }}</span>
  59. </el-tooltip>
  60. </template>
  61. </el-table-column>
  62. <el-table-column
  63. prop="processStatus"
  64. label="状态"
  65. align="center"
  66. width="60"
  67. >
  68. <template slot-scope="scope">
  69. <dict-tag
  70. :options="dict.type.biz_process_status"
  71. :value="scope.row.processStatus"
  72. />
  73. </template>
  74. </el-table-column>
  75. </el-table>
  76. </div>
  77. <!-- 特征提取 -->
  78. <div class="tPanel">
  79. <el-table size="mini" :data="featureExtractionList">
  80. <el-table-column
  81. prop="processedDataName"
  82. label="处理前数据"
  83. align="center"
  84. >
  85. <template slot-scope="scope">
  86. <el-tooltip
  87. class="item"
  88. effect="dark"
  89. :content="scope.row.processedDataName"
  90. placement="top"
  91. >
  92. <span class="beforeFile">{{
  93. scope.row.processedDataName
  94. }}</span>
  95. </el-tooltip>
  96. </template>
  97. </el-table-column>
  98. <el-table-column
  99. prop="resultDataName"
  100. label="处理后数据"
  101. align="center"
  102. >
  103. <template slot-scope="scope">
  104. <el-tooltip
  105. class="item"
  106. effect="dark"
  107. :content="scope.row.resultDataName"
  108. placement="top"
  109. >
  110. <span class="file" @click="handleFile(scope.row, 4)">{{
  111. scope.row.resultDataName
  112. }}</span>
  113. </el-tooltip>
  114. </template>
  115. </el-table-column>
  116. <el-table-column
  117. prop="processStatus"
  118. label="状态"
  119. align="center"
  120. width="60"
  121. >
  122. <template slot-scope="scope">
  123. <dict-tag
  124. :options="dict.type.biz_process_status"
  125. :value="scope.row.processStatus"
  126. />
  127. </template>
  128. </el-table-column>
  129. </el-table>
  130. </div>
  131. <!-- 故障预测 -->
  132. <div class="tPanel">
  133. <el-table size="mini" :data="faultPredictionList">
  134. <el-table-column
  135. prop="processedDataName"
  136. label="处理前数据"
  137. align="center"
  138. >
  139. <template slot-scope="scope">
  140. <el-tooltip
  141. class="item"
  142. effect="dark"
  143. :content="scope.row.processedDataName"
  144. placement="top"
  145. >
  146. <span class="beforeFile">{{
  147. scope.row.processedDataName
  148. }}</span>
  149. </el-tooltip>
  150. </template>
  151. </el-table-column>
  152. <el-table-column
  153. prop="resultDataName"
  154. label="处理后数据"
  155. align="center"
  156. >
  157. <template slot-scope="scope">
  158. <el-tooltip
  159. class="item"
  160. effect="dark"
  161. :content="scope.row.resultDataName"
  162. placement="top"
  163. >
  164. <span class="file" @click="handleFile(scope.row, 6)">{{
  165. scope.row.resultDataName
  166. }}</span>
  167. </el-tooltip>
  168. </template>
  169. </el-table-column>
  170. <el-table-column
  171. prop="processStatus"
  172. label="状态"
  173. align="center"
  174. width="60"
  175. >
  176. <template slot-scope="scope">
  177. <dict-tag
  178. :options="dict.type.biz_process_status"
  179. :value="scope.row.processStatus"
  180. />
  181. </template>
  182. </el-table-column>
  183. </el-table>
  184. </div>
  185. </div>
  186. <div class="step">
  187. <div class="yuan">
  188. <div class="img yuanBg odd">
  189. <div class="tag">原始数据</div>
  190. </div>
  191. </div>
  192. <div class="one">
  193. <div class="img oneBg even" @click="handleProcess(0)">
  194. <div class="tag">补全</div>
  195. </div>
  196. </div>
  197. <div class="two">
  198. <div class="img twoBg odd" @click="handleProcess(1)">
  199. <div class="tag">去噪</div>
  200. </div>
  201. </div>
  202. <div class="three">
  203. <div class="img threeBg even" @click="handleProcess(2)">
  204. <div class="tag">扩充</div>
  205. </div>
  206. </div>
  207. <div class="four">
  208. <div class="img fourBg odd" @click="handleProcess(3)">
  209. <div class="tag">特征提取</div>
  210. <div class="tag2">故障诊断</div>
  211. </div>
  212. </div>
  213. <div class="five">
  214. <div class="img fiveBg even" @click="handleProcess(4)">
  215. <div class="tag">退化评估</div>
  216. </div>
  217. </div>
  218. <div class="six">
  219. <div
  220. class="img sixBg odd noAfter"
  221. style="content: none"
  222. @click="handleProcess(5)"
  223. >
  224. <div class="tag">故障预测</div>
  225. </div>
  226. </div>
  227. </div>
  228. <div class="bottomPanel">
  229. <!-- 补全 -->
  230. <div class="bPanel">
  231. <el-table size="mini" :data="completionList">
  232. <el-table-column
  233. prop="processedDataName"
  234. label="处理前数据"
  235. align="center"
  236. >
  237. <template slot-scope="scope">
  238. <el-tooltip
  239. class="item"
  240. effect="dark"
  241. :content="scope.row.processedDataName"
  242. placement="top"
  243. >
  244. <span class="beforeFile">{{
  245. scope.row.processedDataName
  246. }}</span>
  247. </el-tooltip>
  248. </template>
  249. </el-table-column>
  250. <el-table-column
  251. prop="resultDataName"
  252. label="处理后数据"
  253. align="center"
  254. >
  255. <template slot-scope="scope">
  256. <el-tooltip
  257. class="item"
  258. effect="dark"
  259. :content="scope.row.resultDataName"
  260. placement="top"
  261. >
  262. <span class="file" @click="handleFile(scope.row, 1)">{{
  263. scope.row.resultDataName
  264. }}</span>
  265. </el-tooltip>
  266. </template>
  267. </el-table-column>
  268. <el-table-column
  269. prop="processStatus"
  270. label="状态"
  271. align="center"
  272. width="60"
  273. >
  274. <template slot-scope="scope">
  275. <dict-tag
  276. :options="dict.type.biz_process_status"
  277. :value="scope.row.processStatus"
  278. />
  279. </template>
  280. </el-table-column>
  281. </el-table>
  282. </div>
  283. <!-- 扩充 -->
  284. <div class="bPanel">
  285. <el-table size="mini" :data="expansionList">
  286. <el-table-column
  287. prop="processedDataName"
  288. label="处理前数据"
  289. align="center"
  290. >
  291. <template slot-scope="scope">
  292. <el-tooltip
  293. class="item"
  294. effect="dark"
  295. :content="scope.row.processedDataName"
  296. placement="top"
  297. >
  298. <span class="beforeFile">{{
  299. scope.row.processedDataName
  300. }}</span>
  301. </el-tooltip>
  302. </template>
  303. </el-table-column>
  304. <el-table-column
  305. prop="resultDataName"
  306. label="处理后数据"
  307. align="center"
  308. >
  309. <template slot-scope="scope">
  310. <el-tooltip
  311. class="item"
  312. effect="dark"
  313. :content="scope.row.processedDataName"
  314. placement="top"
  315. >
  316. <span class="file" @click="handleFile(scope.row, 3)">{{
  317. scope.row.processedDataName
  318. }}</span>
  319. </el-tooltip>
  320. </template>
  321. </el-table-column>
  322. <el-table-column
  323. prop="processStatus"
  324. label="状态"
  325. align="center"
  326. width="60"
  327. >
  328. <template slot-scope="scope">
  329. <dict-tag
  330. :options="dict.type.biz_process_status"
  331. :value="scope.row.processStatus"
  332. />
  333. </template>
  334. </el-table-column>
  335. </el-table>
  336. </div>
  337. <!-- 退化评估 -->
  338. <div class="bPanel">
  339. <el-table size="mini" :data="assessmentList">
  340. <el-table-column
  341. prop="processedDataName"
  342. label="处理前数据"
  343. align="center"
  344. >
  345. <template slot-scope="scope">
  346. <el-tooltip
  347. class="item"
  348. effect="dark"
  349. :content="scope.row.processedDataName"
  350. placement="top"
  351. >
  352. <span class="beforeFile">{{
  353. scope.row.processedDataName
  354. }}</span>
  355. </el-tooltip>
  356. </template>
  357. </el-table-column>
  358. <el-table-column
  359. prop="resultDataName"
  360. label="处理后数据"
  361. align="center"
  362. >
  363. <template slot-scope="scope">
  364. <el-tooltip
  365. class="item"
  366. effect="dark"
  367. :content="scope.row.resultDataName"
  368. placement="top"
  369. >
  370. <span class="file" @click="handleFile(scope.row, 5)">{{
  371. scope.row.resultDataName
  372. }}</span>
  373. </el-tooltip>
  374. </template>
  375. </el-table-column>
  376. <el-table-column
  377. prop="processStatus"
  378. label="状态"
  379. align="center"
  380. width="60"
  381. >
  382. <template slot-scope="scope">
  383. <dict-tag
  384. :options="dict.type.biz_process_status"
  385. :value="scope.row.processStatus"
  386. />
  387. </template>
  388. </el-table-column>
  389. </el-table>
  390. </div>
  391. <div></div>
  392. </div>
  393. </div>
  394. <div class="first">
  395. <h4 style="margin: 13px 0px 0px 20px; color: #fff">算法统计</h4>
  396. <div class="chart">
  397. <RingChart
  398. v-if="flag"
  399. :total="ringTotal"
  400. :agloTypeData="agloTypeData"
  401. />
  402. <BarChart v-if="flag" :agloTypeData="agloTypeData" width="700px" />
  403. </div>
  404. </div>
  405. <el-dialog
  406. :title="title"
  407. :visible.sync="dialogVisible"
  408. width="30%"
  409. :close-on-click-modal="false"
  410. >
  411. <el-form ref="formRef" :model="form" :rules="rules" label-width="80px">
  412. <el-form-item
  413. v-if="dialogType === 3"
  414. label="选择数据类型"
  415. label-width="120px"
  416. >
  417. <el-radio-group v-removeAriaHidden v-model="type">
  418. <el-radio :label="2">去噪</el-radio>
  419. <el-radio :label="3">扩充</el-radio>
  420. <!-- <el-radio :label="4">特征提取</el-radio> -->
  421. </el-radio-group>
  422. </el-form-item>
  423. <el-form-item label="数据" prop="processType">
  424. <el-select
  425. v-model="form.processedDataId"
  426. placeholder="请选择执行的数据"
  427. >
  428. <el-option
  429. v-for="(item, index) in optionalData"
  430. :key="index"
  431. :label="item.dataName"
  432. :value="item.id"
  433. ></el-option>
  434. </el-select>
  435. </el-form-item>
  436. <el-form-item label="算法" prop="processType">
  437. <el-select v-model="form.processAlgId" placeholder="请选择执行的算法">
  438. <el-option
  439. v-for="(item, index) in optionalAglo"
  440. :key="index"
  441. :label="item.algName"
  442. :value="item.id"
  443. ></el-option>
  444. </el-select>
  445. </el-form-item>
  446. </el-form>
  447. <span slot="footer" class="dialog-footer">
  448. <el-button @click="dialogVisible = false">取 消</el-button>
  449. <el-button type="primary" @click="submitHandle()">确 定</el-button>
  450. </span>
  451. </el-dialog>
  452. <el-dialog
  453. v-loading="loading"
  454. title="数据展示"
  455. :visible.sync="fileShowVisible"
  456. width="80%"
  457. :close-on-click-modal="false"
  458. >
  459. <el-button
  460. v-if="!['4', '5'].includes(fileType)"
  461. style="margin-left: 50px"
  462. type="text"
  463. @click="changeShow"
  464. >{{ isTableShow ? "表格展示" : "曲线展示" }}</el-button
  465. >
  466. <div v-if="isTableShow && !['4', '5'].includes(fileType)">
  467. <vxe-table
  468. border="none"
  469. size="mini"
  470. show-overflow
  471. highlight-hover-row
  472. height="400"
  473. :row-config="{ isHover: true, isCurrent: true }"
  474. :sort-config="{ trigger: 'cell' }"
  475. :data="completionData"
  476. >
  477. <vxe-table-column
  478. v-for="(item, index) in completionHeadData"
  479. :key="index"
  480. align="center"
  481. :field="'val' + index"
  482. :title="item"
  483. ></vxe-table-column>
  484. </vxe-table>
  485. </div>
  486. <!-- <div v-if="!isTableShow && fileType !== '5'" ref="beforeChartRef" style="width: 100%; height: 400px;"></div> -->
  487. <PreCharts
  488. v-if="!isTableShow && !['4', '5'].includes(fileType)"
  489. :title="'处理前数据'"
  490. :chartData="preChartData"
  491. />
  492. <CurveCharts
  493. style="margin-top: 20px"
  494. v-if="!isTableShow && !['4', '5'].includes(fileType) && !isImgShow"
  495. :title="'处理后数据'"
  496. :chartData="resultChartData"
  497. />
  498. <!-- 有图片显示图片,没图片显示数据 -->
  499. <div
  500. v-if="!isTableShow && !['4', '5'].includes(fileType) && isImgShow"
  501. class="imgShow"
  502. >
  503. <div class="imgTitle">处理后图片</div>
  504. <ImagePreview class="image-preview" :src="imgUrl"></ImagePreview>
  505. </div>
  506. <!-- <div
  507. v-if="!isTableShow && !['4', '5'].includes(fileType)"
  508. ref="completionChartRef"
  509. style="width: 100%; height: 400px"
  510. ></div> -->
  511. <ImagePreview
  512. class="image-preview"
  513. v-if="['4', '5'].includes(fileType)"
  514. :src="imgPreviewUrl"
  515. ></ImagePreview>
  516. <div class="remark">指标结果:{{ agloRemark }}</div>
  517. </el-dialog>
  518. </div>
  519. </template>
  520. <script>
  521. import CountTo from "vue-count-to";
  522. import RingChart from "@/views/homePage/ringChart";
  523. import PreCharts from "@/views/homePage/preCharts";
  524. import CurveCharts from "@/views/homePage/curveCharts";
  525. import BarChart from "@/views/dashboard/BarChart";
  526. import { getAlgConfigByType, listAlgConfig } from "@/api/system/algConfig";
  527. import { getDataProcessByType, addProcess } from "@/api/system/process";
  528. import { getDataByType, getData, listData } from "@/api/system/data";
  529. export default {
  530. name: "Index",
  531. dicts: ["biz_alg_type", "biz_process_status"],
  532. components: {
  533. CountTo,
  534. RingChart,
  535. BarChart,
  536. PreCharts,
  537. CurveCharts,
  538. },
  539. data() {
  540. return {
  541. loading: false,
  542. rules: {},
  543. title: "选择数据",
  544. baseUrl: process.env.VUE_APP_BASE_API,
  545. dialogVisible: false,
  546. fileShowVisible: false,
  547. originalList: [],
  548. denoisingList: [],
  549. completionList: [],
  550. expansionList: [],
  551. featureExtractionList: [],
  552. assessmentList: [],
  553. faultPredictionList: [],
  554. optionalData: [],
  555. optionalAglo: [],
  556. form: {
  557. processedDataId: null,
  558. processAlgId: null,
  559. },
  560. // 对话框展示数据内容
  561. completionData: [],
  562. completionHeadData: [],
  563. isTableShow: false,
  564. resultFileId: null,
  565. // filePath: null,
  566. fileType: null,
  567. imgPreviewUrl: null,
  568. type: 2,
  569. dialogType: null,
  570. preChartData: {},
  571. resultChartData: {},
  572. nowRow: {},
  573. nowTypeNum: null,
  574. agloRemark: "",
  575. ringTotal: 0,
  576. agloTypeData: [],
  577. flag: false,
  578. isImgShow: false,
  579. imgUrl: null,
  580. };
  581. },
  582. mounted() {},
  583. created() {
  584. this.getTotal();
  585. this.getTableData();
  586. },
  587. watch: {
  588. fileShowVisible(value) {
  589. if (!value) {
  590. this.isTableShow = false;
  591. }
  592. },
  593. type(value) {
  594. getDataByType(value).then((res) => {
  595. this.optionalData = res.data;
  596. });
  597. getAlgConfigByType(3).then((res) => {
  598. this.optionalAglo = res.data;
  599. });
  600. },
  601. },
  602. methods: {
  603. getTotal() {
  604. const queryParams = { pageNum: 1, pageSize: 1000 };
  605. listAlgConfig(queryParams).then((response) => {
  606. this.total = response.total;
  607. const typeFrequency = response.rows.map((item) => {
  608. return item.algType;
  609. });
  610. const countedTypeFrequency = typeFrequency?.reduce((obj, name) => {
  611. if (name in obj) {
  612. obj[name]++;
  613. } else {
  614. obj[name] = 1;
  615. }
  616. return obj;
  617. }, {});
  618. const agloType = this.dict.type.biz_alg_type;
  619. for (let key in this.dict.type.biz_alg_type) {
  620. this.agloTypeData.push({
  621. value: countedTypeFrequency[key],
  622. name: agloType[key].label,
  623. });
  624. }
  625. this.flag = true;
  626. });
  627. },
  628. getTableData() {
  629. const query = {
  630. dataType: 0,
  631. };
  632. listData(query).then((res) => {
  633. this.originalList = [];
  634. this.originalList = res.rows;
  635. });
  636. getDataProcessByType(0).then((res) => {
  637. this.completionList = [];
  638. this.completionList = res.data;
  639. });
  640. getDataProcessByType(1).then((res) => {
  641. this.denoisingList = [];
  642. this.denoisingList = res.data;
  643. });
  644. getDataProcessByType(2).then((res) => {
  645. this.expansionList = [];
  646. this.expansionList = res.data;
  647. });
  648. getDataProcessByType(3).then((res) => {
  649. this.featureExtractionList = [];
  650. this.featureExtractionList = res.data;
  651. });
  652. getDataProcessByType(4).then((res) => {
  653. this.assessmentList = [];
  654. this.assessmentList = res.data;
  655. });
  656. getDataProcessByType(5).then((res) => {
  657. this.faultPredictionList = [];
  658. this.faultPredictionList = res.data;
  659. });
  660. },
  661. goTarget(href) {
  662. window.open(href, "_blank");
  663. },
  664. handleProcess(type) {
  665. this.dialogVisible = true;
  666. this.dialogType = type;
  667. let match;
  668. if (type === 3) {
  669. const relation = [
  670. [3, 2],
  671. [3, 3],
  672. ];
  673. match = relation.find((item) => item[0] === type)[1];
  674. } else if (type === 5) {
  675. match = type - 1;
  676. } else {
  677. match = type;
  678. }
  679. // const relation = [[1, 0], [2, 1], [3, 2], [4, 2], [4, 3], [5, 4], [6, 4]]
  680. // const match = relation.find(item => item[0] === type)[1];
  681. getDataByType(match).then((res) => {
  682. this.optionalData = res.data;
  683. });
  684. getAlgConfigByType(type).then((res) => {
  685. this.optionalAglo = res.data;
  686. });
  687. },
  688. submitHandle() {
  689. addProcess(this.form).then((response) => {
  690. this.$modal.msgSuccess("开始执行");
  691. this.dialogVisible = false;
  692. this.form = {
  693. processedDataId: null,
  694. processAlgId: null,
  695. };
  696. this.optionalData = [];
  697. this.optionalAglo = [];
  698. this.getTableData();
  699. });
  700. },
  701. handleFile(row, typeNum) {
  702. this.nowRow = row;
  703. this.nowTypeNum = typeNum;
  704. this.resultFileId = row.resultDataId;
  705. this.fileType = row.processType;
  706. let _this = this;
  707. this.loading = true;
  708. if (typeNum === 5 || typeNum === 6) {
  709. getData(row.resultDataId).then((res) => {
  710. this.agloRemark = res.data.remark;
  711. this.imgPreviewUrl = res.data.imagePath;
  712. this.loading = false;
  713. this.fileShowVisible = true;
  714. });
  715. } else {
  716. getData(row.processedDataId).then((processedRes) => {
  717. const resData = processedRes.data;
  718. const url = process.env.VUE_APP_BASE_API + resData.dataPath;
  719. this.fetchLogFile(url)
  720. .then((text) => {
  721. let data, content, head;
  722. data = this.handleFileData(text);
  723. content = data.contentData;
  724. head = data.headData;
  725. if (resData.dataType == 0) {
  726. this.handlePreChartOption(content, head, true);
  727. } else {
  728. this.handlePreChartOption(content, head, false);
  729. }
  730. })
  731. .catch((error) => {
  732. console.error("Failed to fetch the log file:", error);
  733. this.$modal.msgSuccess("文件读取错误");
  734. this.loading = false;
  735. });
  736. });
  737. getData(row.resultDataId)
  738. .then((resultRes) => {
  739. const resData = resultRes.data;
  740. this.agloRemark = resData.remark;
  741. const url = process.env.VUE_APP_BASE_API + resData.dataPath;
  742. // resultRes.data.imagePath =
  743. // "/profile/upload/2024/12/06/testdata1_故障预测_20241206181334A015.jpeg";
  744. // console.log("resData.dataType", resData);
  745. if (resData.imagePath && resData.dataType == "4") {
  746. this.imgUrl = resData.imagePath;
  747. this.isImgShow = true;
  748. this.loading = false;
  749. this.fileShowVisible = true;
  750. } else {
  751. this.fetchLogFile(url).then((text) => {
  752. let data, content, head;
  753. data = this.handleFileData(text);
  754. content = data.contentData;
  755. head = data.headData;
  756. this.switchHandle(content, head, resData.dataType);
  757. });
  758. }
  759. })
  760. .catch((error) => {
  761. console.error("Failed to fetch the log file:", error);
  762. this.$modal.msgSuccess("文件读取错误");
  763. this.loading = false;
  764. });
  765. }
  766. },
  767. switchHandle(content, head, dataType) {
  768. switch (dataType) {
  769. case "0":
  770. this.fileShowVisible = true;
  771. this.handleResultChartOption(content, head, true);
  772. // this.loading = false;
  773. break;
  774. case "1":
  775. this.fileShowVisible = true;
  776. this.handleResultChartOption(content, head, false);
  777. // this.loading = false;
  778. break;
  779. case "2":
  780. this.fileShowVisible = true;
  781. this.$nextTick(() => {
  782. this.handleResultChartOption(content, head, false);
  783. // this.loading = false;
  784. });
  785. break;
  786. case "3":
  787. this.fileShowVisible = true;
  788. this.$nextTick(() => {
  789. this.handleResultChartOption(content, head, false);
  790. // this.loading = false;
  791. });
  792. break;
  793. case "4":
  794. this.fileShowVisible = true;
  795. this.$nextTick(() => {
  796. this.handleResultChartOption(content, head, false);
  797. // this.loading = false;
  798. });
  799. break;
  800. case "5":
  801. break;
  802. case "6":
  803. break;
  804. default:
  805. break;
  806. }
  807. },
  808. // 读取文件内容
  809. async fetchLogFile(url) {
  810. try {
  811. const response = await fetch(url, { method: "GET" });
  812. if (!response.ok) {
  813. throw new Error(`HTTP error! status: ${response.status}`);
  814. }
  815. return await response.text();
  816. } catch (error) {
  817. throw error;
  818. }
  819. },
  820. // 对数据的处理(不包含时间)
  821. handleFileData(fileData) {
  822. // 每行数据转换成数组、过滤出存在的空白行、将没行数据按照,号分割
  823. const data = fileData
  824. .split("\r\n")
  825. .filter((line) => line.trim() !== "")
  826. .map((row) => row.split(","));
  827. let headData = [];
  828. for (let i = 1; i <= data[0].length; i++) {
  829. headData.push(`曲线${i}`);
  830. }
  831. const contentData = Array.from({ length: headData.length }, () => []);
  832. for (let i = 0; i < data.length; i++) {
  833. data[i].forEach((value, index) => {
  834. contentData[index].push(value * 1);
  835. });
  836. }
  837. return { contentData, headData };
  838. },
  839. // 对数据的处理(包含时间)
  840. handleDataIncludeTime(fileData) {
  841. data = fileData
  842. .split("\r\n")
  843. .filter((line) => line.trim() !== "")
  844. .map((row) => row.split(","));
  845. data[0].shift();
  846. const completionHead = data[0];
  847. const completionContent = Array.from(
  848. { length: completionHead.length },
  849. () => []
  850. );
  851. const timeData = [];
  852. for (let i = 1; i < data.length; i++) {
  853. data[i].forEach((value, index) => {
  854. if (index === 0) {
  855. timeData.push(value);
  856. } else {
  857. completionContent[index - 1].push(value * 1);
  858. }
  859. });
  860. }
  861. return {
  862. contentData: completionContent,
  863. headData: completionHead,
  864. timeData,
  865. };
  866. },
  867. handlePreChartOption(content, head, ismarkPoint) {
  868. this.preChartData = {
  869. legendData: [],
  870. xAxisData: [],
  871. yAxisData: [],
  872. seriesData: [],
  873. };
  874. let series;
  875. if (ismarkPoint) {
  876. series = content.map((lineData, index) => ({
  877. name: `${head[index]}`,
  878. type: "line",
  879. data: lineData,
  880. connectNulls: true, // 连接相邻的非空数据点
  881. markPoint: {
  882. data: lineData
  883. .map((value, idx) => ({
  884. value: !value || value === 0 ? "-" : null,
  885. xAxis: idx,
  886. yAxis: lineData[idx - 1],
  887. // yAxis: 0,
  888. // itemStyle: { color: color[index] }, // 高亮显示缺失值
  889. }))
  890. .filter((point) => point.value),
  891. },
  892. }));
  893. } else {
  894. series = content.map((lineData, index) => ({
  895. name: `${head[index]}`,
  896. type: "line",
  897. // data: lineData,
  898. data: lineData,
  899. connectNulls: true,
  900. }));
  901. }
  902. this.preChartData.seriesData = series;
  903. this.preChartData.xAxisData = content[0].map((_, index) => index);
  904. },
  905. // 图表设置
  906. handleResultChartOption(content, head, ismarkPoint) {
  907. this.resultChartData = {
  908. legendData: [],
  909. xAxisData: [],
  910. yAxisData: [],
  911. seriesData: [],
  912. };
  913. let series;
  914. if (ismarkPoint) {
  915. series = content.map((lineData, index) => ({
  916. name: `${head[index]}`,
  917. type: "line",
  918. data: lineData,
  919. connectNulls: true, // 连接相邻的非空数据点
  920. markPoint: {
  921. data: lineData
  922. .map((value, idx) => ({
  923. value: value || value === 0 ? "缺失" : null,
  924. xAxis: idx,
  925. yAxis: lineData[idx - 1],
  926. // yAxis: value,
  927. // itemStyle: { color: color[index] }, // 高亮显示缺失值
  928. }))
  929. .filter((point) => point.value),
  930. },
  931. }));
  932. } else {
  933. series = content.map((lineData, index) => ({
  934. name: `${head[index]}`,
  935. type: "line",
  936. data: lineData,
  937. connectNulls: true,
  938. }));
  939. }
  940. this.resultChartData.seriesData = series;
  941. this.resultChartData.xAxisData = content[0].map((_, index) => index);
  942. this.loading = false;
  943. },
  944. // 切换表格/曲线展示
  945. changeShow() {
  946. this.isTableShow = !this.isTableShow;
  947. if (!this.isTableShow) {
  948. this.handleFile(this.nowRow, this.nowTypeNum);
  949. } else {
  950. this.tableShow(this.resultFileId);
  951. }
  952. },
  953. tableShow(id) {
  954. // const url = `${process.env.VUE_APP_BASE_API}${path}`;
  955. getData(id).then((res) => {
  956. const url = `${process.env.VUE_APP_BASE_API}${res.data.dataPath}`;
  957. this.fetchLogFile(url).then((text) => {
  958. const data = text
  959. .split("\r\n")
  960. .filter((line) => line.trim() !== "")
  961. .map((row) => row.split(","));
  962. this.completionHeadData = data.shift();
  963. this.completionData = data.map((row) => {
  964. const rowData = {};
  965. for (let i = 0; i < this.completionHeadData.length; i++) {
  966. rowData[`val${i}`] = row[i] === 0 ? null : row[i];
  967. }
  968. return rowData;
  969. });
  970. });
  971. });
  972. },
  973. imgShow(url, dataType) {
  974. this.fileType = dataType;
  975. this.imgPreviewUrl = url;
  976. this.fileShowVisible = true;
  977. },
  978. },
  979. };
  980. </script>
  981. <style scoped lang="scss">
  982. @import "./index.scss";
  983. </style>