mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-11-13 22:11:42 +08:00
feat&refactor: 完成项目多轮优化与功能迭代
1. 调整开发环境与生产环境接口地址为局域网地址 2. 新增页面滚动监听hook、版权组件与小尺寸阴影工具类 3. 优化多处组件样式、导航栏与tabbar配置 4. 重构恋爱模块配置类型与移除冗余接口 5. 修复多处代码细节与优化用户体验
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
import { randomTagColor } from '@/utils/random'
|
||||
import { markdownConfig } from '@/config/markdown'
|
||||
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
|
||||
import { usePageScroll } from '@/hooks/usePageScroll'
|
||||
import type { IMoment } from '@/api/types/halo'
|
||||
|
||||
definePage({
|
||||
@@ -22,6 +23,7 @@
|
||||
},
|
||||
})
|
||||
|
||||
const { scrollY } = usePageScroll()
|
||||
const appConfigStore = useAppConfigStore()
|
||||
const favoritesStore = useFavoritesStore()
|
||||
const haloConfigs = computed(() => appConfigStore.configs)
|
||||
@@ -268,18 +270,19 @@
|
||||
title: moment.value?.owner?.displayName || '',
|
||||
query: moment.value ? `name=${moment.value.metadata.name}` : '',
|
||||
}))
|
||||
|
||||
onPageScroll((e : any) => {
|
||||
console.log('滚动', e)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="app-page box-border min-h-screen w-screen bg-page pb-safe">
|
||||
<!-- 自定义导航 -->
|
||||
<uh-navbar default-title="瞬间详情" title-color="text-gray-900" />
|
||||
<uh-navbar :scroll-y="scrollY" default-title="瞬间详情" title-color="text-gray-900" />
|
||||
|
||||
<!-- 状态区(加载中/失败可重试/空) -->
|
||||
<uh-data-loading v-if="status !== 'success'" :loading-status="status" min-height="60vh" error-text="瞬间内容加载失败"
|
||||
empty-text="瞬间不存在或已被删除" @refresh="loadMoment" />
|
||||
|
||||
<!-- 瞬间内页(日记式:大字日期刊头 + 阅读正文 + 媒体 + 互动脚注) -->
|
||||
<view v-else-if="moment" class="box-border px-3 pt-2 pb-12">
|
||||
<view class="mb-3 uh-global-card-glass uh-shadow-xs overflow-hidden rounded-2xl box-border pb-4">
|
||||
<!-- 刊头:大字日期 -->
|
||||
@@ -309,11 +312,10 @@
|
||||
|
||||
<!-- 正文 -->
|
||||
<view class="content px-4 mt-6 text-gray-900 text-sm">
|
||||
<mp-html lazy-load :domain="markdownConfig.domain ?? ''"
|
||||
:loading-img="markdownConfig.loadingGif" scroll-table selectable
|
||||
:tag-style="markdownConfig.tagStyle" :container-style="markdownConfig.containStyle"
|
||||
:content="moment.spec.newHtml || ''" :markdown="true" :show-line-number="true"
|
||||
:show-language-name="true" copy-by-long-press />
|
||||
<mp-html lazy-load :domain="markdownConfig.domain ?? ''" :loading-img="markdownConfig.loadingGif"
|
||||
scroll-table selectable :tag-style="markdownConfig.tagStyle"
|
||||
:container-style="markdownConfig.containStyle" :content="moment.spec.newHtml || ''"
|
||||
:markdown="true" :show-line-number="true" :show-language-name="true" copy-by-long-press />
|
||||
</view>
|
||||
|
||||
<!-- 图片附件 -->
|
||||
@@ -351,7 +353,7 @@
|
||||
<view v-if="moment.spec.tags && moment.spec.tags.length !== 0"
|
||||
class="tags flex flex-wrap gap-2 px-4 pt-6">
|
||||
<view v-for="(tag, tagIndex) in moment.spec.tags" :key="tagIndex"
|
||||
class="rounded-full bg-primary px-3 py-1 text-xs font-bold" >
|
||||
class="rounded-full bg-primary px-3 py-1 text-xs font-bold">
|
||||
# {{ tag }}
|
||||
</view>
|
||||
</view>
|
||||
@@ -361,14 +363,16 @@
|
||||
<uh-comment-list v-if="moment" ref="commentListRef" :post-name="moment.metadata.name" :post="moment"
|
||||
kind="Moment" :disallow-comment="!moment.spec.allowComment" @on-comment="handleOnComment" />
|
||||
</view>
|
||||
<!-- 悬浮操作(与文章详情一致:点赞/评论/收藏) -->
|
||||
<view v-if="moment" class="fixed bottom-8 left-1/2 z-10 flex items-center justify-center pb-safe -translate-x-1/2">
|
||||
|
||||
<!-- 悬浮操作 -->
|
||||
<view v-if="moment"
|
||||
class="fixed bottom-8 left-1/2 z-10 flex items-center justify-center pb-safe uh-translate-x-center">
|
||||
<view
|
||||
class="uh-global-card-glass box-border flex items-center justify-center gap-2 border rounded-full p-1 text-primary">
|
||||
<!-- 点赞 -->
|
||||
<view
|
||||
class="uh-global-card-glass box-border h-[72rpx] flex flex-1 items-center justify-center gap-x-1 border rounded-full px-4 shadow-none"
|
||||
:class="{ active: hasUpvoted() }" @click="handleDoLikesClick">
|
||||
:class="[hasUpvoted()?'text-primary':'text-gray-900']" @click="handleDoLikesClick">
|
||||
<wd-icon class-prefix="uhemoji-icon" name="-kiss-" size="36rpx" />
|
||||
<text class="shrink-0 text-sm text-gray-900 font-semibold">点赞</text>
|
||||
</view>
|
||||
@@ -385,7 +389,7 @@
|
||||
@click="handleToggleMomentFavorite">
|
||||
<wd-icon class-prefix="uhemoji-icon" name="-smile-" size="36rpx" />
|
||||
<text class="shrink-0 text-sm font-semibold"
|
||||
:class="momentFavorited ? 'text-primary' : 'text-gray-900'">{{ momentFavorited ? '已收藏' : '收藏' }}</text>
|
||||
:class="[momentFavorited ? 'text-primary' : 'text-gray-900']">{{ momentFavorited ? '已收藏' : '收藏' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -395,4 +399,11 @@
|
||||
:title="commentModal.title" :post-name="commentModal.postName" subject-kind="Moment"
|
||||
@on-close="handleOnCommentModalClose" />
|
||||
</view>
|
||||
</template>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
/* 水平居中定位 */
|
||||
.uh-translate-x-center {
|
||||
transform: translateX(-50%);
|
||||
}
|
||||
</style>
|
||||
@@ -1,337 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 瞬间详情页(源自旧项目 pagesA/moment-detail,新建复刻)
|
||||
* 展示瞬间内容(mp-html) + 图片/音频/视频附件
|
||||
* 试点:useDataLoading 状态机接管加载四态 + 壁纸光斑玻璃卡设计
|
||||
*/
|
||||
import { computed, ref } from 'vue'
|
||||
import { onLoad, onPullDownRefresh, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
|
||||
import { getMomentByName } from '@/api/halo'
|
||||
import { useAppConfigStore } from '@/store/appConfig'
|
||||
import { checkAvatarUrl, checkThumbnailUrl } from '@/utils/url'
|
||||
import { generateUUID } from '@/utils/uuid'
|
||||
import { formatTime as formatTimeUtil } from '@/utils/formatTime'
|
||||
import { randomTagColor } from '@/utils/random'
|
||||
import { markdownConfig } from '@/config/markdown'
|
||||
import { useDataLoading } from '@/hooks/useDataLoading'
|
||||
import type { IMoment } from '@/api/types/halo'
|
||||
|
||||
definePage({
|
||||
style: {
|
||||
navigationBarTitleText: '瞬间详情',
|
||||
enablePullDownRefresh: true,
|
||||
// 下拉/回弹露出的窗口底色对齐页面底色,壁纸光斑由页面内提供
|
||||
backgroundColor: '#f6f3ee',
|
||||
},
|
||||
})
|
||||
|
||||
const appConfigStore = useAppConfigStore()
|
||||
const haloConfigs = computed(() => appConfigStore.configs)
|
||||
|
||||
const bloggerInfo = computed(() => {
|
||||
const blogger = haloConfigs.value.authorConfig?.blogger as { nickname?: string, avatar?: string } | undefined
|
||||
return {
|
||||
nickname: blogger?.nickname || '',
|
||||
avatar: checkAvatarUrl(blogger?.avatar),
|
||||
}
|
||||
})
|
||||
|
||||
const calcUseTagRandomColor = computed(() => !!haloConfigs.value.pageConfig?.momentConfig?.useTagRandomColor)
|
||||
|
||||
/** 站点名称(原 startConfig.title 已随启动页下线,改读 appConfig.appInfo.name) */
|
||||
const siteName = computed(() => {
|
||||
const appInfo = haloConfigs.value.appConfig?.appInfo as { name?: string } | undefined
|
||||
return appInfo?.name || bloggerInfo.value.nickname || 'uni-halo'
|
||||
})
|
||||
|
||||
/* ---------------- 状态 ---------------- */
|
||||
const queryName = ref('')
|
||||
const videoContexts = ref<Record<string, UniApp.VideoContext | undefined>>({})
|
||||
const currentVideoId = ref<string | null>(null)
|
||||
|
||||
/** 瞬间卡片(medium 按类型拆为 images/videos/audios + 正文 tag 清理) */
|
||||
type MomentCard = IMoment & {
|
||||
images?: { type?: string, url: string }[]
|
||||
videos?: { id?: string, url: string }[]
|
||||
audios?: { type?: string, url: string }[]
|
||||
spec: IMoment['spec'] & { newHtml?: string }
|
||||
}
|
||||
|
||||
/** 移除 tag 链接 */
|
||||
function removeTagLinksCompletely(htmlString: string): string {
|
||||
const regex = /<a\b[^>]+class=(['"])[^'"]*\btag\b[^'"]*\1[^>]*>[\s\S]*?<\/a>/gi
|
||||
return htmlString.replace(regex, '')
|
||||
}
|
||||
|
||||
/** 瞬间详情 → 展示卡片(作者兜底 + medium 拆分 + tag 清理) */
|
||||
function buildMomentCard(res: IMoment): MomentCard {
|
||||
const medium = (res.spec.content?.medium || [])
|
||||
.map(x => ({ ...x, url: x.url || '' }))
|
||||
const owner = res.owner
|
||||
return {
|
||||
...res,
|
||||
// 无顶层 owner(如个别历史接口)时兜底为博主信息
|
||||
owner: owner?.displayName
|
||||
? owner
|
||||
: { displayName: bloggerInfo.value.nickname || '', name: bloggerInfo.value.nickname || '', avatar: bloggerInfo.value.avatar },
|
||||
spec: {
|
||||
...res.spec,
|
||||
newHtml: removeTagLinksCompletely(res.spec.content?.html || ''),
|
||||
},
|
||||
images: medium.filter(x => x.type === 'PHOTO').map(x => ({ ...x, url: checkThumbnailUrl(x.url, true) })),
|
||||
videos: medium.filter(x => x.type === 'VIDEO').map(x => ({ ...x, id: generateUUID() })),
|
||||
audios: medium.filter(x => x.type === 'AUDIO'),
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------------- 数据加载(useDataLoading 试点:状态由 hook 接管) ---------------- */
|
||||
const { data: moment, status, run: loadMoment } = useDataLoading(
|
||||
async (): Promise<MomentCard> => {
|
||||
const res = await getMomentByName(queryName.value)
|
||||
uni.setNavigationBarTitle({ title: '瞬间详情' })
|
||||
return buildMomentCard(res.data)
|
||||
},
|
||||
{
|
||||
onSuccess: (card) => {
|
||||
nextTick(() => {
|
||||
createVideoContexts(card.videos || [])
|
||||
})
|
||||
},
|
||||
onError: () => {
|
||||
uni.setNavigationBarTitle({ title: '瞬间详情' })
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
/** 标签颜色(随机模式下按数据稳定,避免每次渲染重新随机变色) */
|
||||
const calcTagColors = computed(() => {
|
||||
const tags = moment.value?.spec.tags || []
|
||||
return tags.map(() => (calcUseTagRandomColor.value ? randomTagColor() : '#4d7c0f'))
|
||||
})
|
||||
|
||||
function formatTime(time?: string): string {
|
||||
// 与旧项目一致:yyyy年MM月dd日 星期w
|
||||
return time ? formatTimeUtil({ d: time, f: 'yyyy年MM月dd日 星期w' }) : ''
|
||||
}
|
||||
|
||||
/* ---------------- 视频互斥 ---------------- */
|
||||
function createVideoContexts(videos: { id?: string }[]) {
|
||||
stopAllVideos()
|
||||
videos.forEach((item) => {
|
||||
if (item.id) {
|
||||
videoContexts.value[item.id] = uni.createVideoContext(`video_${item.id}`)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function stopAllVideos(excludesVideoId: string | null = null) {
|
||||
Object.keys(videoContexts.value).forEach((videoId) => {
|
||||
if (!excludesVideoId || excludesVideoId !== videoId) {
|
||||
videoContexts.value[videoId]?.pause()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function onVideoPlay(videoId: string) {
|
||||
currentVideoId.value = videoId
|
||||
stopAllVideos(videoId)
|
||||
}
|
||||
|
||||
function onVideoPause(videoId: string) {
|
||||
if (currentVideoId.value === videoId) {
|
||||
currentVideoId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
function onVideoEnded() {
|
||||
currentVideoId.value = null
|
||||
}
|
||||
|
||||
/* ---------------- 交互 ---------------- */
|
||||
function handlePreview(index: number, list: { url: string }[]) {
|
||||
uni.previewImage({
|
||||
current: index,
|
||||
urls: list.map(item => item.url),
|
||||
})
|
||||
}
|
||||
|
||||
function handleToTopPage(duration = 500) {
|
||||
uni.pageScrollTo({
|
||||
scrollTop: 0,
|
||||
duration,
|
||||
fail: (err) => {
|
||||
console.error('回顶失败', err)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
/* ---------------- 生命周期 ---------------- */
|
||||
onLoad((options) => {
|
||||
uni.setNavigationBarTitle({ title: '瞬间加载中...' })
|
||||
queryName.value = options?.name || ''
|
||||
loadMoment()
|
||||
})
|
||||
|
||||
onPullDownRefresh(async () => {
|
||||
videoContexts.value = {}
|
||||
currentVideoId.value = null
|
||||
await loadMoment()
|
||||
uni.stopPullDownRefresh()
|
||||
})
|
||||
|
||||
onShareAppMessage(() => ({
|
||||
path: `/pages-blog/moment-detail/moment-detail?name=${moment.value?.metadata.name}`,
|
||||
title: moment.value?.owner?.displayName || '',
|
||||
}))
|
||||
|
||||
onShareTimeline(() => ({
|
||||
title: moment.value?.owner?.displayName || '',
|
||||
query: moment.value ? `name=${moment.value.metadata.name}` : '',
|
||||
}))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="app-page relative box-border min-h-screen w-screen bg-page pb-8">
|
||||
<!-- 壁纸(柔和光斑为卡片毛玻璃取色,固定不随滚动) -->
|
||||
<view class="pointer-events-none fixed inset-0 z-0 overflow-hidden">
|
||||
<view class="absolute h-[420rpx] w-[420rpx] rounded-full bg-[rgba(103,164,242,0.16)] -left-[120rpx] -top-[60rpx]" />
|
||||
<view class="absolute top-[240rpx] h-[360rpx] w-[360rpx] rounded-full bg-[rgba(244,143,177,0.15)] -right-[130rpx]" />
|
||||
<view class="absolute top-[760rpx] h-[400rpx] w-[400rpx] rounded-full bg-[rgba(179,157,219,0.14)] -left-[150rpx]" />
|
||||
<view class="absolute top-[1220rpx] h-[380rpx] w-[380rpx] rounded-full bg-[rgba(185,228,36,0.15)] -right-[120rpx]" />
|
||||
</view>
|
||||
|
||||
<!-- 状态区(加载中/失败可重试/空) -->
|
||||
<uh-data-loading
|
||||
v-if="status !== 'success'"
|
||||
class="relative z-1"
|
||||
:loading-status="status"
|
||||
min-height="60vh"
|
||||
error-text="瞬间内容加载失败"
|
||||
empty-text="瞬间不存在或已被删除"
|
||||
@refresh="loadMoment"
|
||||
/>
|
||||
|
||||
<!-- 瞬间内容(悬浮玻璃卡) -->
|
||||
<view v-else-if="moment" class="moment-card uh-global-card-glass relative z-1 mx-4 mt-5 flex flex-col rounded-[32rpx] p-5">
|
||||
<!-- 用户区 -->
|
||||
<view class="user flex items-center gap-3">
|
||||
<image class="h-[96rpx] w-[96rpx] shrink-0 border-4 border-white/90 rounded-full shadow-lg" :src="moment.owner?.avatar || bloggerInfo.avatar" mode="aspectFill" />
|
||||
<view class="nickname min-w-0 flex flex-1 flex-col">
|
||||
<view class="nickname-text text-[32rpx] text-gray-900 font-bold">
|
||||
{{ moment.owner?.displayName || bloggerInfo.nickname }}
|
||||
</view>
|
||||
<view class="release-time mt-1 text-[24rpx] text-gray-400">
|
||||
{{ formatTime(moment.spec.releaseTime) }}
|
||||
</view>
|
||||
</view>
|
||||
<!-- 互动数据(点赞/评论) -->
|
||||
<view v-if="moment.stats && ((moment.stats.totalComment ?? 0) > 0 || (moment.stats.upvote ?? 0) > 0)" class="stats flex shrink-0 items-center gap-2">
|
||||
<view class="flex items-center gap-1 rounded-full bg-black/5 px-2.5 py-1 text-[22rpx] text-gray-500">
|
||||
<wd-icon name="heart" size="12px" color="#f08585" />
|
||||
<text>{{ moment.stats.upvote || 0 }}</text>
|
||||
</view>
|
||||
<view class="flex items-center gap-1 rounded-full bg-black/5 px-2.5 py-1 text-[22rpx] text-gray-500">
|
||||
<wd-icon name="message" size="12px" color="#7f8ea3" />
|
||||
<text>{{ moment.stats.totalComment || 0 }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 标签 -->
|
||||
<view v-if="moment.spec.tags && moment.spec.tags.length !== 0" class="tags mt-4 flex flex-wrap gap-2">
|
||||
<view v-for="(tag, tagIndex) in moment.spec.tags" :key="tagIndex" class="rounded-full bg-black/5 px-3 py-1 text-[22rpx] font-bold" :style="{ color: calcTagColors[tagIndex] }">
|
||||
# {{ tag }}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 内容 -->
|
||||
<view class="content mt-4">
|
||||
<mp-html
|
||||
class="evan-markdown"
|
||||
lazy-load
|
||||
:domain="markdownConfig.domain ?? ''"
|
||||
:loading-img="markdownConfig.loadingGif"
|
||||
scroll-table
|
||||
selectable
|
||||
:tag-style="markdownConfig.tagStyle"
|
||||
:container-style="markdownConfig.containStyle"
|
||||
:content="moment.spec.newHtml || ''"
|
||||
:markdown="true"
|
||||
:show-line-number="true"
|
||||
:show-language-name="true"
|
||||
copy-by-long-press
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 图片附件 -->
|
||||
<view v-if="moment.images && moment.images.length !== 0" class="mt-5">
|
||||
<view class="mb-3 flex items-center gap-2">
|
||||
<view class="h-[24rpx] w-[6rpx] rounded-full bg-secondary" />
|
||||
<text class="text-[26rpx] text-gray-500 font-bold">图片附件</text>
|
||||
</view>
|
||||
<view class="images flex flex-wrap items-start">
|
||||
<view
|
||||
v-for="(image, mediumIndex) in moment.images"
|
||||
:key="mediumIndex"
|
||||
class="image-item box-border p-1.5"
|
||||
:class="moment.images && moment.images.length === 1 ? 'h-[350rpx] w-full' : (moment.images && moment.images.length === 2 ? 'h-[250rpx] w-1/2' : 'h-[200rpx] w-1/3')"
|
||||
>
|
||||
<image
|
||||
mode="aspectFill"
|
||||
class="image-src h-full w-full rounded-lg"
|
||||
:src="image.url"
|
||||
@click="handlePreview(mediumIndex, moment.images || [])"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 音频附件 -->
|
||||
<view v-if="moment.audios && moment.audios.length !== 0" class="mt-5">
|
||||
<view class="mb-3 flex items-center gap-2">
|
||||
<view class="h-[24rpx] w-[6rpx] rounded-full bg-secondary" />
|
||||
<text class="text-[26rpx] text-gray-500 font-bold">音频附件</text>
|
||||
</view>
|
||||
<view class="audio-list flex flex-col gap-3">
|
||||
<uh-audio-player
|
||||
v-for="audio in moment.audios"
|
||||
:key="audio.url"
|
||||
:src="audio.url"
|
||||
:poster="bloggerInfo.avatar"
|
||||
:name="`来自${siteName}的声音`"
|
||||
:author="bloggerInfo.nickname"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 视频附件 -->
|
||||
<view v-if="moment.videos && moment.videos.length !== 0" class="mt-5">
|
||||
<view class="mb-3 flex items-center gap-2">
|
||||
<view class="h-[24rpx] w-[6rpx] rounded-full bg-secondary" />
|
||||
<text class="text-[26rpx] text-gray-500 font-bold">视频附件</text>
|
||||
</view>
|
||||
<view class="video-list w-full flex flex-col gap-3">
|
||||
<video
|
||||
v-for="(video, index) in moment.videos"
|
||||
:id="`video_${video.id}`"
|
||||
:key="index"
|
||||
class="video-src h-[400rpx] w-full rounded-xl"
|
||||
:src="video.url"
|
||||
:show-mute-btn="true"
|
||||
:controls="true"
|
||||
:show-center-play-btn="true"
|
||||
:enable-progress-gesture="true"
|
||||
@play="onVideoPlay(video.id || '')"
|
||||
@pause="onVideoPause(video.id || '')"
|
||||
@ended="onVideoEnded"
|
||||
/>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 回顶 -->
|
||||
<view class="to-top-btn uh-global-card-glass fixed bottom-[100rpx] right-6 z-6 h-[72rpx] w-[72rpx] flex items-center justify-center rounded-full" @click="handleToTopPage()">
|
||||
<wd-icon name="arrow-up" size="20px" color="#6b7280" />
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
Reference in New Issue
Block a user