From 00bffc05a1e65581f61b074e69bfc2de2b0cc7d8 Mon Sep 17 00:00:00 2001 From: 2008 <59199830@qq.com> Date: Wed, 21 Aug 2024 20:31:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B9=A6=E6=9E=B6=E9=98=B2=E6=AD=A2=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E7=82=B9=E5=87=BB=E5=A4=9A=E6=AC=A1=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 书架防止重复点击多次跳转 --- .../src/main/ets/common/utils/ClickUtils.ets | 21 ++++++++++++++ .../main/ets/componets/common/ReadShow.ets | 9 ++++-- .../ets/componets/search/SearchBookItem.ets | 29 ++++++++++--------- .../pages/view/Find/components/CardItem.ets | 25 +++++++++------- .../bookShelf/components/BookHistoryInfo.ets | 9 ++++-- .../bookShelf/components/BookInfoGrids.ets | 9 ++++-- .../view/bookShelf/components/BookInfos.ets | 9 ++++-- 7 files changed, 75 insertions(+), 36 deletions(-) create mode 100644 entry/src/main/ets/common/utils/ClickUtils.ets diff --git a/entry/src/main/ets/common/utils/ClickUtils.ets b/entry/src/main/ets/common/utils/ClickUtils.ets new file mode 100644 index 00000000..0647e445 --- /dev/null +++ b/entry/src/main/ets/common/utils/ClickUtils.ets @@ -0,0 +1,21 @@ +/** + * @author 2008 + * @datetime 2024/8/21 20:18 + * @className: ClickUtils + * 防止重复点击 + */ +class ClickUtils { + private isClicking:boolean = false; + preventClick(onClickFunction:Function=() => {}, delay:number=1000){ + if(!this.isClicking){ + this.isClicking = true; + onClickFunction(); + setTimeout(()=>{ + this.isClicking = false; + },delay) + } + } +} + +const clickUtil = new ClickUtils(); +export default clickUtil as ClickUtils; \ No newline at end of file diff --git a/entry/src/main/ets/componets/common/ReadShow.ets b/entry/src/main/ets/componets/common/ReadShow.ets index 50e73045..352b4266 100644 --- a/entry/src/main/ets/componets/common/ReadShow.ets +++ b/entry/src/main/ets/componets/common/ReadShow.ets @@ -6,6 +6,7 @@ import bookHistoryDao from '../../database/dao/BookHistoryDao' import { BookHistory } from '../../database/entities/BookHistory' import { Books } from '../../database/entities/Books' import { router } from '@kit.ArkUI' +import clickUtil from '../../common/utils/ClickUtils' @Component export default struct ReadShow { @@ -68,9 +69,11 @@ export default struct ReadShow { } .padding({left:55,right:30}) .onClick(()=>{ - router.pushUrl({ - url: 'pages/view/BookDetailPage', - params: this.book + clickUtil.preventClick(()=>{ + router.pushUrl({ + url: 'pages/view/BookDetailPage', + params: this.book + }) }) }) diff --git a/entry/src/main/ets/componets/search/SearchBookItem.ets b/entry/src/main/ets/componets/search/SearchBookItem.ets index fa18bf8e..77f0fb64 100644 --- a/entry/src/main/ets/componets/search/SearchBookItem.ets +++ b/entry/src/main/ets/componets/search/SearchBookItem.ets @@ -1,5 +1,6 @@ import { SearchBook } from '../../database/entities/SearchBook' import { router } from '@kit.ArkUI' +import clickUtil from '../../common/utils/ClickUtils' @Component export struct SearchBookItem { @@ -58,19 +59,21 @@ export struct SearchBookItem { }.alignItems(HorizontalAlign.Start) } .onClick(()=>{ - router.pushUrl({ - url: 'pages/view/BookDetailPage', - params: { - bookName: this.book.name, - coverUrl: this.book.coverUrl, - author: this.book.author, - intro: this.book.intro, - bookUrl:this.book.bookUrl, - wordCount:this.book.wordCount, - bookType:this.book.bookType, - origin:this.book.source?.bookSourceUrl, - originName:this.book.source?.bookSourceName - } + clickUtil.preventClick(()=>{ + router.pushUrl({ + url: 'pages/view/BookDetailPage', + params: { + bookName: this.book.name, + coverUrl: this.book.coverUrl, + author: this.book.author, + intro: this.book.intro, + bookUrl:this.book.bookUrl, + wordCount:this.book.wordCount, + bookType:this.book.bookType, + origin:this.book.source?.bookSourceUrl, + originName:this.book.source?.bookSourceName + } + }) }) }) diff --git a/entry/src/main/ets/pages/view/Find/components/CardItem.ets b/entry/src/main/ets/pages/view/Find/components/CardItem.ets index 97f302af..7b830465 100644 --- a/entry/src/main/ets/pages/view/Find/components/CardItem.ets +++ b/entry/src/main/ets/pages/view/Find/components/CardItem.ets @@ -1,5 +1,6 @@ import { ExploreRule } from '../../../../database/entities/rule'; import { router } from '@kit.ArkUI'; +import clickUtil from '../../../../common/utils/ClickUtils'; @Component export struct CardItem { @@ -79,17 +80,19 @@ export struct CardItem { .width('100%') .padding({ top: 20 }) .onClick(() => { - router.pushUrl({ - url: 'pages/view/BookDetailPage', - params: { - bookName: this.item.name, - coverUrl: this.item.coverUrl, - author: this.item.author, - intro: this.item.intro, - bookUrl:this.item.bookUrl, - wordCount:this.item.wordCount, - bookType:this.currentIndex - } + clickUtil.preventClick(()=>{ + router.pushUrl({ + url: 'pages/view/BookDetailPage', + params: { + bookName: this.item.name, + coverUrl: this.item.coverUrl, + author: this.item.author, + intro: this.item.intro, + bookUrl:this.item.bookUrl, + wordCount:this.item.wordCount, + bookType:this.currentIndex + } + }) }) }) } diff --git a/entry/src/main/ets/pages/view/bookShelf/components/BookHistoryInfo.ets b/entry/src/main/ets/pages/view/bookShelf/components/BookHistoryInfo.ets index 4f9fbfa1..923fdfab 100644 --- a/entry/src/main/ets/pages/view/bookShelf/components/BookHistoryInfo.ets +++ b/entry/src/main/ets/pages/view/bookShelf/components/BookHistoryInfo.ets @@ -6,6 +6,7 @@ import BookInfoDialogs from './dialog/BookInfoDialogs' import booksUtil from '../../../../common/utils/booksUtils' import { BookHistory } from '../../../../database/entities/BookHistory' import bookHistoryUtils from '../../../../common/utils/BookHistoryUtils' +import clickUtil from '../../../../common/utils/ClickUtils' @Component /** @@ -78,9 +79,11 @@ export default struct BookHistoryInfo{ } .alignItems(HorizontalAlign.Start) .onClick(()=>{ - router.pushUrl({ - url: 'pages/view/BookDetailPage', - params: this.book + clickUtil.preventClick(()=>{ + router.pushUrl({ + url: 'pages/view/BookDetailPage', + params: this.book + }) }) }) } diff --git a/entry/src/main/ets/pages/view/bookShelf/components/BookInfoGrids.ets b/entry/src/main/ets/pages/view/bookShelf/components/BookInfoGrids.ets index ebeed3e0..07b5db7d 100644 --- a/entry/src/main/ets/pages/view/bookShelf/components/BookInfoGrids.ets +++ b/entry/src/main/ets/pages/view/bookShelf/components/BookInfoGrids.ets @@ -4,6 +4,7 @@ import { router } from '@kit.ArkUI' import BookInfoDialogs from './dialog/BookInfoDialogs' import CommonConstants from '../../../../common/constants/CommonConstants' import FontConstants from '../../../../common/constants/FontConstants' +import clickUtil from '../../../../common/utils/ClickUtils' @Component /** @@ -119,9 +120,11 @@ export default struct BookInfoGrids{ .alignItems(HorizontalAlign.Start) .padding({ left:8,right:8,bottom:5,top:5 }) .onClick(()=>{ - router.pushUrl({ - url: 'pages/view/BookDetailPage', - params: this.book + clickUtil.preventClick(()=>{ + router.pushUrl({ + url: 'pages/view/BookDetailPage', + params: this.book + }) }) }) .gesture( diff --git a/entry/src/main/ets/pages/view/bookShelf/components/BookInfos.ets b/entry/src/main/ets/pages/view/bookShelf/components/BookInfos.ets index bb64712c..87d2595e 100644 --- a/entry/src/main/ets/pages/view/bookShelf/components/BookInfos.ets +++ b/entry/src/main/ets/pages/view/bookShelf/components/BookInfos.ets @@ -3,6 +3,7 @@ import { router } from '@kit.ArkUI' import BookInfoDialogs from './dialog/BookInfoDialogs' import CommonConstants from '../../../../common/constants/CommonConstants' import FontConstants from '../../../../common/constants/FontConstants' +import clickUtil from '../../../../common/utils/ClickUtils' @Component /** @@ -81,9 +82,11 @@ export default struct BookInfos{ } } .onClick(()=>{ - router.pushUrl({ - url: 'pages/view/BookDetailPage', - params: this.book + clickUtil.preventClick(()=>{ + router.pushUrl({ + url: 'pages/view/BookDetailPage', + params: this.book + }) }) }) .gesture(