Compare commits
2 Commits
89102d7f8c
...
271f2e081e
Author | SHA1 | Date |
---|---|---|
|
271f2e081e | |
|
84a5066097 |
|
@ -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,18 +47,34 @@ export function VideoContent() {
|
|||
data: resources,
|
||||
refetch,
|
||||
isLoading,
|
||||
}: { data: ResourceDto[]; refetch: () => void; isLoading: boolean } =
|
||||
api.resource.findMany.useQuery({
|
||||
where: {
|
||||
deletedAt: null,
|
||||
postId: null,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
});
|
||||
}: {
|
||||
data: ResourceDto[];
|
||||
refetch: () => void;
|
||||
isLoading: boolean;
|
||||
} = api.resource.findMany.useQuery({
|
||||
where: {
|
||||
deletedAt: null,
|
||||
postId: null,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
});
|
||||
|
||||
// 处理资源数据
|
||||
// 定义常见文件类型和它们的扩展名
|
||||
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
|
||||
.toLowerCase()
|
||||
.includes(searchTerm.toLowerCase())
|
||||
);
|
||||
// 根据搜索词和文件类型筛选
|
||||
const filteredFileResources = processedResources.filter((res) => {
|
||||
// 首先检查是否符合搜索词
|
||||
const matchesSearch = res.searchableFilename
|
||||
.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,13 +251,31 @@ export function VideoContent() {
|
|||
<p>支持视频、excel、文档、ppt等多种格式文件</p>
|
||||
</div>
|
||||
</header>
|
||||
<Input.Search
|
||||
placeholder="搜索文件名"
|
||||
allowClear
|
||||
onSearch={(value) => setSearchTerm(value)}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
style={{ width: 300 }}
|
||||
/>
|
||||
<div className="flex flex-wrap items-center gap-4 mb-4">
|
||||
<Input.Search
|
||||
placeholder="搜索文件名"
|
||||
allowClear
|
||||
onSearch={(value) => setSearchTerm(value)}
|
||||
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">
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -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]);
|
||||
|
|
|
@ -1,121 +1,180 @@
|
|||
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 = ''
|
||||
params,
|
||||
search = "",
|
||||
}: {
|
||||
search?: string,
|
||||
params: NonVoid<RouterInputs["post"]["findManyWithPagination"]>;
|
||||
search?: string;
|
||||
params: NonVoid<RouterInputs["post"]["findManyWithPagination"]>;
|
||||
}) {
|
||||
const [keyword, setKeyword] = useState<string | undefined>('');
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
useEffect(() => {
|
||||
const [keyword, setKeyword] = useState<string | undefined>("");
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const [selectedCategory, setSelectedCategory] = useState<string>("all");
|
||||
|
||||
setKeyword(search || '')
|
||||
}, [search])
|
||||
const { data, isLoading } = api.post.findManyWithPagination.useQuery({
|
||||
page: currentPage,
|
||||
pageSize: params.pageSize,
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
title: {
|
||||
contains: keyword,
|
||||
},
|
||||
},
|
||||
],
|
||||
...params?.where,
|
||||
},
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
select: {
|
||||
...postDetailSelect,
|
||||
...params.select,
|
||||
},
|
||||
});
|
||||
const { data: categoriesData } = api.term.findMany.useQuery({
|
||||
where: {
|
||||
taxonomy: {
|
||||
slug: "category",
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const debouncedSearch = useMemo(
|
||||
() =>
|
||||
debounce((value: string) => {
|
||||
setKeyword(value);
|
||||
setCurrentPage(1);
|
||||
}, 300),
|
||||
[]
|
||||
);
|
||||
// Cleanup debounce on unmount
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
debouncedSearch.cancel();
|
||||
};
|
||||
}, [debouncedSearch]);
|
||||
const handleSearch = (value: string) => {
|
||||
debouncedSearch(value);
|
||||
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]);
|
||||
|
||||
const { data, isLoading } = api.post.findManyWithPagination.useQuery({
|
||||
page: currentPage,
|
||||
pageSize: params.pageSize,
|
||||
where: {
|
||||
OR: [
|
||||
{
|
||||
title: {
|
||||
contains: keyword,
|
||||
},
|
||||
},
|
||||
],
|
||||
...(selectedCategory !== "all"
|
||||
? {
|
||||
terms: {
|
||||
some: {
|
||||
id: selectedCategory,
|
||||
},
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
...params?.where,
|
||||
},
|
||||
orderBy: {
|
||||
updatedAt: "desc",
|
||||
},
|
||||
select: {
|
||||
...postDetailSelect,
|
||||
...params.select,
|
||||
},
|
||||
});
|
||||
|
||||
const debouncedSearch = useMemo(
|
||||
() =>
|
||||
debounce((value: string) => {
|
||||
setKeyword(value);
|
||||
setCurrentPage(1);
|
||||
}, 300),
|
||||
[]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
debouncedSearch.cancel();
|
||||
};
|
||||
}, [debouncedSearch]);
|
||||
|
||||
const handlePageChange = (page: number) => {
|
||||
setCurrentPage(page);
|
||||
// Scroll to top when page changes
|
||||
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||
};
|
||||
const handleSearch = (value: string) => {
|
||||
debouncedSearch(value);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full">
|
||||
{/* Search Bar */}
|
||||
<div className="p-6 transition-all ">
|
||||
<Input
|
||||
value={keyword}
|
||||
variant="filled"
|
||||
className="w-full bg-white"
|
||||
placeholder="搜索信件标题..."
|
||||
allowClear
|
||||
size="large"
|
||||
onChange={(e) => handleSearch(e.target.value)}
|
||||
prefix={<SearchOutlined className="text-gray-400" />}
|
||||
/>
|
||||
</div>
|
||||
const handlePageChange = (page: number) => {
|
||||
setCurrentPage(page);
|
||||
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||
};
|
||||
|
||||
{/* Content Area */}
|
||||
<div className="flex-grow px-6">
|
||||
{isLoading ? (
|
||||
<div className="flex justify-center items-center pt-6">
|
||||
<Spin size="large"></Spin>
|
||||
</div>
|
||||
) : data?.items.length ? (
|
||||
<>
|
||||
<div className="grid grid-cols-1 md:grid-cols-1 lg:grid-cols-1 gap-4 mb-6">
|
||||
{data.items.map((letter: any) => (
|
||||
<LetterCard key={letter.id} letter={letter} />
|
||||
))}
|
||||
</div>
|
||||
<div className="flex justify-center pb-6">
|
||||
<Pagination
|
||||
current={currentPage}
|
||||
total={data.totalCount}
|
||||
pageSize={params.pageSize}
|
||||
onChange={handlePageChange}
|
||||
showSizeChanger={false}
|
||||
showQuickJumper
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="flex flex-col justify-center items-center pt-6">
|
||||
<Empty
|
||||
const handleCategoryChange = (value: string) => {
|
||||
setSelectedCategory(value);
|
||||
setCurrentPage(1);
|
||||
};
|
||||
|
||||
description={
|
||||
keyword ? "未找到相关信件" : "暂无信件"
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
return (
|
||||
<div className="flex flex-col h-full">
|
||||
<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"
|
||||
className="w-full bg-white"
|
||||
placeholder="搜索信件标题..."
|
||||
allowClear
|
||||
size="large"
|
||||
onChange={(e) => handleSearch(e.target.value)}
|
||||
prefix={<SearchOutlined className="text-gray-400" />}
|
||||
/>
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
<div className="flex-grow px-6">
|
||||
{isLoading ? (
|
||||
<div className="flex justify-center items-center pt-6">
|
||||
<Spin size="large"></Spin>
|
||||
</div>
|
||||
) : data?.items.length ? (
|
||||
<>
|
||||
<div className="grid grid-cols-1 md:grid-cols-1 lg:grid-cols-1 gap-4 mb-6">
|
||||
{data.items.map((letter: any) => (
|
||||
<LetterCard key={letter.id} letter={letter} />
|
||||
))}
|
||||
</div>
|
||||
<div className="flex justify-center pb-6">
|
||||
<Pagination
|
||||
current={currentPage}
|
||||
total={data.totalCount}
|
||||
pageSize={params.pageSize}
|
||||
onChange={handlePageChange}
|
||||
showSizeChanger={false}
|
||||
showQuickJumper
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="flex flex-col justify-center items-center pt-6">
|
||||
<Empty
|
||||
description={
|
||||
keyword || selectedCategory !== "all"
|
||||
? "未找到相关信件"
|
||||
: "暂无信件"
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue