Skip to content

Commit 57a261a

Browse files
committed
feat: 优化 Controller
1 parent d16b0d6 commit 57a261a

File tree

6 files changed

+635
-465
lines changed

6 files changed

+635
-465
lines changed

components/content/ProseImg.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { HanaImgViewer as ImgViewer } from 'hana-img-viewer'
2+
import { HanaImgViewer } from 'hana-img-viewer'
33
44
const props = defineProps<{
55
src: string
@@ -48,6 +48,6 @@ const refinedSrc = computed(() => {
4848

4949
<template>
5050
<div class="m-auto w-full md:w-3/5">
51-
<ImgViewer v-bind="{ ...props, src: refinedSrc }" />
51+
<HanaImgViewer v-bind="{ ...props, src: refinedSrc }" />
5252
</div>
5353
</template>

components/hana/Controller.vue

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,45 @@
11
<script setup lang="ts">
2+
import { useStore } from '~/store'
3+
24
const props = defineProps<{
35
scrollTop: number // 当前整个容器的滚动偏移量,只接收不修改
46
scrollHeight: number
57
clientHeight: number
68
}>()
79
8-
const { scrollTop, scrollHeight, clientHeight } = toRefs(props)
10+
const { dialogStore } = useStore()
11+
const { dialogCount } = toRefs(dialogStore)
12+
13+
const route = useRoute()
14+
const { path } = toRefs(route)
915
16+
// #region 滚动相关逻辑
1017
const { progress } = useLoadingIndicator()
1118
const canScroll = ref(false)
1219
1320
watchEffect(() => {
14-
canScroll.value = scrollHeight.value > clientHeight.value
21+
canScroll.value = props.scrollHeight > props.clientHeight
1522
})
1623
1724
const curScrollPercent = computed(() => {
18-
const percent = Math.ceil((scrollTop.value / (scrollHeight.value - clientHeight.value)) * 100)
25+
const percent = Math.ceil((props.scrollTop / (props.scrollHeight - props.clientHeight)) * 100)
1926
return Math.min(percent, 100)
2027
})
2128
2229
const showPercent = ref(true)
2330
function toggleShowPercent() {
2431
showPercent.value = !showPercent.value
2532
}
33+
// #endregion
34+
35+
// #region 评论相关逻辑
36+
const commentWhiteList = ['/recently'] // 在白名单中的路径不显示评论
2637
2738
const hasComments = ref(false)
2839
2940
function checkCommentsExistence() {
41+
if (commentWhiteList.includes(path.value))
42+
return null
3043
const commentsElement = document.querySelector('#comments')
3144
hasComments.value = !!commentsElement
3245
return commentsElement
@@ -62,8 +75,9 @@ function scrollToTop() {
6275
})
6376
}
6477
}
78+
// #endregion
6579
66-
/* 音量控制相关逻辑 */
80+
// #region 音量控制相关逻辑
6781
const isIdle = ref(true)
6882
const volume = ref(0)
6983
const previousVolume = ref(0)
@@ -112,13 +126,14 @@ function handleInput(e: Event) {
112126
const target = e.target as HTMLInputElement
113127
$audioPlayer.setVolume(target.valueAsNumber)
114128
}
129+
// #endregion
115130
</script>
116131

117132
<template>
118133
<transition-group name="controller" tag="div" class="fixed bottom-10 right-10 flex flex-col gap-4">
119134
<div
120-
v-if="!isIdle"
121-
class="relative w-14 overflow-hidden hana-card transition-all duration-300 hidden xl:block"
135+
v-if="dialogCount === 0 && !isIdle"
136+
class="relative w-14 overflow-hidden hana-card transition-all duration-300"
122137
:style="{ height: controllerHeight }"
123138
@mouseenter="toggleShowVolumePanel"
124139
@mouseleave="toggleShowVolumePanel"
@@ -151,7 +166,7 @@ function handleInput(e: Event) {
151166
</div>
152167
</div>
153168

154-
<div v-if="hasComments" class="relative hana-card hidden xl:block">
169+
<div v-if="dialogCount === 0 && hasComments" class="relative hana-card">
155170
<HanaTooltip content="滚到评论" position="left" animation="slide">
156171
<div class="size-10 hana-button items-center justify-center font-bold" @click="scrollToComments">
157172
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
@@ -164,7 +179,7 @@ function handleInput(e: Event) {
164179
</HanaTooltip>
165180
</div>
166181

167-
<div v-if="canScroll" class="relative hana-card hidden xl:block">
182+
<div v-if="dialogCount === 0 && canScroll" class="relative hana-card">
168183
<HanaTooltip content="返回顶部" position="left" animation="slide">
169184
<div
170185
class="size-10 hana-button items-center justify-center font-bold"

components/recently/DetailDialog.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import type { ActivityItem } from '~/types/activity'
3-
import { HanaImgViewer as ImgViewer } from 'hana-img-viewer'
3+
import { HanaImgViewer } from 'hana-img-viewer'
44
55
const props = defineProps<{ item?: ActivityItem }>()
66
@@ -31,14 +31,15 @@ const visible = defineModel<boolean>()
3131
{{ props.item.content }}
3232
</p>
3333
<div v-if="props.item.images && props.item.images.length" class="flex flex-col gap-5">
34-
<ImgViewer
34+
<HanaImgViewer
3535
v-for="image in props.item.images"
3636
:key="image"
3737
:src="image"
3838
class="size-full cursor-pointer overflow-hidden rounded-xl object-cover"
3939
loading="lazy"
4040
/>
4141
</div>
42+
<RecentlyMusicCard v-if="props.item?.music && props.item.music.length > 0" :music="props.item.music" />
4243
</main>
4344
<footer class="py-5">
4445
<Comment type="recently" />

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "hana-blog",
33
"type": "module",
44
"private": true,
5-
"packageManager": "[email protected].2",
5+
"packageManager": "[email protected].3",
66
"scripts": {
77
"build": "nuxt build",
88
"dev": "nuxt dev",

0 commit comments

Comments
 (0)