<template>
  <layout :back-handle="toBack"> </layout>
</template>

<script>
import Layout from "./Layout.vue";
import uploadTaskMixin from "../mixins/uploadTaskMixin";
import setTimeMixins from "../mixins/setTimeMixins";
import db from "../plugins/db";

export default {
  name: "home",
  mixins: [uploadTaskMixin, setTimeMixins],
  components: { Layout },
  data() {
    return {};
  },
  created() {
    this.initUploadTask();
    this.updateUnuploadCount();
  },
  methods: {
    // unupload count
    async updateUnuploadCount() {
      this.clearSetTs();
      const unuploadNo = await db.countScanList({ isUpload: 0 });
      this.$store.commit("client/setUnuploadNo", unuploadNo);
      this.addSetTime(() => {
        this.updateUnuploadCount();
      }, 2 * 1000);
    },
    toBack() {
      if (this.$route.name === "TaskManage") {
        this.$confirm("确定要退出采集吗?", "提示", {
          type: "warning"
        })
          .then(() => {
            this.$router.go(-1);
          })
          .catch(() => {});
      } else {
        this.$router.go(-1);
      }
    }
  },
  beforeDestroy() {
    this.stopUpload();
    this.clearSetTs();
  }
};
</script>
