[BugFix] Fix a bug when one of the datalist is unconnected then all page will go to 404

This commit is contained in:
majiayu000
2023-10-26 19:43:29 +08:00
parent a606f7cd94
commit 5945f98684

View File

@@ -1,26 +1,23 @@
<template> <template>
<n-card <n-card hoverable class="hot-list" :header-style="{ padding: '16px' }" :content-style="{ padding: '0 16px' }"
hoverable :footer-style="{ padding: '16px' }" @click="toList">
class="hot-list"
:header-style="{ padding: '16px' }"
:content-style="{ padding: '0 16px' }"
:footer-style="{ padding: '16px' }"
@click="toList"
>
<template #header> <template #header>
<Transition name="fade" mode="out-in"> <Transition name="fade" mode="out-in">
<template v-if="!hotListData"> <template v-if="errorFlag">
<div class="loading">
</div>
</template>
<template v-else-if="!hotListData">
<div class="loading"> <div class="loading">
<n-skeleton text round /> <n-skeleton text round />
</div> </div>
</template> </template>
<template v-else> <template v-else>
<div class="title"> <div class="title">
<n-avatar <n-avatar class="ico" :src="`/logo/${hotType}.png`" fallback-src="/ico/icon_error.png" />
class="ico"
:src="`/logo/${hotType}.png`"
fallback-src="/ico/icon_error.png"
/>
<n-text class="name">{{ hotListData.title }}</n-text> <n-text class="name">{{ hotListData.title }}</n-text>
<n-text class="subtitle" :depth="2"> <n-text class="subtitle" :depth="2">
{{ hotListData.subtitle }} {{ hotListData.subtitle }}
@@ -31,32 +28,32 @@
</template> </template>
<n-scrollbar class="news-list" ref="scrollbarRef"> <n-scrollbar class="news-list" ref="scrollbarRef">
<Transition name="fade" mode="out-in"> <Transition name="fade" mode="out-in">
<template v-if="!hotListData || listLoading"> <template v-if="errorFlag">
<div>
<n-result status="404" title="热点资源不存在" description="生活总归带点荒谬">
<template #footer>
<n-button>找点乐子吧</n-button>
</template>
</n-result>
</div>
</template>
<template v-else-if="!hotListData || listLoading">
<div class="loading"> <div class="loading">
<n-skeleton text round :repeat="10" height="20px" /> <n-skeleton text round :repeat="10" height="20px" />
</div> </div>
</template> </template>
<template v-else> <template v-else>
<div class="lists" :id="hotType + 'Lists'"> <div class="lists" :id="hotType + 'Lists'">
<div <div class="item" v-for="(item, index) in hotListData.data.slice(0, 15)" :key="item">
class="item" <n-text class="num" :class="index === 0
v-for="(item, index) in hotListData.data.slice(0, 15)" ? 'one'
:key="item" : index === 1
> ? 'two'
<n-text : index === 2
class="num"
:class="
index === 0
? 'one'
: index === 1
? 'two'
: index === 2
? 'three' ? 'three'
: null : null
" " :depth="2">{{ index + 1 }}</n-text>
:depth="2"
>{{ index + 1 }}</n-text
>
<n-text class="text" @click.stop="jumpLink(item)"> <n-text class="text" @click.stop="jumpLink(item)">
{{ item.title }} {{ item.title }}
</n-text> </n-text>
@@ -67,7 +64,11 @@
</n-scrollbar> </n-scrollbar>
<template #footer> <template #footer>
<Transition name="fade" mode="out-in"> <Transition name="fade" mode="out-in">
<template v-if="!hotListData"> <template v-if="errorFlag">
<div class="loading">
</div>
</template>
<template v-else-if="!hotListData">
<div class="loading"> <div class="loading">
<n-skeleton text round /> <n-skeleton text round />
</div> </div>
@@ -81,13 +82,7 @@
<n-space class="controls"> <n-space class="controls">
<n-popover v-if="hotListData.data.length > 15"> <n-popover v-if="hotListData.data.length > 15">
<template #trigger> <template #trigger>
<n-button <n-button size="tiny" secondary strong round @click.stop="toList">
size="tiny"
secondary
strong
round
@click.stop="toList"
>
<template #icon> <template #icon>
<n-icon :component="More" /> <n-icon :component="More" />
</template> </template>
@@ -97,13 +92,7 @@
</n-popover> </n-popover>
<n-popover> <n-popover>
<template #trigger> <template #trigger>
<n-button <n-button size="tiny" secondary strong round @click.stop="getNewData">
size="tiny"
secondary
strong
round
@click.stop="getNewData"
>
<template #icon> <template #icon>
<n-icon :component="Refresh" /> <n-icon :component="Refresh" />
</template> </template>
@@ -147,6 +136,8 @@ const hotListData = ref(null);
const scrollbarRef = ref(null); const scrollbarRef = ref(null);
const listLoading = ref(false); const listLoading = ref(false);
const errorFlag = ref(false);
// 获取热榜数据 // 获取热榜数据
const getHotListsData = (type, isNew = false) => { const getHotListsData = (type, isNew = false) => {
// hotListData.value = null; // hotListData.value = null;
@@ -165,18 +156,20 @@ const getHotListsData = (type, isNew = false) => {
} }
}) })
.catch((error) => { .catch((error) => {
console.error("资源请求失败:" + error);
switch (error?.response.status) { errorFlag.value = true;
case 403:
router.push("/403"); // switch (error?.response.status) {
break; // case 403:
case 500: // router.push("/403");
router.push("/500"); // break;
break; // case 500:
default: // router.push("/500");
router.push("/404"); // break;
break; // default:
} // router.push("/500");
// break;
// }
}); });
}; };
@@ -241,6 +234,7 @@ onMounted(() => {
border-radius: 12px; border-radius: 12px;
transition: all 0.3s; transition: all 0.3s;
cursor: pointer; cursor: pointer;
.fade-enter-active, .fade-enter-active,
.fade-leave-active { .fade-leave-active {
transition: opacity 0.3s ease-in-out; transition: opacity 0.3s ease-in-out;
@@ -250,37 +244,45 @@ onMounted(() => {
.fade-leave-to { .fade-leave-to {
opacity: 0; opacity: 0;
} }
.title { .title {
display: flex; display: flex;
align-items: center; align-items: center;
font-size: 16px; font-size: 16px;
height: 26px; height: 26px;
.n-avatar { .n-avatar {
background-color: transparent; background-color: transparent;
width: 20px; width: 20px;
height: 20px; height: 20px;
margin-right: 8px; margin-right: 8px;
} }
.subtitle { .subtitle {
margin-left: auto; margin-left: auto;
font-size: 12px; font-size: 12px;
} }
} }
.message { .message {
display: flex; display: flex;
align-items: flex-end; align-items: flex-end;
justify-content: space-between; justify-content: space-between;
font-size: 12px; font-size: 12px;
height: 24px; height: 24px;
.time { .time {
padding: 0 6px; padding: 0 6px;
} }
} }
:deep(.news-list) { :deep(.news-list) {
height: 300px; height: 300px;
.n-scrollbar-rail { .n-scrollbar-rail {
right: 0; right: 0;
} }
.loading { .loading {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
@@ -288,8 +290,10 @@ onMounted(() => {
justify-content: space-between; justify-content: space-between;
} }
} }
.lists { .lists {
padding-right: 6px; padding-right: 6px;
.item { .item {
display: flex; display: flex;
align-items: center; align-items: center;
@@ -299,9 +303,11 @@ onMounted(() => {
border-radius: 8px; border-radius: 8px;
transition: all 0.3s; transition: all 0.3s;
cursor: pointer; cursor: pointer;
&:nth-last-of-type(1) { &:nth-last-of-type(1) {
margin-bottom: 0; margin-bottom: 0;
} }
.num { .num {
width: 24px; width: 24px;
height: 24px; height: 24px;
@@ -314,40 +320,49 @@ onMounted(() => {
background-color: var(--n-border-color); background-color: var(--n-border-color);
border-radius: 8px; border-radius: 8px;
transition: all 0.3s; transition: all 0.3s;
&:hover { &:hover {
background-color: var(--n-close-color-hover); background-color: var(--n-close-color-hover);
} }
&.one { &.one {
background-color: #ea444d; background-color: #ea444d;
color: #fff; color: #fff;
} }
&.two { &.two {
background-color: #ed702d; background-color: #ed702d;
color: #fff; color: #fff;
} }
&.three { &.three {
background-color: #eead3f; background-color: #eead3f;
color: #fff; color: #fff;
} }
} }
.text { .text {
position: relative; position: relative;
display: inline-block; display: inline-block;
width: 100%; width: 100%;
transition: all 0.3s; transition: all 0.3s;
@media (min-width: 768px) { @media (min-width: 768px) {
&:hover { &:hover {
transform: translateX(4px); transform: translateX(4px);
&::after { &::after {
width: 90%; width: 90%;
} }
} }
} }
@media (max-width: 768px) { @media (max-width: 768px) {
&:active { &:active {
color: #ea444d; color: #ea444d;
} }
} }
&::after { &::after {
content: ""; content: "";
width: 0; width: 0;
@@ -363,11 +378,13 @@ onMounted(() => {
} }
} }
} }
:deep(.n-card-header) { :deep(.n-card-header) {
.loading { .loading {
height: 26px; height: 26px;
} }
} }
:deep(.n-card__footer) { :deep(.n-card__footer) {
.loading { .loading {
height: 24px; height: 24px;