4.1 同步发版内容到天梯
This commit is contained in:
@ -1,12 +1,10 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Upload, Button, message, Modal, Spin } from "antd";
|
||||
import { UploadOutlined, CloseSquareOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
|
||||
|
||||
import { createNewFileBid, removeFileByOid, getFileListByBid } from "./service"
|
||||
|
||||
import { getSessionRoleData, getSessionUserData,getUserToken } from '@/utils/session';
|
||||
|
||||
import { getSessionRoleData, getUserToken } from '@/utils/session';
|
||||
import { UploadProps } from 'antd/lib/upload/interface';
|
||||
import { downloadFile, getFileListByBid, uploadAttachmentPath } from '../DownloadUtils';
|
||||
import { createNewFileBid, removeFileByOid } from '@/services/download_';
|
||||
|
||||
interface ExtendUploadProps {
|
||||
bid?: string;
|
||||
@ -57,7 +55,7 @@ const ExtendUpload: React.FC<ExtendUploadProps> = (props) => {
|
||||
const fileBeforeUpload = (curFile: any, curFileList: any) => {
|
||||
const promise = new Promise<File | void>((resolve, reject) => {
|
||||
if (maxSize === 0) {
|
||||
|
||||
|
||||
} else {
|
||||
let curSize = curFile.size / 1024 / 1024;
|
||||
if (maxSize <= curSize) {
|
||||
@ -66,7 +64,7 @@ const ExtendUpload: React.FC<ExtendUploadProps> = (props) => {
|
||||
}
|
||||
}
|
||||
if (maxCount === 0) {
|
||||
|
||||
|
||||
} else {
|
||||
let curCount = fileList.length;
|
||||
if (maxCount <= curCount) {
|
||||
@ -95,10 +93,10 @@ const ExtendUpload: React.FC<ExtendUploadProps> = (props) => {
|
||||
const fileChange = async (info: any) => {
|
||||
const { file, fileList } = info;
|
||||
setSpin(true);
|
||||
if (file.status === 'uploading' ||file.status === 'removed' || file.status === 'done' || file.status === 'error') {
|
||||
if (file.status === 'uploading' || file.status === 'removed' || file.status === 'done' || file.status === 'error') {
|
||||
if (file.status === 'uploading') {
|
||||
setFileList(fileList);
|
||||
}else {
|
||||
} else {
|
||||
if (file.status === 'removed') {
|
||||
if (file?.uid !== "") {
|
||||
await removeFileByOid(file.uid)
|
||||
@ -112,7 +110,7 @@ const ExtendUpload: React.FC<ExtendUploadProps> = (props) => {
|
||||
//重新获取文件列表并确认是否返回文件id
|
||||
fileListById(returnValue)
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
fileListById(returnValue)
|
||||
}
|
||||
}
|
||||
@ -135,56 +133,35 @@ const ExtendUpload: React.FC<ExtendUploadProps> = (props) => {
|
||||
return promise;
|
||||
}
|
||||
|
||||
const fileDownLoad = (file: any) => {
|
||||
window.fetch(file.url, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
// JwtToken: getSessionUserData() == null ? null : getSessionUserData().userId,
|
||||
Authorization:getUserToken(),
|
||||
currentRoleCode: getSessionRoleData()?.roleCode,
|
||||
},
|
||||
credentials: 'include',
|
||||
}).then((response) => {
|
||||
// 这里才是下载附件逻辑处理的地方
|
||||
response.blob().then(blob => {
|
||||
const blobUrl = window.URL.createObjectURL(blob);
|
||||
const aElement = document.createElement("a");
|
||||
const filename = file.name; // 设置文件名称
|
||||
aElement.href = blobUrl; // 设置a标签路径
|
||||
aElement.download = filename;
|
||||
aElement.click();
|
||||
window.URL.revokeObjectURL(blobUrl);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<Spin spinning={spin}>
|
||||
<Upload
|
||||
{...uploadProps}
|
||||
key={"file" + returnValue}
|
||||
action="/api/core-service-ebtp-updownload/v1/attachment/upload/"
|
||||
data={{ businessId: returnValue }}
|
||||
headers={{
|
||||
// JwtToken: getSessionUserData() == null ? null : getSessionUserData().userId,
|
||||
Authorization:getUserToken(),
|
||||
currentRoleCode: getSessionRoleData()?.roleCode,
|
||||
}}
|
||||
name="file"
|
||||
beforeUpload={fileBeforeUpload}
|
||||
onChange={fileChange}
|
||||
onRemove={fileRemove}
|
||||
showUploadList={{
|
||||
removeIcon: <CloseSquareOutlined />,
|
||||
}}
|
||||
onPreview={fileDownLoad}
|
||||
fileList={fileList}
|
||||
>
|
||||
{!uploadProps?.disabled ?
|
||||
<Button disabled={uploadProps?.disabled} icon={<UploadOutlined />}>{btnName}</Button>
|
||||
: null}
|
||||
</Upload>
|
||||
<Spin spinning={spin}>
|
||||
<Upload
|
||||
{...uploadProps}
|
||||
key={"file" + returnValue}
|
||||
action={uploadAttachmentPath}
|
||||
data={{
|
||||
appCode: 'ebtp-cloud-frontend',
|
||||
objectId: returnValue,
|
||||
}}
|
||||
headers={{
|
||||
Authorization: getUserToken(),
|
||||
currentRoleCode: getSessionRoleData()?.roleCode,
|
||||
}}
|
||||
name="multipartFiles"
|
||||
beforeUpload={fileBeforeUpload}
|
||||
onChange={fileChange}
|
||||
onRemove={fileRemove}
|
||||
showUploadList={{
|
||||
removeIcon: <CloseSquareOutlined />,
|
||||
}}
|
||||
onPreview={downloadFile}
|
||||
fileList={fileList}
|
||||
>
|
||||
{!uploadProps?.disabled ?
|
||||
<Button disabled={uploadProps?.disabled} icon={<UploadOutlined />}>{btnName}</Button>
|
||||
: null}
|
||||
</Upload>
|
||||
</Spin>
|
||||
</>
|
||||
)
|
||||
|
Reference in New Issue
Block a user