index.vue 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  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. :before-close="handleClose"
  411. >
  412. <el-form ref="formRef" :model="form" :rules="rules" label-width="80px">
  413. <el-form-item
  414. v-if="dialogType === 3"
  415. label="选择数据类型"
  416. label-width="120px"
  417. >
  418. <el-radio-group v-removeAriaHidden v-model="radioDatatype">
  419. <el-radio :label="2">去噪</el-radio>
  420. <el-radio :label="3">扩充</el-radio>
  421. <!-- <el-radio :label="4">特征提取</el-radio> -->
  422. </el-radio-group>
  423. </el-form-item>
  424. <el-form-item label="数据" prop="processedDataId">
  425. <el-select
  426. v-model="form.processedDataId"
  427. placeholder="请选择执行的数据"
  428. >
  429. <el-option
  430. v-for="(item, index) in optionalData"
  431. :key="index"
  432. :label="item.dataName"
  433. :value="item.id"
  434. ></el-option>
  435. </el-select>
  436. </el-form-item>
  437. <el-form-item label="算法" prop="processAlgId">
  438. <el-select v-model="form.processAlgId" placeholder="请选择执行的算法">
  439. <el-option
  440. v-for="(item, index) in optionalAglo"
  441. :key="index"
  442. :label="item.algName"
  443. :value="item.id"
  444. ></el-option>
  445. </el-select>
  446. </el-form-item>
  447. </el-form>
  448. <span slot="footer" class="dialog-footer">
  449. <el-button @click="handleClose">取 消</el-button>
  450. <el-button type="primary" @click="submitHandle()">确 定</el-button>
  451. </span>
  452. </el-dialog>
  453. <el-dialog
  454. v-loading="loading"
  455. title="数据展示"
  456. :visible.sync="fileShowVisible"
  457. width="80%"
  458. :close-on-click-modal="false"
  459. >
  460. <el-button
  461. v-if="!['4', '5'].includes(fileType)"
  462. style="margin-left: 50px"
  463. type="text"
  464. @click="changeShow"
  465. >{{ isTableShow ? "表格展示" : "曲线展示" }}</el-button
  466. >
  467. <div v-if="isTableShow && !['4', '5'].includes(fileType)">
  468. <vxe-table
  469. border="none"
  470. size="mini"
  471. show-overflow
  472. highlight-hover-row
  473. height="400"
  474. :row-config="{ isHover: true, isCurrent: true }"
  475. :sort-config="{ trigger: 'cell' }"
  476. :data="completionData"
  477. >
  478. <vxe-table-column
  479. v-for="(item, index) in completionHeadData"
  480. :key="index"
  481. align="center"
  482. :field="'val' + index"
  483. :title="item"
  484. ></vxe-table-column>
  485. </vxe-table>
  486. </div>
  487. <!-- <div v-if="!isTableShow && fileType !== '5'" ref="beforeChartRef" style="width: 100%; height: 400px;"></div> -->
  488. <PreCharts
  489. v-if="!isTableShow && !['4', '5'].includes(fileType)"
  490. :title="'处理前数据'"
  491. :chartData="preChartData"
  492. />
  493. <CurveCharts
  494. style="margin-top: 20px"
  495. v-if="!isTableShow && !['4', '5'].includes(fileType) && !isImgShow"
  496. :title="'处理后数据'"
  497. :chartData="resultChartData"
  498. />
  499. <!-- 有图片显示图片,没图片显示数据 -->
  500. <div
  501. v-if="!isTableShow && !['4', '5'].includes(fileType) && isImgShow"
  502. class="imgShow"
  503. >
  504. <div class="imgTitle">处理后图片</div>
  505. <ImagePreview class="image-preview" :src="imgUrl"></ImagePreview>
  506. </div>
  507. <!-- <div
  508. v-if="!isTableShow && !['4', '5'].includes(fileType)"
  509. ref="completionChartRef"
  510. style="width: 100%; height: 400px"
  511. ></div> -->
  512. <ImagePreview
  513. class="image-preview"
  514. v-if="['4', '5'].includes(fileType)"
  515. :src="imgPreviewUrl"
  516. ></ImagePreview>
  517. <div class="remark">指标结果:{{ agloRemark }}</div>
  518. </el-dialog>
  519. </div>
  520. </template>
  521. <script>
  522. import CountTo from "vue-count-to";
  523. import RingChart from "@/views/homePage/ringChart";
  524. import PreCharts from "@/views/homePage/preCharts";
  525. import CurveCharts from "@/views/homePage/curveCharts";
  526. import BarChart from "@/views/dashboard/BarChart";
  527. import { getAlgConfigByType, listAlgConfig } from "@/api/system/algConfig";
  528. import { getDataProcessByType, addProcess } from "@/api/system/process";
  529. import { getDataByType, getData, listData } from "@/api/system/data";
  530. export default {
  531. name: "Index",
  532. dicts: ["biz_alg_type", "biz_process_status"],
  533. components: {
  534. CountTo,
  535. RingChart,
  536. BarChart,
  537. PreCharts,
  538. CurveCharts,
  539. },
  540. data() {
  541. return {
  542. loading: false,
  543. rules: {},
  544. title: "选择数据",
  545. baseUrl: process.env.VUE_APP_BASE_API,
  546. dialogVisible: false,
  547. fileShowVisible: false,
  548. originalList: [],
  549. denoisingList: [],
  550. completionList: [],
  551. expansionList: [],
  552. featureExtractionList: [],
  553. assessmentList: [],
  554. faultPredictionList: [],
  555. optionalData: [],
  556. optionalAglo: [],
  557. form: {
  558. processedDataId: null,
  559. processAlgId: null,
  560. },
  561. // 对话框展示数据内容
  562. completionData: [],
  563. completionHeadData: [],
  564. isTableShow: false,
  565. resultFileId: null,
  566. // filePath: null,
  567. fileType: null,
  568. imgPreviewUrl: null,
  569. radioDatatype: 2,
  570. dialogType: null,
  571. preChartData: {},
  572. resultChartData: {},
  573. nowRow: {},
  574. nowTypeNum: null,
  575. agloRemark: "",
  576. ringTotal: 0,
  577. agloTypeData: [],
  578. flag: false,
  579. isImgShow: false,
  580. imgUrl: null,
  581. };
  582. },
  583. mounted() {},
  584. created() {
  585. this.getTotal();
  586. this.getTableData();
  587. },
  588. watch: {
  589. fileShowVisible(value) {
  590. if (!value) {
  591. this.isTableShow = false;
  592. }
  593. },
  594. radioDatatype(value) {
  595. getDataByType(value).then((res) => {
  596. this.optionalData = res.data;
  597. });
  598. // getAlgConfigByType(3).then((res) => {
  599. // this.optionalAglo = res.data;
  600. // });
  601. },
  602. },
  603. methods: {
  604. getTotal() {
  605. const queryParams = { pageNum: 1, pageSize: 1000 };
  606. listAlgConfig(queryParams).then((response) => {
  607. this.ringTotal = response.total;
  608. const typeFrequency = response.rows.map((item) => {
  609. return item.algType;
  610. });
  611. const countedTypeFrequency = typeFrequency?.reduce((obj, name) => {
  612. if (name in obj) {
  613. obj[name]++;
  614. } else {
  615. obj[name] = 1;
  616. }
  617. return obj;
  618. }, {});
  619. const agloType = this.dict.type.biz_alg_type;
  620. for (let key in this.dict.type.biz_alg_type) {
  621. this.agloTypeData.push({
  622. value: countedTypeFrequency[key],
  623. name: agloType[key].label,
  624. });
  625. }
  626. this.flag = true;
  627. });
  628. },
  629. getTableData() {
  630. const query = {
  631. dataType: 0,
  632. };
  633. listData(query).then((res) => {
  634. this.originalList = [];
  635. this.originalList = res.rows;
  636. });
  637. getDataProcessByType(0).then((res) => {
  638. this.completionList = [];
  639. this.completionList = res.data;
  640. });
  641. getDataProcessByType(1).then((res) => {
  642. this.denoisingList = [];
  643. this.denoisingList = res.data;
  644. });
  645. getDataProcessByType(2).then((res) => {
  646. this.expansionList = [];
  647. this.expansionList = res.data;
  648. });
  649. getDataProcessByType(3).then((res) => {
  650. this.featureExtractionList = [];
  651. this.featureExtractionList = res.data;
  652. });
  653. getDataProcessByType(4).then((res) => {
  654. this.assessmentList = [];
  655. this.assessmentList = res.data;
  656. });
  657. getDataProcessByType(5).then((res) => {
  658. this.faultPredictionList = [];
  659. this.faultPredictionList = res.data;
  660. });
  661. },
  662. goTarget(href) {
  663. window.open(href, "_blank");
  664. },
  665. handleProcess(type) {
  666. this.dialogVisible = true;
  667. this.dialogType = type;
  668. let match;
  669. if (type === 3) {
  670. const relation = [
  671. [3, 2],
  672. [3, 3],
  673. ];
  674. match = relation.find((item) => item[0] === type)[1];
  675. } else if (type === 5) {
  676. match = type - 1;
  677. } else {
  678. match = type;
  679. }
  680. // const relation = [[1, 0], [2, 1], [3, 2], [4, 2], [4, 3], [5, 4], [6, 4]]
  681. // const match = relation.find(item => item[0] === type)[1];
  682. getDataByType(match).then((res) => {
  683. this.optionalData = res.data;
  684. });
  685. getAlgConfigByType(type).then((res) => {
  686. this.optionalAglo = res.data;
  687. });
  688. },
  689. submitHandle() {
  690. addProcess(this.form).then((response) => {
  691. this.$modal.msgSuccess("开始执行");
  692. this.getTableData();
  693. });
  694. },
  695. handleClose() {
  696. this.radioDatatype = 2;
  697. this.dialogVisible = false;
  698. this.form = {
  699. processedDataId: null,
  700. processAlgId: null,
  701. };
  702. this.optionalData = [];
  703. this.optionalAglo = [];
  704. },
  705. handleFile(row, typeNum) {
  706. this.nowRow = row;
  707. this.nowTypeNum = typeNum;
  708. this.resultFileId = row.resultDataId;
  709. this.fileType = row.processType;
  710. let _this = this;
  711. this.loading = true;
  712. if (typeNum === 5 || typeNum === 6) {
  713. getData(row.resultDataId).then((res) => {
  714. this.agloRemark = res.data.remark;
  715. this.imgPreviewUrl = res.data.imagePath;
  716. this.loading = false;
  717. this.fileShowVisible = true;
  718. });
  719. } else {
  720. getData(row.processedDataId).then((processedRes) => {
  721. const resData = processedRes.data;
  722. const url = process.env.VUE_APP_BASE_API + resData.dataPath;
  723. this.fetchLogFile(url)
  724. .then((text) => {
  725. let data, content, head;
  726. data = this.handleFileData(text);
  727. content = data.contentData;
  728. head = data.headData;
  729. if (resData.dataType == 0) {
  730. this.handlePreChartOption(content, head, true);
  731. } else {
  732. this.handlePreChartOption(content, head, false);
  733. }
  734. })
  735. .catch((error) => {
  736. console.error("Failed to fetch the log file:", error);
  737. this.$modal.msgSuccess("文件读取错误");
  738. this.loading = false;
  739. });
  740. });
  741. getData(row.resultDataId)
  742. .then((resultRes) => {
  743. const resData = resultRes.data;
  744. this.agloRemark = resData.remark;
  745. const url = process.env.VUE_APP_BASE_API + resData.dataPath;
  746. // resultRes.data.imagePath =
  747. // "/profile/upload/2024/12/06/testdata1_故障预测_20241206181334A015.jpeg";
  748. // console.log("resData.dataType", resData);
  749. if (resData.imagePath && resData.dataType == "4") {
  750. this.imgUrl = resData.imagePath;
  751. this.isImgShow = true;
  752. this.loading = false;
  753. this.fileShowVisible = true;
  754. } else {
  755. this.fetchLogFile(url).then((text) => {
  756. let data, content, head;
  757. data = this.handleFileData(text);
  758. content = data.contentData;
  759. head = data.headData;
  760. this.switchHandle(content, head, resData.dataType);
  761. });
  762. }
  763. })
  764. .catch((error) => {
  765. console.error("Failed to fetch the log file:", error);
  766. this.$modal.msgSuccess("文件读取错误");
  767. this.loading = false;
  768. });
  769. }
  770. },
  771. switchHandle(content, head, dataType) {
  772. switch (dataType) {
  773. case "0":
  774. this.fileShowVisible = true;
  775. this.handleResultChartOption(content, head, true);
  776. // this.loading = false;
  777. break;
  778. case "1":
  779. this.fileShowVisible = true;
  780. this.handleResultChartOption(content, head, false);
  781. // this.loading = false;
  782. break;
  783. case "2":
  784. this.fileShowVisible = true;
  785. this.$nextTick(() => {
  786. this.handleResultChartOption(content, head, false);
  787. // this.loading = false;
  788. });
  789. break;
  790. case "3":
  791. this.fileShowVisible = true;
  792. this.$nextTick(() => {
  793. this.handleResultChartOption(content, head, false);
  794. // this.loading = false;
  795. });
  796. break;
  797. case "4":
  798. this.fileShowVisible = true;
  799. this.$nextTick(() => {
  800. this.handleResultChartOption(content, head, false);
  801. // this.loading = false;
  802. });
  803. break;
  804. case "5":
  805. break;
  806. case "6":
  807. break;
  808. default:
  809. break;
  810. }
  811. },
  812. // 读取文件内容
  813. async fetchLogFile(url) {
  814. try {
  815. const response = await fetch(url, { method: "GET" });
  816. if (!response.ok) {
  817. throw new Error(`HTTP error! status: ${response.status}`);
  818. }
  819. return await response.text();
  820. } catch (error) {
  821. throw error;
  822. }
  823. },
  824. // 对数据的处理(不包含时间)
  825. handleFileData(fileData) {
  826. // 每行数据转换成数组、过滤出存在的空白行、将没行数据按照,号分割
  827. const data = fileData
  828. .split("\r\n")
  829. .filter((line) => line.trim() !== "")
  830. .map((row) => row.split(","));
  831. let headData = [];
  832. for (let i = 1; i <= data[0].length; i++) {
  833. headData.push(`数据${i}`);
  834. }
  835. const contentData = Array.from({ length: headData.length }, () => []);
  836. for (let i = 0; i < data.length; i++) {
  837. data[i].forEach((value, index) => {
  838. contentData[index].push(value * 1);
  839. });
  840. }
  841. return { contentData, headData };
  842. },
  843. // 对数据的处理(包含时间)
  844. handleDataIncludeTime(fileData) {
  845. data = fileData
  846. .split("\r\n")
  847. .filter((line) => line.trim() !== "")
  848. .map((row) => row.split(","));
  849. data[0].shift();
  850. const completionHead = data[0];
  851. const completionContent = Array.from(
  852. { length: completionHead.length },
  853. () => []
  854. );
  855. const timeData = [];
  856. for (let i = 1; i < data.length; i++) {
  857. data[i].forEach((value, index) => {
  858. if (index === 0) {
  859. timeData.push(value);
  860. } else {
  861. completionContent[index - 1].push(value * 1);
  862. }
  863. });
  864. }
  865. return {
  866. contentData: completionContent,
  867. headData: completionHead,
  868. timeData,
  869. };
  870. },
  871. handlePreChartOption(content, head, ismarkPoint) {
  872. this.preChartData = {
  873. legendData: [],
  874. xAxisData: [],
  875. yAxisData: [],
  876. seriesData: [],
  877. };
  878. let series;
  879. if (ismarkPoint) {
  880. series = content.map((lineData, index) => ({
  881. name: `${head[index]}`,
  882. type: "line",
  883. data: lineData,
  884. connectNulls: true, // 连接相邻的非空数据点
  885. markPoint: {
  886. data: lineData
  887. .map((value, idx) => ({
  888. value: !value || value === 0 ? "-" : null,
  889. xAxis: idx,
  890. yAxis: lineData[idx - 1],
  891. // yAxis: 0,
  892. // itemStyle: { color: color[index] }, // 高亮显示缺失值
  893. }))
  894. .filter((point) => point.value),
  895. },
  896. }));
  897. } else {
  898. series = content.map((lineData, index) => ({
  899. name: `${head[index]}`,
  900. type: "line",
  901. // data: lineData,
  902. data: lineData,
  903. connectNulls: true,
  904. }));
  905. }
  906. this.preChartData.seriesData = series;
  907. this.preChartData.xAxisData = content[0].map((_, index) => index);
  908. },
  909. // 图表设置
  910. handleResultChartOption(content, head, ismarkPoint) {
  911. this.resultChartData = {
  912. legendData: [],
  913. xAxisData: [],
  914. yAxisData: [],
  915. seriesData: [],
  916. };
  917. let series;
  918. if (ismarkPoint) {
  919. series = content.map((lineData, index) => ({
  920. name: `${head[index]}`,
  921. type: "line",
  922. data: lineData,
  923. connectNulls: true, // 连接相邻的非空数据点
  924. markPoint: {
  925. data: lineData
  926. .map((value, idx) => ({
  927. value: value || value === 0 ? "缺失" : null,
  928. xAxis: idx,
  929. yAxis: lineData[idx - 1],
  930. // yAxis: value,
  931. // itemStyle: { color: color[index] }, // 高亮显示缺失值
  932. }))
  933. .filter((point) => point.value),
  934. },
  935. }));
  936. } else {
  937. series = content.map((lineData, index) => ({
  938. name: `${head[index]}`,
  939. type: "line",
  940. data: lineData,
  941. connectNulls: true,
  942. }));
  943. }
  944. this.resultChartData.seriesData = series;
  945. this.resultChartData.xAxisData = content[0].map((_, index) => index);
  946. this.loading = false;
  947. },
  948. // 切换表格/曲线展示
  949. changeShow() {
  950. this.isTableShow = !this.isTableShow;
  951. if (!this.isTableShow) {
  952. this.handleFile(this.nowRow, this.nowTypeNum);
  953. } else {
  954. this.tableShow(this.resultFileId);
  955. }
  956. },
  957. tableShow(id) {
  958. // const url = `${process.env.VUE_APP_BASE_API}${path}`;
  959. getData(id).then((res) => {
  960. const url = `${process.env.VUE_APP_BASE_API}${res.data.dataPath}`;
  961. this.fetchLogFile(url).then((text) => {
  962. const data = text
  963. .split("\r\n")
  964. .filter((line) => line.trim() !== "")
  965. .map((row) => row.split(","));
  966. this.completionHeadData = data.shift();
  967. this.completionData = data.map((row) => {
  968. const rowData = {};
  969. for (let i = 0; i < this.completionHeadData.length; i++) {
  970. rowData[`val${i}`] = row[i] === 0 ? null : row[i];
  971. }
  972. return rowData;
  973. });
  974. });
  975. });
  976. },
  977. imgShow(url, dataType) {
  978. this.fileType = dataType;
  979. this.imgPreviewUrl = url;
  980. this.fileShowVisible = true;
  981. },
  982. },
  983. };
  984. </script>
  985. <style scoped lang="scss">
  986. @import "./index.scss";
  987. </style>