Skip to content

Commit

Permalink
Merge pull request #265 from mgz0227/dev_2008
Browse files Browse the repository at this point in the history
书架防止重复点击多次跳转
  • Loading branch information
MaoXiaoone authored Aug 21, 2024
2 parents c1ccea7 + 00bffc0 commit 31edaa4
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 36 deletions.
21 changes: 21 additions & 0 deletions entry/src/main/ets/common/utils/ClickUtils.ets
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 6 additions & 3 deletions entry/src/main/ets/componets/common/ReadShow.ets
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
})
})
})

Expand Down
29 changes: 16 additions & 13 deletions entry/src/main/ets/componets/search/SearchBookItem.ets
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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
}
})
})
})

Expand Down
25 changes: 14 additions & 11 deletions entry/src/main/ets/pages/view/Find/components/CardItem.ets
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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
}
})
})
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand Down Expand Up @@ -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
})
})
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 31edaa4

Please sign in to comment.