Compare commits

..

2 Commits

Author SHA1 Message Date
Li1304553726 271f2e081e add 2025-05-09 10:01:51 +08:00
Li1304553726 84a5066097 add 2025-05-08 16:31:48 +08:00
5 changed files with 247 additions and 148 deletions

View File

@ -10,6 +10,9 @@ import {
Input,
Alert,
Pagination,
Select,
Space,
Tag,
} from "antd";
import { TusUploader } from "@web/src/components/common/uploader/TusUploader";
import { SendOutlined, DeleteOutlined, LoginOutlined } from "@ant-design/icons";
@ -27,6 +30,7 @@ export function VideoContent() {
const [fileIds, setFileIds] = useState<string[]>([]);
const [uploaderKey, setUploaderKey] = useState<number>(0);
const [searchTerm, setSearchTerm] = useState("");
const [fileType, setFileType] = useState<string>("all");
// 分页状态
const [imagePage, setImagePage] = useState(1);
@ -43,8 +47,11 @@ export function VideoContent() {
data: resources,
refetch,
isLoading,
}: { data: ResourceDto[]; refetch: () => void; isLoading: boolean } =
api.resource.findMany.useQuery({
}: {
data: ResourceDto[];
refetch: () => void;
isLoading: boolean;
} = api.resource.findMany.useQuery({
where: {
deletedAt: null,
postId: null,
@ -54,7 +61,20 @@ export function VideoContent() {
},
});
// 处理资源数据
// 定义常见文件类型和它们的扩展名
const fileTypes = {
all: { label: "全部", extensions: [] },
document: { label: "文档", extensions: ["doc", "docx", "pdf", "txt"] },
spreadsheet: { label: "表格", extensions: ["xls", "xlsx", "csv"] },
presentation: { label: "ppt", extensions: ["ppt", "pptx"] },
video: {
label: "音视频",
extensions: ["mp4", "avi", "mov", "webm", "mp3", "wav", "ogg"],
},
archive: { label: "压缩包", extensions: ["zip", "rar", "7z"] },
};
// 修改资源处理逻辑,加入文件类型筛选
const { imageResources, fileResources, imagePagination, filePagination } =
useMemo(() => {
if (!resources) {
@ -74,10 +94,11 @@ export function VideoContent() {
const original = `http://${env.SERVER_IP}:${env.UPLOAD_PORT}/uploads/${resource.url}`;
const isImg = isImage(resource.url);
// 确保 title 存在,优先使用 resource.title然后是 resource.meta.filename
// 提取文件扩展名
const extension = resource.url.split(".").pop()?.toLowerCase() || "";
const displayTitle =
resource.title || resource.meta?.filename || "未命名文件";
// 用于搜索的名称,确保从 meta.filename 获取(如果存在)
const searchableFilename = resource.meta?.filename || "";
return {
@ -85,20 +106,27 @@ export function VideoContent() {
url: isImg ? getCompressedImageUrl(original) : original,
originalUrl: original,
isImage: isImg,
title: displayTitle, // 用于显示
searchableFilename: searchableFilename, // 用于搜索
title: displayTitle,
searchableFilename: searchableFilename,
extension: extension,
};
})
.filter(Boolean);
// 根据搜索词筛选文件资源 (基于 searchableFilename)
const filteredFileResources = processedResources.filter(
(res) =>
!res.isImage &&
res.searchableFilename
// 根据搜索词和文件类型筛选
const filteredFileResources = processedResources.filter((res) => {
// 首先检查是否符合搜索词
const matchesSearch = res.searchableFilename
.toLowerCase()
.includes(searchTerm.toLowerCase())
);
.includes(searchTerm.toLowerCase());
// 然后检查文件类型
const matchesType =
fileType === "all" ||
fileTypes[fileType]?.extensions.includes(res.extension);
return !res.isImage && matchesSearch && matchesType;
});
const allImageResources = processedResources.filter((res) => res.isImage);
@ -124,7 +152,7 @@ export function VideoContent() {
data: filteredFileResources,
},
};
}, [resources, imagePage, filePage, searchTerm]); // searchTerm 作为依赖项
}, [resources, imagePage, filePage, searchTerm, fileType]); // 添加fileType依赖
const createMutation = api.resource.create.useMutation({});
const handleSubmit = async () => {
@ -223,6 +251,7 @@ export function VideoContent() {
<p>excelppt等多种格式文件</p>
</div>
</header>
<div className="flex flex-wrap items-center gap-4 mb-4">
<Input.Search
placeholder="搜索文件名"
allowClear
@ -230,6 +259,23 @@ export function VideoContent() {
onChange={(e) => setSearchTerm(e.target.value)}
style={{ width: 300 }}
/>
<Select
value={fileType}
onChange={(value) => setFileType(value)}
style={{ width: 120 }}
options={Object.entries(fileTypes).map(([key, { label }]) => ({
value: key,
label: label,
}))}
/>
{/* {fileType !== "all" && (
<Tag color="blue" closable onClose={() => setFileType("all")}>
{fileTypes[fileType]?.label}
</Tag>
)} */}
</div>
{!isAuthenticated && (
<Alert
message="请先登录"
@ -373,20 +419,20 @@ export function VideoContent() {
</div>
<div className="flex-1 min-w-0">
<div className="font-medium truncate">
{resource.title}
{resource.meta?.filename}
</div>
{resource.description && (
{/* {resource.meta?.filetype && (
<div className="text-xs text-gray-500 mt-1">
: {resource.description}
: {resource.meta?.filetype}
</div>
)}
)} */}
<div className="text-xs text-gray-500 flex items-center gap-2">
<span>
{dayjs(resource.createdAt).format("YYYY-MM-DD")}
</span>
<span>
{resource.meta?.size &&
formatFileSize(resource.meta.size)}
formatFileSize(resource.meta?.size)}
</span>
</div>
</div>
@ -416,12 +462,6 @@ export function VideoContent() {
</div>
)}
{fileResources.length === 0 && searchTerm && (
<div className="text-center py-4 text-gray-500">
"{searchTerm}"
</div>
)}
{/* 文件分页 */}
{filePagination.total > pageSize && (
<div className="flex justify-center mt-6">

View File

@ -14,7 +14,7 @@ export function ExampleContent() {
const [loading, setLoading] = useState(true);
const [currentPage, setCurrentPage] = useState(1);
const [searchTerm, setSearchTerm] = useState("");
const pageSize = 6; // 每页显示5条案例
const pageSize = 10; // 每页显示5条案例
const isDomainAdmin = useMemo(() => {
return hasSomePermissions("MANAGE_DOM_STAFF", "MANAGE_ANY_STAFF");
}, [hasSomePermissions]);

View File

@ -14,7 +14,7 @@ export function PublicityContent() {
const [loading, setLoading] = useState(true);
const [currentPage, setCurrentPage] = useState(1);
const [searchTerm, setSearchTerm] = useState("");
const pageSize = 6; // 每页显示5条新闻
const pageSize = 10; // 每页显示5条新闻
const isDomainAdmin = useMemo(() => {
return hasSomePermissions("MANAGE_DOM_STAFF", "MANAGE_ANY_STAFF");
}, [hasSomePermissions]);

View File

@ -14,7 +14,7 @@ export function ScienceContent() {
const [loading, setLoading] = useState(true);
const [currentPage, setCurrentPage] = useState(1);
const [searchTerm, setSearchTerm] = useState("");
const pageSize = 6; // 每页显示5条科普
const pageSize = 10; // 每页显示5条科普
const isDomainAdmin = useMemo(() => {
return hasSomePermissions("MANAGE_DOM_STAFF", "MANAGE_ANY_STAFF");
}, [hasSomePermissions]);

View File

@ -1,24 +1,48 @@
import { useState, useEffect, useMemo } from "react";
import { Input, Pagination, Empty, Spin } from "antd";
import { Input, Pagination, Empty, Spin, Radio, Space, Tag } from "antd";
import { api, RouterInputs } from "@nice/client";
import { LetterCard } from "../LetterCard";
import { NonVoid } from "@nice/utils";
import { SearchOutlined } from "@ant-design/icons";
import { SearchOutlined, FilterOutlined } from "@ant-design/icons";
import debounce from "lodash/debounce";
import { postDetailSelect } from "@nice/common";
export default function LetterList({
params,
search = ''
search = "",
}: {
search?: string,
search?: string;
params: NonVoid<RouterInputs["post"]["findManyWithPagination"]>;
}) {
const [keyword, setKeyword] = useState<string | undefined>('');
const [keyword, setKeyword] = useState<string | undefined>("");
const [currentPage, setCurrentPage] = useState(1);
useEffect(() => {
const [selectedCategory, setSelectedCategory] = useState<string>("all");
const { data: categoriesData } = api.term.findMany.useQuery({
where: {
taxonomy: {
slug: "category",
},
},
});
const categoryOptions = useMemo(() => {
const options = [{ value: "all", label: "全部分类" }];
if (categoriesData) {
categoriesData.forEach((category) => {
options.push({
value: category.id,
label: category.name,
});
});
}
return options;
}, [categoriesData]);
useEffect(() => {
setKeyword(search || "");
}, [search]);
setKeyword(search || '')
}, [search])
const { data, isLoading } = api.post.findManyWithPagination.useQuery({
page: currentPage,
pageSize: params.pageSize,
@ -30,6 +54,15 @@ export default function LetterList({
},
},
],
...(selectedCategory !== "all"
? {
terms: {
some: {
id: selectedCategory,
},
},
}
: {}),
...params?.where,
},
orderBy: {
@ -49,26 +82,51 @@ export default function LetterList({
}, 300),
[]
);
// Cleanup debounce on unmount
useEffect(() => {
return () => {
debouncedSearch.cancel();
};
}, [debouncedSearch]);
const handleSearch = (value: string) => {
debouncedSearch(value);
};
const handlePageChange = (page: number) => {
setCurrentPage(page);
// Scroll to top when page changes
window.scrollTo({ top: 0, behavior: "smooth" });
};
const handleCategoryChange = (value: string) => {
setSelectedCategory(value);
setCurrentPage(1);
};
return (
<div className="flex flex-col h-full">
{/* Search Bar */}
<div className="p-6 transition-all">
<div className="flex items-center mb-4">
<Radio.Group
value={selectedCategory}
onChange={(e) => handleCategoryChange(e.target.value)}
optionType="button"
buttonStyle="solid"
className="flex-wrap"
>
{categoryOptions.map((option) => (
<Radio.Button
key={option.value}
value={option.value}
className="my-1"
>
{option.label}
</Radio.Button>
))}
</Radio.Group>
</div>
<Space direction="vertical" className="w-full" size="middle">
<Input
value={keyword}
variant="filled"
@ -79,9 +137,9 @@ export default function LetterList({
onChange={(e) => handleSearch(e.target.value)}
prefix={<SearchOutlined className="text-gray-400" />}
/>
</Space>
</div>
{/* Content Area */}
<div className="flex-grow px-6">
{isLoading ? (
<div className="flex justify-center items-center pt-6">
@ -108,9 +166,10 @@ export default function LetterList({
) : (
<div className="flex flex-col justify-center items-center pt-6">
<Empty
description={
keyword ? "未找到相关信件" : "暂无信件"
keyword || selectedCategory !== "all"
? "未找到相关信件"
: "暂无信件"
}
/>
</div>