数据列表查询对接完成
This commit is contained in:
@@ -40,10 +40,10 @@ export function SearchResultHeader({
|
||||
value={sortBy}
|
||||
onChange={(e) => onSortChange(e.target.value)}
|
||||
>
|
||||
<option value="relevance">相关度排序</option>
|
||||
<option value="relevance">相关排序</option>
|
||||
<option value="newest">最新更新</option>
|
||||
<option value="popular">使用频率</option>
|
||||
<option value="rating">评分最高</option>
|
||||
{/* <option value="popular">使用频率</option>
|
||||
<option value="rating">评分最高</option> */}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
import { useState } from 'react';
|
||||
// import { useState } from 'react';
|
||||
import { useNavigate } from '@remix-run/react';
|
||||
|
||||
interface Template {
|
||||
id: string;
|
||||
title: string;
|
||||
type: string;
|
||||
// type: string;
|
||||
description: string;
|
||||
updateTime: string;
|
||||
useCount: number;
|
||||
rating: number;
|
||||
// useCount: number;
|
||||
// rating: number;
|
||||
category: string;
|
||||
file_path?: string;
|
||||
file_format?: string;
|
||||
}
|
||||
|
||||
interface TemplateCardProps {
|
||||
@@ -18,21 +20,71 @@ interface TemplateCardProps {
|
||||
}
|
||||
|
||||
export function TemplateCard({ template, onClick }: TemplateCardProps) {
|
||||
const [isFavorited, setIsFavorited] = useState(false);
|
||||
// 注释掉收藏功能,后续版本再开发
|
||||
// const [isFavorited, setIsFavorited] = useState(false);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleFavoriteClick = (e: React.MouseEvent) => {
|
||||
/* const handleFavoriteClick = (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
setIsFavorited(!isFavorited);
|
||||
}; */
|
||||
|
||||
// MinIO下载URL构建函数
|
||||
const buildDownloadUrl = (filePath: string): string => {
|
||||
// 使用实际的MinIO配置
|
||||
const minioHost = 'http://nas.7bm.co:9000';
|
||||
const bucketName = 'docauditai';
|
||||
|
||||
// 确保文件路径不以/开头
|
||||
const cleanPath = filePath.startsWith('/') ? filePath.substring(1) : filePath;
|
||||
|
||||
return `${minioHost}/${bucketName}/${cleanPath}`;
|
||||
};
|
||||
|
||||
// 下载文件函数
|
||||
const downloadFile = async (filePath: string, fileName: string) => {
|
||||
try {
|
||||
const downloadUrl = buildDownloadUrl(filePath);
|
||||
|
||||
// 清理文件名,移除可能导致问题的字符
|
||||
const cleanFileName = fileName.replace(/[<>:"/\\|?*]/g, '_');
|
||||
|
||||
// 创建临时下载链接
|
||||
const link = document.createElement('a');
|
||||
link.href = downloadUrl;
|
||||
link.download = cleanFileName;
|
||||
link.target = '_blank';
|
||||
|
||||
// 触发下载
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
|
||||
console.log('开始下载文件:', cleanFileName);
|
||||
} catch (error) {
|
||||
console.error('下载文件失败:', error);
|
||||
alert('下载失败,请稍后重试');
|
||||
}
|
||||
};
|
||||
|
||||
const handleActionClick = (e: React.MouseEvent, action: string) => {
|
||||
e.stopPropagation();
|
||||
|
||||
switch (action) {
|
||||
case '立即使用':
|
||||
console.log('下载并使用模板:', template.id);
|
||||
// 这里应该触发下载逻辑
|
||||
case '立即下载':
|
||||
// 添加调试信息
|
||||
console.log('模板数据:', template);
|
||||
console.log('文件路径:', template.file_path);
|
||||
console.log('文件格式:', template.file_format);
|
||||
|
||||
if (template.file_path) {
|
||||
// 构建文件名,使用模板标题和文件格式
|
||||
const fileExtension = template.file_format || 'docx';
|
||||
const fileName = `${template.title}.${fileExtension}`;
|
||||
downloadFile(template.file_path, fileName);
|
||||
} else {
|
||||
alert('文件路径不存在,无法下载');
|
||||
}
|
||||
break;
|
||||
case '预览':
|
||||
// 导航到模板详情页面
|
||||
@@ -43,7 +95,7 @@ export function TemplateCard({ template, onClick }: TemplateCardProps) {
|
||||
}
|
||||
};
|
||||
|
||||
const renderStars = (rating: number) => {
|
||||
/* const renderStars = (rating: number) => {
|
||||
const stars = [];
|
||||
const fullStars = Math.floor(rating);
|
||||
const hasHalfStar = rating % 1 !== 0;
|
||||
@@ -58,7 +110,7 @@ export function TemplateCard({ template, onClick }: TemplateCardProps) {
|
||||
}
|
||||
}
|
||||
return stars;
|
||||
};
|
||||
}; */
|
||||
|
||||
const handleKeyDown = (e: React.KeyboardEvent) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
@@ -76,28 +128,43 @@ export function TemplateCard({ template, onClick }: TemplateCardProps) {
|
||||
tabIndex={0}
|
||||
aria-label={`查看${template.title}详情`}
|
||||
>
|
||||
<div className="template-header">
|
||||
{/* 注释掉头部的type和rating显示 */}
|
||||
{/* <div className="template-header">
|
||||
<div className="template-type">{template.type}</div>
|
||||
<div className="flex items-center gap-1 text-yellow-500">
|
||||
{renderStars(template.rating)}
|
||||
<span className="text-xs ml-1">{template.rating}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div> */}
|
||||
|
||||
<h3 className="template-title">{template.title}</h3>
|
||||
<p className="template-desc">{template.description}</p>
|
||||
<p
|
||||
className="template-desc"
|
||||
style={{
|
||||
height: '4.5rem', // 固定高度约3行文字
|
||||
overflow: 'hidden',
|
||||
textOverflow: 'ellipsis',
|
||||
display: '-webkit-box',
|
||||
WebkitLineClamp: 3, // 限制3行
|
||||
WebkitBoxOrient: 'vertical',
|
||||
lineHeight: '1.5rem'
|
||||
}}
|
||||
>
|
||||
{template.description}
|
||||
</p>
|
||||
|
||||
<div className="template-meta">
|
||||
<span>更新时间:{template.updateTime}</span>
|
||||
<span>使用次数:{template.useCount.toLocaleString()}</span>
|
||||
{/* 注释掉使用次数显示 */}
|
||||
{/* <span>使用次数:{template.useCount.toLocaleString()}</span> */}
|
||||
</div>
|
||||
|
||||
<div className="template-actions mt-3">
|
||||
<button
|
||||
className="action-btn primary"
|
||||
onClick={(e) => handleActionClick(e, '立即使用')}
|
||||
onClick={(e) => handleActionClick(e, '立即下载')}
|
||||
>
|
||||
立即使用
|
||||
立即下载
|
||||
</button>
|
||||
<button
|
||||
className="action-btn"
|
||||
@@ -105,13 +172,14 @@ export function TemplateCard({ template, onClick }: TemplateCardProps) {
|
||||
>
|
||||
预览
|
||||
</button>
|
||||
<button
|
||||
{/* 注释掉收藏按钮 */}
|
||||
{/* <button
|
||||
className="action-btn"
|
||||
onClick={handleFavoriteClick}
|
||||
title={isFavorited ? '取消收藏' : '收藏'}
|
||||
>
|
||||
<i className={isFavorited ? 'ri-star-fill text-yellow-500' : 'ri-star-line'}></i>
|
||||
</button>
|
||||
</button> */}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -3,12 +3,14 @@ import { TemplateCard } from './TemplateCard';
|
||||
interface Template {
|
||||
id: string;
|
||||
title: string;
|
||||
type: string;
|
||||
// type: string;
|
||||
description: string;
|
||||
updateTime: string;
|
||||
useCount: number;
|
||||
rating: number;
|
||||
// useCount: number;
|
||||
// rating: number;
|
||||
category: string;
|
||||
file_path?: string;
|
||||
file_format?: string;
|
||||
}
|
||||
|
||||
interface TemplateGridProps {
|
||||
|
||||
Reference in New Issue
Block a user