Showing
8 changed files
with
35 additions
and
24 deletions
... | ... | @@ -2,12 +2,12 @@ |
2 | 2 | * @Author: Vben |
3 | 3 | * @Description: logo component |
4 | 4 | --> |
5 | -<!-- TODO: appLogo --> | |
5 | + | |
6 | 6 | <template> |
7 | 7 | <div class="anticon" :class="getAppLogoClass" @click="goHome"> |
8 | - <img src="../../../assets/images/logo.png" /> | |
8 | + <img :src="getLogo" /> | |
9 | 9 | <div class="ml-2 md:opacity-100" :class="getTitleClass" v-show="showTitle"> |
10 | - {{ title }} | |
10 | + {{ getTitle }} | |
11 | 11 | </div> |
12 | 12 | </div> |
13 | 13 | </template> |
... | ... | @@ -55,6 +55,12 @@ |
55 | 55 | function goHome() { |
56 | 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 | 64 | </script> |
59 | 65 | <style lang="less" scoped> |
60 | 66 | @prefix-cls: ~'@{namespace}-app-logo'; | ... | ... |
... | ... | @@ -29,6 +29,7 @@ export const APP_LOCAL_CACHE_KEY = 'COMMON__LOCAL__KEY__'; |
29 | 29 | // base global session key |
30 | 30 | export const APP_SESSION_CACHE_KEY = 'COMMON__SESSION__KEY__'; |
31 | 31 | |
32 | +export const PLATFORM = 'PLATFORM'; | |
32 | 33 | export enum CacheTypeEnum { |
33 | 34 | SESSION, |
34 | 35 | LOCAL, | ... | ... |
... | ... | @@ -25,7 +25,7 @@ import { router } from '/@/router'; |
25 | 25 | import { usePermissionStore } from '/@/store/modules/permission'; |
26 | 26 | import { RouteRecordRaw } from 'vue-router'; |
27 | 27 | import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic'; |
28 | - | |
28 | +import { createLocalStorage } from '/@/utils/cache/index'; | |
29 | 29 | interface UserState { |
30 | 30 | platInfo: any; |
31 | 31 | userInfo: Nullable<UserInfo>; |
... | ... | @@ -41,7 +41,7 @@ export const useUserStore = defineStore({ |
41 | 41 | id: 'app-user', |
42 | 42 | state: (): UserState => ({ |
43 | 43 | //平台信息 |
44 | - platInfo: null, | |
44 | + platInfo: createLocalStorage().get('platformInfo') || null, | |
45 | 45 | // user info |
46 | 46 | userInfo: null, |
47 | 47 | // token |
... | ... | @@ -58,7 +58,7 @@ export const useUserStore = defineStore({ |
58 | 58 | |
59 | 59 | getters: { |
60 | 60 | getPlatInfo(): any { |
61 | - return this.platInfo; | |
61 | + return this.platInfo || getAuthCache('platInfo'); | |
62 | 62 | }, |
63 | 63 | getUserInfo(): UserInfo { |
64 | 64 | return this.userInfo || getAuthCache<UserInfo>(USER_INFO_KEY) || {}; | ... | ... |
... | ... | @@ -5,6 +5,7 @@ import type { RouteLocationNormalized } from 'vue-router'; |
5 | 5 | import { createLocalStorage, createSessionStorage } from '/@/utils/cache'; |
6 | 6 | import { Memory } from './memory'; |
7 | 7 | import { |
8 | + PLATFORM, | |
8 | 9 | TOKEN_KEY, |
9 | 10 | JWT_TOKEN_KEY, |
10 | 11 | REFRESH_TOKEN_KEY, |
... | ... | @@ -21,6 +22,7 @@ import { toRaw } from 'vue'; |
21 | 22 | import { pick, omit } from 'lodash-es'; |
22 | 23 | |
23 | 24 | interface BasicStore { |
25 | + [PLATFORM]: Object; | |
24 | 26 | [TOKEN_KEY]: string | number | null | undefined; |
25 | 27 | [JWT_TOKEN_KEY]: string | number | null | undefined; |
26 | 28 | [REFRESH_TOKEN_KEY]: string | number | null | undefined; | ... | ... |
... | ... | @@ -79,11 +79,10 @@ |
79 | 79 | const { t } = useI18n(); |
80 | 80 | const { notification, createErrorModal } = useMessage(); |
81 | 81 | const { prefixCls } = useDesign('login'); |
82 | - const userStore = useUserStore(); | |
83 | 82 | |
84 | 83 | const { setLoginState, getLoginState } = useLoginState(); |
85 | 84 | const { getFormRules } = useFormRules(); |
86 | - | |
85 | + const userStore = useUserStore(); | |
87 | 86 | const formRef = ref(); |
88 | 87 | const loading = ref(false); |
89 | 88 | |
... | ... | @@ -134,5 +133,15 @@ |
134 | 133 | } finally { |
135 | 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 | 147 | </script> | ... | ... |
... | ... | @@ -95,8 +95,7 @@ |
95 | 95 | import type { FileItem } from '/@/components/Upload/src/typing'; |
96 | 96 | import { logoUpload, iconUpload, bgUpload, getPlatForm, updatePlatForm } from '/@/api/oem/index'; |
97 | 97 | import { PlusOutlined } from '@ant-design/icons-vue'; |
98 | - import { createLocalStorage } from '/@/utils/cache/index'; | |
99 | - | |
98 | + import { useUserStore } from '/@/store/modules/user'; | |
100 | 99 | export default defineComponent({ |
101 | 100 | components: { |
102 | 101 | BasicForm, |
... | ... | @@ -113,6 +112,7 @@ |
113 | 112 | tip: '拼命加载中...', |
114 | 113 | }); |
115 | 114 | const { createMessage } = useMessage(); |
115 | + const userStore = useUserStore(); | |
116 | 116 | const [registerForm, { getFieldsValue, setFieldsValue }] = useForm({ |
117 | 117 | schemas, |
118 | 118 | showSubmitButton: false, |
... | ... | @@ -198,26 +198,18 @@ |
198 | 198 | try { |
199 | 199 | const fieldValue = getFieldsValue(); |
200 | 200 | compState.value.loading = true; |
201 | - await updatePlatForm({ | |
201 | + const newFieldValue = { | |
202 | 202 | ...fieldValue, |
203 | 203 | logo: unref(logoPic), |
204 | 204 | icon: unref(iconPic), |
205 | 205 | background: unref(bgPic), |
206 | - }); | |
206 | + }; | |
207 | + await updatePlatForm(newFieldValue); | |
207 | 208 | compState.value.loading = false; |
208 | 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 | 213 | } catch (e) { |
222 | 214 | createMessage.error('保存信息失败'); |
223 | 215 | } | ... | ... |