111
Some checks failed
Node CI / build (14.x, macOS-latest) (push) Has been cancelled
Node CI / build (14.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (14.x, windows-latest) (push) Has been cancelled
Node CI / build (16.x, macOS-latest) (push) Has been cancelled
Node CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (16.x, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
coverage CI / build (push) Has been cancelled
Node pnpm CI / build (16.x, macOS-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, windows-latest) (push) Has been cancelled
Some checks failed
Node CI / build (14.x, macOS-latest) (push) Has been cancelled
Node CI / build (14.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (14.x, windows-latest) (push) Has been cancelled
Node CI / build (16.x, macOS-latest) (push) Has been cancelled
Node CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node CI / build (16.x, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
coverage CI / build (push) Has been cancelled
Node pnpm CI / build (16.x, macOS-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, ubuntu-latest) (push) Has been cancelled
Node pnpm CI / build (16.x, windows-latest) (push) Has been cancelled
This commit is contained in:
@@ -109,25 +109,30 @@
|
||||
height: 200px;
|
||||
overflow: hidden;
|
||||
background: #000;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
|
||||
.gallery-video {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-card-actions {
|
||||
border-radius: 0 0 @jp-radius @jp-radius;
|
||||
.video-play-mask {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: rgba(0, 0, 0, 0.35);
|
||||
opacity: 0;
|
||||
transition: opacity 0.3s;
|
||||
color: #fff;
|
||||
font-size: 40px;
|
||||
}
|
||||
|
||||
> li > span {
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
.anticon {
|
||||
color: #ff7875;
|
||||
}
|
||||
}
|
||||
&:hover .video-play-mask {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import {
|
||||
Upload,
|
||||
Button,
|
||||
@@ -7,30 +7,37 @@ import {
|
||||
Spin,
|
||||
Empty,
|
||||
message,
|
||||
Typography,
|
||||
Modal,
|
||||
Typography
|
||||
} from 'antd';
|
||||
import {
|
||||
UploadOutlined,
|
||||
ArrowLeftOutlined,
|
||||
CameraOutlined,
|
||||
VideoCameraOutlined,
|
||||
DeleteOutlined
|
||||
} from '@ant-design/icons';
|
||||
import type { UploadFile } from 'antd/es/upload/interface';
|
||||
import { history } from '@umijs/max';
|
||||
import JobPortalHeader from '@/components/JobPortalHeader';
|
||||
import { uploadShowcaseFile, getShowcaseFileList } from '@/services/jobportal/user';
|
||||
import { getFileDisplayUrl } from '@/utils/fileUrl';
|
||||
import './index.less';
|
||||
|
||||
const { Title, Text } = Typography;
|
||||
|
||||
/** 从缓存获取用户ID */
|
||||
interface ShowcaseItem {
|
||||
uid: string;
|
||||
type: string;
|
||||
url: string;
|
||||
createTime: string;
|
||||
}
|
||||
|
||||
/** 从 getInfoCache 缓存获取 userId */
|
||||
const getUserIdFromCache = (): number | null => {
|
||||
try {
|
||||
const cached = localStorage.getItem('userInfo');
|
||||
const cached = localStorage.getItem('getInfoCache');
|
||||
if (cached) {
|
||||
const userInfo = JSON.parse(cached);
|
||||
return userInfo?.userId || null;
|
||||
const data = JSON.parse(cached);
|
||||
return data?.user?.userId || null;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('读取缓存用户信息失败:', error);
|
||||
@@ -38,27 +45,78 @@ const getUserIdFromCache = (): number | null => {
|
||||
return null;
|
||||
};
|
||||
|
||||
/** 根据文件名后缀推断类型 */
|
||||
const guessType = (filename: string): string => {
|
||||
const ext = filename.split('.').pop()?.toLowerCase() || '';
|
||||
const videoExts = ['mp4', 'mov', 'avi', 'wmv', 'flv', 'mkv', 'webm', 'm4v'];
|
||||
if (videoExts.includes(ext)) return 'video/mp4';
|
||||
return 'image/jpeg';
|
||||
};
|
||||
|
||||
/** 格式化时间 */
|
||||
const formatTime = (time?: string): string => {
|
||||
if (!time) return '';
|
||||
try {
|
||||
const date = new Date(time);
|
||||
return date.toLocaleString('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
});
|
||||
} catch {
|
||||
return time;
|
||||
}
|
||||
};
|
||||
|
||||
/** 服务器文件 → 展示条目 */
|
||||
const serverFileToItem = (row: {
|
||||
id: number;
|
||||
fileUrl: string;
|
||||
createTime?: string;
|
||||
}): ShowcaseItem => ({
|
||||
uid: `server-${row.id}`,
|
||||
type: guessType(row.fileUrl),
|
||||
url: getFileDisplayUrl(row.fileUrl),
|
||||
createTime: formatTime(row.createTime),
|
||||
});
|
||||
|
||||
const isVideo = (type: string): boolean => type.startsWith('video/');
|
||||
|
||||
const ShowcasePage: React.FC = () => {
|
||||
const [uploadedFiles, setUploadedFiles] = useState<UploadFile[]>([]);
|
||||
const [items, setItems] = useState<ShowcaseItem[]>([]);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [previewVisible, setPreviewVisible] = useState(false);
|
||||
const [previewFile, setPreviewFile] = useState<UploadFile | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [previewItem, setPreviewItem] = useState<ShowcaseItem | null>(null);
|
||||
|
||||
const userId = getUserIdFromCache();
|
||||
|
||||
const isVideo = (file: UploadFile): boolean => {
|
||||
const type = file.type || '';
|
||||
return type.startsWith('video/');
|
||||
};
|
||||
const fetchFileList = useCallback(async () => {
|
||||
if (!userId) {
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
setLoading(true);
|
||||
const response = await getShowcaseFileList(userId);
|
||||
if (response?.code === 200 || response?.code === 0) {
|
||||
const rows = response.rows || response.data || [];
|
||||
setItems(rows.map(serverFileToItem));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取文件列表失败:', error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
}, [userId]);
|
||||
|
||||
const isImage = (file: UploadFile): boolean => {
|
||||
const type = file.type || '';
|
||||
return type.startsWith('image/');
|
||||
};
|
||||
useEffect(() => {
|
||||
fetchFileList();
|
||||
}, [fetchFileList]);
|
||||
|
||||
/** 自定义上传逻辑 */
|
||||
const customUpload = async (options: any) => {
|
||||
const { file, onSuccess, onError, onProgress } = options;
|
||||
const { file, onSuccess, onError } = options;
|
||||
|
||||
if (!userId) {
|
||||
message.error('请先登录');
|
||||
@@ -66,33 +124,17 @@ const ShowcasePage: React.FC = () => {
|
||||
return;
|
||||
}
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append('file', file as File);
|
||||
|
||||
try {
|
||||
setUploading(true);
|
||||
const response = await fetch(
|
||||
`/app/file/upload?bussinessid=${userId}`,
|
||||
{
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
}
|
||||
);
|
||||
const response = await uploadShowcaseFile(userId, file as File);
|
||||
|
||||
if (response.ok) {
|
||||
const result = await response.json();
|
||||
if (result.code === 200 || result.code === 0) {
|
||||
message.success(`${file.name} 上传成功`);
|
||||
onSuccess(result, file);
|
||||
// 将上传成功的文件添加到展示列表
|
||||
setUploadedFiles((prev) => [...prev, file]);
|
||||
} else {
|
||||
message.error(result.msg || `${file.name} 上传失败`);
|
||||
onError(new Error(result.msg || '上传失败'));
|
||||
}
|
||||
if (response?.code === 200 || response?.code === 0) {
|
||||
message.success(`${file.name} 上传成功`);
|
||||
onSuccess(response, file);
|
||||
await fetchFileList();
|
||||
} else {
|
||||
message.error(`${file.name} 上传失败`);
|
||||
onError(new Error('上传失败'));
|
||||
message.error(response?.msg || `${file.name} 上传失败`);
|
||||
onError(new Error(response?.msg || '上传失败'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('上传失败:', error);
|
||||
@@ -103,26 +145,12 @@ const ShowcasePage: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
/** 上传前校验:仅允许图片和视频 */
|
||||
const beforeUpload = (file: File): boolean => {
|
||||
const isImageOrVideo = file.type.startsWith('image/') || file.type.startsWith('video/');
|
||||
if (!isImageOrVideo) {
|
||||
const isValid = file.type.startsWith('image/') || file.type.startsWith('video/');
|
||||
if (!isValid) {
|
||||
message.error('只支持上传图片和视频文件!');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
/** 移除已上传文件 */
|
||||
const handleRemove = (file: UploadFile) => {
|
||||
setUploadedFiles((prev) => prev.filter((f) => f.uid !== file.uid));
|
||||
message.info('已移除');
|
||||
};
|
||||
|
||||
/** 预览文件 */
|
||||
const handlePreview = (file: UploadFile) => {
|
||||
setPreviewFile(file);
|
||||
setPreviewVisible(true);
|
||||
return isValid;
|
||||
};
|
||||
|
||||
const handleBack = () => {
|
||||
@@ -133,27 +161,21 @@ const ShowcasePage: React.FC = () => {
|
||||
<div className="showcase-page">
|
||||
<JobPortalHeader showSearch={false} showHotJobs={false} />
|
||||
|
||||
<Spin spinning={uploading}>
|
||||
<Spin spinning={uploading || loading}>
|
||||
<div className="page-content">
|
||||
{/* 返回按钮 */}
|
||||
<div className="back-button">
|
||||
<Button
|
||||
type="text"
|
||||
icon={<ArrowLeftOutlined />}
|
||||
onClick={handleBack}
|
||||
>
|
||||
<Button type="text" icon={<ArrowLeftOutlined />} onClick={handleBack}>
|
||||
返回个人中心
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* 页面标题 */}
|
||||
<div className="page-header">
|
||||
<Title level={2}>我的风采</Title>
|
||||
<Text type="secondary">上传你的个人照片和视频,展示你的风采</Text>
|
||||
</div>
|
||||
|
||||
{/* 上传区域 */}
|
||||
<Card className="upload-card" bordered={false}>
|
||||
<Card className="upload-card">
|
||||
<div className="upload-section">
|
||||
<Upload
|
||||
customRequest={customUpload}
|
||||
@@ -180,7 +202,7 @@ const ShowcasePage: React.FC = () => {
|
||||
</Card>
|
||||
|
||||
{/* 已上传内容展示 */}
|
||||
{uploadedFiles.length === 0 ? (
|
||||
{items.length === 0 ? (
|
||||
<Empty
|
||||
description="暂无上传内容,快去上传吧"
|
||||
style={{ marginTop: '60px' }}
|
||||
@@ -189,87 +211,59 @@ const ShowcasePage: React.FC = () => {
|
||||
<div className="showcase-gallery">
|
||||
<div className="gallery-header">
|
||||
<Title level={4}>已上传内容</Title>
|
||||
<Text type="secondary">共 {uploadedFiles.length} 个文件</Text>
|
||||
<Text type="secondary">共 {items.length} 条记录</Text>
|
||||
</div>
|
||||
<div className="gallery-grid">
|
||||
{uploadedFiles.map((file, index) => (
|
||||
{items.map((item) => (
|
||||
<Card
|
||||
key={file.uid || index}
|
||||
key={item.uid}
|
||||
className="gallery-card"
|
||||
hoverable
|
||||
cover={
|
||||
isVideo(file) ? (
|
||||
<div className="video-cover">
|
||||
<video
|
||||
src={URL.createObjectURL(file.originFileObj as File)}
|
||||
controls
|
||||
className="gallery-video"
|
||||
/>
|
||||
isVideo(item.type) ? (
|
||||
<div className="video-cover" onClick={() => setPreviewItem(item)}>
|
||||
<video src={item.url} className="gallery-video" />
|
||||
<div className="video-play-mask">
|
||||
<VideoCameraOutlined />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="image-cover">
|
||||
<Image
|
||||
src={URL.createObjectURL(file.originFileObj as File)}
|
||||
alt={file.name}
|
||||
src={item.url}
|
||||
alt="风采图片"
|
||||
className="gallery-image"
|
||||
preview={{
|
||||
mask: <CameraOutlined />,
|
||||
}}
|
||||
preview={{ mask: <CameraOutlined /> }}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
actions={[
|
||||
<DeleteOutlined
|
||||
key="delete"
|
||||
onClick={() => handleRemove(file)}
|
||||
style={{ color: '#ff4d4f' }}
|
||||
/>,
|
||||
]}
|
||||
>
|
||||
<Card.Meta
|
||||
title={file.name}
|
||||
description={
|
||||
<Text type="secondary">
|
||||
{file.size
|
||||
? file.size > 1024 * 1024
|
||||
? `${(file.size / 1024 / 1024).toFixed(2)} MB`
|
||||
: `${(file.size / 1024).toFixed(2)} KB`
|
||||
: ''}
|
||||
</Text>
|
||||
}
|
||||
/>
|
||||
<Card.Meta description={<Text type="secondary">上传时间:{item.createTime}</Text>} />
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 视频预览弹窗 */}
|
||||
<Modal
|
||||
open={previewVisible}
|
||||
footer={null}
|
||||
onCancel={() => setPreviewVisible(false)}
|
||||
width={800}
|
||||
title={previewFile?.name || '预览'}
|
||||
>
|
||||
{previewFile && isVideo(previewFile) && (
|
||||
<video
|
||||
src={URL.createObjectURL(previewFile.originFileObj as File)}
|
||||
controls
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
)}
|
||||
{previewFile && isImage(previewFile) && (
|
||||
<Image
|
||||
src={URL.createObjectURL(previewFile.originFileObj as File)}
|
||||
alt={previewFile.name}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
</Spin>
|
||||
|
||||
{/* 视频放大预览 */}
|
||||
<Modal
|
||||
open={!!previewItem}
|
||||
footer={null}
|
||||
onCancel={() => setPreviewItem(null)}
|
||||
width={900}
|
||||
>
|
||||
{previewItem && (
|
||||
<video
|
||||
src={previewItem.url}
|
||||
controls
|
||||
autoPlay
|
||||
style={{ width: '100%', display: 'block' }}
|
||||
/>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user