zxl
19 小时以前 172933f098017bc4c4f57dcda0d490ea12bb13bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<template>
  <div>
    <Row class="header">
      <img :src="domainLogo" class="logo" width="220px" />
    </Row>
  </div>
</template>
 
<script>
import { getBaseSite } from "@/api/common.js";
export default {
  data() {
    return {
      domainLogo: require("@/assets/logo.png"),
    };
  },
  methods: {
    init() {
      if (
        !localStorage.getItem("icon") ||
        !localStorage.getItem("title") ||
        !localStorage.getItem("icontitle_expiration_time")
      ) {
        this.getSite();
      } else {
        // 如果缓存过期,则获取最新的信息
        if (new Date() > localStorage.getItem("icontitle_expiration_time")) {
          this.getSite();
          return;
        } else {
          this.domainLogo = localStorage.getItem("icon");
          let link =
            document.querySelector("link[rel*='icon']") ||
            document.createElement("link");
          link.type = "image/x-icon";
          link.href = localStorage.getItem("icon");
          link.rel = "shortcut icon";
          document.getElementsByTagName("head")[0].appendChild(link);
          window.document.title = localStorage.getItem("title") + " - 运营后台";
        }
      }
    },
    getSite() {
      //获取domainLogo
      getBaseSite().then((res) => {
        const { domainLogo, domainIcon, siteName } = JSON.parse(res.result.settingValue);
        this.domainLogo = domainLogo;
        // 过期时间
        var expirationTime = new Date().setHours(new Date().getHours() + 1);
        // 存放过期时间
        localStorage.setItem("icontitle_expiration_time", expirationTime);
        // 存放信息
        localStorage.setItem("icon", domainLogo);
        localStorage.setItem("domainIcon", domainIcon);
        localStorage.setItem("title", siteName);
        let link =
          document.querySelector("link[rel*='icon']") ||
          document.createElement("link");
        link.type = "image/x-icon";
        link.href = domainLogo;
        link.rel = "shortcut icon";
        document.getElementsByTagName("head")[0].appendChild(link);
        window.document.title = siteName + " - 运营后台";
      });
    },
  },
  mounted() {
    this.init();
  },
};
</script>
 
<style lang="scss" scoped>
.header {
  margin-bottom: 6vh;
  text-align: center;
  display: flex;
  justify-content: center !important;
}
.logo {
  width: 440px;
  height: 158px;
}
</style>