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:
153
src/pages/Management/EnterpriseShowcase/index.less
Normal file
153
src/pages/Management/EnterpriseShowcase/index.less
Normal file
@@ -0,0 +1,153 @@
|
||||
.enterprise-showcase-page {
|
||||
min-height: 100vh;
|
||||
padding-top: 72px;
|
||||
padding-bottom: 40px;
|
||||
background: #f0f2f5;
|
||||
|
||||
.es-page-content {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 0 24px;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.es-back-button {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.es-page-header {
|
||||
margin-bottom: 24px;
|
||||
|
||||
h2 {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.es-upload-card {
|
||||
margin-bottom: 24px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.es-upload-section {
|
||||
.es-upload-area {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 40px 20px;
|
||||
border: 2px dashed #d9d9d9;
|
||||
border-radius: 12px;
|
||||
background: #fafafa;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
|
||||
&:hover {
|
||||
border-color: #1890ff;
|
||||
background: #e6f4ff;
|
||||
}
|
||||
|
||||
.es-upload-icons {
|
||||
display: flex;
|
||||
gap: 24px;
|
||||
margin-bottom: 16px;
|
||||
|
||||
.es-upload-icon {
|
||||
font-size: 40px;
|
||||
color: #1890ff;
|
||||
}
|
||||
}
|
||||
|
||||
.es-upload-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.es-showcase-gallery {
|
||||
.es-gallery-header {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
|
||||
h4 {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.es-gallery-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.es-gallery-card {
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
|
||||
.es-image-cover {
|
||||
height: 200px;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #f5f5f5;
|
||||
|
||||
.es-gallery-image {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
}
|
||||
|
||||
.es-video-cover {
|
||||
height: 200px;
|
||||
overflow: hidden;
|
||||
background: #000;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
|
||||
.es-gallery-video {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.es-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;
|
||||
}
|
||||
|
||||
&:hover .es-video-play-mask {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.enterprise-showcase-page {
|
||||
padding-top: 64px;
|
||||
|
||||
.es-page-content {
|
||||
padding: 0 12px;
|
||||
}
|
||||
|
||||
.es-gallery-grid {
|
||||
grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
266
src/pages/Management/EnterpriseShowcase/index.tsx
Normal file
266
src/pages/Management/EnterpriseShowcase/index.tsx
Normal file
@@ -0,0 +1,266 @@
|
||||
import React, { useState, useEffect, useCallback } from 'react';
|
||||
import {
|
||||
Upload,
|
||||
Button,
|
||||
Card,
|
||||
Image,
|
||||
Spin,
|
||||
Empty,
|
||||
message,
|
||||
Typography,
|
||||
Modal,
|
||||
} from 'antd';
|
||||
import {
|
||||
UploadOutlined,
|
||||
CameraOutlined,
|
||||
VideoCameraOutlined,
|
||||
ArrowLeftOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { history } from '@umijs/max';
|
||||
import { uploadShowcaseFile, getShowcaseFileList } from '@/services/jobportal/user';
|
||||
import { getFileDisplayUrl } from '@/utils/fileUrl';
|
||||
import EnterpriseHeader from '@/components/EnterpriseHeader';
|
||||
import './index.less';
|
||||
|
||||
const { Title, Text } = Typography;
|
||||
|
||||
interface ShowcaseItem {
|
||||
uid: string;
|
||||
type: string;
|
||||
url: string;
|
||||
createTime: string;
|
||||
}
|
||||
|
||||
/** 从 getInfoCache 缓存获取 userId */
|
||||
const getUserIdFromCache = (): number | null => {
|
||||
try {
|
||||
const cached = localStorage.getItem('getInfoCache');
|
||||
if (cached) {
|
||||
const data = JSON.parse(cached);
|
||||
return data?.user?.userId || null;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('读取缓存用户信息失败:', error);
|
||||
}
|
||||
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 EnterpriseShowcase: React.FC = () => {
|
||||
const [items, setItems] = useState<ShowcaseItem[]>([]);
|
||||
const [uploading, setUploading] = useState(false);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [previewItem, setPreviewItem] = useState<ShowcaseItem | null>(null);
|
||||
|
||||
const userId = getUserIdFromCache();
|
||||
|
||||
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]);
|
||||
|
||||
useEffect(() => {
|
||||
fetchFileList();
|
||||
}, [fetchFileList]);
|
||||
|
||||
const customUpload = async (options: any) => {
|
||||
const { file, onSuccess, onError } = options;
|
||||
|
||||
if (!userId) {
|
||||
message.error('请先登录');
|
||||
onError(new Error('未登录'));
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
setUploading(true);
|
||||
const response = await uploadShowcaseFile(userId, file as File);
|
||||
|
||||
if (response?.code === 200 || response?.code === 0) {
|
||||
message.success(`${file.name} 上传成功`);
|
||||
onSuccess(response, file);
|
||||
await fetchFileList();
|
||||
} else {
|
||||
message.error(response?.msg || `${file.name} 上传失败`);
|
||||
onError(new Error(response?.msg || '上传失败'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('上传失败:', error);
|
||||
message.error(`${file.name} 上传失败`);
|
||||
onError(error as Error);
|
||||
} finally {
|
||||
setUploading(false);
|
||||
}
|
||||
};
|
||||
|
||||
const beforeUpload = (file: File): boolean => {
|
||||
const isValid = file.type.startsWith('image/') || file.type.startsWith('video/');
|
||||
if (!isValid) {
|
||||
message.error('只支持上传图片和视频文件!');
|
||||
}
|
||||
return isValid;
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="enterprise-showcase-page">
|
||||
<EnterpriseHeader />
|
||||
<Spin spinning={uploading || loading}>
|
||||
<div className="es-page-content">
|
||||
<div className="es-back-button">
|
||||
<Button type="text" icon={<ArrowLeftOutlined />} onClick={() => history.go(-1)}>
|
||||
返回上一页
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div className="es-page-header">
|
||||
<Title level={2}>企业风采</Title>
|
||||
<Text type="secondary">上传企业照片和视频,展示企业风采</Text>
|
||||
</div>
|
||||
|
||||
{/* 上传区域 */}
|
||||
<Card className="es-upload-card">
|
||||
<div className="es-upload-section">
|
||||
<Upload
|
||||
customRequest={customUpload}
|
||||
beforeUpload={beforeUpload}
|
||||
showUploadList={false}
|
||||
accept="image/*,video/*"
|
||||
multiple
|
||||
>
|
||||
<div className="es-upload-area">
|
||||
<div className="es-upload-icons">
|
||||
<CameraOutlined className="es-upload-icon" />
|
||||
<VideoCameraOutlined className="es-upload-icon" />
|
||||
</div>
|
||||
<div className="es-upload-text">
|
||||
<Text strong>点击或拖拽上传</Text>
|
||||
<Text type="secondary">支持图片和视频文件,大小不限</Text>
|
||||
</div>
|
||||
<Button type="primary" icon={<UploadOutlined />}>
|
||||
选择文件
|
||||
</Button>
|
||||
</div>
|
||||
</Upload>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
{/* 已上传内容展示 */}
|
||||
{items.length === 0 ? (
|
||||
<Empty
|
||||
description="暂无上传内容,快去上传吧"
|
||||
style={{ marginTop: '60px' }}
|
||||
/>
|
||||
) : (
|
||||
<div className="es-showcase-gallery">
|
||||
<div className="es-gallery-header">
|
||||
<Title level={4}>已上传内容</Title>
|
||||
<Text type="secondary">共 {items.length} 条记录</Text>
|
||||
</div>
|
||||
<div className="es-gallery-grid">
|
||||
{items.map((item) => (
|
||||
<Card
|
||||
key={item.uid}
|
||||
className="es-gallery-card"
|
||||
hoverable
|
||||
cover={
|
||||
isVideo(item.type) ? (
|
||||
<div className="es-video-cover" onClick={() => setPreviewItem(item)}>
|
||||
<video src={item.url} className="es-gallery-video" />
|
||||
<div className="es-video-play-mask">
|
||||
<VideoCameraOutlined />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="es-image-cover">
|
||||
<Image
|
||||
src={item.url}
|
||||
alt="企业风采图片"
|
||||
className="es-gallery-image"
|
||||
preview={{ mask: <CameraOutlined /> }}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
>
|
||||
<Card.Meta description={<Text type="secondary">上传时间:{item.createTime}</Text>} />
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</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>
|
||||
);
|
||||
};
|
||||
|
||||
export default EnterpriseShowcase;
|
||||
Reference in New Issue
Block a user