fix:更新优化
This commit is contained in:
parent
60ef9adaff
commit
bee237f3b1
@ -24,7 +24,7 @@ function flattenDocIds(nodes: ManualTreeNode[]): number[] {
|
||||
}
|
||||
|
||||
export default async function ManualIndexPage() {
|
||||
const tree = await publicApi.getManualTree();
|
||||
const tree = await publicApi.getManualTree().catch(() => [] as ManualTreeNode[]);
|
||||
const docIds = flattenDocIds(tree);
|
||||
|
||||
// 优先展示第一篇文档的内容;树中无文档节点时显示空态
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import type { Metadata } from 'next';
|
||||
import { publicApi } from '@/lib/services';
|
||||
import { NewsCard } from '@/components/front/NewsCard';
|
||||
import type { NewsCategory } from '@/lib/types';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: '新闻资讯',
|
||||
@ -18,7 +19,7 @@ export default async function NewsPage({ searchParams }: PageProps) {
|
||||
const categoryId = searchParams.categoryId ? Number(searchParams.categoryId) : undefined;
|
||||
|
||||
const [categories, newsRes] = await Promise.all([
|
||||
publicApi.getNewsCategories().catch(() => []),
|
||||
publicApi.getNewsCategories().catch(() => [] as NewsCategory[]),
|
||||
publicApi
|
||||
.getNews({ page, pageSize: 10, categoryId, keyword: searchParams.keyword })
|
||||
.catch(() => ({ list: [], total: 0, page, pageSize: 10 })),
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import type { Metadata } from 'next';
|
||||
import { publicApi } from '@/lib/services';
|
||||
import { ProductCard } from '@/components/front/ProductCard';
|
||||
import type { ProductCategory } from '@/lib/types';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: '产品中心',
|
||||
@ -18,7 +19,7 @@ export default async function ProductsPage({ searchParams }: PageProps) {
|
||||
const categoryId = searchParams.categoryId ? Number(searchParams.categoryId) : undefined;
|
||||
|
||||
const [categories, productsRes] = await Promise.all([
|
||||
publicApi.getProductCategories().catch(() => []),
|
||||
publicApi.getProductCategories().catch(() => [] as ProductCategory[]),
|
||||
publicApi
|
||||
.getProducts({
|
||||
page,
|
||||
|
||||
@ -56,8 +56,11 @@ http.interceptors.request.use((config: InternalAxiosRequestConfig) => {
|
||||
});
|
||||
|
||||
// 响应拦截:拆包 + 401 跳登录
|
||||
// 注:onFulfilled 在拦截器中返回业务数据(拆包后的 data)而非 AxiosResponse,
|
||||
// 这是项目约定的解包模式;axios 1.x 的类型签名不灵活,必须 cast 为 any
|
||||
http.interceptors.response.use(
|
||||
(response) => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
(response): any => {
|
||||
const body = response.data as ApiResult<unknown>;
|
||||
if (body && typeof body.code === 'number') {
|
||||
if (body.code === 200) {
|
||||
|
||||
@ -1,14 +1,13 @@
|
||||
/**
|
||||
* 前台公开 API(无需 token)
|
||||
*/
|
||||
import { http } from './api';
|
||||
import { http, type Paginated } from './api';
|
||||
import type {
|
||||
Banner,
|
||||
Manual,
|
||||
ManualTreeNode,
|
||||
News,
|
||||
NewsCategory,
|
||||
Paginated,
|
||||
Product,
|
||||
ProductCategory,
|
||||
SiteConfig,
|
||||
|
||||
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user