Commit 5eddcd3d1716c338e5ce2e3307e31057be470711
1 parent
fbd61b48
perf(src/components): 优化个人头像展示和web站点icon显示
Showing
3 changed files
with
34 additions
and
14 deletions
| ... | ... | @@ -29,9 +29,10 @@ import { GoSystemInfo } from '@/components/GoSystemInfo/index' |
| 29 | 29 | import { icon } from '@/plugins' |
| 30 | 30 | import { useUserStore } from '@/store/external/modules/user' |
| 31 | 31 | import { useSyncRemote } from '@/views/chart/hooks/external/useRemote.hook' |
| 32 | -import { getPlatformInfo } from '@/api/external/common' | |
| 33 | 32 | import Person from './person.png' |
| 34 | -import DefaultWebsiteIcon from '../../../../public/favicon.ico' | |
| 33 | +import { useSetWebsiteIcon } from '@/hooks/external/useSetWebsiteIcon.hook' | |
| 34 | + | |
| 35 | +const { getPlatform } = useSetWebsiteIcon() | |
| 35 | 36 | |
| 36 | 37 | const { PersonIcon, LogOutOutlineIcon, SettingsSharpIcon } = icon.ionicons5 |
| 37 | 38 | |
| ... | ... | @@ -85,18 +86,6 @@ onMounted(() => { |
| 85 | 86 | } |
| 86 | 87 | }) |
| 87 | 88 | |
| 88 | -const getPlatform = async () => { | |
| 89 | - const rest = await getPlatformInfo() | |
| 90 | - replaceWebsiteIcon(rest?.icon) | |
| 91 | -} | |
| 92 | - | |
| 93 | -const replaceWebsiteIcon = (icon: string) => { | |
| 94 | - const linkEl = document.querySelectorAll('link[rel*="icon"]') | |
| 95 | - linkEl.forEach(item => { | |
| 96 | - item.setAttribute('href', icon || DefaultWebsiteIcon) | |
| 97 | - }) | |
| 98 | -} | |
| 99 | - | |
| 100 | 89 | const options = ref([ |
| 101 | 90 | { |
| 102 | 91 | label: '我的信息', | ... | ... |
src/hooks/external/useSetWebsiteIcon.hook.ts
0 → 100644
| 1 | +import DefaultWebsiteIcon from '../../../public/favicon.ico' | |
| 2 | +import { getPlatformInfo } from '@/api/external/common' | |
| 3 | + | |
| 4 | +export const useSetWebsiteIcon = () => { | |
| 5 | + const getPlatform = async () => { | |
| 6 | + //防止接口报错阻塞页面 | |
| 7 | + try { | |
| 8 | + const rest = await getPlatformInfo() | |
| 9 | + replaceWebsiteIcon(rest?.icon || DefaultWebsiteIcon) | |
| 10 | + } finally { | |
| 11 | + console.log() | |
| 12 | + } | |
| 13 | + } | |
| 14 | + | |
| 15 | + const replaceWebsiteIcon = (icon: string) => { | |
| 16 | + const linkEl = document.querySelectorAll('link[rel*="icon"]') | |
| 17 | + linkEl.forEach(item => { | |
| 18 | + item.setAttribute('href', icon) | |
| 19 | + }) | |
| 20 | + } | |
| 21 | + return { | |
| 22 | + getPlatform | |
| 23 | + } | |
| 24 | +} | ... | ... |
| ... | ... | @@ -16,11 +16,18 @@ import 'vue3-sketch-ruler/lib/style.css' |
| 16 | 16 | |
| 17 | 17 | // THINGS_KIT 内容安全协议hook |
| 18 | 18 | import { useWebSecurityPolicy } from './hooks/external/useWebSecurityPolicy' |
| 19 | +// THINGS_KIT web站点icon设置hook | |
| 20 | +import { useSetWebsiteIcon } from '@/hooks/external/useSetWebsiteIcon.hook' | |
| 21 | + | |
| 19 | 22 | |
| 20 | 23 | async function appInit() { |
| 21 | 24 | // THINGS_KIT 内容安全协议hook |
| 22 | 25 | useWebSecurityPolicy() |
| 23 | 26 | |
| 27 | + // THINGS_KIT web站点icon设置hook | |
| 28 | + const { getPlatform } = useSetWebsiteIcon() | |
| 29 | + getPlatform() | |
| 30 | + | |
| 24 | 31 | const goAppProvider = createApp(GoAppProvider) |
| 25 | 32 | |
| 26 | 33 | const app = createApp(App) | ... | ... |