Skip to content

Commit

Permalink
feat: ✨ 骨架屏
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuba-Ahhh committed Sep 22, 2024
1 parent 3e4119b commit ede0b55
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/components/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ const Navbar = () => {
</Link>
</li>
<div className="navbar-end flex-grow flex justify-end items-center space-x-4">
<li className="hover:text-gray-400">
<li className="hover:text-black transition duration-200 ease-in-out">
<Link to="/">首页</Link>
</li>
<li className="hover:text-gray-400">
<li className="hover:text-black transition duration-200 ease-in-out">
<Link to="/list">小说列表</Link>
</li>
<li className="hover:text-gray-400">
<li className="hover:text-black transition duration-200 ease-in-out">
<Link to="/search">搜索</Link>
</li>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface Result<T = unknown> {
}

const service: AxiosInstance = axios.create({
baseURL: '/api',
baseURL: process.env.NODE_ENV === 'production' ? 'https://api.book.bbdaxia.com/api' : '/api',
timeout: 0,
});

Expand Down
17 changes: 15 additions & 2 deletions src/views/BookListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { http } from '../utils/request';

import { useNavigate } from 'react-router-dom';

import Loading from '../components/Loading';
import Tabs from '../components/Tabs';
import { Author } from 'assets/svg';

Expand Down Expand Up @@ -70,7 +69,21 @@ const BookList = ({ initialCategory = '全部类型' }: BookListProps) => {
/>
<div className="h-8" />
{loading ? (
<Loading />
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
{Array.from({ length: 16 }).map((_, index) => (
<div key={index} className="card card-compact bg-base-200 animate-pulse">
<div className="h-64 bg-gray-300" /> {/* 骨架屏占位 */}
<div className="card-body flex flex-col items-start">
<h2 className="h-6 bg-gray-300 rounded mb-2 w-full"> </h2> {/* 骨架屏占位 */}
<p className="h-4 bg-gray-300 rounded mb-3 w-full" /> {/* 骨架屏占位 */}
<div className="flex justify-between items-center w-full">
<span className="h-4 bg-gray-300 rounded w-1/3" /> {/* 骨架屏占位 */}
<span className="h-4 bg-gray-300 rounded w-1/3" /> {/* 骨架屏占位 */}
</div>
</div>
</div>
))}
</div>
) : books?.length > 0 ? (
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
{books.map((book) => (
Expand Down
29 changes: 21 additions & 8 deletions src/views/SearchView.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { useState } from 'react';
import { http } from '../utils/request';
import { uuid } from 'zhuba-tools';
import { Author } from 'assets/svg';

interface SearchResult {
img: string;
type: string;
name: string;
url: string;
new: string;
Expand Down Expand Up @@ -57,24 +60,34 @@ const SearchPage = () => {
{loading ? (
<p className="text-center">正在搜索...</p>
) : searchResults?.length > 0 ? (
<div className="space-y-4">
<div className="grid gap-6 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
{searchResults.map((result) => (
<div key={uuid()} className="card w-full shadow-xl">
<div className="card-body">
<div
key={uuid()}
className="card card-compact hover:shadow-lg hover:rounded-lg transition-shadow duration-300 cursor-pointer"
>
<img
src={`https://api.book.bbdaxia.com${result.img}`}
alt={result.name}
className="w-full h-64 object-contain mt-4" // 增加上边距
/>
<div className="card-body flex-col items-start p-4">
<h2 className="text-xl font-semibold mb-2">
{result.name} {result.author}
</h2>
<p className="text-sm text-gray-600">{result.new}</p>
<div>
<p className="text-sm text-gray-600 line-clamp-4 mb-3">{result.desc}</p>
<div className="flex justify-between items-center w-full">
<span className="text-sm font-medium text-orange-500">热度: {result.new}</span>
<a
href={`/book/${encodeURIComponent(result.book[0].url)}`}
className="text-blue-600 hover:underline mr-4 cursor-pointer"
>
查看详情
</a>
<a href={result.newurl} className="text-green-600 hover:underline cursor-pointer">
阅读最新章节
</a>
</div>
<div className="flex items-center space-x-1 mt-3 text-gray-500">
<Author />
<p className="text-sm truncate">{result.author}</p>
</div>
</div>
</div>
Expand Down

0 comments on commit ede0b55

Please sign in to comment.