🐛 修复技术栈图表初始化时序并保留首屏占位

This commit is contained in:
2026-11-16 23:08:27 +08:00
parent ea7fcb25ab
commit 4d8258ffe1
4 changed files with 40 additions and 54 deletions
+31 -35
View File
@@ -1,13 +1,13 @@
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, ref } from 'vue'; import { onMounted, ref } from 'vue';
import Highcharts from 'highcharts'; import Highcharts from 'highcharts';
import { DataAnomaly } from '~/types/PostMetaData'; import type { DataAnomaly } from '~/types/PostMetaData';
import 'overlayscrollbars/overlayscrollbars.css'; import 'overlayscrollbars/overlayscrollbars.css';
import useColorModeStore from '~/stores/colorModeStore'; import useColorModeStore from '~/stores/colorModeStore';
import useIconStore from '~/stores/iconStore'; import useIconStore from '~/stores/iconStore';
const props = withDefaults(defineProps<{ const props = withDefaults(defineProps<{
asyncKey: string; // asyncKey: string;
techStack?: string[] | DataAnomaly; techStack?: string[] | DataAnomaly;
techStackPercent?: number[] | DataAnomaly; techStackPercent?: number[] | DataAnomaly;
techStackIconNames?: string[] | DataAnomaly; techStackIconNames?: string[] | DataAnomaly;
@@ -25,19 +25,10 @@ const techStackDarkIconSVG = ref<string[]>([]);
const { colorMode } = storeToRefs(useColorModeStore()); const { colorMode } = storeToRefs(useColorModeStore());
// 没有这个 asyncKey 会加载不出正确的图标 // 没有这个 asyncKey 会加载不出正确的图标
const { pending } = useAsyncData(props.asyncKey, async () => { // const { pending } = useAsyncData(props.asyncKey, async () => {
if (props.techStackIconNames === DataAnomaly.DataNotFound || props.techStackIconNames === DataAnomaly.Invalid) // if (props.techStackIconNames === DataAnomaly.DataNotFound || props.techStackIconNames === DataAnomaly.Invalid)
return []; // return [];
const iconStore = useIconStore(); // });
for (const iconName of props.techStackIconNames) {
await iconStore.setIconInfo(iconName);
}
for (const iconName of props.techStackIconNames) {
techStackLightIconSVG.value.push(iconStore.getColoredIcon(iconName, '#666'));
techStackDarkIconSVG.value.push(iconStore.getColoredIcon(iconName, '#aaa'));
}
return [];
});
function toPercent(num: number | undefined): string { function toPercent(num: number | undefined): string {
if (num === undefined || isNaN(num)) return '0%'; if (num === undefined || isNaN(num)) return '0%';
@@ -46,7 +37,7 @@ function toPercent(num: number | undefined): string {
return (rounded === 0 ? '0' : rounded.toFixed(2).replace(/\.?0+$/, '')) + '%'; return (rounded === 0 ? '0' : rounded.toFixed(2).replace(/\.?0+$/, '')) + '%';
} }
const noDataAvailable = ref(false); const noDataAvailable = ref(true);
const renderChart = () => { const renderChart = () => {
const techStack = props.techStack as string[]; const techStack = props.techStack as string[];
const techStackPercent = props.techStackPercent as number[]; const techStackPercent = props.techStackPercent as number[];
@@ -140,22 +131,27 @@ const renderChart = () => {
}; };
let colorModeCallBackKey = ''; let colorModeCallBackKey = '';
onMounted(() => { onMounted(async () => {
if (props.techStack === DataAnomaly.DataNotFound || props.techStack === DataAnomaly.Invalid if ([props.techStack, props.techStackPercent, props.techStackIconNames, props.techStackThemeColors].some((x) => !Array.isArray(x)
|| props.techStackPercent === DataAnomaly.DataNotFound || props.techStackPercent === DataAnomaly.Invalid || x.length === 0)) {
|| props.techStackThemeColors === DataAnomaly.DataNotFound || props.techStackThemeColors === DataAnomaly.Invalid
|| props.techStack.length === 0 || props.techStackPercent.length === 0 || props.techStackThemeColors.length === 0) {
noDataAvailable.value = true;
return; return;
} }
// window.addEventListener('resize', renderChart);
colorModeCallBackKey = useColorModeStore().registerCallBack(renderChart); const iconStore = useIconStore();
watch(pending, (isPending) => {
if (!isPending) { await Promise.all((props.techStackIconNames as string[]).map((iconName) =>
// 数据加载完成后的回调逻辑 iconStore.setIconInfo(iconName),
renderChart(); ));
for (const iconName of props.techStackIconNames) {
techStackLightIconSVG.value.push(iconStore.getColoredIcon(iconName, '#666'));
techStackDarkIconSVG.value.push(iconStore.getColoredIcon(iconName, '#aaa'));
} }
}); noDataAvailable.value = false;
await nextTick();
renderChart();
colorModeCallBackKey = useColorModeStore().registerCallBack(renderChart);
}); });
onUnmounted(() => { onUnmounted(() => {
@@ -163,15 +159,15 @@ onUnmounted(() => {
useColorModeStore().unregisterCallBack(colorModeCallBackKey); useColorModeStore().unregisterCallBack(colorModeCallBackKey);
}); });
const mounted = ref(false); // const mounted = ref(false);
onMounted(() => { // onMounted(() => {
mounted.value = true; // mounted.value = true;
}); // });
</script> </script>
<template> <template>
<div class="h-full"> <div class="h-full">
<div v-if="!mounted||noDataAvailable" class="flex items-center justify-center h-full p-8"> <div v-if="noDataAvailable" class="flex items-center justify-center h-full p-8">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 112.01"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 112.01">
<g id="_图层_1" data-name="图层 1"> <g id="_图层_1" data-name="图层 1">
<polyline <polyline
@@ -189,7 +185,7 @@ onMounted(() => {
</g> </g>
<g id="_图层_2" data-name="图层 2"> <g id="_图层_2" data-name="图层 2">
<text <text
class="[font-family:ArialMT,Arial] text-xl stroke-old-neutral-600 dark:stroke-old-neutral-400 fill-old-neutral-600 dark:fill-old-neutral-400" class="font-[ArialMT,Arial] text-xl stroke-old-neutral-600 dark:stroke-old-neutral-400 fill-old-neutral-600 dark:fill-old-neutral-400"
transform="translate(89.48 61.61)"> transform="translate(89.48 61.61)">
<tspan x="0" y="0">No Data</tspan> <tspan x="0" y="0">No Data</tspan>
</text> </text>
@@ -18,7 +18,7 @@ onMounted(() => {
<div class="light:bg-old-neutral-200 dark:bg-old-neutral-800 p-5 mt-3"> <div class="light:bg-old-neutral-200 dark:bg-old-neutral-800 p-5 mt-3">
<div class="text-2xl pb-2">技术栈(相对熟练度)</div> <div class="text-2xl pb-2">技术栈(相对熟练度)</div>
<TechStackCard <TechStackCard
v-if="mounted" async-key="about page" :tech-stack="techStack" :tech-stack="techStack"
:tech-stack-percent="techStackPercent" :tech-stack-icon-names="techStackIconNames" :tech-stack-percent="techStackPercent" :tech-stack-icon-names="techStackIconNames"
:tech-stack-theme-colors="techStackThemeColors"/> :tech-stack-theme-colors="techStackThemeColors"/>
</div> </div>
@@ -140,7 +140,6 @@ onMounted(() => {
> >
<TechStackCard <TechStackCard
v-if="breakpointsHelper.greater('lg').value" v-if="breakpointsHelper.greater('lg').value"
:async-key="'stack:' + metaData.id"
:tech-stack="metaData.tech_stack" :tech-stack="metaData.tech_stack"
:tech-stack-icon-names="metaData.tech_stack_icon_names" :tech-stack-icon-names="metaData.tech_stack_icon_names"
:tech-stack-theme-colors="metaData.tech_stack_theme_colors" :tech-stack-theme-colors="metaData.tech_stack_theme_colors"
+2 -11
View File
@@ -94,26 +94,17 @@ onMounted(() => {
</div> </div>
<div class="flex mt-2 justify-between h-28"> <div class="flex mt-2 justify-between h-28">
<easy-scroll-bar v-if="mounted"> <easy-scroll-bar>
{{ metaData?.description }} {{ metaData?.description }}
</easy-scroll-bar> </easy-scroll-bar>
<div v-else class="w-4/5">
<USkeleton class="h-4 mb-3 w-full bg-old-neutral-600"/>
<USkeleton class="h-4 mb-3 w-full bg-old-neutral-600"/>
<USkeleton class="h-4 mb-3 w-full bg-old-neutral-600"/>
</div>
<div v-if="mounted" class="">
<TechStackCard <TechStackCard
:async-key="'stack:' + metaData?.id"
:tech-stack="metaData?.tech_stack" :tech-stack="metaData?.tech_stack"
:tech-stack-icon-names="metaData?.tech_stack_icon_names" :tech-stack-icon-names="metaData?.tech_stack_icon_names"
:tech-stack-theme-colors="metaData?.tech_stack_theme_colors" :tech-stack-theme-colors="metaData?.tech_stack_theme_colors"
:tech-stack-percent="metaData?.tech_stack_percent" :tech-stack-percent="metaData?.tech_stack_percent"
class="lg:w-64 w-0 transition-[width] duration-500" class="lg:min-w-64 w-0 transition-[width] duration-500"
/> />
</div> </div>
<div v-else class="min-w-64"/>
</div>
<hr/> <hr/>
<div class="flex mt-2"> <div class="flex mt-2">
<div title="创建时间" class="flex items-center"> <div title="创建时间" class="flex items-center">