-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
234 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import request from '@/utils/request'; | ||
|
||
// 获取图片云列表 | ||
export const getImgList = async <T>(params: T) => { | ||
return request.get('/cloud/list', params, { showLoading: false }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import { Button, Image, Alert, Pagination, Upload, Space, Popover, Tooltip, Spin } from 'antd'; | ||
import { useEffect, useMemo, useState } from 'react'; | ||
import { CheckOutlined, CopyOutlined, InfoCircleOutlined, RedoOutlined, UploadOutlined } from '@ant-design/icons'; | ||
import type { UploadProps } from 'antd'; | ||
import copy from 'copy-to-clipboard'; | ||
import { message } from '@/utils/AntdGlobal'; | ||
import storage from '@/utils/storage'; | ||
import { getImgList } from '@/api/cdn'; | ||
import styles from './index.module.less'; | ||
|
||
export default function ImgCloud() { | ||
const [loading, setLoading] = useState(true); | ||
const [total, setTotal] = useState<number>(100); | ||
const [current, setCurrent] = useState<number>(1); | ||
const [pageSize, setPageSize] = useState<number>(12); | ||
const [state, setState] = useState(false); | ||
const [list, setList] = useState< | ||
Array<{ id: number; type: string; origin_name: string; file_name: string; size: number; user_name: string; created_at: string; url: string }> | ||
>([]); | ||
|
||
useEffect(() => { | ||
getList(); | ||
}, []); | ||
|
||
// 加载页面列表 | ||
const getList = async (pageNum: number = current, size: number = pageSize) => { | ||
setLoading(true); | ||
try { | ||
const res = await getImgList({ | ||
pageNum, | ||
pageSize: size, | ||
}); | ||
setTotal(res?.total || 0); | ||
setList(res?.list || []); | ||
setLoading(false); | ||
} catch (error) { | ||
setLoading(false); | ||
} | ||
}; | ||
|
||
// 切换页码和每页条数回调 | ||
const handleChange = (_current: number, size: number) => { | ||
setCurrent(_current); | ||
setPageSize(size); | ||
}; | ||
|
||
const props: UploadProps = useMemo(() => { | ||
const token = storage.get('token'); | ||
return { | ||
name: 'file', | ||
action: 'http://localhost:5000/api/cloud/upload/files', | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
}, | ||
showUploadList: false, | ||
onChange(info) { | ||
const { status, response } = info.file; | ||
setLoading(true); | ||
if (status !== 'uploading') { | ||
console.log('上传中...'); | ||
} | ||
if (status === 'done') { | ||
setLoading(false); | ||
if (response.code == 0) { | ||
getList(); | ||
} else { | ||
message.error(response.message); | ||
} | ||
} else if (status === 'error') { | ||
message.error(`上传失败,请稍后重试`); | ||
} | ||
}, | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div className={styles.imgCloud}> | ||
<div className={styles.content}> | ||
<Alert type="info" showIcon message="Marsview提供在线CDN服务,方便对远程图片和文件的管理;普通用户最多可上传5个文件,每个文件最大支持5M;" /> | ||
<Space> | ||
<Upload {...props}> | ||
<Button type="primary" icon={<UploadOutlined />}> | ||
上传 | ||
</Button> | ||
</Upload> | ||
<Button shape="circle" icon={<RedoOutlined />} onClick={() => getList()}></Button> | ||
</Space> | ||
</div> | ||
<Spin spinning={loading} size="large"> | ||
<div className={styles.imgList}> | ||
{list.map((item, index) => { | ||
return ( | ||
<div className={styles.imgCard} key={index}> | ||
<div className={styles.imgRound}> | ||
<div className={styles.icons}> | ||
<Space> | ||
<Popover | ||
placement="right" | ||
content={ | ||
<div> | ||
<p> | ||
<span style={{ display: 'inline-block', width: 80 }}>大小:</span> | ||
<span>{(item.size / 1024).toFixed(2)} KB</span> | ||
</p> | ||
<p> | ||
<span style={{ display: 'inline-block', width: 80 }}>创建时间:</span> | ||
<span>{item.created_at}</span> | ||
</p> | ||
<p> | ||
<span style={{ display: 'inline-block', width: 80 }}>创建人:</span> | ||
<span>{item.user_name}</span> | ||
</p> | ||
</div> | ||
} | ||
title={item.origin_name} | ||
trigger="click" | ||
> | ||
<InfoCircleOutlined /> | ||
</Popover> | ||
<Tooltip title="复制"> | ||
{state ? ( | ||
<CheckOutlined /> | ||
) : ( | ||
<CopyOutlined | ||
onClick={() => { | ||
copy(item.url); | ||
setState(true); | ||
setTimeout(() => { | ||
setState(false); | ||
}, 3000); | ||
message.success('复制成功'); | ||
}} | ||
/> | ||
)} | ||
</Tooltip> | ||
</Space> | ||
</div> | ||
<Image src={item.type.startsWith('image') ? item.url : 'https://marsview.cdn.bcebos.com/js.png'} width={100} /> | ||
</div> | ||
<div className={styles.desc}>{(item.size / 1024).toFixed(2)} KB</div> | ||
</div> | ||
); | ||
})} | ||
</div> | ||
</Spin> | ||
<div className={styles.imgPagination}> | ||
<Pagination total={total} current={current} pageSize={pageSize} align="center" showSizeChanger={false} onChange={handleChange} /> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
.imgCloud { | ||
padding: 30px; | ||
overflow-y: auto; | ||
height: calc(100vh - 64px); | ||
} | ||
.content { | ||
margin-bottom: 30px; | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
gap: 20px; | ||
} | ||
.imgList { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 30px; | ||
.imgCard { | ||
position: relative; | ||
text-align: center; | ||
.desc { | ||
font-size: 12px; | ||
color: #999; | ||
} | ||
.imgRound { | ||
width: 142px; | ||
height: 142px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
border-radius: 10px; | ||
overflow: hidden; | ||
border: 1px solid #eee; | ||
padding: 20px; | ||
margin-bottom: 5px; | ||
cursor: pointer; | ||
&:hover { | ||
.icons { | ||
visibility: visible; | ||
} | ||
} | ||
.icons { | ||
position: absolute; | ||
top: 0; | ||
right: 5px; | ||
visibility: hidden; | ||
} | ||
} | ||
} | ||
} | ||
|
||
.imgPagination { | ||
position: absolute; | ||
top: 0; | ||
right: 24px; | ||
margin-top: 20%; | ||
:global { | ||
.ant-pagination { | ||
flex-direction: column; | ||
} | ||
button { | ||
svg { | ||
transform: rotate(90deg); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters