From 0aec486291c1110cb414e97809f17fc187aba17d Mon Sep 17 00:00:00 2001 From: mhhhh Date: Tue, 31 May 2022 09:51:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9logo=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buyer/src/App.vue | 65 +++++++++++++++++++++++++++----------- manager/src/views/Main.vue | 59 ++++++++++++++++++++++++---------- 2 files changed, 88 insertions(+), 36 deletions(-) diff --git a/buyer/src/App.vue b/buyer/src/App.vue index e886fb2a..ae17ac3a 100644 --- a/buyer/src/App.vue +++ b/buyer/src/App.vue @@ -9,27 +9,54 @@ import storage from "@/plugins/storage"; import { getBaseSite } from "@/api/common.js"; export default { name: "App", - mounted() { - //获取基本站点信息 - getBaseSite().then((res) => { - if (res.success && res.result.settingValue) { - let data = JSON.parse(res.result.settingValue); - this.$store.commit("SET_LOGOIMG", data.buyerSideLogo); - this.$store.commit("SET_SITENAME", data.siteName); - storage.setItem("siteName", data.siteName); - window.document.title = data.siteName; - //动态获取icon - let link = - document.querySelector("link[rel*='icon']") || - document.createElement("link"); - link.type = "image/x-icon"; - link.href = data.buyerSideLogo; - link.rel = "shortcut icon"; - document.getElementsByTagName("head")[0].appendChild(link); - } - }); + this.init(); }, + methods:{ + init(){ + if(!localStorage.getItem("siteName")||!localStorage.getItem("logoImg")||!localStorage.getItem("sitelogo_expiration_time")) { + this.getSite(); + }else{ + // 如果缓存过期,则获取最新的信息 + if (new Date() > localStorage.getItem("sitelogo_expiration_time")) { + this.getSite(); + return; + }else{ + window.document.title = localStorage.getItem("siteName"); + //动态获取icon + let link =document.querySelector("link[rel*='icon']") ||document.createElement("link"); + link.type = "image/x-icon"; + link.href = localStorage.getItem("logoImg"); + link.rel = "shortcut icon"; + document.getElementsByTagName("head")[0].appendChild(link); + } + } + + }, + getSite(){ + //获取基本站点信息 + getBaseSite().then((res) => { + if (res.success && res.result.settingValue) { + let data = JSON.parse(res.result.settingValue); + // 过期时间 + var expirationTime = new Date().setHours(new Date().getHours() + 1); + // 存放过期时间 + localStorage.setItem("sitelogo_expiration_time", expirationTime); + // 存放信息 + localStorage.setItem('siteName', data.siteName); + localStorage.setItem('logoImg', data.buyerSideLogo); + + window.document.title = data.siteName; + //动态获取icon + let link =document.querySelector("link[rel*='icon']") ||document.createElement("link"); + link.type = "image/x-icon"; + link.href = data.buyerSideLogo; + link.rel = "shortcut icon"; + document.getElementsByTagName("head")[0].appendChild(link); + } + }); + } + } };