Skip to content

Commit 8152e9d

Browse files
committed
feat: 支持H5震动反馈设置
1 parent 5556cae commit 8152e9d

9 files changed

Lines changed: 44 additions & 22 deletions

File tree

src/common/publicData.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ export const defaultSettingData = {
201201
'displaySize',
202202
'toggleTabbar',
203203
'backtop'
204-
]
204+
],
205+
h5Vibration: true
205206
}
206207

207208
export const colorList = [

src/h5/assets/main.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
--fbw-tabbar-height: var(--van-tabbar-height);
33
}
44

5+
html,
6+
body {
7+
user-select: none;
8+
}
9+
510
.page-wrapper {
611
width: 100vw;
712
height: calc(100vh - var(--fbw-tabbar-height));

src/h5/pages/home/index.vue

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import UseCommonStore from '@h5/stores/commonStore.js'
33
import UseSettingStore from '@h5/stores/settingStore.js'
44
import * as api from '@h5/api/index.js'
5-
import { vibrate } from '@h5/utils/index.js'
65
import { showImagePreview, showNotify, showConfirmDialog } from 'vant'
76
import { useTranslation } from 'i18next-vue'
87
@@ -495,7 +494,7 @@ const handleFavoriteTouchStart = (event) => {
495494
// 添加最大值限制
496495
if (favoriteHold.count < 100) {
497496
favoriteHold.count++
498-
vibrate() // 每次计数增加时震动反馈
497+
settingStore.vibrate() // 每次计数增加时震动反馈
499498
} else {
500499
// 达到最大值时停止计数并提示用户
501500
clearInterval(favoriteHold.interval)
@@ -604,7 +603,7 @@ const onAddToFavorites = async () => {
604603
const res = await api.addToFavorites(currentImage.id)
605604
if (res.success) {
606605
currentImage.isFavorite = true
607-
vibrate()
606+
settingStore.vibrate()
608607
}
609608
}
610609
@@ -617,7 +616,7 @@ const onRemoveFavorites = async () => {
617616
const res = await api.removeFavorites(currentImage.id)
618617
if (res.success) {
619618
currentImage.isFavorite = false
620-
vibrate()
619+
settingStore.vibrate()
621620
}
622621
}
623622
@@ -657,7 +656,6 @@ const onPreviewImage = async (index) => {
657656
maxZoom: 100,
658657
minZoom: 1 / 3
659658
})
660-
vibrate()
661659
}
662660
663661
// 图片项触摸相关状态
@@ -678,7 +676,6 @@ const handleImageTouchStart = (index, event) => {
678676
longPress.timer = setTimeout(() => {
679677
longPress.selectedIndex = index
680678
flags.showActionPopup = true
681-
vibrate() // 触发震动反馈
682679
}, 500) // 500毫秒长按触发
683680
}
684681
@@ -774,7 +771,7 @@ const saveImage = async () => {
774771
type: 'success',
775772
message: t('messages.saveSuccess')
776773
})
777-
vibrate()
774+
settingStore.vibrate()
778775
} catch (error) {
779776
showNotify({
780777
type: 'danger',
@@ -830,7 +827,7 @@ const deleteImage = async () => {
830827
type: 'success',
831828
message: t('messages.deleteSuccess')
832829
})
833-
vibrate()
830+
settingStore.vibrate()
834831
} else {
835832
showNotify({
836833
type: 'danger',

src/h5/pages/setting/index.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,16 @@ onMounted(() => {
453453
</template>
454454
</van-picker>
455455
</van-popup>
456+
457+
<van-cell :title="t('h5.pages.setting.form.h5Vibration')">
458+
<template #right-icon>
459+
<van-switch
460+
v-model="settingDataForm.h5Vibration"
461+
size="20px"
462+
@change="onSettingDataChange('h5Vibration')"
463+
/>
464+
</template>
465+
</van-cell>
456466
</van-cell-group>
457467

458468
<van-cell-group inset :title="t('h5.pages.setting.about')">

src/h5/stores/settingStore.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ const UseSettingStore = defineStore('setting', {
3232
this.settingData = Object.assign({}, this.settingData, res.data)
3333
}
3434
})
35+
},
36+
vibrate(duration = 50) {
37+
if (this.settingData.h5Vibration && navigator.vibrate) {
38+
navigator.vibrate(duration)
39+
}
3540
}
3641
}
3742
})

src/h5/utils/index.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/i18n/locale/lang/en-US.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@
135135
"h5EnabledFloatingButtons": {
136136
"label": "Enabled Floating Buttons",
137137
"placeholder": "Please select enabled floating buttons"
138-
}
138+
},
139+
"h5Vibration": "Vibration"
139140
},
140141
"privacyPasswordForm": {
141142
"old": {
@@ -508,7 +509,8 @@
508509
"h5EnabledFloatingButtons": {
509510
"label": "Enabled Floating Buttons",
510511
"placeholder": ""
511-
}
512+
},
513+
"h5Vibration": "Vibration"
512514
},
513515
"about": "About",
514516
"version": "Version"

src/i18n/locale/lang/zh-CN.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@
135135
"h5EnabledFloatingButtons": {
136136
"label": "启用悬浮按钮",
137137
"placeholder": "请选择悬浮按钮"
138-
}
138+
},
139+
"h5Vibration": "震动反馈"
139140
},
140141
"privacyPasswordForm": {
141142
"old": {
@@ -508,7 +509,8 @@
508509
"h5EnabledFloatingButtons": {
509510
"label": "启用悬浮按钮",
510511
"placeholder": ""
511-
}
512+
},
513+
"h5Vibration": "震动反馈"
512514
},
513515
"about": "关于",
514516
"version": "版本"

src/renderer/windows/MainWindow/pages/Setting.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,6 @@ onBeforeUnmount(() => {
705705
v-model="settingDataForm.allowedFileExt"
706706
multiple
707707
collapse-tags
708-
collapse-tags-tooltip
709708
:placeholder="t('pages.Setting.settingDataForm.allowedFileExt.placeholder')"
710709
style="width: 290px"
711710
@change="onAllowedFileExtChange"
@@ -917,7 +916,6 @@ onBeforeUnmount(() => {
917916
v-model="settingDataForm.downloadSources"
918917
multiple
919918
collapse-tags
920-
collapse-tags-tooltip
921919
style="width: 290px"
922920
@change="onSettingDataFormChange"
923921
>
@@ -1257,7 +1255,6 @@ onBeforeUnmount(() => {
12571255
v-model="settingDataForm.h5EnabledFloatingButtons"
12581256
multiple
12591257
collapse-tags
1260-
collapse-tags-tooltip
12611258
:placeholder="
12621259
t('pages.Setting.settingDataForm.h5EnabledFloatingButtons.placeholder')
12631260
"
@@ -1272,6 +1269,15 @@ onBeforeUnmount(() => {
12721269
/>
12731270
</el-select>
12741271
</el-form-item>
1272+
<el-form-item
1273+
:label="t('pages.Setting.settingDataForm.h5Vibration')"
1274+
prop="h5Vibration"
1275+
>
1276+
<el-checkbox
1277+
v-model="settingDataForm.h5Vibration"
1278+
@change="onSettingDataFormChange"
1279+
/>
1280+
</el-form-item>
12751281
</div>
12761282
12771283
<div class="form-card">

0 commit comments

Comments
 (0)