<template>
  <div class="home" v-loading="loading">
    <div class="second">
      <div class="topPanel">
        <!-- 原始数据 -->
        <div class="tPanel">
          <el-table size="mini" :data="originalList">
            <el-table-column prop="dataName" label="数据" align="center">
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.dataName"
                  placement="top"
                >
                  <!--  @click="handleFile(scope.row.id, null)" -->
                  <span class="file">{{ scope.row.dataName }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- 去噪 -->
        <div class="tPanel">
          <el-table size="mini" :data="denoisingList">
            <el-table-column
              prop="processedDataName"
              label="处理前数据"
              align="center"
            >
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.processedDataName"
                  placement="top"
                >
                  <span class="beforeFile">{{
                    scope.row.processedDataName
                  }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column
              prop="resultDataName"
              label="处理后数据"
              align="center"
            >
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.resultDataName"
                  placement="top"
                >
                  <span class="file" @click="handleFile(scope.row, 2)">{{
                    scope.row.resultDataName
                  }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column
              prop="processStatus"
              label="状态"
              align="center"
              width="60"
            >
              <template slot-scope="scope">
                <dict-tag
                  :options="dict.type.biz_process_status"
                  :value="scope.row.processStatus"
                />
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- 特征提取 -->
        <div class="tPanel">
          <el-table size="mini" :data="featureExtractionList">
            <el-table-column
              prop="processedDataName"
              label="处理前数据"
              align="center"
            >
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.processedDataName"
                  placement="top"
                >
                  <span class="beforeFile">{{
                    scope.row.processedDataName
                  }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column
              prop="resultDataName"
              label="处理后数据"
              align="center"
            >
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.resultDataName"
                  placement="top"
                >
                  <span class="file" @click="handleFile(scope.row, 4)">{{
                    scope.row.resultDataName
                  }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column
              prop="processStatus"
              label="状态"
              align="center"
              width="60"
            >
              <template slot-scope="scope">
                <dict-tag
                  :options="dict.type.biz_process_status"
                  :value="scope.row.processStatus"
                />
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- 故障预测 -->
        <div class="tPanel">
          <el-table size="mini" :data="faultPredictionList">
            <el-table-column
              prop="processedDataName"
              label="处理前数据"
              align="center"
            >
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.processedDataName"
                  placement="top"
                >
                  <span class="beforeFile">{{
                    scope.row.processedDataName
                  }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column
              prop="resultDataName"
              label="处理后数据"
              align="center"
            >
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.resultDataName"
                  placement="top"
                >
                  <span class="file" @click="handleFile(scope.row, 6)">{{
                    scope.row.resultDataName
                  }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column
              prop="processStatus"
              label="状态"
              align="center"
              width="60"
            >
              <template slot-scope="scope">
                <dict-tag
                  :options="dict.type.biz_process_status"
                  :value="scope.row.processStatus"
                />
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
      <div class="step">
        <div class="yuan">
          <div class="img yuanBg odd">
            <div class="tag">原始数据</div>
          </div>
        </div>
        <div class="one">
          <div class="img oneBg even" @click="handleProcess(0)">
            <div class="tag">补全</div>
          </div>
        </div>
        <div class="two">
          <div class="img twoBg odd" @click="handleProcess(1)">
            <div class="tag">去噪</div>
          </div>
        </div>
        <div class="three">
          <div class="img threeBg even" @click="handleProcess(2)">
            <div class="tag">扩充</div>
          </div>
        </div>
        <div class="four">
          <div class="img fourBg odd" @click="handleProcess(3)">
            <div class="tag">特征提取</div>
            <div class="tag2">故障诊断</div>
          </div>
        </div>
        <div class="five">
          <div class="img fiveBg even" @click="handleProcess(4)">
            <div class="tag">退化评估</div>
          </div>
        </div>
        <div class="six">
          <div
            class="img sixBg odd noAfter"
            style="content: none"
            @click="handleProcess(5)"
          >
            <div class="tag">故障预测</div>
          </div>
        </div>
      </div>
      <div class="bottomPanel">
        <!-- 补全 -->
        <div class="bPanel">
          <el-table size="mini" :data="completionList">
            <el-table-column
              prop="processedDataName"
              label="处理前数据"
              align="center"
            >
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.processedDataName"
                  placement="top"
                >
                  <span class="beforeFile">{{
                    scope.row.processedDataName
                  }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column
              prop="resultDataName"
              label="处理后数据"
              align="center"
            >
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.resultDataName"
                  placement="top"
                >
                  <span class="file" @click="handleFile(scope.row, 1)">{{
                    scope.row.resultDataName
                  }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column
              prop="processStatus"
              label="状态"
              align="center"
              width="60"
            >
              <template slot-scope="scope">
                <dict-tag
                  :options="dict.type.biz_process_status"
                  :value="scope.row.processStatus"
                />
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- 扩充 -->
        <div class="bPanel">
          <el-table size="mini" :data="expansionList">
            <el-table-column
              prop="processedDataName"
              label="处理前数据"
              align="center"
            >
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.processedDataName"
                  placement="top"
                >
                  <span class="beforeFile">{{
                    scope.row.processedDataName
                  }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column
              prop="resultDataName"
              label="处理后数据"
              align="center"
            >
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.processedDataName"
                  placement="top"
                >
                  <span class="file" @click="handleFile(scope.row, 3)">{{
                    scope.row.processedDataName
                  }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column
              prop="processStatus"
              label="状态"
              align="center"
              width="60"
            >
              <template slot-scope="scope">
                <dict-tag
                  :options="dict.type.biz_process_status"
                  :value="scope.row.processStatus"
                />
              </template>
            </el-table-column>
          </el-table>
        </div>
        <!-- 退化评估 -->
        <div class="bPanel">
          <el-table size="mini" :data="assessmentList">
            <el-table-column
              prop="processedDataName"
              label="处理前数据"
              align="center"
            >
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.processedDataName"
                  placement="top"
                >
                  <span class="beforeFile">{{
                    scope.row.processedDataName
                  }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column
              prop="resultDataName"
              label="处理后数据"
              align="center"
            >
              <template slot-scope="scope">
                <el-tooltip
                  class="item"
                  effect="dark"
                  :content="scope.row.resultDataName"
                  placement="top"
                >
                  <span class="file" @click="handleFile(scope.row, 5)">{{
                    scope.row.resultDataName
                  }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column
              prop="processStatus"
              label="状态"
              align="center"
              width="60"
            >
              <template slot-scope="scope">
                <dict-tag
                  :options="dict.type.biz_process_status"
                  :value="scope.row.processStatus"
                />
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div></div>
      </div>
    </div>
    <div class="first">
      <h4 style="margin: 13px 0px 0px 20px; color: #fff">算法统计</h4>
      <div class="chart">
        <RingChart
          v-if="flag"
          :total="ringTotal"
          :agloTypeData="agloTypeData"
        />
        <BarChart v-if="flag" :agloTypeData="agloTypeData" width="700px" />
      </div>
    </div>
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="30%"
      :close-on-click-modal="false"
    >
      <el-form ref="formRef" :model="form" :rules="rules" label-width="80px">
        <el-form-item
          v-if="dialogType === 3"
          label="选择数据类型"
          label-width="120px"
        >
          <el-radio-group v-removeAriaHidden v-model="type">
            <el-radio :label="2">去噪</el-radio>
            <el-radio :label="3">扩充</el-radio>
            <!-- <el-radio :label="4">特征提取</el-radio> -->
          </el-radio-group>
        </el-form-item>
        <el-form-item label="数据" prop="processType">
          <el-select
            v-model="form.processedDataId"
            placeholder="请选择执行的数据"
          >
            <el-option
              v-for="(item, index) in optionalData"
              :key="index"
              :label="item.dataName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="算法" prop="processType">
          <el-select v-model="form.processAlgId" placeholder="请选择执行的算法">
            <el-option
              v-for="(item, index) in optionalAglo"
              :key="index"
              :label="item.algName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitHandle()">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      v-loading="loading"
      title="数据展示"
      :visible.sync="fileShowVisible"
      width="80%"
      :close-on-click-modal="false"
    >
      <el-button
        v-if="!['4', '5'].includes(fileType)"
        style="margin-left: 50px"
        type="text"
        @click="changeShow"
        >{{ isTableShow ? "表格展示" : "曲线展示" }}</el-button
      >
      <div v-if="isTableShow && !['4', '5'].includes(fileType)">
        <vxe-table
          border="none"
          size="mini"
          show-overflow
          highlight-hover-row
          height="400"
          :row-config="{ isHover: true, isCurrent: true }"
          :sort-config="{ trigger: 'cell' }"
          :data="completionData"
        >
          <vxe-table-column
            v-for="(item, index) in completionHeadData"
            :key="index"
            align="center"
            :field="'val' + index"
            :title="item"
          ></vxe-table-column>
        </vxe-table>
      </div>
      <!-- <div v-if="!isTableShow && fileType !== '5'" ref="beforeChartRef" style="width: 100%; height: 400px;"></div> -->

      <PreCharts
        v-if="!isTableShow && !['4', '5'].includes(fileType)"
        :title="'处理前数据'"
        :chartData="preChartData"
      />

      <CurveCharts
        style="margin-top: 20px"
        v-if="!isTableShow && !['4', '5'].includes(fileType) && !isImgShow"
        :title="'处理后数据'"
        :chartData="resultChartData"
      />
      <!-- 有图片显示图片，没图片显示数据 -->
      <div
        v-if="!isTableShow && !['4', '5'].includes(fileType) && isImgShow"
        class="imgShow"
      >
        <div class="imgTitle">处理后图片</div>
        <ImagePreview class="image-preview" :src="imgUrl"></ImagePreview>
      </div>

      <!-- <div
        v-if="!isTableShow && !['4', '5'].includes(fileType)"
        ref="completionChartRef"
        style="width: 100%; height: 400px"
      ></div> -->
      <ImagePreview
        class="image-preview"
        v-if="['4', '5'].includes(fileType)"
        :src="imgPreviewUrl"
      ></ImagePreview>

      <div class="remark">指标结果：{{ agloRemark }}</div>
    </el-dialog>
  </div>
</template>

<script>
import CountTo from "vue-count-to";
import RingChart from "@/views/homePage/ringChart";
import PreCharts from "@/views/homePage/preCharts";
import CurveCharts from "@/views/homePage/curveCharts";
import BarChart from "@/views/dashboard/BarChart";
import { getAlgConfigByType, listAlgConfig } from "@/api/system/algConfig";
import { getDataProcessByType, addProcess } from "@/api/system/process";
import { getDataByType, getData, listData } from "@/api/system/data";

export default {
  name: "Index",
  dicts: ["biz_alg_type", "biz_process_status"],
  components: {
    CountTo,
    RingChart,
    BarChart,
    PreCharts,
    CurveCharts,
  },
  data() {
    return {
      loading: false,
      rules: {},
      title: "选择数据",
      baseUrl: process.env.VUE_APP_BASE_API,
      dialogVisible: false,
      fileShowVisible: false,
      originalList: [],
      denoisingList: [],
      completionList: [],
      expansionList: [],
      featureExtractionList: [],
      assessmentList: [],
      faultPredictionList: [],
      optionalData: [],
      optionalAglo: [],
      form: {
        processedDataId: null,
        processAlgId: null,
      },
      // 对话框展示数据内容
      completionData: [],
      completionHeadData: [],
      isTableShow: false,
      resultFileId: null,
      // filePath: null,
      fileType: null,
      imgPreviewUrl: null,
      type: 2,
      dialogType: null,
      preChartData: {},
      resultChartData: {},
      nowRow: {},
      nowTypeNum: null,
      agloRemark: "",
      ringTotal: 0,
      agloTypeData: [],
      flag: false,
      isImgShow: false,
      imgUrl: null,
    };
  },
  mounted() {},
  created() {
    this.getTotal();
    this.getTableData();
  },
  watch: {
    fileShowVisible(value) {
      if (!value) {
        this.isTableShow = false;
      }
    },
    type(value) {
      getDataByType(value).then((res) => {
        this.optionalData = res.data;
      });
      getAlgConfigByType(3).then((res) => {
        this.optionalAglo = res.data;
      });
    },
  },
  methods: {
    getTotal() {
      const queryParams = { pageNum: 1, pageSize: 1000 };
      listAlgConfig(queryParams).then((response) => {
        this.total = response.total;

        const typeFrequency = response.rows.map((item) => {
          return item.algType;
        });
        const countedTypeFrequency = typeFrequency?.reduce((obj, name) => {
          if (name in obj) {
            obj[name]++;
          } else {
            obj[name] = 1;
          }
          return obj;
        }, {});

        const agloType = this.dict.type.biz_alg_type;
        for (let key in this.dict.type.biz_alg_type) {
          this.agloTypeData.push({
            value: countedTypeFrequency[key],
            name: agloType[key].label,
          });
        }
        this.flag = true;
      });
    },
    getTableData() {
      const query = {
        dataType: 0,
      };
      listData(query).then((res) => {
        this.originalList = [];
        this.originalList = res.rows;
      });
      getDataProcessByType(0).then((res) => {
        this.completionList = [];
        this.completionList = res.data;
      });
      getDataProcessByType(1).then((res) => {
        this.denoisingList = [];
        this.denoisingList = res.data;
      });
      getDataProcessByType(2).then((res) => {
        this.expansionList = [];
        this.expansionList = res.data;
      });
      getDataProcessByType(3).then((res) => {
        this.featureExtractionList = [];
        this.featureExtractionList = res.data;
      });
      getDataProcessByType(4).then((res) => {
        this.assessmentList = [];
        this.assessmentList = res.data;
      });
      getDataProcessByType(5).then((res) => {
        this.faultPredictionList = [];
        this.faultPredictionList = res.data;
      });
    },
    goTarget(href) {
      window.open(href, "_blank");
    },
    handleProcess(type) {
      this.dialogVisible = true;
      this.dialogType = type;
      let match;
      if (type === 3) {
        const relation = [
          [3, 2],
          [3, 3],
        ];
        match = relation.find((item) => item[0] === type)[1];
      } else if (type === 5) {
        match = type - 1;
      } else {
        match = type;
      }
      // const relation = [[1, 0], [2, 1], [3, 2], [4, 2], [4, 3], [5, 4], [6, 4]]
      // const match = relation.find(item => item[0] === type)[1];
      getDataByType(match).then((res) => {
        this.optionalData = res.data;
      });
      getAlgConfigByType(type).then((res) => {
        this.optionalAglo = res.data;
      });
    },
    submitHandle() {
      addProcess(this.form).then((response) => {
        this.$modal.msgSuccess("开始执行");
        this.dialogVisible = false;
        this.form = {
          processedDataId: null,
          processAlgId: null,
        };
        this.optionalData = [];
        this.optionalAglo = [];
        this.getTableData();
      });
    },
    handleFile(row, typeNum) {
      this.nowRow = row;
      this.nowTypeNum = typeNum;
      this.resultFileId = row.resultDataId;
      this.fileType = row.processType;
      let _this = this;
      this.loading = true;
      if (typeNum === 5 || typeNum === 6) {
        getData(row.resultDataId).then((res) => {
          this.agloRemark = res.data.remark;
          this.imgPreviewUrl = res.data.imagePath;
          this.loading = false;
          this.fileShowVisible = true;
        });
      } else {
        getData(row.processedDataId).then((processedRes) => {
          const resData = processedRes.data;
          const url = process.env.VUE_APP_BASE_API + resData.dataPath;
          this.fetchLogFile(url)
            .then((text) => {
              let data, content, head;
              data = this.handleFileData(text);
              content = data.contentData;
              head = data.headData;
              if (resData.dataType == 0) {
                this.handlePreChartOption(content, head, true);
              } else {
                this.handlePreChartOption(content, head, false);
              }
            })
            .catch((error) => {
              console.error("Failed to fetch the log file:", error);
              this.$modal.msgSuccess("文件读取错误");
              this.loading = false;
            });
        });
        getData(row.resultDataId)
          .then((resultRes) => {
            const resData = resultRes.data;
            this.agloRemark = resData.remark;
            const url = process.env.VUE_APP_BASE_API + resData.dataPath;
            // resultRes.data.imagePath =
            //   "/profile/upload/2024/12/06/testdata1_故障预测_20241206181334A015.jpeg";
            // console.log("resData.dataType", resData);
            if (resData.imagePath && resData.dataType == "4") {
              this.imgUrl = resData.imagePath;
              this.isImgShow = true;
              this.loading = false;
              this.fileShowVisible = true;
            } else {
              this.fetchLogFile(url).then((text) => {
                let data, content, head;
                data = this.handleFileData(text);
                content = data.contentData;
                head = data.headData;
                this.switchHandle(content, head, resData.dataType);
              });
            }
          })
          .catch((error) => {
            console.error("Failed to fetch the log file:", error);
            this.$modal.msgSuccess("文件读取错误");
            this.loading = false;
          });
      }
    },

    switchHandle(content, head, dataType) {
      switch (dataType) {
        case "0":
          this.fileShowVisible = true;
          this.handleResultChartOption(content, head, true);
          // this.loading = false;
          break;
        case "1":
          this.fileShowVisible = true;
          this.handleResultChartOption(content, head, false);
          // this.loading = false;
          break;
        case "2":
          this.fileShowVisible = true;
          this.$nextTick(() => {
            this.handleResultChartOption(content, head, false);
            // this.loading = false;
          });
          break;
        case "3":
          this.fileShowVisible = true;
          this.$nextTick(() => {
            this.handleResultChartOption(content, head, false);
            // this.loading = false;
          });
          break;
        case "4":
          this.fileShowVisible = true;
          this.$nextTick(() => {
            this.handleResultChartOption(content, head, false);
            // this.loading = false;
          });
          break;
        case "5":
          break;
        case "6":
          break;
        default:
          break;
      }
    },
    // 读取文件内容
    async fetchLogFile(url) {
      try {
        const response = await fetch(url, { method: "GET" });
        if (!response.ok) {
          throw new Error(`HTTP error! status: ${response.status}`);
        }
        return await response.text();
      } catch (error) {
        throw error;
      }
    },
    // 对数据的处理(不包含时间)
    handleFileData(fileData) {
      // 每行数据转换成数组、过滤出存在的空白行、将没行数据按照,号分割
      const data = fileData
        .split("\r\n")
        .filter((line) => line.trim() !== "")
        .map((row) => row.split(","));
      let headData = [];
      for (let i = 1; i <= data[0].length; i++) {
        headData.push(`曲线${i}`);
      }
      const contentData = Array.from({ length: headData.length }, () => []);
      for (let i = 0; i < data.length; i++) {
        data[i].forEach((value, index) => {
          contentData[index].push(value * 1);
        });
      }
      return { contentData, headData };
    },
    // 对数据的处理(包含时间)
    handleDataIncludeTime(fileData) {
      data = fileData
        .split("\r\n")
        .filter((line) => line.trim() !== "")
        .map((row) => row.split(","));
      data[0].shift();
      const completionHead = data[0];
      const completionContent = Array.from(
        { length: completionHead.length },
        () => []
      );
      const timeData = [];
      for (let i = 1; i < data.length; i++) {
        data[i].forEach((value, index) => {
          if (index === 0) {
            timeData.push(value);
          } else {
            completionContent[index - 1].push(value * 1);
          }
        });
      }
      return {
        contentData: completionContent,
        headData: completionHead,
        timeData,
      };
    },
    handlePreChartOption(content, head, ismarkPoint) {
      this.preChartData = {
        legendData: [],
        xAxisData: [],
        yAxisData: [],
        seriesData: [],
      };
      let series;
      if (ismarkPoint) {
        series = content.map((lineData, index) => ({
          name: `${head[index]}`,
          type: "line",
          data: lineData,
          connectNulls: true, // 连接相邻的非空数据点
          markPoint: {
            data: lineData
              .map((value, idx) => ({
                value: !value || value === 0 ? "-" : null,
                xAxis: idx,
                yAxis: lineData[idx - 1],
                // yAxis: 0,
                // itemStyle: { color: color[index] }, // 高亮显示缺失值
              }))
              .filter((point) => point.value),
          },
        }));
      } else {
        series = content.map((lineData, index) => ({
          name: `${head[index]}`,
          type: "line",
          // data: lineData,
          data: lineData,
          connectNulls: true,
        }));
      }
      this.preChartData.seriesData = series;
      this.preChartData.xAxisData = content[0].map((_, index) => index);
    },
    // 图表设置
    handleResultChartOption(content, head, ismarkPoint) {
      this.resultChartData = {
        legendData: [],
        xAxisData: [],
        yAxisData: [],
        seriesData: [],
      };
      let series;
      if (ismarkPoint) {
        series = content.map((lineData, index) => ({
          name: `${head[index]}`,
          type: "line",
          data: lineData,
          connectNulls: true, // 连接相邻的非空数据点
          markPoint: {
            data: lineData
              .map((value, idx) => ({
                value: value || value === 0 ? "缺失" : null,
                xAxis: idx,
                yAxis: lineData[idx - 1],
                // yAxis: value,
                // itemStyle: { color: color[index] }, // 高亮显示缺失值
              }))
              .filter((point) => point.value),
          },
        }));
      } else {
        series = content.map((lineData, index) => ({
          name: `${head[index]}`,
          type: "line",
          data: lineData,
          connectNulls: true,
        }));
      }
      this.resultChartData.seriesData = series;
      this.resultChartData.xAxisData = content[0].map((_, index) => index);
      this.loading = false;
    },
    // 切换表格/曲线展示
    changeShow() {
      this.isTableShow = !this.isTableShow;
      if (!this.isTableShow) {
        this.handleFile(this.nowRow, this.nowTypeNum);
      } else {
        this.tableShow(this.resultFileId);
      }
    },
    tableShow(id) {
      // const url = `${process.env.VUE_APP_BASE_API}${path}`;
      getData(id).then((res) => {
        const url = `${process.env.VUE_APP_BASE_API}${res.data.dataPath}`;
        this.fetchLogFile(url).then((text) => {
          const data = text
            .split("\r\n")
            .filter((line) => line.trim() !== "")
            .map((row) => row.split(","));
          this.completionHeadData = data.shift();
          this.completionData = data.map((row) => {
            const rowData = {};
            for (let i = 0; i < this.completionHeadData.length; i++) {
              rowData[`val${i}`] = row[i] === 0 ? null : row[i];
            }
            return rowData;
          });
        });
      });
    },
    imgShow(url, dataType) {
      this.fileType = dataType;
      this.imgPreviewUrl = url;
      this.fileShowVisible = true;
    },
  },
};
</script>

<style scoped lang="scss">
@import "./index.scss";
</style>
