修改logo接口缓存
parent
f19071542a
commit
0aec486291
|
@ -9,27 +9,54 @@ import storage from "@/plugins/storage";
|
|||
import { getBaseSite } from "@/api/common.js";
|
||||
export default {
|
||||
name: "App",
|
||||
|
||||
mounted() {
|
||||
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);
|
||||
this.$store.commit("SET_LOGOIMG", data.buyerSideLogo);
|
||||
this.$store.commit("SET_SITENAME", data.siteName);
|
||||
storage.setItem("siteName", data.siteName);
|
||||
// 过期时间
|
||||
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");
|
||||
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);
|
||||
}
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<style lang="scss">
|
||||
|
|
|
@ -129,24 +129,27 @@ export default {
|
|||
if (currWidth <= 1200) {
|
||||
this.sliceNum = 2;
|
||||
}
|
||||
//获取domainLogo
|
||||
getBaseSite().then((res) => {
|
||||
const { domainLogo, siteName } = JSON.parse(res.result.settingValue);
|
||||
|
||||
this.domainLogo = domainLogo;
|
||||
//动态获取icon
|
||||
this.setStore("icon", this.domainLogo);
|
||||
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 = this.domainLogo;
|
||||
link.href = localStorage.getItem("icon");
|
||||
link.rel = "shortcut icon";
|
||||
document.getElementsByTagName("head")[0].appendChild(link);
|
||||
//动态获取siteName
|
||||
this.setStore("title", siteName);
|
||||
window.document.title = siteName + " - 运营后台";
|
||||
}),
|
||||
window.document.title = localStorage.getItem("title") + " - 运营后台";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 读取未读消息数
|
||||
getNoticePage({}).then((res) => {
|
||||
|
@ -157,6 +160,28 @@ export default {
|
|||
}
|
||||
});
|
||||
},
|
||||
getSite(){
|
||||
//获取domainLogo
|
||||
getBaseSite().then((res) => {
|
||||
const { domainLogo, 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('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 + " - 运营后台";
|
||||
})
|
||||
},
|
||||
//用户头像下方抽屉点击
|
||||
handleClickUserDropdown(name) {
|
||||
//个人中心
|
||||
|
|
Loading…
Reference in New Issue