From 66182572a68b9e6c07b2db4bc3c93e2bf8a371fe Mon Sep 17 00:00:00 2001 From: seaheart Date: Sat, 8 Jul 2023 20:31:54 +0800 Subject: [PATCH] fix share problem --- src/common/model/share/Share.ts | 7 +-- src/pages/share/Detail.tsx | 61 +++++++++------------ src/pages/share/widget/ShareMatterPanel.tsx | 27 +++++++-- 3 files changed, 50 insertions(+), 45 deletions(-) diff --git a/src/common/model/share/Share.ts b/src/common/model/share/Share.ts index afbcabb..4f4b392 100644 --- a/src/common/model/share/Share.ts +++ b/src/common/model/share/Share.ts @@ -24,9 +24,6 @@ export default class Share extends BaseEntity { matters: Matter[] = []; spaceUuid: string | null = null; - //当前分享正在查看的根目录matter的uuid。前端辅助字段。 - rootUuid: string = Matter.MATTER_ROOT; - //本地临时字段 expireOption: ShareExpireOption = ShareExpireOption.MONTH; @@ -97,11 +94,11 @@ export default class Share extends BaseEntity { } //下载zip包 - downloadZip(puuid?: string) { + downloadZip(rootUuid: string, puuid?: string) { window.open( `${EnvUtil.currentHost()}${Share.URL_ZIP}?shareUuid=${this.uuid}&code=${ this.code - }&puuid=${puuid}&rootUuid=${this.rootUuid}` + }&puuid=${puuid}&rootUuid=${rootUuid}` ); } diff --git a/src/pages/share/Detail.tsx b/src/pages/share/Detail.tsx index 0e6b8a8..8806abe 100644 --- a/src/pages/share/Detail.tsx +++ b/src/pages/share/Detail.tsx @@ -48,6 +48,7 @@ export default class Detail extends TankComponent { share = new Share(this); pager = new Pager(this, Matter, Detail.sharePagerSize); user = Moon.getSingleton().user; + currentShareRootUuid = BrowserUtil.getQueryByName('shareRootUuid'); // 当前查看的分享的根目录uuid constructor(props: IProps) { super(props); @@ -57,9 +58,6 @@ export default class Detail extends TankComponent { this.share.uuid = this.props.match.params.uuid; if (this.user.hasLogin()) { - //如果query中有rootUuid那么就更新. - this.share.rootUuid = - BrowserUtil.getQueryByName('shareRootUuid') || this.share.rootUuid; this.pager.enableHistory(); this.pager.urlPage = Share.URL_MATTER_PAGE; this.refresh(); @@ -73,47 +71,38 @@ export default class Detail extends TankComponent { } refresh() { - const puuid = BrowserUtil.getQueryByName('puuid') || Matter.MATTER_ROOT; - if (puuid === Matter.MATTER_ROOT) { - this.share.rootUuid = Matter.MATTER_ROOT; - } + const puuid = BrowserUtil.getQueryByName('puuid') || Matter.MATTER_ROOT; // 当前目录的puuid - this.share.httpBrowse(puuid, this.share.rootUuid, () => { + this.share.httpBrowse(puuid, this.currentShareRootUuid!, () => { + this.needShareCode = false; + + // 根目录下matters已经通过browse接口拿到了 if (puuid === Matter.MATTER_ROOT) { this.pager.clear(); this.pager.totalItems = this.share.matters.length; this.pager.data = this.share.matters; + } else { + this.refreshMatterPager(); } //刷新面包屑,面包屑依赖于这个接口 this.refreshBreadcrumbs(); - - this.needShareCode = false; this.updateUI(); }); - - this.refreshMatterPager(); } refreshMatterPager() { - //只有当鉴权通过,并且不是分享根目录时需要才去进行page请求,根目录下matters已经通过browse接口拿到了 const puuid = BrowserUtil.getQueryByName('puuid'); - if (!this.needShareCode && puuid && puuid !== Matter.MATTER_ROOT) { - const { - uuid: shareUuid, - code: shareCode, - rootUuid: shareRootUuid, - } = this.share; - this.pager.setFilterValues({ - puuid, - shareUuid, - shareCode, - shareRootUuid, - orderCreateTime: SortDirection.DESC, // 默认以时间降序 - orderDir: SortDirection.DESC, // 默认文件夹排在前面 - }); - this.pager.httpList(); - } + const { uuid: shareUuid, code: shareCode } = this.share; + this.pager.setFilterValues({ + puuid, + shareUuid, + shareCode, + shareRootUuid: this.currentShareRootUuid, + orderCreateTime: SortDirection.DESC, // 默认以时间降序 + orderDir: SortDirection.DESC, // 默认文件夹排在前面 + }); + this.pager.httpList(); } getFiles(value: string) { @@ -123,7 +112,7 @@ export default class Detail extends TankComponent { downloadZip() { const puuid = BrowserUtil.getQueryByName('puuid') || Matter.MATTER_ROOT; - this.share.downloadZip(puuid); + this.share.downloadZip(this.currentShareRootUuid!, puuid); } cancelShare() { @@ -146,7 +135,11 @@ export default class Detail extends TankComponent { this.pager.data.forEach((item) => { if (item.isImage()) { imageArray.push( - item.getSharePreviewUrl(share.uuid!, share.code!, share.rootUuid) + item.getSharePreviewUrl( + share.uuid!, + share.code!, + this.currentShareRootUuid! + ) ); if (item.uuid === matter.uuid) { startIndex = imageArray.length - 1; @@ -161,10 +154,10 @@ export default class Detail extends TankComponent { const paramId = this.props.match.params.uuid; if (matterUuid) { - //share.rootUuid 一旦设置好了,只要根文件夹不换,那么就一直不会变。 + // currentShareRootUuid 一旦设置好了,只要根文件夹不换,那么就一直不会变。 const puuid = BrowserUtil.getQueryByName('puuid'); if (!puuid || puuid === Matter.MATTER_ROOT) { - this.share.rootUuid = matterUuid; + this.currentShareRootUuid = matterUuid; this.pager.clear(); } @@ -174,7 +167,6 @@ export default class Detail extends TankComponent { Sun.navigateQueryTo({ path: `/share/detail/${paramId}`, query }); } else { // 回到分享根目录,先将rootUuid交给根目录 - this.share.rootUuid = Matter.MATTER_ROOT; this.pager.clear(); Sun.navigateQueryTo({ path: `/share/detail/${paramId}` }); } @@ -297,6 +289,7 @@ export default class Detail extends TankComponent { key={matter.uuid!} matter={matter} share={share} + currentShareRootUuid={this.currentShareRootUuid!} onGoToDirectory={this.goToDirectory.bind(this)} onPreviewImage={this.previewImage.bind(this)} /> diff --git a/src/pages/share/widget/ShareMatterPanel.tsx b/src/pages/share/widget/ShareMatterPanel.tsx index f3a33c5..2053e5d 100644 --- a/src/pages/share/widget/ShareMatterPanel.tsx +++ b/src/pages/share/widget/ShareMatterPanel.tsx @@ -19,6 +19,7 @@ import ImageUtil from '../../../common/util/ImageUtil'; interface IProps { matter: Matter; share: Share; + currentShareRootUuid: string; onPreviewImage: (matter: Matter) => any; onGoToDirectory: (id: string) => any; } @@ -34,7 +35,13 @@ export default class ShareMatterPanel extends TankComponent { } clickRow() { - const { matter, share, onGoToDirectory, onPreviewImage } = this.props; + const { + matter, + share, + currentShareRootUuid, + onGoToDirectory, + onPreviewImage, + } = this.props; if (matter.dir) { onGoToDirectory(matter.uuid!); @@ -44,17 +51,25 @@ export default class ShareMatterPanel extends TankComponent { onPreviewImage(matter); } else { matter.preview( - matter.getSharePreviewUrl(share.uuid!, share.code!, share.rootUuid) + matter.getSharePreviewUrl( + share.uuid!, + share.code!, + currentShareRootUuid + ) ); } } } getIcon() { - const { matter, share } = this.props; + const { matter, share, currentShareRootUuid } = this.props; if (matter.isImage()) { return ImageUtil.handleImageUrl( - matter.getSharePreviewUrl(share.uuid!, share.code!, share.rootUuid), + matter.getSharePreviewUrl( + share.uuid!, + share.code!, + currentShareRootUuid + ), false, 100, 100 @@ -65,9 +80,9 @@ export default class ShareMatterPanel extends TankComponent { } download() { - const { matter, share } = this.props; + const { matter, share, currentShareRootUuid } = this.props; matter.download( - matter.getShareDownloadUrl(share.uuid!, share.code!, share.rootUuid) + matter.getShareDownloadUrl(share.uuid!, share.code!, currentShareRootUuid) ); }