Commit 0e686625a5cb847f38719458febd4b2431c2f303

Authored by sqy
1 parent e18b6398

'暫存oemLogo代碼,待解決本地緩存問題'

@@ -32,6 +32,7 @@ export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal') @@ -32,6 +32,7 @@ export function loginApi(params: LoginParams, mode: ErrorMessageMode = 'modal')
32 }, 32 },
33 { 33 {
34 errorMessageMode: mode, 34 errorMessageMode: mode,
  35 + joinPrefix: false,
35 } 36 }
36 ); 37 );
37 } 38 }
@@ -2,12 +2,12 @@ @@ -2,12 +2,12 @@
2 * @Author: Vben 2 * @Author: Vben
3 * @Description: logo component 3 * @Description: logo component
4 --> 4 -->
5 -<!-- TODO: appLogo --> 5 +
6 <template> 6 <template>
7 <div class="anticon" :class="getAppLogoClass" @click="goHome"> 7 <div class="anticon" :class="getAppLogoClass" @click="goHome">
8 - <img src="../../../assets/images/logo.png" /> 8 + <img :src="getLogo" />
9 <div class="ml-2 md:opacity-100" :class="getTitleClass" v-show="showTitle"> 9 <div class="ml-2 md:opacity-100" :class="getTitleClass" v-show="showTitle">
10 - {{ title }} 10 + {{ getTitle }}
11 </div> 11 </div>
12 </div> 12 </div>
13 </template> 13 </template>
@@ -55,6 +55,12 @@ @@ -55,6 +55,12 @@
55 function goHome() { 55 function goHome() {
56 go(userStore.getUserInfo.homePath || PageEnum.BASE_HOME); 56 go(userStore.getUserInfo.homePath || PageEnum.BASE_HOME);
57 } 57 }
  58 + const getLogo = computed(() => {
  59 + return userStore.platInfo.logo ?? '/src/assets/images/logo.png';
  60 + });
  61 + const getTitle = computed(() => {
  62 + return userStore.platInfo.name ?? title;
  63 + });
58 </script> 64 </script>
59 <style lang="less" scoped> 65 <style lang="less" scoped>
60 @prefix-cls: ~'@{namespace}-app-logo'; 66 @prefix-cls: ~'@{namespace}-app-logo';
@@ -29,6 +29,7 @@ export const APP_LOCAL_CACHE_KEY = 'COMMON__LOCAL__KEY__'; @@ -29,6 +29,7 @@ export const APP_LOCAL_CACHE_KEY = 'COMMON__LOCAL__KEY__';
29 // base global session key 29 // base global session key
30 export const APP_SESSION_CACHE_KEY = 'COMMON__SESSION__KEY__'; 30 export const APP_SESSION_CACHE_KEY = 'COMMON__SESSION__KEY__';
31 31
  32 +export const PLATFORM = 'PLATFORM';
32 export enum CacheTypeEnum { 33 export enum CacheTypeEnum {
33 SESSION, 34 SESSION,
34 LOCAL, 35 LOCAL,
@@ -25,7 +25,7 @@ import { router } from '/@/router'; @@ -25,7 +25,7 @@ import { router } from '/@/router';
25 import { usePermissionStore } from '/@/store/modules/permission'; 25 import { usePermissionStore } from '/@/store/modules/permission';
26 import { RouteRecordRaw } from 'vue-router'; 26 import { RouteRecordRaw } from 'vue-router';
27 import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic'; 27 import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic';
28 - 28 +import { createLocalStorage } from '/@/utils/cache/index';
29 interface UserState { 29 interface UserState {
30 platInfo: any; 30 platInfo: any;
31 userInfo: Nullable<UserInfo>; 31 userInfo: Nullable<UserInfo>;
@@ -41,7 +41,7 @@ export const useUserStore = defineStore({ @@ -41,7 +41,7 @@ export const useUserStore = defineStore({
41 id: 'app-user', 41 id: 'app-user',
42 state: (): UserState => ({ 42 state: (): UserState => ({
43 //平台信息 43 //平台信息
44 - platInfo: null, 44 + platInfo: createLocalStorage().get('platformInfo') || null,
45 // user info 45 // user info
46 userInfo: null, 46 userInfo: null,
47 // token 47 // token
@@ -58,7 +58,7 @@ export const useUserStore = defineStore({ @@ -58,7 +58,7 @@ export const useUserStore = defineStore({
58 58
59 getters: { 59 getters: {
60 getPlatInfo(): any { 60 getPlatInfo(): any {
61 - return this.platInfo; 61 + return this.platInfo || getAuthCache('platInfo');
62 }, 62 },
63 getUserInfo(): UserInfo { 63 getUserInfo(): UserInfo {
64 return this.userInfo || getAuthCache<UserInfo>(USER_INFO_KEY) || {}; 64 return this.userInfo || getAuthCache<UserInfo>(USER_INFO_KEY) || {};
@@ -5,6 +5,7 @@ import type { RouteLocationNormalized } from 'vue-router'; @@ -5,6 +5,7 @@ import type { RouteLocationNormalized } from 'vue-router';
5 import { createLocalStorage, createSessionStorage } from '/@/utils/cache'; 5 import { createLocalStorage, createSessionStorage } from '/@/utils/cache';
6 import { Memory } from './memory'; 6 import { Memory } from './memory';
7 import { 7 import {
  8 + PLATFORM,
8 TOKEN_KEY, 9 TOKEN_KEY,
9 JWT_TOKEN_KEY, 10 JWT_TOKEN_KEY,
10 REFRESH_TOKEN_KEY, 11 REFRESH_TOKEN_KEY,
@@ -21,6 +22,7 @@ import { toRaw } from 'vue'; @@ -21,6 +22,7 @@ import { toRaw } from 'vue';
21 import { pick, omit } from 'lodash-es'; 22 import { pick, omit } from 'lodash-es';
22 23
23 interface BasicStore { 24 interface BasicStore {
  25 + [PLATFORM]: Object;
24 [TOKEN_KEY]: string | number | null | undefined; 26 [TOKEN_KEY]: string | number | null | undefined;
25 [JWT_TOKEN_KEY]: string | number | null | undefined; 27 [JWT_TOKEN_KEY]: string | number | null | undefined;
26 [REFRESH_TOKEN_KEY]: string | number | null | undefined; 28 [REFRESH_TOKEN_KEY]: string | number | null | undefined;
@@ -79,11 +79,10 @@ @@ -79,11 +79,10 @@
79 const { t } = useI18n(); 79 const { t } = useI18n();
80 const { notification, createErrorModal } = useMessage(); 80 const { notification, createErrorModal } = useMessage();
81 const { prefixCls } = useDesign('login'); 81 const { prefixCls } = useDesign('login');
82 - const userStore = useUserStore();  
83 82
84 const { setLoginState, getLoginState } = useLoginState(); 83 const { setLoginState, getLoginState } = useLoginState();
85 const { getFormRules } = useFormRules(); 84 const { getFormRules } = useFormRules();
86 - 85 + const userStore = useUserStore();
87 const formRef = ref(); 86 const formRef = ref();
88 const loading = ref(false); 87 const loading = ref(false);
89 88
@@ -134,5 +133,15 @@ @@ -134,5 +133,15 @@
134 } finally { 133 } finally {
135 loading.value = false; 134 loading.value = false;
136 } 135 }
  136 +
  137 + const res = await getPlatForm();
  138 + userStore.setPlatInfo(res);
  139 + // 设置icon
  140 + let link = (document.querySelector("link[rel*='icon']") ||
  141 + document.createElement('link')) as HTMLLinkElement;
  142 + link.type = 'image/x-icon';
  143 + link.rel = 'shortcut icon';
  144 + link.href = res.icon ?? '/public/favicon.ico';
  145 + document.getElementsByTagName('head')[0].appendChild(link);
137 } 146 }
138 </script> 147 </script>
@@ -95,8 +95,7 @@ @@ -95,8 +95,7 @@
95 import type { FileItem } from '/@/components/Upload/src/typing'; 95 import type { FileItem } from '/@/components/Upload/src/typing';
96 import { logoUpload, iconUpload, bgUpload, getPlatForm, updatePlatForm } from '/@/api/oem/index'; 96 import { logoUpload, iconUpload, bgUpload, getPlatForm, updatePlatForm } from '/@/api/oem/index';
97 import { PlusOutlined } from '@ant-design/icons-vue'; 97 import { PlusOutlined } from '@ant-design/icons-vue';
98 - import { createLocalStorage } from '/@/utils/cache/index';  
99 - 98 + import { useUserStore } from '/@/store/modules/user';
100 export default defineComponent({ 99 export default defineComponent({
101 components: { 100 components: {
102 BasicForm, 101 BasicForm,
@@ -113,6 +112,7 @@ @@ -113,6 +112,7 @@
113 tip: '拼命加载中...', 112 tip: '拼命加载中...',
114 }); 113 });
115 const { createMessage } = useMessage(); 114 const { createMessage } = useMessage();
  115 + const userStore = useUserStore();
116 const [registerForm, { getFieldsValue, setFieldsValue }] = useForm({ 116 const [registerForm, { getFieldsValue, setFieldsValue }] = useForm({
117 schemas, 117 schemas,
118 showSubmitButton: false, 118 showSubmitButton: false,
@@ -198,26 +198,18 @@ @@ -198,26 +198,18 @@
198 try { 198 try {
199 const fieldValue = getFieldsValue(); 199 const fieldValue = getFieldsValue();
200 compState.value.loading = true; 200 compState.value.loading = true;
201 - await updatePlatForm({ 201 + const newFieldValue = {
202 ...fieldValue, 202 ...fieldValue,
203 logo: unref(logoPic), 203 logo: unref(logoPic),
204 icon: unref(iconPic), 204 icon: unref(iconPic),
205 background: unref(bgPic), 205 background: unref(bgPic),
206 - }); 206 + };
  207 + await updatePlatForm(newFieldValue);
207 compState.value.loading = false; 208 compState.value.loading = false;
208 createMessage.success('保存信息成功'); 209 createMessage.success('保存信息成功');
209 210
210 - // 保存一份数据到本地缓存中.  
211 - const storage = createLocalStorage();  
212 - storage.set('platformInfo', fieldValue);  
213 - //保存到store  
214 - // 设置icon  
215 - let link = (document.querySelector("link[rel*='icon']") ||  
216 - document.createElement('link')) as HTMLLinkElement;  
217 - link.type = 'image/x-icon';  
218 - link.rel = 'shortcut icon';  
219 - link.href = fieldValue.icon;  
220 - document.getElementsByTagName('head')[0].appendChild(link); 211 + userStore.platInfo = newFieldValue;
  212 + // console.log()
221 } catch (e) { 213 } catch (e) {
222 createMessage.error('保存信息失败'); 214 createMessage.error('保存信息失败');
223 } 215 }
@@ -190,7 +190,7 @@ export const schemas: FormSchema[] = [ @@ -190,7 +190,7 @@ export const schemas: FormSchema[] = [
190 colProps: { 190 colProps: {
191 span: 5, 191 span: 5,
192 style: { 192 style: {
193 - marginLeft: '-80px', 193 + marginLeft: '-5rem',
194 }, 194 },
195 }, 195 },
196 }, 196 },