mirror of
https://github.com/eyebluecn/tank-front
synced 2024-04-21 12:31:55 +00:00
upload cancel.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import {message} from "antd";
|
import { message } from "antd";
|
||||||
|
import axios, { CancelTokenSource } from "axios";
|
||||||
import BaseEntity from "../base/BaseEntity";
|
import BaseEntity from "../base/BaseEntity";
|
||||||
import Filter from "../base/filter/Filter";
|
import Filter from "../base/filter/Filter";
|
||||||
import HttpUtil from "../../util/HttpUtil";
|
import HttpUtil from "../../util/HttpUtil";
|
||||||
@@ -52,6 +53,8 @@ export default class Matter extends BaseEntity {
|
|||||||
progress: number = 0;
|
progress: number = 0;
|
||||||
//实时上传速度 byte/s
|
//实时上传速度 byte/s
|
||||||
speed: number = 0;
|
speed: number = 0;
|
||||||
|
//取消上传source
|
||||||
|
cancelSource: CancelTokenSource = axios.CancelToken.source();
|
||||||
|
|
||||||
static URL_MATTER_CREATE_DIRECTORY = "/api/matter/create/directory";
|
static URL_MATTER_CREATE_DIRECTORY = "/api/matter/create/directory";
|
||||||
static URL_MATTER_SOFT_DELETE = "/api/matter/soft/delete";
|
static URL_MATTER_SOFT_DELETE = "/api/matter/soft/delete";
|
||||||
@@ -121,7 +124,7 @@ export default class Matter extends BaseEntity {
|
|||||||
new InputFilter("分享uuid", "shareUuid"),
|
new InputFilter("分享uuid", "shareUuid"),
|
||||||
new InputFilter("提取码", "shareCode"),
|
new InputFilter("提取码", "shareCode"),
|
||||||
new InputFilter("分享根目录", "shareRootUuid"),
|
new InputFilter("分享根目录", "shareRootUuid"),
|
||||||
new SortFilter('删除时间排序', 'orderDeleteTime'),
|
new SortFilter("删除时间排序", "orderDeleteTime"),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,7 +197,7 @@ export default class Matter extends BaseEntity {
|
|||||||
if (this.isImage()) {
|
if (this.isImage()) {
|
||||||
ImagePreviewer.showSinglePhoto(previewUrl);
|
ImagePreviewer.showSinglePhoto(previewUrl);
|
||||||
} else {
|
} else {
|
||||||
if(shareMode) {
|
if (shareMode) {
|
||||||
PreviewerHelper.preview(this, previewUrl);
|
PreviewerHelper.preview(this, previewUrl);
|
||||||
} else {
|
} else {
|
||||||
PreviewerHelper.preview(this);
|
PreviewerHelper.preview(this);
|
||||||
@@ -208,7 +211,7 @@ export default class Matter extends BaseEntity {
|
|||||||
finallyCallback?: any
|
finallyCallback?: any
|
||||||
) {
|
) {
|
||||||
let that = this;
|
let that = this;
|
||||||
let form = {userUuid: that.userUuid, name: that.name, puuid: that.puuid};
|
let form = { userUuid: that.userUuid, name: that.name, puuid: that.puuid };
|
||||||
|
|
||||||
return this.httpPost(
|
return this.httpPost(
|
||||||
Matter.URL_MATTER_CREATE_DIRECTORY,
|
Matter.URL_MATTER_CREATE_DIRECTORY,
|
||||||
@@ -225,7 +228,7 @@ export default class Matter extends BaseEntity {
|
|||||||
httpSoftDelete(successCallback?: any, errorCallback?: any) {
|
httpSoftDelete(successCallback?: any, errorCallback?: any) {
|
||||||
this.httpPost(
|
this.httpPost(
|
||||||
Matter.URL_MATTER_SOFT_DELETE,
|
Matter.URL_MATTER_SOFT_DELETE,
|
||||||
{uuid: this.uuid},
|
{ uuid: this.uuid },
|
||||||
function (response: any) {
|
function (response: any) {
|
||||||
typeof successCallback === "function" && successCallback(response);
|
typeof successCallback === "function" && successCallback(response);
|
||||||
},
|
},
|
||||||
@@ -233,10 +236,14 @@ export default class Matter extends BaseEntity {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
httpSoftDeleteBatch(uuids: string, successCallback?: any, errorCallback?: any) {
|
httpSoftDeleteBatch(
|
||||||
|
uuids: string,
|
||||||
|
successCallback?: any,
|
||||||
|
errorCallback?: any
|
||||||
|
) {
|
||||||
this.httpPost(
|
this.httpPost(
|
||||||
Matter.URL_MATTER_SOFT_DELETE_BATCH,
|
Matter.URL_MATTER_SOFT_DELETE_BATCH,
|
||||||
{uuids: uuids},
|
{ uuids: uuids },
|
||||||
function (response: any) {
|
function (response: any) {
|
||||||
typeof successCallback === "function" && successCallback(response);
|
typeof successCallback === "function" && successCallback(response);
|
||||||
},
|
},
|
||||||
@@ -247,7 +254,7 @@ export default class Matter extends BaseEntity {
|
|||||||
httpDelete(successCallback?: any, errorCallback?: any) {
|
httpDelete(successCallback?: any, errorCallback?: any) {
|
||||||
this.httpPost(
|
this.httpPost(
|
||||||
Matter.URL_MATTER_DELETE,
|
Matter.URL_MATTER_DELETE,
|
||||||
{uuid: this.uuid},
|
{ uuid: this.uuid },
|
||||||
function (response: any) {
|
function (response: any) {
|
||||||
typeof successCallback === "function" && successCallback(response);
|
typeof successCallback === "function" && successCallback(response);
|
||||||
},
|
},
|
||||||
@@ -258,7 +265,7 @@ export default class Matter extends BaseEntity {
|
|||||||
httpDeleteBatch(uuids: string, successCallback?: any, errorCallback?: any) {
|
httpDeleteBatch(uuids: string, successCallback?: any, errorCallback?: any) {
|
||||||
this.httpPost(
|
this.httpPost(
|
||||||
Matter.URL_MATTER_DELETE_BATCH,
|
Matter.URL_MATTER_DELETE_BATCH,
|
||||||
{uuids: uuids},
|
{ uuids: uuids },
|
||||||
function (response: any) {
|
function (response: any) {
|
||||||
typeof successCallback === "function" && successCallback(response);
|
typeof successCallback === "function" && successCallback(response);
|
||||||
},
|
},
|
||||||
@@ -269,7 +276,7 @@ export default class Matter extends BaseEntity {
|
|||||||
httpRecovery(successCallback?: any, errorCallback?: any) {
|
httpRecovery(successCallback?: any, errorCallback?: any) {
|
||||||
this.httpPost(
|
this.httpPost(
|
||||||
Matter.URL_MATTER_RECOVERY,
|
Matter.URL_MATTER_RECOVERY,
|
||||||
{uuid: this.uuid},
|
{ uuid: this.uuid },
|
||||||
function (response: any) {
|
function (response: any) {
|
||||||
typeof successCallback === "function" && successCallback(response);
|
typeof successCallback === "function" && successCallback(response);
|
||||||
},
|
},
|
||||||
@@ -280,7 +287,7 @@ export default class Matter extends BaseEntity {
|
|||||||
httpRecoveryBatch(uuids: string, successCallback?: any, errorCallback?: any) {
|
httpRecoveryBatch(uuids: string, successCallback?: any, errorCallback?: any) {
|
||||||
this.httpPost(
|
this.httpPost(
|
||||||
Matter.URL_MATTER_RECOVERY_BATCH,
|
Matter.URL_MATTER_RECOVERY_BATCH,
|
||||||
{uuids: uuids},
|
{ uuids: uuids },
|
||||||
function (response: any) {
|
function (response: any) {
|
||||||
typeof successCallback === "function" && successCallback(response);
|
typeof successCallback === "function" && successCallback(response);
|
||||||
},
|
},
|
||||||
@@ -297,7 +304,7 @@ export default class Matter extends BaseEntity {
|
|||||||
let that = this;
|
let that = this;
|
||||||
this.httpPost(
|
this.httpPost(
|
||||||
Matter.URL_MATTER_RENAME,
|
Matter.URL_MATTER_RENAME,
|
||||||
{uuid: this.uuid, name: name},
|
{ uuid: this.uuid, name: name },
|
||||||
function (response: any) {
|
function (response: any) {
|
||||||
that.assign(response.data.data);
|
that.assign(response.data.data);
|
||||||
typeof successCallback === "function" && successCallback(response);
|
typeof successCallback === "function" && successCallback(response);
|
||||||
@@ -315,7 +322,7 @@ export default class Matter extends BaseEntity {
|
|||||||
let that = this;
|
let that = this;
|
||||||
this.httpPost(
|
this.httpPost(
|
||||||
Matter.URL_CHANGE_PRIVACY,
|
Matter.URL_CHANGE_PRIVACY,
|
||||||
{uuid: this.uuid, privacy: privacy},
|
{ uuid: this.uuid, privacy: privacy },
|
||||||
function (response: any) {
|
function (response: any) {
|
||||||
that.privacy = privacy;
|
that.privacy = privacy;
|
||||||
if (typeof successCallback === "function") {
|
if (typeof successCallback === "function") {
|
||||||
@@ -335,7 +342,7 @@ export default class Matter extends BaseEntity {
|
|||||||
successCallback?: any,
|
successCallback?: any,
|
||||||
errorCallback?: any
|
errorCallback?: any
|
||||||
) {
|
) {
|
||||||
let form: any = {srcUuids: srcUuids};
|
let form: any = { srcUuids: srcUuids };
|
||||||
if (destUuid) {
|
if (destUuid) {
|
||||||
form.destUuid = destUuid;
|
form.destUuid = destUuid;
|
||||||
} else {
|
} else {
|
||||||
@@ -495,6 +502,11 @@ export default class Matter extends BaseEntity {
|
|||||||
SafeUtil.safeCallback(successCallback)(response);
|
SafeUtil.safeCallback(successCallback)(response);
|
||||||
},
|
},
|
||||||
function (err: any) {
|
function (err: any) {
|
||||||
|
if (axios.isCancel(err)) {
|
||||||
|
that.clear();
|
||||||
|
SafeUtil.safeCallback(failureCallback)();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const response = err.response;
|
const response = err.response;
|
||||||
that.errorMessage = response;
|
that.errorMessage = response;
|
||||||
that.clear();
|
that.clear();
|
||||||
@@ -524,10 +536,17 @@ export default class Matter extends BaseEntity {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
that.updateUI();
|
that.updateUI();
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cancelToken: that.cancelSource.token,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cancelUpload() {
|
||||||
|
this.cancelSource.cancel();
|
||||||
|
}
|
||||||
|
|
||||||
//清除文件
|
//清除文件
|
||||||
clear() {
|
clear() {
|
||||||
//filter,privacy不变
|
//filter,privacy不变
|
||||||
|
|||||||
+40
-49
@@ -1,91 +1,82 @@
|
|||||||
import axios, {AxiosRequestConfig} from "axios";
|
import axios, { AxiosRequestConfig } from "axios";
|
||||||
import SafeUtil from "./SafeUtil";
|
import SafeUtil from "./SafeUtil";
|
||||||
|
|
||||||
|
|
||||||
//http请求全部收口在这个工具类中,可以快速切换http框架。
|
//http请求全部收口在这个工具类中,可以快速切换http框架。
|
||||||
export default class HttpUtil {
|
export default class HttpUtil {
|
||||||
|
static httpGet(
|
||||||
|
url: any,
|
||||||
static httpGet(url: any, params = {}, successCallback?: any, errorCallback?: any, finallyCallback?: any, opts?: any) {
|
params = {},
|
||||||
|
successCallback?: any,
|
||||||
|
errorCallback?: any,
|
||||||
|
finallyCallback?: any,
|
||||||
|
opts?: any
|
||||||
|
) {
|
||||||
axios
|
axios
|
||||||
.get(url, {
|
.get(url, {
|
||||||
params: params
|
params: params,
|
||||||
})
|
})
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
SafeUtil.safeCallback(successCallback)(response)
|
SafeUtil.safeCallback(successCallback)(response);
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
|
SafeUtil.safeCallback(errorCallback)(error);
|
||||||
SafeUtil.safeCallback(errorCallback)(error)
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.finally(function () {
|
.finally(function () {
|
||||||
|
SafeUtil.safeCallback(finallyCallback)();
|
||||||
SafeUtil.safeCallback(finallyCallback)()
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static httpPost(
|
||||||
static httpPost(url: any, params = {}, successCallback?: any, errorCallback?: any, finallyCallback?: any, opts?: any) {
|
url: any,
|
||||||
|
params = {},
|
||||||
|
successCallback?: any,
|
||||||
|
errorCallback?: any,
|
||||||
|
finallyCallback?: any,
|
||||||
|
opts?: any
|
||||||
|
) {
|
||||||
return axios
|
return axios
|
||||||
.post(url, params, opts)
|
.post(url, params, opts)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
SafeUtil.safeCallback(successCallback)(response);
|
||||||
SafeUtil.safeCallback(successCallback)(response)
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
|
SafeUtil.safeCallback(errorCallback)(error);
|
||||||
SafeUtil.safeCallback(errorCallback)(error)
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.finally(function () {
|
.finally(function () {
|
||||||
|
SafeUtil.safeCallback(finallyCallback)();
|
||||||
SafeUtil.safeCallback(finallyCallback)()
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 上传文件的请求
|
* 上传文件的请求
|
||||||
*/
|
*/
|
||||||
static httpPostFile(url: string,
|
static httpPostFile(
|
||||||
formData: FormData,
|
url: string,
|
||||||
successCallback?: any,
|
formData: FormData,
|
||||||
errorCallback?: any,
|
successCallback?: any,
|
||||||
finallyCallback?: any,
|
errorCallback?: any,
|
||||||
processCallback?: (progressEvent: any) => void,
|
finallyCallback?: any,
|
||||||
opts?: any) {
|
processCallback?: (progressEvent: any) => void,
|
||||||
|
opts?: any
|
||||||
|
) {
|
||||||
const config: AxiosRequestConfig = {
|
const config: AxiosRequestConfig = {
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'multipart/form-data'
|
"Content-Type": "multipart/form-data",
|
||||||
},
|
},
|
||||||
onUploadProgress: processCallback
|
cancelToken: opts ? opts.cancelToken : "",
|
||||||
}
|
onUploadProgress: processCallback,
|
||||||
|
};
|
||||||
|
|
||||||
axios
|
axios
|
||||||
.post(url, formData, config)
|
.post(url, formData, config)
|
||||||
.then(function (response) {
|
.then(function (response) {
|
||||||
|
SafeUtil.safeCallback(successCallback)(response);
|
||||||
SafeUtil.safeCallback(successCallback)(response)
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(function (error) {
|
.catch(function (error) {
|
||||||
|
SafeUtil.safeCallback(errorCallback)(error);
|
||||||
SafeUtil.safeCallback(errorCallback)(error)
|
|
||||||
|
|
||||||
})
|
})
|
||||||
.finally(function () {
|
.finally(function () {
|
||||||
|
SafeUtil.safeCallback(finallyCallback)();
|
||||||
SafeUtil.safeCallback(finallyCallback)()
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.media {
|
.media {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
.media-body {
|
.media-body {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
color: #555;
|
color: #555;
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import TankComponent from "../../../common/component/TankComponent";
|
|||||||
import Matter from "../../../common/model/matter/Matter";
|
import Matter from "../../../common/model/matter/Matter";
|
||||||
import StringUtil from "../../../common/util/StringUtil";
|
import StringUtil from "../../../common/util/StringUtil";
|
||||||
import { Progress } from "antd";
|
import { Progress } from "antd";
|
||||||
|
import { CloseOutlined } from "@ant-design/icons";
|
||||||
import "./UploadMatterPanel.less";
|
import "./UploadMatterPanel.less";
|
||||||
import Lang from "../../../common/model/global/Lang";
|
import Lang from "../../../common/model/global/Lang";
|
||||||
import {UserRole} from "../../../common/model/user/UserRole";
|
|
||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
matter: Matter;
|
matter: Matter;
|
||||||
@@ -23,19 +23,13 @@ export default class UploadMatterPanel extends TankComponent<IProps, IState> {
|
|||||||
return `${percent.toFixed(1)}%`;
|
return `${percent.toFixed(1)}%`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
|
this.props.matter.reactComponent = this;
|
||||||
this.props.matter.reactComponent = this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps: Readonly<IProps>, nextContext: any) {
|
componentWillReceiveProps(nextProps: Readonly<IProps>, nextContext: any) {}
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
this.props.matter.reactComponent = null
|
this.props.matter.reactComponent = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
@@ -46,6 +40,9 @@ export default class UploadMatterPanel extends TankComponent<IProps, IState> {
|
|||||||
<div className="huge-block clearfix">
|
<div className="huge-block clearfix">
|
||||||
<div className="media">
|
<div className="media">
|
||||||
<div className="media-body">{matter.file!.name}</div>
|
<div className="media-body">{matter.file!.name}</div>
|
||||||
|
<div className="media-cancel">
|
||||||
|
<CloseOutlined onClick={() => matter.cancelUpload()} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Progress
|
<Progress
|
||||||
className="progress"
|
className="progress"
|
||||||
|
|||||||
Reference in New Issue
Block a user