进度条

This commit is contained in:
梅航 2024-08-06 14:27:20 +08:00
parent 78214be4be
commit 20132c3086
2 changed files with 342 additions and 236 deletions

View File

@ -1,19 +1,19 @@
.sharedFilesModel { .sharedFilesModel {
>div:nth-child(1) { > div:nth-child(1) {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
>span { > span {
color: #EEEEEE; color: #EEEEEE;
font-size: 16px; font-size: 16px;
} }
>div { > div {
display: flex; display: flex;
align-items: center; align-items: center;
>span { > span {
margin-right: 20px; margin-right: 20px;
cursor: pointer; cursor: pointer;
font-size: 16px; font-size: 16px;
@ -21,7 +21,15 @@
} }
} }
>div:nth-child(2) { > div:nth-child(2) {
margin: 20px 0; margin: 20px 0;
} }
.updateDiv {
color: #ffffff;
.ant-progress .ant-progress-text {
color: #ffffff;
}
}
} }

View File

@ -1,12 +1,19 @@
import styles from '@/components/SharedFilesModel/index.module.scss' import styles from '@/components/SharedFilesModel/index.module.scss'
import { DeleteOutlined, ProfileOutlined, ReloadOutlined, SearchOutlined, VerticalAlignBottomOutlined } from '@ant-design/icons'; import {
import { Button, Input, Modal, Pagination, Table, message } from 'antd'; DeleteOutlined,
import { useState, useImperativeHandle, forwardRef, useEffect } from "react"; ProfileOutlined,
import { PostRoomFile, DeleteRoomFile, GetRoomUpFileurl, GetRoomFileDwUrl, GetRoomFile } from '@/api/Meeting'; ReloadOutlined,
SearchOutlined,
VerticalAlignBottomOutlined
} from '@ant-design/icons';
import {Button, Input, message, Modal, Pagination, Progress, Table} from 'antd';
import {forwardRef, useEffect, useImperativeHandle, useState} from "react";
import {DeleteRoomFile, GetRoomFile, GetRoomFileDwUrl, GetRoomUpFileurl, PostRoomFile} from '@/api/Meeting';
import axios from 'axios'; import axios from 'axios';
import { useLocation } from 'react-router-dom'; import {useLocation} from 'react-router-dom';
import { storage } from '@/utils'; import {storage} from '@/utils';
const { Column } = Table
const {Column} = Table
const SharedFilesModel = forwardRef((props: any, ref: any) => { const SharedFilesModel = forwardRef((props: any, ref: any) => {
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
@ -14,7 +21,7 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => {
setIsSharedFilesModel(true) setIsSharedFilesModel(true)
} }
})) }))
const { state } = useLocation(); const {state} = useLocation();
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]); const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
const [showRowSelection, setShowRowSelection] = useState(false); const [showRowSelection, setShowRowSelection] = useState(false);
const [isSharedFilesModel, setIsSharedFilesModel] = useState(false); const [isSharedFilesModel, setIsSharedFilesModel] = useState(false);
@ -26,6 +33,7 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => {
pageIndex: 1, pageIndex: 1,
pageSize: 10, pageSize: 10,
}) })
const [uploadProgress, setUploadProgress] = useState(0);
useEffect(() => { useEffect(() => {
let userInfo = JSON.parse(storage.getItem('user') as string) let userInfo = JSON.parse(storage.getItem('user') as string)
setUser(userInfo) setUser(userInfo)
@ -66,13 +74,18 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => {
> >
<div> <div>
<div className={styles.sharedFilesModel}> <div className={styles.sharedFilesModel}>
<div> <div className={styles.updateDiv}>
<span>{fileList.total}</span> <span>{fileList.total}</span>
<div style={{ color: 'white' }}> <div>
<Progress percent={uploadProgress} strokeColor={'green'} trailColor={'#e8e8e8'}
percentPosition={{align: 'center', type: 'inner'}}
size={{width: 100, height: 20}}/>
</div>
<div style={{color: 'white'}}>
<Input <Input
placeholder="搜索" placeholder="搜索"
style={{ width: '200px' }} style={{width: '200px'}}
prefix={<SearchOutlined style={{ color: 'white' }} />} prefix={<SearchOutlined style={{color: 'white'}}/>}
onChange={(e) => { onChange={(e) => {
setFileList({ setFileList({
...fileList, ...fileList,
@ -109,10 +122,10 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => {
pageIndex: 1 pageIndex: 1
}) })
} }
}} /> }}/>
<ProfileOutlined title={showRowSelection ? '取消框选' : '显示框选'} onClick={() => { <ProfileOutlined title={showRowSelection ? '取消框选' : '显示框选'} onClick={() => {
setShowRowSelection(!showRowSelection) setShowRowSelection(!showRowSelection)
}} style={{ color: showRowSelection ? '#5575F2' : 'white' }} /> }} style={{color: showRowSelection ? '#5575F2' : 'white'}}/>
{showRowSelection ? <DeleteOutlined title='删除' onClick={() => { {showRowSelection ? <DeleteOutlined title='删除' onClick={() => {
if (selectedRowKeys.length) { if (selectedRowKeys.length) {
DeleteRoomFile(selectedRowKeys).then(res => { DeleteRoomFile(selectedRowKeys).then(res => {
@ -124,8 +137,8 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => {
} else { } else {
message.error('请选择文件!') message.error('请选择文件!')
} }
}} /> : null} }}/> : null}
<Button type="primary" style={{ backgroundColor: '#31353A' }} <Button type="primary" style={{backgroundColor: '#31353A'}}
onClick={() => { onClick={() => {
const file = document.createElement("input") as any; const file = document.createElement("input") as any;
file.accept = "image/*,.doc,.docx,.ppt,.pptx,.xls,.xlsx,application/pdf"; file.accept = "image/*,.doc,.docx,.ppt,.pptx,.xls,.xlsx,application/pdf";
@ -155,7 +168,14 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => {
"Content-Type": "multipart/form-data", "Content-Type": "multipart/form-data",
"Authorization": `Bearer ${user.token}` "Authorization": `Bearer ${user.token}`
}, },
withCredentials: false withCredentials: false,
onUploadProgress: (progressEvent: any) => {
// 获取上传进度
const {loaded, total} = progressEvent;
const progress = Math.round((loaded * 100) / total);
console.log(`上传进度: ${progress}%`);
setUploadProgress(progress)
}
}) })
await PostRoomFile({ await PostRoomFile({
fileUrl: res.data.key, fileUrl: res.data.key,
@ -182,17 +202,17 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => {
} : undefined} } : undefined}
dataSource={fileList.data} dataSource={fileList.data}
pagination={false} pagination={false}
scroll={{ y: '40vh' }} scroll={{y: '40vh'}}
style={{ width: '100%' }} style={{width: '100%'}}
> >
<Column title="文件" dataIndex="fileName" key="fileName" width={140} /> <Column title="文件" dataIndex="fileName" key="fileName" width={140}/>
<Column title="更新时间" dataIndex="modifyTime" key="modifyTime" width={200} /> <Column title="更新时间" dataIndex="modifyTime" key="modifyTime" width={200}/>
<Column title="大小" render={(item) => ( <Column title="大小" render={(item) => (
<> <>
<span>{item.size / 1024 > 1000 ? (item.size / (1024 * 1024)).toFixed(2) + 'MB' : (item.size / 1024).toFixed(2) + 'KB'}</span> <span>{item.size / 1024 > 1000 ? (item.size / (1024 * 1024)).toFixed(2) + 'MB' : (item.size / 1024).toFixed(2) + 'KB'}</span>
</> </>
)} /> )}/>
<Column title="上传者" dataIndex="userName" key="userName" /> <Column title="上传者" dataIndex="userName" key="userName"/>
<Column title="下载次数" <Column title="下载次数"
render={(item) => ( render={(item) => (
<> <>
@ -202,32 +222,110 @@ const SharedFilesModel = forwardRef((props: any, ref: any) => {
/> />
<Column title="操作" render={(item) => ( <Column title="操作" render={(item) => (
<> <>
<VerticalAlignBottomOutlined title='下载' style={{ color: '#5575F2', cursor: 'pointer' }} onClick={() => { <VerticalAlignBottomOutlined title='下载'
style={{color: '#5575F2', cursor: 'pointer'}}
onClick={async () => {
GetRoomFileDwUrl(item.fileUrl, item.id).then(res => { GetRoomFileDwUrl(item.fileUrl, item.id).then(res => {
console.log(res)
if (res.code === 200) { if (res.code === 200) {
// const downloadLink = document.createElement("a");
// downloadLink.href = res.data;
// downloadLink.download = item.fileName;
axios({
url: res.data,
method: 'GET',
// headers: {
// "Authorization": `Bearer ${user.token}`,
// "responseType": 'stream'
// },
onDownloadProgress: (progressEvent: any) => {
const totalLength = item.size;
console.log(2222222)
if (totalLength !== null) {
const percentComplete = (progressEvent.loaded / totalLength * 100).toFixed(2);
console.log(`下载进度: ${percentComplete}%`);
item.percentComplete = percentComplete
}
}
}).then(() => {
const downloadLink = document.createElement("a"); const downloadLink = document.createElement("a");
downloadLink.href = res.data; downloadLink.href = res.data;
downloadLink.download = item.fileName; downloadLink.download = item.fileName;
downloadLink.click(); downloadLink.click();
getRoomFile() getRoomFile()
})
// downloadLink.click();
// getRoomFile()
} }
}) })
}} />
// const url = "https://wgshare.oss-cn-chengdu.aliyuncs.com/share_file/559167236182085/20421555/b24e2c41f47140308c47cdd77e6305c7.jpg?Expires=1722923931&OSSAccessKeyId=LTAI5tQYVQHkkXxXTmjwiSDv&Signature=eJTWD93ifV2v1R6XCHSOa6j1R%2FE%3D"
// axios({
// url,
// method: 'GET',
// // headers: {
// // "Authorization": `Bearer ${user.token}`,
// // "responseType": 'stream'
// // },
// onDownloadProgress: (progressEvent: any) => {
// const totalLength = item.size;
// console.log(2222222)
// if (totalLength !== null) {
// const percentComplete = (progressEvent.loaded / totalLength * 100).toFixed(2);
// console.log(`下载进度: ${percentComplete}%`);
// }
// }
// })
// .then((response: any) => {
// const downloadLink = document.createElement("a");
// downloadLink.href = response.data;
// downloadLink.download = item.fileName;
// downloadLink.click();
// getRoomFile()
// })
// await axios.get(`${import.meta.env.VITE_BASE_URL_API}/room/file-dw-url?fileUrl=${item.fileUrl}&fileId=${item.id}`, {
// headers: {
// "Authorization": `Bearer ${user.token}`,
// "responseType": 'stream'
// },
// onDownloadProgress: (progressEvent: any) => {
// const totalLength = item.size;
// const percentComplete = (progressEvent.loaded / totalLength * 100).toFixed(2);
// console.log(`下载进度: ${percentComplete}%`);
// }
// })
// await axios.get(`${import.meta.env.VITE_BASE_URL_API}/room/file-dw-url?fileUrl=${item.fileUrl}&fileId=${item.id}`, {
// headers: {
// "ResponseType": "blob",
// "Authorization": `Bearer ${user.token}`
// },
// withCredentials: false,
// onDownloadProgress: (progressEvent: any) => {
// console.log(progressEvent, 33333)
// // 获取上传进度
// const {loaded, total} = progressEvent;
// const progress = Math.round((loaded * 100) / total);
// console.log(`下载进度: ${progress}%`);
// setUploadProgress(progress)
// }
// })
}}/>
{/* <FolderOutlined title='文件' style={{ color: '#FFA000', cursor: 'pointer' }} /> */} {/* <FolderOutlined title='文件' style={{ color: '#FFA000', cursor: 'pointer' }} /> */}
</> </>
)} /> )}/>
</Table> </Table>
<div style={{ display: 'flex', justifyContent: 'center', marginTop: '10px' }}> <div style={{display: 'flex', justifyContent: 'center', marginTop: '10px'}}>
<Pagination size="small" total={fileList.total} onChange={(e) => { <Pagination size="small" total={fileList.total} onChange={(e) => {
setFileList({ setFileList({
...fileList, ...fileList,
pageIndex: e pageIndex: e
}) })
}} pageSize={fileList.pageSize} current={fileList.pageIndex} hideOnSinglePage={true} /> }} pageSize={fileList.pageSize} current={fileList.pageIndex} hideOnSinglePage={true}/>
</div> </div>
</div> </div>
</div> </div>
<div style={{ display: 'flex', alignItems: 'center', justifyContent: 'flex-end' }}> <div style={{display: 'flex', alignItems: 'center', justifyContent: 'flex-end'}}>
</div> </div>
</div> </div>