diff --git a/src/common/model/download/token/DownloadToken.ts b/src/common/model/download/token/DownloadToken.ts new file mode 100644 index 0000000..81a9433 --- /dev/null +++ b/src/common/model/download/token/DownloadToken.ts @@ -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 + ); + } +} diff --git a/src/pages/matter/widget/imageCache/ImageCacheList.tsx b/src/pages/matter/widget/imageCache/ImageCacheList.tsx new file mode 100644 index 0000000..0767e0a --- /dev/null +++ b/src/pages/matter/widget/imageCache/ImageCacheList.tsx @@ -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 { + selectedImageCaches: ImageCache[] = []; + pager = new Pager(this, ImageCache, 2); + + constructor(props: IProps) { + super(props); + this.state = {}; + } + + componentDidMount() { + this.refresh(); + } + + deleteBatch = () => { + Modal.confirm({ + title: "此操作不可撤回, 是否继续?", + icon: , + 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 ; + return ( +
+ + + {selectedImageCaches.length ? ( + + ) : null} + {selectedImageCaches.length !== pager.data.length ? ( + + ) : null} + {pager.data.length && + selectedImageCaches.length === pager.data.length ? ( + + ) : null} + +
+ } + /> + + {pager.data.map((imageCache) => ( + + ))} + + + + ); + } +} diff --git a/src/pages/matter/widget/imageCache/ImageCachePanel.tsx b/src/pages/matter/widget/imageCache/ImageCachePanel.tsx new file mode 100644 index 0000000..9a8ecdd --- /dev/null +++ b/src/pages/matter/widget/imageCache/ImageCachePanel.tsx @@ -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 { + //正在向服务器提交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: , + onOk: () => { + this.props.imageCache.httpDel(() => { + MessageBoxUtil.success("操作成功"); + this.props.onDeleteSuccess!(); + }); + }, + }); + }; + + render() { + const { imageCache } = this.props; + + return ( +
+
+ SafeUtil.stopPropagationWrap(e)( + this.props.onPreviewImageCache(imageCache) + ) + } + > +
+
+
+ + SafeUtil.stopPropagationWrap(e)} + checked={imageCache.check} + onChange={this.checkToggle} + /> + + + + +
+
+ + {/*在大屏下的操作栏*/} +
+ {imageCache.uuid ? ( +
+ + SafeUtil.stopPropagationWrap(e)(this.deleteImageCache()) + } + /> + + {FileUtil.humanFileSize(imageCache.size)} + + + {DateUtil.simpleDateHourMinute(imageCache.updateTime)} + +
+ ) : null} +
+
+
+ {imageCache.name} +
+
+ + {/*todo 在小屏下的操作栏*/} +
+
+
+ ); + } +}