HistorySearchTable.vue 6.46 KB
<template>
  <div style="width: 100%;height: 100%;">
    <el-table
      v-if="tableData.length > 0"
      ref="singleTable"
      :data="tableData"
      :header-cell-style="{ textAlign: 'center' ,height:'100%',lineHeight:'100%' }"
      border
      height="calc(100% - 100px)"
      highlight-current-row
      @current-change="handleCurrentChange"
      style="width: 100%;text-align: center">
      <el-table-column
        type="index"
        fixed
        align="center"
        width="100"
        label="序号">
      </el-table-column>
      <el-table-column
        property="name"
        align="center"
        label="名称">
      </el-table-column>
      <el-table-column
        property="deviceId"
        align="center"
        label="设备">
      </el-table-column>
      <el-table-column
        property="channelName"
        align="center"
        label="通道名称">
      </el-table-column>
      <el-table-column
        align="center"
        label="日期">
        <template slot-scope="scope">
          {{`${scope.row.startTime}-${scope.row.endTime}`}}
        </template>
      </el-table-column>
      <el-table-column
        property="status"
        align="center"
        label="状态">
        <template slot-scope="scope">
          <span v-if="scope.row.status===null ||scope.row.status === '0'"><el-tag>未上传</el-tag></span>
          <span v-if="scope.row.status==='2'"><el-tag type="info">上传中</el-tag></span>
          <span v-if="scope.row.status==='3'"><el-tag type="success">已上传</el-tag></span>
        </template>
      </el-table-column>
      <el-table-column
        fixed="right"
        align="center"
        label="操作">
        <template slot-scope="scope">
          <el-button icon="el-icon-video-play" size="small" style="border: none" @click="playHistoryVideo(scope.row)"></el-button>
          <el-button v-if="scope.row.status === '0'" icon="el-icon-upload" size="small" style="border: none" @click="uploadHistoryVideo(scope.row)"></el-button>
          <el-button v-if="scope.row.status === '3'"
                     icon="el-icon-download"
                     :disabled="scope.row.disabled"
                     size="small" style="border: none"
                     @click="downloadHistoryVideo(scope.row)">
            {{ scope.row.disabled ? `${scope.row.countdown}s` : '' }}
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-empty v-else style="width: 100%;height: 100%"></el-empty>
  </div>
</template>

<script>
//这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等),
//例如:import 《组件名称》 from '《组件路径》,
  export default {
    //import引入的组件需要注入到对象中才能使用"
    name: "historySearchTable",
    components: {},
    props: {
      tableData: {
        type: Array,
        default: []
      }
    },
    data() {
      //这里存放数据"
      return {
        currentRow: null,
        historyTimer: null,
        countdown: 10, // 假设倒计时为10秒
        disabled: false
      };
    },
    //计算属性 类似于data概念",
    computed: {},
    //监控data中的数据变化",
    watch: {},
    //方法集合",
    methods: {
      /**
       * 选中行
       * @param val
       */
      handleCurrentChange(val) {
        this.currentRow = val;
      },
      setCurrent(row) {
        this.$refs.singleTable.setCurrentRow(row);
      },
      /**
       * 播放历史视频
       * @param row
       */
      playHistoryVideo(row){
        this.$emit("playHistoryVideo", row);
      },
      /**
       * 上传历史视频
       * @param row
       */
      uploadHistoryVideo(row){
        this.$emit('uploadHistoryVideo', row);
      },
      /**
       * 下载历史视频
       * @param row
       */
      downloadHistoryVideo(data){
        if (data.disabled) return;
        if (data.historyTimer){
          this.$message.warning("点击太频繁,请稍后重试")
          return;
        }
        data.disabled = true;
        data.countdown = 10; // 重置倒计时
        data.isCountingDown = true;
        const timer = setInterval(() => {
          if (data.countdown > 0) {
            data.countdown--;
          } else {
            clearInterval(timer);
            data.disabled = false;
            data.countdown = 10; // 重置倒计时
            data.isCountingDown = false;
          }
        }, 1000);
        data.historyTimer = timer; // 保存计时器引用
        /**
         * 下载历史视频
         */
        this.$axios({
          url: `/api/jt1078/query/history/download/${data.name}`, // 请求URL
          method: 'GET', // 将FTP文件路径作为参数传递
          responseType: 'blob', // 告知axios以二进制数据流的形式处理响应
        }).then((response) => {
          const blob = new Blob([response.data], { type: 'application/octet-stream' });
          const link = document.createElement('a');
          link.href = window.URL.createObjectURL(blob);
          link.download = data.name + ".mp4"; // 设置下载文件名
          document.body.appendChild(link);
          link.click();
          document.body.removeChild(link);
          clearInterval(timer);
          data.disabled = false;
          data.countdown = 10; // 重置倒计时
          data.isCountingDown = false;
          data.historyTimer = null;
          this.$message.success(`${link.download} 下载成功`);
        }).catch(error => {
          clearInterval(timer);
          data.disabled = false;
          data.countdown = 10; // 重置倒计时
          data.isCountingDown = false;
          data.historyTimer = null;
          this.$message.error(`${data.name} 下载失败`);
          console.error("下载失败", error);
        });
      }
    },
    //生命周期 - 创建完成(可以访问当前this实例)",
    created() {
    },
    //生命周期 - 挂载完成(可以访问DOM元素)",
    mounted() {
    },
    beforeCreate() {
    }, //生命周期 - 创建之前",
    beforeMount() {
    }, //生命周期 - 挂载之前",
    beforeUpdate() {
    }, //生命周期 - 更新之前",
    updated() {
    }, //生命周期 - 更新之后",
    beforeDestroy() {
      clearInterval(this.historyTimer)
    }, //生命周期 - 销毁之前",
    destroyed() {
    }, //生命周期 - 销毁完成",
    activated() {
    } //如果页面有keep-alive缓存功能,这个函数会触发",
  };
</script>
<style scoped>

</style>