Commit 75d91a7d9d81976403db437c7a5afbc84235720e

Authored by fengwotao
1 parent ab900665

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

... ... @@ -80,7 +80,10 @@
80 80 // import { useUserStore } from '/@/store/modules/user';
81 81 import { getPlatForm } from '/@/api/oem/index';
82 82 import defaultShowLogoImg from '/@/assets/svg/login-bg.svg';
  83 + import defaultShowLogoDarkImg from '/@/assets/svg/login-bg-dark.svg';
83 84 import { useTitle } from '@vueuse/core';
  85 + import { createLocalStorage } from '/@/utils/cache';
  86 + // import {usePlatform} from '/@/views/system/customize/hook/usePlatformInfo'
84 87
85 88 defineProps({
86 89 sessionTimeout: {
... ... @@ -91,8 +94,14 @@
91 94 const defaultTitle = ref('');
92 95 const defaultLogo = ref('');
93 96 const logoUrl = ref('');
  97 + // const userStore = useUserStore();
  98 + const storage = createLocalStorage();
  99 +
94 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 105 logoUrl.value = res?.background;
97 106 defaultTitle.value = res?.name || title;
98 107 defaultLogo.value = res?.logo;
... ... @@ -100,13 +109,38 @@
100 109 document.createElement('link')) as HTMLLinkElement;
101 110 link.type = 'image/x-icon';
102 111 link.rel = 'shortcut icon';
103   - link.href = res.icon ?? '/favicon.ico';
  112 + link.href = res?.icon ?? '/favicon.ico';
104 113 document.getElementsByTagName('head')[0].appendChild(link);
  114 + let defaultLogoBg = document.createElement('style');
  115 + let defaultLogoDarkBg = document.createElement('style');
105 116 if (logoUrl.value !== undefined) {
  117 + //企业自定义
106 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 129 } else {
108 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 146 // const userStore = useUserStore();
... ... @@ -200,9 +234,8 @@
200 234 width: 100%;
201 235 height: 100%;
202 236 margin-left: -48%;
203   - background-image: v-bind(logourl);
204   - // background-image: url(/@/assets/svg/login-bg.svg);
205 237 background-position: 100%;
  238 + // background-image: url(/@/assets/svg/login-bg.svg);
206 239 background-repeat: no-repeat;
207 240 background-size: auto 100%;
208 241 content: '';
... ...
1 1 import { getPlatForm } from '/@/api/oem';
  2 +import { createLocalStorage } from '/@/utils/cache';
2 3
3 4 enum DefaultPlatform {
4 5 LOGO = '/resource/img/logo.png',
... ... @@ -8,6 +9,16 @@ enum DefaultPlatform {
8 9
9 10 export const usePlatform = async () => {
10 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 23 const createLoadingEffect = () => {
13 24 const wrap = document.createElement('div');
... ...