mirror of
https://github.com/eyebluecn/tank-front
synced 2026-10-19 16:16:18 +00:00
download token
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import BaseEntity from "../../base/BaseEntity";
|
||||
import DateUtil from "../../../util/DateUtil";
|
||||
import SafeUtil from "../../../util/SafeUtil";
|
||||
|
||||
export default class DownloadToken extends BaseEntity {
|
||||
userUuid: string | null = null;
|
||||
matterUuid: string | null = null;
|
||||
expireTime: string | null = null;
|
||||
ip: string | null = null;
|
||||
|
||||
static URL_FETCH_DOWNLOAD_TOKEN = "/api/alien/fetch/download/token";
|
||||
|
||||
constructor(reactComponent?: React.Component) {
|
||||
super(reactComponent);
|
||||
}
|
||||
|
||||
getUrlPrefix() {
|
||||
return "/api/download/token";
|
||||
}
|
||||
|
||||
assign(obj: any) {
|
||||
super.assign(obj);
|
||||
this.assignEntity("expireTime", Date);
|
||||
}
|
||||
|
||||
getFilters() {
|
||||
return [...super.getFilters()];
|
||||
}
|
||||
|
||||
httpFetchDownloadToken(
|
||||
matterUuid: string,
|
||||
successCallback?: () => any,
|
||||
errorCallback?: () => any
|
||||
) {
|
||||
let that = this;
|
||||
let date = new Date(new Date().getTime() + 10 * 60 * 1000);
|
||||
|
||||
let form = {
|
||||
expireTime: DateUtil.simpleDateTime(date),
|
||||
matterUuid,
|
||||
};
|
||||
this.httpPost(
|
||||
DownloadToken.URL_FETCH_DOWNLOAD_TOKEN,
|
||||
form,
|
||||
function (response: any) {
|
||||
that.assign(response.data.data);
|
||||
SafeUtil.safeCallback(successCallback)(response);
|
||||
},
|
||||
errorCallback
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
import React from "react";
|
||||
import { Button, Modal, Pagination, Space } from "antd";
|
||||
import Pager from "../../../../common/model/base/Pager";
|
||||
import ImageCache from "../../../../common/model/image/cache/ImageCache";
|
||||
import TankComponent from "../../../../common/component/TankComponent";
|
||||
import ImageCachePanel from "./ImageCachePanel";
|
||||
import ImagePreviewer from "../../../widget/previewer/ImagePreviewer";
|
||||
import MessageBoxUtil from "../../../../common/util/MessageBoxUtil";
|
||||
import { ExclamationCircleFilled } from "@ant-design/icons";
|
||||
import { Empty } from "antd";
|
||||
import TankTitle from "../../../widget/TankTitle";
|
||||
|
||||
interface IProps {
|
||||
initFilter: any;
|
||||
}
|
||||
|
||||
interface IState {}
|
||||
|
||||
export default class ImageCacheList extends TankComponent<IProps, IState> {
|
||||
selectedImageCaches: ImageCache[] = [];
|
||||
pager = new Pager<ImageCache>(this, ImageCache, 2);
|
||||
|
||||
constructor(props: IProps) {
|
||||
super(props);
|
||||
this.state = {};
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
this.refresh();
|
||||
}
|
||||
|
||||
deleteBatch = () => {
|
||||
Modal.confirm({
|
||||
title: "此操作不可撤回, 是否继续?",
|
||||
icon: <ExclamationCircleFilled twoToneColor="#FFDC00" />,
|
||||
onOk: () => {
|
||||
const uuids = this.selectedImageCaches.map((i) => i.uuid).toString();
|
||||
const imageCache = new ImageCache();
|
||||
imageCache.httpDeleteBatch(uuids, () => {
|
||||
MessageBoxUtil.success("操作成功");
|
||||
this.refresh();
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
checkBatch = (check: boolean) => {
|
||||
this.pager.data.forEach((i) => {
|
||||
i.check = check;
|
||||
});
|
||||
this.checkImageCache();
|
||||
};
|
||||
|
||||
refresh = () => {
|
||||
const { initFilter } = this.props;
|
||||
if (initFilter) {
|
||||
for (let key in initFilter) {
|
||||
if (initFilter.hasOwnProperty(key)) {
|
||||
this.pager.setFilterValue(key, initFilter[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.pager.page = 0;
|
||||
this.pager.httpList();
|
||||
this.selectedImageCaches = [];
|
||||
};
|
||||
|
||||
checkImageCache = (imageCache?: ImageCache) => {
|
||||
if (imageCache) {
|
||||
if (imageCache.check) {
|
||||
this.selectedImageCaches.push(imageCache);
|
||||
} else {
|
||||
const index = this.selectedImageCaches.findIndex(
|
||||
(item) => item.uuid === imageCache.uuid
|
||||
);
|
||||
this.selectedImageCaches.splice(index, 1);
|
||||
}
|
||||
} else {
|
||||
this.selectedImageCaches.splice(0, this.selectedImageCaches.length);
|
||||
this.pager.data.forEach((imageCache) => {
|
||||
if (imageCache.check) {
|
||||
this.selectedImageCaches.push(imageCache);
|
||||
}
|
||||
});
|
||||
}
|
||||
this.updateUI();
|
||||
};
|
||||
|
||||
previewImageCache = (imageCache: ImageCache) => {
|
||||
//从matter开始预览图片
|
||||
const imageArray: string[] = [];
|
||||
let startIndex = -1;
|
||||
this.pager.data.forEach((item) => {
|
||||
imageArray.push(item.getResizeUrl());
|
||||
if (item.uuid === imageCache.uuid) {
|
||||
startIndex = imageArray.length - 1;
|
||||
}
|
||||
});
|
||||
|
||||
ImagePreviewer.showMultiPhoto(imageArray, startIndex);
|
||||
};
|
||||
|
||||
changePage = (page: number) => {
|
||||
this.pager.page = page - 1; // page的页数0基
|
||||
this.pager.httpList();
|
||||
this.updateUI();
|
||||
};
|
||||
|
||||
render() {
|
||||
const { selectedImageCaches, pager } = this;
|
||||
if (!pager.data.length) return <Empty description="暂无图片缓存数据"/>;
|
||||
return (
|
||||
<div>
|
||||
<TankTitle
|
||||
name={"图片缓存"}
|
||||
children={
|
||||
<div>
|
||||
<Space>
|
||||
{selectedImageCaches.length ? (
|
||||
<Button type="primary" onClick={this.deleteBatch}>
|
||||
删除
|
||||
</Button>
|
||||
) : null}
|
||||
{selectedImageCaches.length !== pager.data.length ? (
|
||||
<Button type="primary" onClick={() => this.checkBatch(true)}>
|
||||
全选
|
||||
</Button>
|
||||
) : null}
|
||||
{pager.data.length &&
|
||||
selectedImageCaches.length === pager.data.length ? (
|
||||
<Button type="primary" onClick={() => this.checkBatch(false)}>
|
||||
取消
|
||||
</Button>
|
||||
) : null}
|
||||
</Space>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
|
||||
{pager.data.map((imageCache) => (
|
||||
<ImageCachePanel
|
||||
key={imageCache.uuid!}
|
||||
imageCache={imageCache}
|
||||
onDeleteSuccess={this.refresh}
|
||||
onCheckImageCache={this.checkImageCache}
|
||||
onPreviewImageCache={this.previewImageCache}
|
||||
/>
|
||||
))}
|
||||
|
||||
<Pagination
|
||||
className="mt10 pull-right"
|
||||
onChange={this.changePage}
|
||||
current={pager.page + 1}
|
||||
total={pager.totalItems}
|
||||
pageSize={pager.pageSize}
|
||||
hideOnSinglePage
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
import React from "react";
|
||||
import TankComponent from "../../../../common/component/TankComponent";
|
||||
import { Checkbox, Modal } from "antd";
|
||||
import SafeUtil from "../../../../common/util/SafeUtil";
|
||||
import ImageCache from "../../../../common/model/image/cache/ImageCache";
|
||||
import ImageUtil from "../../../../common/util/ImageUtil";
|
||||
import { CheckboxChangeEvent } from "antd/es/checkbox";
|
||||
import { DeleteFilled, ExclamationCircleFilled } from "@ant-design/icons";
|
||||
import MessageBoxUtil from "../../../../common/util/MessageBoxUtil";
|
||||
import FileUtil from "../../../../common/util/FileUtil";
|
||||
import DateUtil from "../../../../common/util/DateUtil";
|
||||
import "./ImageCachePanel.less";
|
||||
|
||||
interface IProps {
|
||||
imageCache: ImageCache;
|
||||
onCheckImageCache: (imageCache?: ImageCache) => any;
|
||||
onPreviewImageCache: (imageCache: ImageCache) => any;
|
||||
onDeleteSuccess: () => any;
|
||||
}
|
||||
|
||||
interface IState {}
|
||||
|
||||
export default class ImageCachePanel extends TankComponent<IProps, IState> {
|
||||
//正在向服务器提交rename的请求
|
||||
renamingLoading = false;
|
||||
showMore = false;
|
||||
|
||||
clickRow = () => {};
|
||||
|
||||
checkToggle = (e: CheckboxChangeEvent) => {
|
||||
const { imageCache, onCheckImageCache } = this.props;
|
||||
imageCache.check = e.target.checked;
|
||||
onCheckImageCache(imageCache);
|
||||
};
|
||||
|
||||
deleteImageCache = () => {
|
||||
Modal.confirm({
|
||||
title: "此操作不可撤回, 是否继续?",
|
||||
icon: <ExclamationCircleFilled twoToneColor="#FFDC00" />,
|
||||
onOk: () => {
|
||||
this.props.imageCache.httpDel(() => {
|
||||
MessageBoxUtil.success("操作成功");
|
||||
this.props.onDeleteSuccess!();
|
||||
});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
render() {
|
||||
const { imageCache } = this.props;
|
||||
|
||||
return (
|
||||
<div className="widget-image-cache-panel">
|
||||
<div
|
||||
onClick={(e) =>
|
||||
SafeUtil.stopPropagationWrap(e)(
|
||||
this.props.onPreviewImageCache(imageCache)
|
||||
)
|
||||
}
|
||||
>
|
||||
<div className="media">
|
||||
<div className="pull-left">
|
||||
<div className="left-part">
|
||||
<span className="basic-span basic-span-hot">
|
||||
<Checkbox
|
||||
onClick={(e) => SafeUtil.stopPropagationWrap(e)}
|
||||
checked={imageCache.check}
|
||||
onChange={this.checkToggle}
|
||||
/>
|
||||
</span>
|
||||
<span className="basic-span">
|
||||
<img
|
||||
className="image-cache-icon"
|
||||
src={ImageUtil.handleImageUrl(
|
||||
imageCache.getOriginUrl(),
|
||||
false,
|
||||
100,
|
||||
100
|
||||
)}
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/*在大屏下的操作栏*/}
|
||||
<div className="pull-right visible-pc">
|
||||
{imageCache.uuid ? (
|
||||
<div className="right-part">
|
||||
<DeleteFilled
|
||||
className="image-cache-operation btn-action red"
|
||||
onClick={(e) =>
|
||||
SafeUtil.stopPropagationWrap(e)(this.deleteImageCache())
|
||||
}
|
||||
/>
|
||||
<span className="image-cache-size">
|
||||
{FileUtil.humanFileSize(imageCache.size)}
|
||||
</span>
|
||||
<span className="image-cache-date">
|
||||
{DateUtil.simpleDateHourMinute(imageCache.updateTime)}
|
||||
</span>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<div className="media-body">
|
||||
<div className="middle-part">
|
||||
<span className="image-cache-name">{imageCache.name}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/*todo 在小屏下的操作栏*/}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user