<template>
  <div class="home">
    <div class="home-head">
      <div class="head-title">档案电子化扫描系统</div>
      <div class="head-actions">
        <span class="action-icon" title="返回" @click="toBack">
          <i class="el-icon-arrow-left"></i>
        </span>
        <span class="action-icon" title="最小化" @click="minWin">
          <i class="el-icon-minus"></i>
        </span>
        <span class="action-icon" title="最大化" @click="maxWin">
          <i class="el-icon-files"></i>
        </span>
        <span class="action-icon" title="关闭" @click="close">
          <i class="el-icon-close"></i>
        </span>
        <span
          v-if="isDev"
          class="action-icon action-logout"
          @click="logout"
          title="退出"
        >
          <i class="el-icon-switch-button"></i>
        </span>
      </div>
    </div>
    <div class="home-body">
      <router-view />
    </div>
    <div v-if="showFooter" class="home-footer">
      <div class="home-footer-ip">
        <i class="el-icon-monitor"></i><span>{{ domain || "0.0.0.0" }}</span>
      </div>
      <div class="home-footer-version">版本号：{{ version }}</div>
    </div>
  </div>
</template>

<script>
const { ipcRenderer } = require("electron");
const pkInfo = require("../../package.json");

export default {
  name: "layout",
  props: {
    backHandle: {
      type: Function
    },
    showFooter: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      isDev: process.env.NODE_ENV === "development",
      version: pkInfo.version
    };
  },
  computed: {
    domain() {
      return this.$store.state.domain;
    }
  },
  methods: {
    logout() {
      this.$router.push({ name: "Login" });
    },
    toBack() {
      if (this.backHandle && typeof this.backHandle === "function") {
        this.backHandle();
      } else {
        window.history.go(-1);
      }
    },
    minWin() {
      ipcRenderer.send("minimize-window");
    },
    maxWin() {
      ipcRenderer.send("maximize-window");
    },
    close() {
      this.$confirm(
        "请确保当前窗口没有任务正在进行，确认要关闭当前窗口吗？",
        "提示",
        {
          type: "warning"
        }
      )
        .then(() => {
          ipcRenderer.send("close-window");
        })
        .catch(() => {});
    }
  }
};
</script>
