Commit 75d91a7d9d81976403db437c7a5afbc84235720e

Authored by fengwotao
1 parent ab900665

pref:优化登录页背景图显示和重复请求

@@ -80,7 +80,10 @@ @@ -80,7 +80,10 @@
80 // import { useUserStore } from '/@/store/modules/user'; 80 // import { useUserStore } from '/@/store/modules/user';
81 import { getPlatForm } from '/@/api/oem/index'; 81 import { getPlatForm } from '/@/api/oem/index';
82 import defaultShowLogoImg from '/@/assets/svg/login-bg.svg'; 82 import defaultShowLogoImg from '/@/assets/svg/login-bg.svg';
  83 + import defaultShowLogoDarkImg from '/@/assets/svg/login-bg-dark.svg';
83 import { useTitle } from '@vueuse/core'; 84 import { useTitle } from '@vueuse/core';
  85 + import { createLocalStorage } from '/@/utils/cache';
  86 + // import {usePlatform} from '/@/views/system/customize/hook/usePlatformInfo'
84 87
85 defineProps({ 88 defineProps({
86 sessionTimeout: { 89 sessionTimeout: {
@@ -91,8 +94,14 @@ @@ -91,8 +94,14 @@
91 const defaultTitle = ref(''); 94 const defaultTitle = ref('');
92 const defaultLogo = ref(''); 95 const defaultLogo = ref('');
93 const logoUrl = ref(''); 96 const logoUrl = ref('');
  97 + // const userStore = useUserStore();
  98 + const storage = createLocalStorage();
  99 +
94 onMounted(async () => { 100 onMounted(async () => {
95 - const res = await getPlatForm(); 101 + let res = storage.get('platformInfo');
  102 + if (res === '' || res === null) {
  103 + res = await getPlatForm();
  104 + }
96 logoUrl.value = res?.background; 105 logoUrl.value = res?.background;
97 defaultTitle.value = res?.name || title; 106 defaultTitle.value = res?.name || title;
98 defaultLogo.value = res?.logo; 107 defaultLogo.value = res?.logo;
@@ -100,13 +109,38 @@ @@ -100,13 +109,38 @@
100 document.createElement('link')) as HTMLLinkElement; 109 document.createElement('link')) as HTMLLinkElement;
101 link.type = 'image/x-icon'; 110 link.type = 'image/x-icon';
102 link.rel = 'shortcut icon'; 111 link.rel = 'shortcut icon';
103 - link.href = res.icon ?? '/favicon.ico'; 112 + link.href = res?.icon ?? '/favicon.ico';
104 document.getElementsByTagName('head')[0].appendChild(link); 113 document.getElementsByTagName('head')[0].appendChild(link);
  114 + let defaultLogoBg = document.createElement('style');
  115 + let defaultLogoDarkBg = document.createElement('style');
105 if (logoUrl.value !== undefined) { 116 if (logoUrl.value !== undefined) {
  117 + //企业自定义
106 ifCustom.value = false; 118 ifCustom.value = false;
  119 + //默认图片
  120 + defaultLogoBg.innerHTML = `.vben-login::before{
  121 + background-image:url("");
  122 + position:absolute;
  123 + }`;
  124 + //切换黑暗模式图片
  125 + defaultLogoDarkBg.innerHTML = `html[data-theme='dark'] .vben-login::before{
  126 + background-image:url("");
  127 + position:absolute;
  128 + }`;
107 } else { 129 } else {
108 logoUrl.value = 'url(' + defaultShowLogoImg + ')'; 130 logoUrl.value = 'url(' + defaultShowLogoImg + ')';
  131 + //默认图片
  132 + defaultLogoBg.innerHTML = `.vben-login::before{
  133 + background-image:url(${defaultShowLogoImg});
  134 + position:absolute;
  135 + }`;
  136 + //切换黑暗模式图片
  137 + defaultLogoDarkBg.innerHTML = `html[data-theme='dark'] .vben-login::before{
  138 + background-image:url(${defaultShowLogoDarkImg});
  139 + position:absolute;
  140 + }`;
109 } 141 }
  142 + document.head.appendChild(defaultLogoBg);
  143 + document.head.appendChild(defaultLogoDarkBg);
110 }); 144 });
111 145
112 // const userStore = useUserStore(); 146 // const userStore = useUserStore();
@@ -200,9 +234,8 @@ @@ -200,9 +234,8 @@
200 width: 100%; 234 width: 100%;
201 height: 100%; 235 height: 100%;
202 margin-left: -48%; 236 margin-left: -48%;
203 - background-image: v-bind(logourl);  
204 - // background-image: url(/@/assets/svg/login-bg.svg);  
205 background-position: 100%; 237 background-position: 100%;
  238 + // background-image: url(/@/assets/svg/login-bg.svg);
206 background-repeat: no-repeat; 239 background-repeat: no-repeat;
207 background-size: auto 100%; 240 background-size: auto 100%;
208 content: ''; 241 content: '';
1 import { getPlatForm } from '/@/api/oem'; 1 import { getPlatForm } from '/@/api/oem';
  2 +import { createLocalStorage } from '/@/utils/cache';
2 3
3 enum DefaultPlatform { 4 enum DefaultPlatform {
4 LOGO = '/resource/img/logo.png', 5 LOGO = '/resource/img/logo.png',
@@ -8,6 +9,16 @@ enum DefaultPlatform { @@ -8,6 +9,16 @@ enum DefaultPlatform {
8 9
9 export const usePlatform = async () => { 10 export const usePlatform = async () => {
10 const platformInfo = await getPlatForm(); 11 const platformInfo = await getPlatForm();
  12 + const storage = createLocalStorage();
  13 + if (
  14 + platformInfo === '' ||
  15 + platformInfo === null ||
  16 + Object.getOwnPropertyNames(platformInfo).length === 0
  17 + ) {
  18 + storage.set('platformInfo', 1234);
  19 + } else {
  20 + storage.set('platformInfo', platformInfo);
  21 + }
11 22
12 const createLoadingEffect = () => { 23 const createLoadingEffect = () => {
13 const wrap = document.createElement('div'); 24 const wrap = document.createElement('div');