<template>
  <div class="app download">
    <div class="download-bg"></div>
    <div class="download-body">
      <div class="download-content">
        <div class="school-logo">
          <img :src="info.logo" :alt="info.name" />
        </div>
        <div class="download-logo">
          <img src="./assets/logo.png" alt="客户端" />
        </div>
        <h1 class="download-title">在线考试客户端</h1>
        <p class="download-version">版本号：{{ info.version.name }}</p>
        <div class="btn-primary" @click="toDownload">点击下载</div>
      </div>
    </div>
  </div>
</template>

<script>
import { getSchoolInfo } from "./api";

function getParam(paramName) {
  const hs = window.location.href.split(/\?|&/);
  const validh = hs.find((item) => item.startsWith(paramName));
  if (!validh) return;
  return validh.split("=")[1];
}

export default {
  name: "app",
  data() {
    return {
      info: {
        name: "",
        logo: "",
        packagePath: "",
        version: {
          name: "",
        },
      },
    };
  },
  created() {
    this.getData();
  },
  methods: {
    async getData() {
      const code = getParam("code");
      if (!code) {
        window.alert("学校code丢失！");
        return;
      }
      const res = await getSchoolInfo(code);
      this.info = res.data.data;
    },
    toDownload() {
      window.open(this.info.packagePath);
    },
  },
};
</script>
