Skip to content

Commit 33f37ec

Browse files
committed
feat: 新增收藏动效
1 parent 9c2154d commit 33f37ec

4 files changed

Lines changed: 34 additions & 5 deletions

File tree

src/h5/assets/images/star.gif

1.16 MB
Loading

src/h5/pages/home/index.vue

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const flags = reactive({
2525
isAnimating: false,
2626
// 是否正在长按收藏
2727
isFavoriteHolding: false,
28+
// 长按收藏显示提示动效
29+
showFavoriteToast: false,
2830
// 是否操作弹层
2931
showActionPopup: false
3032
})
@@ -149,6 +151,7 @@ const initFlag = () => {
149151
flags.finished = false
150152
flags.isAnimating = false
151153
flags.isFavoriteHolding = false
154+
flags.showFavoriteToast = false
152155
flags.showActionPopup = false
153156
}
154157
@@ -494,17 +497,19 @@ const handleFavoriteTouchStart = (event) => {
494497
// 添加最大值限制
495498
if (favoriteHold.count < 100) {
496499
favoriteHold.count++
497-
settingStore.vibrate() // 每次计数增加时震动反馈
500+
flags.showFavoriteToast = true
501+
settingStore.vibrate(Math.min(Math.max(10, favoriteHold.count), 100))
498502
} else {
499503
// 达到最大值时停止计数并提示用户
500504
clearInterval(favoriteHold.interval)
501505
favoriteHold.interval = null
506+
flags.showFavoriteToast = false
502507
showNotify({
503508
type: 'warning',
504509
message: t('messages.maxFavoriteCountReached')
505510
})
506511
}
507-
}, 500) // 每500毫秒增加一次计数
512+
}, 200) // 每200毫秒增加一次计数
508513
}, 800) // 800毫秒后开始计数
509514
}
510515
@@ -530,6 +535,7 @@ const handleFavoriteTouchMove = (event) => {
530535
531536
// 重置状态
532537
flags.isFavoriteHolding = false
538+
flags.showFavoriteToast = false
533539
favoriteHold.count = 0
534540
}
535541
}
@@ -563,6 +569,7 @@ const handleFavoriteTouchEnd = async () => {
563569
564570
// 重置状态
565571
flags.isFavoriteHolding = false
572+
flags.showFavoriteToast = false
566573
favoriteHold.count = 0
567574
return
568575
}
@@ -603,7 +610,10 @@ const onAddToFavorites = async () => {
603610
const res = await api.addToFavorites(currentImage.id)
604611
if (res.success) {
605612
currentImage.isFavorite = true
606-
settingStore.vibrate()
613+
flags.showFavoriteToast = true
614+
settingStore.vibrate(() => {
615+
flags.showFavoriteToast = false
616+
})
607617
}
608618
}
609619
@@ -676,6 +686,7 @@ const handleImageTouchStart = (index, event) => {
676686
longPress.timer = setTimeout(() => {
677687
longPress.selectedIndex = index
678688
flags.showActionPopup = true
689+
settingStore.vibrate()
679690
}, 500) // 500毫秒长按触发
680691
}
681692
@@ -1062,6 +1073,17 @@ const handlePageShow = () => {}
10621073
</div>
10631074
</div>
10641075
</van-popup>
1076+
1077+
<!-- 收藏提示 -->
1078+
<van-toast
1079+
v-model:show="flags.showFavoriteToast"
1080+
:overlay="false"
1081+
style="background-color: transparent"
1082+
>
1083+
<template #message>
1084+
<img src="@h5/assets/images/star.gif" style="width: 50vw; max-width: 200px; padding: 0" />
1085+
</template>
1086+
</van-toast>
10651087
</template>
10661088
10671089
<style scoped lang="scss">

src/h5/pages/setting/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ onMounted(() => {
191191

192192
<template>
193193
<div class="page-wrapper page-setting">
194-
<van-nav-bar :title="t('h5.pages.setting.title')" left-arrow fixed @click-left="goBack" />
194+
<van-nav-bar :title="t('h5.pages.setting.title')" fixed />
195195

196196
<div class="page-setting-inner">
197197
<van-cell-group inset :title="t('h5.pages.setting.form.appSettings')">

src/h5/stores/settingStore.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@ const UseSettingStore = defineStore('setting', {
3333
}
3434
})
3535
},
36-
vibrate(duration = 50) {
36+
vibrate(duration = 10, callback = null) {
37+
if (typeof duration === 'function') {
38+
callback = duration
39+
duration = 10
40+
}
3741
if (this.settingData.h5Vibration && navigator.vibrate) {
3842
navigator.vibrate(duration)
3943
}
44+
if (callback) {
45+
setTimeout(callback, duration)
46+
}
4047
}
4148
}
4249
})

0 commit comments

Comments
 (0)