修改logo缓存

master
mhhhh 2022-05-31 11:04:40 +08:00
commit 21289f5a92
2 changed files with 88 additions and 36 deletions

View File

@ -9,27 +9,54 @@ import storage from "@/plugins/storage";
import { getBaseSite } from "@/api/common.js"; import { getBaseSite } from "@/api/common.js";
export default { export default {
name: "App", name: "App",
mounted() { mounted() {
// this.init();
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);
}
});
}, },
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);
}
});
}
}
}; };
</script> </script>
<style lang="scss"> <style lang="scss">

View File

@ -129,24 +129,27 @@ export default {
if (currWidth <= 1200) { if (currWidth <= 1200) {
this.sliceNum = 2; this.sliceNum = 2;
} }
//domainLogo
getBaseSite().then((res) => {
const { domainLogo, siteName } = JSON.parse(res.result.settingValue);
this.domainLogo = domainLogo; if(!localStorage.getItem("icon")||!localStorage.getItem("title")||!localStorage.getItem("icontitle_expiration_time")) {
//icon this.getSite();
this.setStore("icon", this.domainLogo); }else{
let link = //
document.querySelector("link[rel*='icon']") || if (new Date() > localStorage.getItem("icontitle_expiration_time")) {
document.createElement("link"); this.getSite();
link.type = "image/x-icon"; return;
link.href = this.domainLogo; }else{
link.rel = "shortcut icon"; this.domainLogo = localStorage.getItem("icon");
document.getElementsByTagName("head")[0].appendChild(link); let link =
//siteName document.querySelector("link[rel*='icon']") ||
this.setStore("title", siteName); document.createElement("link");
window.document.title = siteName + " - 运营后台"; 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") + " - 运营后台";
}
}
// //
getNoticePage({}).then((res) => { 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) { handleClickUserDropdown(name) {
// //