🐛 修复技术栈图表初始化时序并保留首屏占位
This commit is contained in:
@@ -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);
|
|
||||||
|
const iconStore = useIconStore();
|
||||||
|
|
||||||
|
await Promise.all((props.techStackIconNames as string[]).map((iconName) =>
|
||||||
|
iconStore.setIconInfo(iconName),
|
||||||
|
));
|
||||||
|
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);
|
colorModeCallBackKey = useColorModeStore().registerCallBack(renderChart);
|
||||||
watch(pending, (isPending) => {
|
|
||||||
if (!isPending) {
|
|
||||||
// 数据加载完成后的回调逻辑
|
|
||||||
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"
|
||||||
|
|||||||
@@ -94,25 +94,16 @@ 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">
|
<TechStackCard
|
||||||
<USkeleton class="h-4 mb-3 w-full bg-old-neutral-600"/>
|
:tech-stack="metaData?.tech_stack"
|
||||||
<USkeleton class="h-4 mb-3 w-full bg-old-neutral-600"/>
|
:tech-stack-icon-names="metaData?.tech_stack_icon_names"
|
||||||
<USkeleton class="h-4 mb-3 w-full bg-old-neutral-600"/>
|
:tech-stack-theme-colors="metaData?.tech_stack_theme_colors"
|
||||||
</div>
|
:tech-stack-percent="metaData?.tech_stack_percent"
|
||||||
<div v-if="mounted" class="">
|
class="lg:min-w-64 w-0 transition-[width] duration-500"
|
||||||
<TechStackCard
|
/>
|
||||||
:async-key="'stack:' + metaData?.id"
|
|
||||||
:tech-stack="metaData?.tech_stack"
|
|
||||||
:tech-stack-icon-names="metaData?.tech_stack_icon_names"
|
|
||||||
:tech-stack-theme-colors="metaData?.tech_stack_theme_colors"
|
|
||||||
:tech-stack-percent="metaData?.tech_stack_percent"
|
|
||||||
class="lg:w-64 w-0 transition-[width] duration-500"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<div v-else class="min-w-64"/>
|
|
||||||
</div>
|
</div>
|
||||||
<hr/>
|
<hr/>
|
||||||
<div class="flex mt-2">
|
<div class="flex mt-2">
|
||||||
|
|||||||
Reference in New Issue
Block a user