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:
@@ -230,6 +230,11 @@ export default [
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '/management/enterprise-showcase',// 企业风采
|
||||
layout: false,
|
||||
component: './Management/EnterpriseShowcase',
|
||||
},
|
||||
{
|
||||
path: '*',
|
||||
layout: false,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { HomeOutlined } from '@ant-design/icons';
|
||||
import { HomeOutlined, CameraOutlined } from '@ant-design/icons';
|
||||
import { history } from '@umijs/max';
|
||||
import portalLogo from '@/assets/logo.png';
|
||||
import './index.less';
|
||||
|
||||
@@ -19,6 +20,10 @@ const EnterpriseHeader: React.FC = () => {
|
||||
window.open(PORTAL_HOME_URL, '_blank');
|
||||
};
|
||||
|
||||
const handleGoShowcase = () => {
|
||||
history.push('/management/enterprise-showcase');
|
||||
};
|
||||
|
||||
const header = (
|
||||
<div className="enterprise-header">
|
||||
<div className="header-left">
|
||||
@@ -28,6 +33,10 @@ const EnterpriseHeader: React.FC = () => {
|
||||
</div>
|
||||
|
||||
<div className="header-right">
|
||||
<div className="home-link-btn" onClick={handleGoShowcase}>
|
||||
<CameraOutlined />
|
||||
<span>企业风采</span>
|
||||
</div>
|
||||
<div className="home-link-btn" onClick={handleGoHome}>
|
||||
<HomeOutlined />
|
||||
<span>返回首页</span>
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
};
|
||||
|
||||
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;
|
||||
@@ -136,3 +136,21 @@ export async function deleteMessage(ids: number, options?: Record<string, any>)
|
||||
});
|
||||
}
|
||||
|
||||
/** 上传我的风采文件 POST /app/file/upload */
|
||||
export async function uploadShowcaseFile(userId: number, file: File) {
|
||||
const formData = new FormData();
|
||||
formData.append('file', file);
|
||||
return request(`/app/file/upload?bussinessid=${userId}`, {
|
||||
method: 'POST',
|
||||
data: formData,
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取我的风采文件列表 GET /app/file/list */
|
||||
export async function getShowcaseFileList(userId: number) {
|
||||
return request('/app/file/list', {
|
||||
method: 'GET',
|
||||
params: { bussinessid: userId },
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
15
src/utils/fileUrl.ts
Normal file
15
src/utils/fileUrl.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/**
|
||||
* 文件展示 URL 拼接工具
|
||||
* 开发环境走相对路径,生产环境拼接固定域名
|
||||
*/
|
||||
|
||||
const PROD_DOMAIN = 'http://39.98.44.136:6024';
|
||||
|
||||
/** 根据服务端返回的 fileUrl 字段拼出可用于 <img>/<video> src 的完整地址 */
|
||||
export function getFileDisplayUrl(fileUrl: string): string {
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
if (isDev) {
|
||||
return `/data/file/${fileUrl}`;
|
||||
}
|
||||
return `${PROD_DOMAIN}/data/file/${fileUrl}`;
|
||||
}
|
||||
Reference in New Issue
Block a user