mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-11-13 22:11:42 +08:00
refactor: 移除启动页逻辑,新增全局组件与偏好设置系统
1. 移除旧版启动页分流逻辑,直接跳转首页 2. 新增返回顶部、章节标题、导航栏等全局组件 3. 重构偏好设置系统,实现站点默认与本地差异分层管理 4. 删除冗余的测试mock、插件模块与样式文件 5. 优化文章卡片与评论组件样式,更新全局主题色 6. 清理废弃的请求参数与配置项
This commit is contained in:
@@ -1,12 +1,8 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 文章卡片(源自旧项目 components/article-card,新建复刻)
|
||||
* 支持布局:左图右文(lr_image_text)/左文右图(lr_text_image)/上图下文(tb_image_text)/上文下图(tb_text_image)/仅文字(only_text)
|
||||
*/
|
||||
import { computed } from 'vue'
|
||||
import dayjs from 'dayjs'
|
||||
import { checkThumbnailUrl } from '@/utils/url'
|
||||
import { useSettingStore } from '@/store/setting'
|
||||
import { formatTime} from '@/utils/formatTime'
|
||||
import type { IPost } from '@/api/types/halo'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
@@ -39,7 +35,7 @@ const cardType = computed(() => {
|
||||
/** 发布时间格式化 yyyy-MM-dd */
|
||||
const publishTimeText = computed(() => {
|
||||
const time = props.article.spec.publishTime
|
||||
return time ? dayjs(time).format('YYYY-MM-DD') : ''
|
||||
return time ? formatTime({d:time,f:'yyyy-MM-dd'}) : ''
|
||||
})
|
||||
|
||||
/** 阅读数(兼容 status.stats.visits 与旧版顶层 stats.visit) */
|
||||
@@ -53,21 +49,23 @@ function handleClick() {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="uh-article-card mb-3 flex overflow-hidden rounded-xl bg-white p-2.5 shadow-sm" :class="cardType" @click="handleClick">
|
||||
<view class="left">
|
||||
<image class="thumbnail" :src="checkThumbnailUrl(article.spec.cover)" mode="aspectFill" lazy-load />
|
||||
</view>
|
||||
<view class="right">
|
||||
<view class="title">
|
||||
<text v-if="article.spec.pinned" class="is-top">置顶</text>
|
||||
<text class="title-text text-overflow">{{ article.spec.title }}</text>
|
||||
<view class="uh-global-card-glass overflow-hidden relative rounded-xl p-3" @click="handleClick">
|
||||
<!-- v-if="article.spec.pinned" -->
|
||||
<text class="absolute right-6 top-6 z-1 bg-secondary text-gray-60 text-xs px-2 py-1 rounded-lg"> 置顶 </text>
|
||||
<image class="w-full h-36 rounded-lg" :src="checkThumbnailUrl(article.spec.cover)" mode="aspectFill" lazy-load />
|
||||
<view class="flex flex-col w-full gap-y-2 text-sm">
|
||||
<view class="mt-2 font-bold truncate">
|
||||
{{ article.spec.title }}
|
||||
</view>
|
||||
<view class="content text-overflow-2">
|
||||
<view class="content line-clamp-2 text-gray-600">
|
||||
{{ article.status?.excerpt }}
|
||||
</view>
|
||||
<view class="foot">
|
||||
<view class="create-time">
|
||||
<text class="time-label">发布时间:</text>
|
||||
<view class="flex items-center justify-between text-xs text-gray-500">
|
||||
<view class="flex items-center gap-x-1">
|
||||
<image :src="article.owner.avatar" class="uh-global-card-glass rounded-full w-5 h-5" mode="aspectFill"></image>
|
||||
<text>{{article.owner.displayName}}</text>
|
||||
</view>
|
||||
<view class="flex items-center gap-x-2">
|
||||
{{ publishTimeText }}
|
||||
</view>
|
||||
<view class="visits">
|
||||
@@ -79,261 +77,3 @@ function handleClick() {
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.uh-article-card {
|
||||
box-sizing: border-box;
|
||||
margin: 0 24rpx;
|
||||
|
||||
&.h_row_col1 {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
&.home.h_row_col2 {
|
||||
margin: 12rpx;
|
||||
|
||||
.left {
|
||||
width: 100%;
|
||||
height: 200rpx;
|
||||
|
||||
.thumbnail :deep(uni-image) {
|
||||
border-radius: 6rpx 6rpx 0 0 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.right {
|
||||
.title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 26rpx;
|
||||
font-weight: bold;
|
||||
|
||||
.is-top {
|
||||
height: 36rpx;
|
||||
margin-right: 10rpx;
|
||||
line-height: 36rpx;
|
||||
transform: scale(0.9);
|
||||
}
|
||||
}
|
||||
|
||||
.foot {
|
||||
justify-content: space-between;
|
||||
|
||||
.create-time {
|
||||
font-size: 24rpx;
|
||||
|
||||
.time-label {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.visits {
|
||||
font-size: 24rpx;
|
||||
margin-left: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.tb_text_image {
|
||||
padding: 12rpx;
|
||||
|
||||
.left .thumbnail :deep(uni-image) {
|
||||
border-radius: 6rpx !important;
|
||||
}
|
||||
}
|
||||
|
||||
&.only_text {
|
||||
padding: 24rpx;
|
||||
|
||||
.right .foot {
|
||||
.create-time .time-label {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.visits {
|
||||
font-size: 24rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.lr_text_image {
|
||||
.left {
|
||||
order: 2;
|
||||
padding-left: 30rpx;
|
||||
}
|
||||
|
||||
.right {
|
||||
order: 1;
|
||||
padding-left: 0;
|
||||
}
|
||||
}
|
||||
|
||||
&.tb_image_text {
|
||||
flex-direction: column;
|
||||
padding: 24rpx;
|
||||
|
||||
.left {
|
||||
width: 100%;
|
||||
height: 340rpx;
|
||||
|
||||
.thumbnail :deep(uni-image) {
|
||||
border-radius: 6rpx 6rpx 0 0 !important;
|
||||
}
|
||||
}
|
||||
|
||||
.right {
|
||||
padding-left: 0;
|
||||
padding: 24rpx 0 0;
|
||||
width: 100%;
|
||||
|
||||
.foot {
|
||||
justify-content: flex-start;
|
||||
|
||||
.create-time .time-label {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.visits {
|
||||
margin-left: 24rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.tb_text_image {
|
||||
flex-direction: column;
|
||||
|
||||
.left {
|
||||
width: 100%;
|
||||
height: 340rpx;
|
||||
order: 2;
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
|
||||
.right {
|
||||
padding-left: 0;
|
||||
width: 100%;
|
||||
order: 1;
|
||||
|
||||
.foot {
|
||||
justify-content: flex-start;
|
||||
|
||||
.create-time .time-label {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.visits {
|
||||
margin-left: 24rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
&.only_text {
|
||||
padding: 36rpx;
|
||||
|
||||
.left {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.right {
|
||||
padding-left: 0;
|
||||
|
||||
.content {
|
||||
margin-top: 24rpx;
|
||||
}
|
||||
|
||||
.foot {
|
||||
justify-content: flex-start;
|
||||
margin-top: 24rpx;
|
||||
|
||||
.create-time .time-label {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.visits {
|
||||
margin-left: 24rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.left {
|
||||
width: 240rpx;
|
||||
height: 180rpx;
|
||||
|
||||
.thumbnail {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.right {
|
||||
width: 0;
|
||||
flex-grow: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding-left: 30rpx;
|
||||
box-sizing: border-box;
|
||||
|
||||
.title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 30rpx;
|
||||
|
||||
.is-top {
|
||||
height: 40rpx;
|
||||
padding: 0 12rpx;
|
||||
margin-right: 10rpx;
|
||||
line-height: 40rpx;
|
||||
font-size: 24rpx;
|
||||
white-space: nowrap;
|
||||
vertical-align: 4rpx;
|
||||
color: #fff;
|
||||
background-color: rgba(33, 150, 243, 1);
|
||||
border-radius: 6rpx 12rpx;
|
||||
}
|
||||
|
||||
&-text {
|
||||
color: #303133;
|
||||
}
|
||||
}
|
||||
|
||||
.content {
|
||||
display: -webkit-box;
|
||||
font-size: 26rpx;
|
||||
color: #909399;
|
||||
height: 80rpx;
|
||||
margin-top: 14rpx;
|
||||
line-height: 42rpx;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.foot {
|
||||
display: flex;
|
||||
font-size: 24rpx;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
color: #909399;
|
||||
margin-top: 18rpx;
|
||||
|
||||
.create-time {
|
||||
font-size: 26rpx;
|
||||
|
||||
.time-label {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.visits .number {
|
||||
padding: 0 6rpx;
|
||||
font-size: 26rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 分类小卡片(源自旧项目 components/category-mini-card,新建复刻)
|
||||
*/
|
||||
import { computed } from 'vue'
|
||||
import { checkThumbnailUrl } from '@/utils/url'
|
||||
import type { ICategory } from '@/api/types/halo'
|
||||
|
||||
const props = defineProps<{
|
||||
category: ICategory
|
||||
}>()
|
||||
|
||||
const cover = computed(() => checkThumbnailUrl(props.category.spec.cover))
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="uh-category-mini-card relative inline-block h-[180rpx] w-[260rpx] overflow-hidden rounded-xl text-center text-white">
|
||||
<image class="img" :src="cover" mode="aspectFill" lazy-load />
|
||||
<view class="content absolute inset-0 z-3 flex flex-col items-center justify-center">
|
||||
<view class="name text-[30rpx] font-bold">
|
||||
{{ category.spec.displayName }}
|
||||
</view>
|
||||
<text class="label mt-1 text-[24rpx]">共 {{ category.postCount ?? 0 }} 篇</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.uh-category-mini-card {
|
||||
background-color: #fff;
|
||||
box-shadow: 0 2rpx 24rpx rgb(0 0 0 / 3%);
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
left: 0;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: rgb(0 0 0 / 25%);
|
||||
backdrop-filter: blur(3rpx);
|
||||
}
|
||||
|
||||
.img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.name {
|
||||
color: inherit;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,157 +1,95 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 评论条目(源自旧项目 components/comment-item,新建复刻)
|
||||
*/
|
||||
import { computed } from 'vue'
|
||||
import dayjs from 'dayjs'
|
||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||
import { checkAvatarUrl } from '@/utils/url'
|
||||
import { useSettingStore } from '@/store/setting'
|
||||
import type { IComment } from '@/api/types/halo'
|
||||
import { computed } from 'vue'
|
||||
import dayjs from 'dayjs'
|
||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||
import { checkAvatarUrl } from '@/utils/url'
|
||||
import { useSettingStore } from '@/store/setting'
|
||||
import type { IComment } from '@/api/types/halo'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
comment: IComment
|
||||
isChild?: boolean
|
||||
useActions?: boolean
|
||||
useSolid?: boolean
|
||||
useContentBg?: boolean
|
||||
disallowComment?: boolean
|
||||
postName?: string
|
||||
classItem?: string[]
|
||||
}>(), {
|
||||
isChild: false,
|
||||
useActions: true,
|
||||
useSolid: true,
|
||||
useContentBg: true,
|
||||
disallowComment: false,
|
||||
postName: '',
|
||||
classItem: () => [],
|
||||
})
|
||||
const emit = defineEmits<{
|
||||
(e: 'on-comment', data: { type: string, comment: IComment }): void
|
||||
(e: 'on-copy', raw: string): void
|
||||
(e: 'on-detail', comment: IComment): void
|
||||
}>()
|
||||
dayjs.extend(relativeTime)
|
||||
dayjs.locale('zh-cn')
|
||||
const props = withDefaults(defineProps<{
|
||||
comment : IComment
|
||||
isChild ?: boolean
|
||||
useActions ?: boolean
|
||||
useSolid ?: boolean
|
||||
useContentBg ?: boolean
|
||||
disallowComment ?: boolean
|
||||
postName ?: string
|
||||
classItem ?: string[]
|
||||
}>(), {
|
||||
isChild: false,
|
||||
useActions: true,
|
||||
useSolid: true,
|
||||
useContentBg: true,
|
||||
disallowComment: false,
|
||||
postName: '',
|
||||
classItem: () => [],
|
||||
})
|
||||
const emit = defineEmits<{
|
||||
(e : 'on-comment', data : { type : string, comment : IComment }) : void
|
||||
(e : 'on-copy', raw : string) : void
|
||||
(e : 'on-detail', comment : IComment) : void
|
||||
}>()
|
||||
dayjs.extend(relativeTime)
|
||||
dayjs.locale('zh-cn')
|
||||
|
||||
const settingStore = useSettingStore()
|
||||
const globalAppSettings = computed(() => settingStore.settings)
|
||||
const settingStore = useSettingStore()
|
||||
const globalAppSettings = computed(() => settingStore.settings)
|
||||
|
||||
const avatar = computed(() => checkAvatarUrl(props.comment.spec.owner.avatar))
|
||||
const avatar = computed(() => checkAvatarUrl(props.comment.spec.owner.avatar))
|
||||
|
||||
/** 评论时间 */
|
||||
const createTimeText = computed(() => {
|
||||
const time = props.comment.spec.creationTime
|
||||
return time ? dayjs(time).format('YYYY年MM月DD日') : ''
|
||||
})
|
||||
/** 评论时间 */
|
||||
const createTimeText = computed(() => {
|
||||
const time = props.comment.spec.creationTime
|
||||
return time ? dayjs(time).format('YYYY年MM月DD日') : ''
|
||||
})
|
||||
|
||||
const createTimeAgo = computed(() => {
|
||||
const time = props.comment.spec.creationTime
|
||||
return time ? `${dayjs(time).fromNow(true)}前` : ''
|
||||
})
|
||||
const createTimeAgo = computed(() => {
|
||||
const time = props.comment.spec.creationTime
|
||||
return time ? `${dayjs(time).fromNow(true)}前` : ''
|
||||
})
|
||||
|
||||
function handleOnImageError() {
|
||||
// 头像加载失败时回退默认头像(由 checkAvatarUrl 兜底,此处保持简单)
|
||||
}
|
||||
function handleOnImageError() {
|
||||
// 头像加载失败时回退默认头像(由 checkAvatarUrl 兜底,此处保持简单)
|
||||
}
|
||||
|
||||
function handleOnCopy() {
|
||||
emit('on-copy', props.comment.spec.raw)
|
||||
}
|
||||
function handleOnCopy() {
|
||||
emit('on-copy', props.comment.spec.raw)
|
||||
}
|
||||
|
||||
function handleOnReply() {
|
||||
emit('on-comment', { type: 'user', comment: props.comment })
|
||||
}
|
||||
function handleOnReply() {
|
||||
emit('on-comment', { type: 'user', comment: props.comment })
|
||||
}
|
||||
|
||||
function handleOnDetail() {
|
||||
emit('on-detail', props.comment)
|
||||
}
|
||||
function handleOnDetail() {
|
||||
emit('on-detail', props.comment)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view
|
||||
v-if="comment"
|
||||
class="comment-item mt-7 box-border flex flex-col pt-6"
|
||||
:class="{ 'child-comment-item': isChild, 'no-solid': !useSolid, ...classItem }"
|
||||
>
|
||||
<view class="comment-item-user flex items-center">
|
||||
<image
|
||||
class="user-avatar box-border h-[70rpx] w-[70rpx] shrink-0 border-4 border-white shadow-sm"
|
||||
:class="{ 'is-radius': globalAppSettings.isAvatarRadius }"
|
||||
:src="avatar"
|
||||
mode="aspectFill"
|
||||
@error="handleOnImageError"
|
||||
/>
|
||||
<view class="user-info w-0 flex-1 pl-7">
|
||||
<view class="author text-[26rpx] text-[#606266]">
|
||||
<text class="text-grey text-size-m">{{ comment.spec.owner.displayName }}</text>
|
||||
</view>
|
||||
<view class="mt-1 flex">
|
||||
<view class="time text-grey text-[22rpx] text-[#999]">
|
||||
<text>{{ createTimeText }}</text>
|
||||
<text class="ml-3">{{ createTimeAgo }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="useActions" class="actions flex gap-4">
|
||||
<view v-if="!disallowComment" class="action-btn px-1 py-0.5 text-[24rpx] text-blue" @click="handleOnReply">
|
||||
回复
|
||||
</view>
|
||||
<view class="action-btn text-grey px-1 py-0.5 text-[24rpx]" @click="handleOnCopy">
|
||||
复制
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view
|
||||
class="comment-item-content ml-[98rpx] mt-3 box-border text-[28rpx] text-[#303133] leading-[1.8]"
|
||||
:class="{ 'has-bg': useContentBg, 'not-ml': isChild }"
|
||||
@click="handleOnDetail"
|
||||
v-html="comment.spec.raw"
|
||||
/>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.comment-item {
|
||||
border-top: 2rpx solid #f5f5f5;
|
||||
|
||||
&.child-comment-item {
|
||||
padding-top: 0;
|
||||
margin-left: 80rpx;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
&.no-solid {
|
||||
border: 0;
|
||||
margin-top: 0 !important;
|
||||
}
|
||||
|
||||
.comment-item-user {
|
||||
.user-avatar {
|
||||
border-radius: 12rpx;
|
||||
|
||||
&.is-radius {
|
||||
border-radius: 50%;
|
||||
}
|
||||
}
|
||||
|
||||
.user-info {
|
||||
.time {
|
||||
margin-top: 8rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.comment-item-content {
|
||||
&.has-bg {
|
||||
background-color: #fafafa;
|
||||
padding: 6rpx 24rpx;
|
||||
}
|
||||
|
||||
&.not-ml {
|
||||
margin-left: 98rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<view v-if="comment" class="box-border flex pt-4" :class="{
|
||||
'pl-10':props.isChild,
|
||||
}">
|
||||
<view class="flex shrink-0">
|
||||
<image class="box-border h-10 w-10 shrink-0 rounded-full border border-white uh-shadow-xs border-solid" :src="avatar" mode="aspectFill"
|
||||
@error="handleOnImageError" />
|
||||
</view>
|
||||
<view class="flex-1 box-border pl-2">
|
||||
<view class="text-sm text-gray-500">
|
||||
<text class="text-grey text-xs">{{ comment.spec.owner.displayName }}</text>
|
||||
</view>
|
||||
<view class="mt-0.5 box-border text-sm text-gray-900 leading-5" @click="handleOnDetail"
|
||||
v-html="comment.spec.raw" />
|
||||
<view class="mt-2 flex items-center gap-x-4">
|
||||
<text class="text-gray-900 text-xs">{{ createTimeText }}</text>
|
||||
<view v-if="useActions" class="actions flex gap-2 font-bold">
|
||||
<view v-if="!disallowComment" class="text-xs" @click="handleOnReply">
|
||||
回复
|
||||
</view>
|
||||
<view class="text-grey text-xs" @click="handleOnCopy">
|
||||
复制
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -1,206 +1,176 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 评论列表(源自旧项目 components/comment-list,新建复刻)
|
||||
* 支持一级/二级评论展示、刷新、回复入口
|
||||
*/
|
||||
import { ref } from 'vue'
|
||||
import { getPostCommentList } from '@/api/halo'
|
||||
import type { IComment, ICommentListRes } from '@/api/types/halo'
|
||||
import { ref } from 'vue'
|
||||
import { getPostCommentList } from '@/api/halo'
|
||||
import { checkAvatarUrl } from '@/utils/url'
|
||||
import type { IComment, ICommentListRes } from '@/api/types/halo'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
disallowComment?: boolean
|
||||
postName: string
|
||||
post: { metadata: { name: string } }
|
||||
}>(), {
|
||||
disallowComment: false,
|
||||
})
|
||||
const props = withDefaults(defineProps<{
|
||||
disallowComment ?: boolean
|
||||
postName : string
|
||||
post : { metadata : { name : string } }
|
||||
}>(), {
|
||||
disallowComment: false,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'on-comment', data: { isComment: boolean, postName: string, title: string }): void
|
||||
(e: 'on-comment-detail', data: { postName: string, comment: IComment }): void
|
||||
(e: 'on-loaded', list: IComment[]): void
|
||||
}>()
|
||||
const emit = defineEmits<{
|
||||
(e : 'on-comment', data : { isComment : boolean, postName : string, title : string }) : void
|
||||
(e : 'on-comment-detail', data : { postName : string, comment : IComment }) : void
|
||||
(e : 'on-loaded', list : IComment[]) : void
|
||||
}>()
|
||||
|
||||
const loading = ref<'loading' | 'success' | 'error'>('loading')
|
||||
const queryParams = ref({
|
||||
group: 'content.halo.run',
|
||||
kind: 'Post',
|
||||
version: 'v1alpha1',
|
||||
name: props.postName,
|
||||
page: 1,
|
||||
size: 50,
|
||||
withReplies: true,
|
||||
replySize: 10,
|
||||
})
|
||||
const result = ref<ICommentListRes | null>(null)
|
||||
const dataList = ref<IComment[]>([])
|
||||
const loading = ref<'loading' | 'success' | 'error'>('loading')
|
||||
const queryParams = ref({
|
||||
group: 'content.halo.run',
|
||||
kind: 'Post',
|
||||
version: 'v1alpha1',
|
||||
name: props.postName,
|
||||
page: 1,
|
||||
size: 50,
|
||||
withReplies: true,
|
||||
replySize: 10,
|
||||
})
|
||||
const result = ref<ICommentListRes | null>(null)
|
||||
const dataList = ref<IComment[]>([])
|
||||
|
||||
async function handleGetData() {
|
||||
loading.value = 'loading'
|
||||
try {
|
||||
const res = await getPostCommentList({ ...queryParams.value })
|
||||
result.value = res.data
|
||||
dataList.value = res.data.items
|
||||
loading.value = 'success'
|
||||
emit('on-loaded', dataList.value)
|
||||
}
|
||||
catch (err) {
|
||||
console.error('获取评论失败', err)
|
||||
loading.value = 'error'
|
||||
}
|
||||
}
|
||||
async function handleGetData() {
|
||||
loading.value = 'loading'
|
||||
try {
|
||||
const res = await getPostCommentList({ ...queryParams.value })
|
||||
result.value = res.data
|
||||
dataList.value = res.data.items.map((item) => {
|
||||
// todo:临时
|
||||
item.spec.owner.avatar = checkAvatarUrl(item.spec.owner.avatar??'https://api.dicebear.com/10.x/adventurer-neutral/svg')
|
||||
return item
|
||||
})
|
||||
loading.value = 'success'
|
||||
emit('on-loaded', dataList.value)
|
||||
}
|
||||
catch (err) {
|
||||
console.error('获取评论失败', err)
|
||||
loading.value = 'error'
|
||||
}
|
||||
}
|
||||
|
||||
function handleToComment(data?: { type: string, comment: IComment }) {
|
||||
if (props.disallowComment) {
|
||||
uni.showToast({ icon: 'none', title: '文章已禁止评论!' })
|
||||
return
|
||||
}
|
||||
if (data) {
|
||||
// 回复某条评论
|
||||
emit('on-comment', {
|
||||
isComment: false,
|
||||
postName: data.comment.metadata.name,
|
||||
title: data.comment.spec.owner.displayName,
|
||||
})
|
||||
}
|
||||
else {
|
||||
// 新增评论
|
||||
emit('on-comment', {
|
||||
isComment: true,
|
||||
postName: props.post.metadata.name,
|
||||
title: '新增评论',
|
||||
})
|
||||
}
|
||||
}
|
||||
function handleToComment(data ?: { type : string, comment : IComment }) {
|
||||
if (props.disallowComment) {
|
||||
uni.showToast({ icon: 'none', title: '文章已禁止评论!' })
|
||||
return
|
||||
}
|
||||
if (data) {
|
||||
// 回复某条评论
|
||||
emit('on-comment', {
|
||||
isComment: false,
|
||||
postName: data.comment.metadata.name,
|
||||
title: data.comment.spec.owner.displayName,
|
||||
})
|
||||
}
|
||||
else {
|
||||
// 新增评论
|
||||
emit('on-comment', {
|
||||
isComment: true,
|
||||
postName: props.post.metadata.name,
|
||||
title: '新增评论',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function handleCopyContent(content: string) {
|
||||
uni.setClipboardData({
|
||||
data: content,
|
||||
showToast: false,
|
||||
success: () => {
|
||||
uni.showToast({ icon: 'none', title: '内容已复制成功!' })
|
||||
},
|
||||
})
|
||||
}
|
||||
function handleCopyContent(content : string) {
|
||||
uni.setClipboardData({
|
||||
data: content,
|
||||
showToast: false,
|
||||
success: () => {
|
||||
uni.showToast({ icon: 'none', title: '内容已复制成功!' })
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
function handleShowCommentDetail(comment: IComment) {
|
||||
emit('on-comment-detail', {
|
||||
postName: props.postName,
|
||||
comment,
|
||||
})
|
||||
}
|
||||
function handleShowCommentDetail(comment : IComment) {
|
||||
emit('on-comment-detail', {
|
||||
postName: props.postName,
|
||||
comment,
|
||||
})
|
||||
}
|
||||
|
||||
handleGetData()
|
||||
handleGetData()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="uh-comment-list">
|
||||
<!-- 顶部区域 -->
|
||||
<view class="comment-list-head relative box-border pl-6 text-[30rpx] font-bold">
|
||||
<view class="title">
|
||||
<text>评论列表</text>
|
||||
<text class="count text-[28rpx] font-normal">({{ result?.total || 0 }}条)</text>
|
||||
</view>
|
||||
<view class="refresh flex items-center gap-1.5 text-[26rpx] text-[#666] font-normal" @click="handleGetData">
|
||||
<wd-icon name="refresh" size="14px" color="#909399" />
|
||||
<text class="refresh-text ml-1.5">刷新</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="w-full box-border px-2">
|
||||
<view class="uh-global-card-glass box-border uh-shadow-xs rounded-xl p-3">
|
||||
<!-- 顶部区域 -->
|
||||
<uh-section-title>
|
||||
评论列表
|
||||
<template #right>
|
||||
<view class="flex items-center gap-1.5 text-xs text-gray-500 font-normal"
|
||||
@click="handleGetData">
|
||||
<wd-icon name="refresh" size="28rpx" />
|
||||
<text class="">刷新</text>
|
||||
</view>
|
||||
</template>
|
||||
</uh-section-title>
|
||||
|
||||
<!-- 内容区域 -->
|
||||
<view class="comment-list-content mt-6 pb-9">
|
||||
<view v-if="loading !== 'success'" class="loading-wrap h-[506rpx] w-full flex items-center justify-center">
|
||||
<view v-if="loading === 'loading'" class="loading flex flex-col items-center justify-center">
|
||||
<view class="loading-text text-[26rpx] text-[#999]">
|
||||
加载中,请稍等...
|
||||
</view>
|
||||
</view>
|
||||
<view v-else-if="loading === 'error'" class="error flex flex-col items-center">
|
||||
<text class="text-grey">加载失败</text>
|
||||
<wd-button v-if="!disallowComment" size="small" plain type="primary" class="mt-2" @click="handleGetData">
|
||||
刷新试试
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 内容区域 -->
|
||||
<view class="mt-2">
|
||||
<view v-if="loading !== 'success'"
|
||||
class="loading-wrap h-[506rpx] w-full flex items-center justify-center">
|
||||
<view v-if="loading === 'loading'" class="loading flex flex-col items-center justify-center">
|
||||
<view class="loading-text text-[26rpx] text-[#999]">
|
||||
加载中,请稍等...
|
||||
</view>
|
||||
</view>
|
||||
<view v-else-if="loading === 'error'" class="error flex flex-col items-center">
|
||||
<text class="text-grey">加载失败</text>
|
||||
<wd-button v-if="!disallowComment" size="small" plain type="primary" class="mt-2"
|
||||
@click="handleGetData">
|
||||
刷新试试
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<block v-else>
|
||||
<view v-if="disallowComment && dataList.length !== 0" class="disallow-tip rounded-xl bg-[#fef0f0] px-3 py-2 text-[26rpx] text-[#f56c6c]">
|
||||
Ծ‸Ծ 博主已设置该文章禁止评论!
|
||||
</view>
|
||||
<block v-else>
|
||||
<view v-if="disallowComment && dataList.length !== 0"
|
||||
class="rounded-xl bg-gray-50 px-3 py-2 text-xs text-red-400">
|
||||
Ծ‸Ծ 博主已设置该文章禁止评论!
|
||||
</view>
|
||||
|
||||
<view v-if="dataList.length === 0" class="empty pt-5">
|
||||
<view class="empty-box flex flex-col items-center">
|
||||
<wd-empty :description="disallowComment ? '暂无评论' : '暂无评论'" />
|
||||
<view v-if="disallowComment" class="empty-tip mt-1.5 text-[24rpx] text-[#f56c6c]">
|
||||
- 文章已开启禁止评论 -
|
||||
</view>
|
||||
<wd-button v-else size="small" plain type="primary" class="mt-2" @click="handleToComment()">
|
||||
抢沙发
|
||||
</wd-button>
|
||||
</view>
|
||||
</view>
|
||||
<view v-if="dataList.length === 0" class="empty py-12">
|
||||
<view class="empty-box flex flex-col items-center">
|
||||
<wd-empty>
|
||||
<template #image>
|
||||
<wd-icon name="empty" size="100rpx" class="text-primary" />
|
||||
</template>
|
||||
<template #bottom>
|
||||
<text class="mt-2 text-sm text-gray-500">{{disallowComment ? '暂无评论' : '暂无评论'}}</text>
|
||||
<view v-if="disallowComment" class="mt-2 text-xs text-red-400">
|
||||
文章已开启禁止评论
|
||||
</view>
|
||||
<view v-else class="mt-2 bg-primary text-black text-sm px-4 py-1.5 rounded-lg" @click="handleToComment()">
|
||||
抢沙发
|
||||
</view>
|
||||
</template>
|
||||
</wd-empty>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<block v-else>
|
||||
<!-- 一级评论 -->
|
||||
<template v-for="comment in dataList" :key="comment.metadata.name">
|
||||
<uh-comment-item
|
||||
:use-content-bg="false"
|
||||
:is-child="false"
|
||||
:comment="comment"
|
||||
:post-name="postName"
|
||||
:disallow-comment="disallowComment"
|
||||
@on-copy="handleCopyContent"
|
||||
@on-comment="handleToComment"
|
||||
@on-detail="handleShowCommentDetail"
|
||||
/>
|
||||
<block v-else>
|
||||
<!-- 一级评论 -->
|
||||
<template v-for="comment in dataList" :key="comment.metadata.name">
|
||||
<uh-comment-item :use-content-bg="false" :is-child="false" :comment="comment"
|
||||
:post-name="postName" :disallow-comment="disallowComment" @on-copy="handleCopyContent"
|
||||
@on-comment="handleToComment" @on-detail="handleShowCommentDetail" />
|
||||
|
||||
<!-- 二级评论 -->
|
||||
<template v-if="comment.replies && comment.replies.items.length !== 0">
|
||||
<uh-comment-item
|
||||
v-for="childComment in comment.replies.items"
|
||||
:key="childComment.metadata.name"
|
||||
:use-content-bg="false"
|
||||
:is-child="true"
|
||||
:comment="childComment"
|
||||
:post-name="postName"
|
||||
:disallow-comment="disallowComment"
|
||||
@on-copy="handleCopyContent"
|
||||
@on-comment="handleToComment"
|
||||
@on-detail="handleShowCommentDetail"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
</block>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.uh-comment-list {
|
||||
.comment-list-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
&::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 8rpx;
|
||||
width: 8rpx;
|
||||
height: 26rpx;
|
||||
background-color: rgb(3 174 252);
|
||||
border-radius: 6rpx;
|
||||
}
|
||||
}
|
||||
|
||||
.comment-list-content {
|
||||
.loading-wrap {
|
||||
.loading-text {
|
||||
/* 无额外样式 */
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<!-- 二级评论 -->
|
||||
<template v-if="comment.replies && comment.replies.items.length !== 0">
|
||||
<uh-comment-item v-for="childComment in comment.replies.items"
|
||||
:key="childComment.metadata.name" :use-content-bg="false" :is-child="true"
|
||||
:comment="childComment" :post-name="postName" :disallow-comment="disallowComment"
|
||||
@on-copy="handleCopyContent" @on-comment="handleToComment"
|
||||
@on-detail="handleShowCommentDetail" />
|
||||
</template>
|
||||
</template>
|
||||
</block>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -0,0 +1,269 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 轮播组件(源自旧项目 components/e-swiper,新建复刻)
|
||||
* 数据高内聚:默认内部请求 plugin-uni-halo 公开 banners 接口(getBanners),支持外部 list 覆盖
|
||||
* 支持:图片轮播、日期角标(useTop,显示当前条目 date 快照)、标题浮层(useTitle)、
|
||||
* 作者/日期信息浮层(useUser)、底部小图指示器(useDot)
|
||||
*/
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { getBanners } from '@/api/uni-halo'
|
||||
import { useAppConfigStore } from '@/store/appConfig'
|
||||
import { checkAvatarUrl, checkThumbnailUrl } from '@/utils/url'
|
||||
import type { IBannerPublicItem } from '@/api/types/uni-halo'
|
||||
|
||||
export interface IBannerItem {
|
||||
/** 条目标识(Banner 为 metadata.name;兼容旧数据) */
|
||||
id ?: string | number
|
||||
/** Banner 条目 metadata.name(custom 详情页跳转用) */
|
||||
name ?: string
|
||||
title ?: string
|
||||
image ?: string
|
||||
src ?: string
|
||||
/** 来源:post=文章快照 / custom=自定义 */
|
||||
type ?: string
|
||||
/** 文章 id(source=post 时跳转文章详情) */
|
||||
postId ?: string
|
||||
content ?: string
|
||||
url ?: string
|
||||
/** 展示日期(ISO 快照) */
|
||||
date ?: string
|
||||
authorName ?: string
|
||||
authorAvatar ?: string
|
||||
[key : string] : unknown
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
title ?: string
|
||||
height ?: string
|
||||
dotPosition ?: string
|
||||
/** 日期角标(显示当前条目 date) */
|
||||
useTop ?: boolean
|
||||
/** 底部小图指示器 */
|
||||
useDot ?: boolean
|
||||
/** 标题浮层 */
|
||||
useTitle ?: boolean
|
||||
/** 作者/日期信息浮层 */
|
||||
useUser ?: boolean
|
||||
/** 轮播数据列表(可选;不传时组件内部调公开 banners 接口拉取) */
|
||||
list ?: IBannerItem[]
|
||||
/** 当前选中的项(指示器坐标位置) */
|
||||
current ?: number
|
||||
/** 是否自动轮播 */
|
||||
autoplay ?: boolean
|
||||
}>(), {
|
||||
title: '',
|
||||
height: '450rpx',
|
||||
dotPosition: 'bottom',
|
||||
useTop: true,
|
||||
useDot: true,
|
||||
useTitle: true,
|
||||
useUser: true,
|
||||
current: 0,
|
||||
autoplay: false,
|
||||
})
|
||||
const appConfigStore = useAppConfigStore()
|
||||
|
||||
const haloConfigs = computed(() => appConfigStore.configs)
|
||||
const bannerConfig = computed(() => haloConfigs.value.pageConfig?.homeConfig?.bannerConfig)
|
||||
|
||||
/* ---------------- 状态 ---------------- */
|
||||
const currentIndex = ref(props.current)
|
||||
/** 是否禁止用户 touch 操作 */
|
||||
const disableTouch = ref(false)
|
||||
|
||||
/* ---------------- 数据(高内聚:内部请求公开接口) ---------------- */
|
||||
const internalList = ref<IBannerItem[]>([])
|
||||
|
||||
/** 展示列表:外部传入(list)优先,否则使用内部拉取数据 */
|
||||
const displayItems = computed<IBannerItem[]>(() =>
|
||||
props.list && props.list.length > 0 ? props.list : internalList.value,
|
||||
)
|
||||
|
||||
/** 公开 Banner 条目 → 轮播展示项 */
|
||||
function mapBanners(items : IBannerPublicItem[]) : IBannerItem[] {
|
||||
return items.map(item => ({
|
||||
id: item.name,
|
||||
name: item.name,
|
||||
title: item.title || '',
|
||||
image: checkThumbnailUrl(item.cover),
|
||||
src: checkThumbnailUrl(item.cover),
|
||||
type: item.source,
|
||||
postId: item.postId,
|
||||
url: item.link,
|
||||
date: item.date,
|
||||
authorName: item.authorName,
|
||||
authorAvatar: item.authorAvatar ? checkAvatarUrl(item.authorAvatar) : '',
|
||||
}))
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
// 外部已传数据时不再重复请求
|
||||
if (props.list && props.list.length > 0) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await getBanners()
|
||||
internalList.value = mapBanners(res.data || [])
|
||||
}
|
||||
catch (err) {
|
||||
console.error('获取轮播图失败', err)
|
||||
}
|
||||
})
|
||||
|
||||
// 列表变化(外部覆盖/接口返回)后索引越界时归零
|
||||
watch(displayItems, (val) => {
|
||||
if (currentIndex.value >= val.length) {
|
||||
currentIndex.value = 0
|
||||
}
|
||||
})
|
||||
|
||||
/* ---------------- 计算属性 ---------------- */
|
||||
const currentItem = computed<IBannerItem>(() =>
|
||||
displayItems.value[currentIndex.value] || {},
|
||||
)
|
||||
|
||||
/** 日期角标(useTop):当前条目 date 快照转换(年/月/日) */
|
||||
const dateParts = computed(() => {
|
||||
const dateStr = currentItem.value.date as string | undefined
|
||||
if (!dateStr) {
|
||||
return null
|
||||
}
|
||||
const d = new Date(dateStr)
|
||||
if (Number.isNaN(d.getTime())) {
|
||||
return null
|
||||
}
|
||||
const monthArray = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
|
||||
return {
|
||||
day: String(d.getDate()).padStart(2, '0'),
|
||||
month: String(d.getMonth() + 1).padStart(2, '0'),
|
||||
monthEn: monthArray[d.getMonth()],
|
||||
year: String(d.getFullYear()),
|
||||
}
|
||||
})
|
||||
|
||||
const currentTitle = computed(() => currentItem.value.title || props.title || '')
|
||||
|
||||
/** 作者日期展示(useUser 用) */
|
||||
const authorDateText = computed(() => {
|
||||
const dateStr = currentItem.value.date as string | undefined
|
||||
if (!dateStr) {
|
||||
return ''
|
||||
}
|
||||
const d = new Date(dateStr)
|
||||
if (Number.isNaN(d.getTime())) {
|
||||
return ''
|
||||
}
|
||||
const pad = (n : number) => String(n).padStart(2, '0')
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
|
||||
})
|
||||
|
||||
/* ---------------- 交互 ---------------- */
|
||||
/** current 改变时会触发 change 事件,event.detail = {current, source} */
|
||||
function change(e : { detail : { current : number, source : string } }) {
|
||||
const { current, source } = e.detail
|
||||
// 只有页面自动切换、手动切换时才轮播,其他不允许
|
||||
if (source === 'autoplay' || source === 'touch') {
|
||||
const event = { current }
|
||||
currentIndex.value = current
|
||||
}
|
||||
}
|
||||
|
||||
/** 手动点击了指示器[小图模式] */
|
||||
function swiperIndTap(index : number) {
|
||||
const event = { current: index }
|
||||
currentIndex.value = index
|
||||
}
|
||||
|
||||
function handleOnClick(item : IBannerItem) {
|
||||
// 审核模式下照常展示 Banner,点击分发不拦截(详情页自行处理审核限制)
|
||||
if (item.type === 'custom') {
|
||||
// 自定义条目:跳转 Banner 详情页,页面内调公开详情接口展示 content/外链
|
||||
if (item.name) {
|
||||
uni.navigateTo({
|
||||
url: `/pages-blog/banner-detail/banner-detail?name=${item.name}`,
|
||||
animationType: 'slide-in-right',
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
// 文章来源
|
||||
uni.navigateTo({
|
||||
url: `/pages-blog/article-detail/article-detail?name=${item.postId}`,
|
||||
animationType: 'slide-in-right',
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view v-if="displayItems.length > 0" class="relative w-full px-4 pt-12 mb-14 box-border">
|
||||
|
||||
<view class="absolute inset-0 blur-[2rpx]">
|
||||
<image :src="displayItems[currentIndex].src" class="h-full w-full" mode="aspectFill"></image>
|
||||
</view>
|
||||
|
||||
<view class="uh-global-card-glass box-border relative w-full overflow-hidden rounded-xl translate-y-12" :class="[dotPosition]">
|
||||
<swiper class="w-full" :style="{ height }" :circular="true" :indicator-dots="false"
|
||||
:autoplay="autoplay" :interval="3000" :duration="1000" :current="currentIndex"
|
||||
:disable-touch="disableTouch" @change="change">
|
||||
<swiper-item v-for="(item, index) in displayItems" :key="index">
|
||||
<image :src="item.image || item.src" class="h-full w-full" mode="aspectFill"
|
||||
@click.stop="handleOnClick(item)" />
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
|
||||
<!-- 指示器 [Top 日期角标]:显示当前条目 date(年/月/日) -->
|
||||
<view v-if="useTop && dateParts"
|
||||
class="box-border absolute inset-x-0 top-0 z-5 flex items-center px-[24rpx] py-[16rpx]">
|
||||
<text class="text-[40rpx] text-white font-bold text-shadow-[0_2rpx_8rpx_rgba(0,0,0,0.4)]">
|
||||
{{ dateParts.day }}
|
||||
</text>
|
||||
<view class="ml-[12rpx] h-[40rpx] w-[2rpx] bg-white/50" />
|
||||
<view class="ml-[12rpx] flex flex-col">
|
||||
<text class="text-[20rpx] text-white text-shadow-[0_2rpx_8rpx_rgba(0,0,0,0.4)]">
|
||||
{{ dateParts.monthEn }}
|
||||
</text>
|
||||
<text class="text-[16rpx] text-white/80">{{ dateParts.year }}</text>
|
||||
</view>
|
||||
<text
|
||||
class="text-overflow-2 ml-[20rpx] block flex-1 text-[24rpx] text-white text-shadow-[0_2rpx_8rpx_rgba(0,0,0,0.4)]">
|
||||
{{ title }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<!-- 指示器 标题区域 + 作者/日期信息(useUser) -->
|
||||
<view v-if="useTitle"
|
||||
class="absolute inset-x-0 bottom-0 z-5 from-black/45 to-transparent bg-gradient-to-t px-[24rpx] pb-[20rpx] pt-[48rpx]">
|
||||
<view v-if="useUser && (currentItem.authorName || authorDateText)"
|
||||
class="mb-[8rpx] flex items-center gap-[8rpx]">
|
||||
<view v-if="currentItem.authorAvatar"
|
||||
class="h-[36rpx] w-[36rpx] overflow-hidden border-[1rpx] border-white/60 rounded-full">
|
||||
<image :src="currentItem.authorAvatar" class="h-full w-full" mode="aspectFill" />
|
||||
</view>
|
||||
<text class="text-[22rpx] text-white/92 text-shadow-[0_1rpx_4rpx_rgba(0,0,0,0.4)]">
|
||||
{{ currentItem.authorName }}
|
||||
</text>
|
||||
<text v-if="authorDateText"
|
||||
class="text-[20rpx] text-white/70 text-shadow-[0_1rpx_4rpx_rgba(0,0,0,0.4)]">
|
||||
{{ authorDateText }}
|
||||
</text>
|
||||
</view>
|
||||
<text v-if="currentTitle"
|
||||
class="text-overflow-2 block text-[28rpx] text-white font-bold text-shadow-[0_2rpx_8rpx_rgba(0,0,0,0.4)]">
|
||||
{{ currentTitle }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<!-- 指示器 [底部小图列表] -->
|
||||
<view v-if="useDot" class="absolute inset-x-0 bottom-3 z-5 flex justify-end px-[24rpx]">
|
||||
<view class="flex gap-1">
|
||||
<view v-for="(item, index) in displayItems" :key="index"
|
||||
class="uh-global-card-glass h-[64rpx] w-[96rpx] overflow-hidden border-[2rpx] rounded-[8rpx]"
|
||||
:class="currentIndex === index ? 'opacity-100 border-white' : 'opacity-60 border-transparent'"
|
||||
@click="swiperIndTap(index)">
|
||||
<image :src="item.image || item.src" class="h-full w-full" mode="aspectFill" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -0,0 +1,132 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { getBanners } from '@/api/uni-halo'
|
||||
import { useAppConfigStore } from '@/store/appConfig'
|
||||
import { checkAvatarUrl, checkThumbnailUrl } from '@/utils/url'
|
||||
import { formatTime } from '@/utils/formatTime'
|
||||
import type { IBannerPublicItem } from '@/api/types/uni-halo'
|
||||
|
||||
export interface IBannerItem {
|
||||
/** 条目标识(Banner 为 metadata.name;兼容旧数据) */
|
||||
id ?: string | number
|
||||
/** Banner 条目 metadata.name(custom 详情页跳转用) */
|
||||
name ?: string
|
||||
title ?: string
|
||||
image ?: string
|
||||
src ?: string
|
||||
/** 来源:post=文章快照 / custom=自定义 */
|
||||
type ?: string
|
||||
/** 文章 id(source=post 时跳转文章详情) */
|
||||
postId ?: string
|
||||
content ?: string
|
||||
url ?: string
|
||||
/** 展示日期(ISO 快照) */
|
||||
date ?: string
|
||||
authorName ?: string
|
||||
authorAvatar ?: string
|
||||
[key : string] : unknown
|
||||
}
|
||||
|
||||
const appConfigStore = useAppConfigStore()
|
||||
|
||||
const haloConfigs = computed(() => appConfigStore.configs)
|
||||
const bannerConfig = computed(() => haloConfigs.value.pageConfig?.homeConfig?.bannerConfig)
|
||||
|
||||
/* ---------------- 数据(高内聚:内部请求公开接口) ---------------- */
|
||||
const bannerList = ref<IBannerItem[]>([])
|
||||
const currentIndex = ref(0)
|
||||
const currentBanner = ref<IBannerItem | null>(null)
|
||||
|
||||
/** 公开 Banner 条目 → 轮播展示项 */
|
||||
function mapBanners(items : IBannerPublicItem[]) : IBannerItem[] {
|
||||
return items.map(item => ({
|
||||
id: item.name,
|
||||
name: item.name,
|
||||
title: item.title || '',
|
||||
image: checkThumbnailUrl(item.cover),
|
||||
src: checkThumbnailUrl(item.cover),
|
||||
type: item.source,
|
||||
postId: item.postId,
|
||||
url: item.link,
|
||||
date: formatTime({
|
||||
d: item.date,
|
||||
f: 'yyyy年MM月dd日 星期w'
|
||||
}),
|
||||
authorName: item.authorName,
|
||||
authorAvatar: item.authorAvatar ? checkAvatarUrl(item.authorAvatar) : '',
|
||||
}))
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const res = await getBanners()
|
||||
bannerList.value = mapBanners(res.data || [])
|
||||
handleBannerChange({
|
||||
detail: { current: 0 }
|
||||
})
|
||||
}
|
||||
catch (err) {
|
||||
console.error('获取轮播图失败', err)
|
||||
}
|
||||
})
|
||||
|
||||
function handleBannerChange(e : any) {
|
||||
currentIndex.value = e?.detail?.current ?? 0
|
||||
currentBanner.value = bannerList.value[currentIndex.value]
|
||||
}
|
||||
|
||||
function handleOnClick(item : IBannerItem) {
|
||||
// 审核模式下照常展示 Banner,点击分发不拦截(详情页自行处理审核限制)
|
||||
if (item.type === 'custom') {
|
||||
// 自定义条目:跳转 Banner 详情页,页面内调公开详情接口展示 content/外链
|
||||
if (item.name) {
|
||||
uni.navigateTo({
|
||||
url: `/pages-blog/banner-detail/banner-detail?name=${item.name}`,
|
||||
animationType: 'slide-in-right',
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
// 文章来源
|
||||
uni.navigateTo({
|
||||
url: `/pages-blog/article-detail/article-detail?name=${item.postId}`,
|
||||
animationType: 'slide-in-right',
|
||||
})
|
||||
}
|
||||
|
||||
function handleToSearch() {
|
||||
uni.navigateTo({ url: '/pages-blog/search/search' })
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view v-if="bannerList.length > 0" class="relative w-full mb-6 box-border ">
|
||||
<view class="box-border relative w-full h-52 overflow-hidden">
|
||||
<swiper class="w-full h-52" :circular="true" :indicator-dots="false" :autoplay="true" :interval="3000"
|
||||
:duration="1000" @change="handleBannerChange">
|
||||
<swiper-item v-for="(item, index) in bannerList" :key="index" class="relative">
|
||||
<image :src="item.image || item.src" class="h-full w-full" mode="aspectFill"
|
||||
@click.stop="handleOnClick(item)" />
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
<view v-if="currentBanner"
|
||||
class="pointer-events-none absolute inset-0 z-10 flex flex-col items-center justify-center gap-y-2 bg-white/5 backdrop-blur-[2rpx]">
|
||||
<text class="text-sm text-gray-900 font-bold bg-secondary px-3 py-0.5 rounded-xl">
|
||||
{{ currentBanner.title }}
|
||||
</text>
|
||||
<text
|
||||
class="text-xs text-white text-shadow-[0_2rpx_8rpx_rgba(0,0,0,0.4)]">{{ currentBanner.date }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="absolute bottom-0 left-0 right-0 h-12 w-full bg-gradient-to-b from-white/0 to-page" />
|
||||
<view class="absolute left-0 right-0 z-10 flex items-center justify-center -translate-y-6">
|
||||
<view
|
||||
class="uh-global-card-glass border w-4/5 rounded-full px-4 py-2 text-sm text-gray-600 flex items-center justify-center gap-x-2"
|
||||
@click="handleToSearch()">
|
||||
<wd-icon name="search-line" size="32rpx"></wd-icon>
|
||||
<text>哈喽,想看些什么 <text class="bg-secondary rounded-xl px-1">{ 内容 }</text> 呢~</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -0,0 +1,102 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed } from 'vue'
|
||||
import { getCategoryList } from '@/api/halo'
|
||||
import { checkThumbnailUrl } from '@/utils/url'
|
||||
import { useAppConfigStore } from '@/store/appConfig'
|
||||
import type { ICategory } from '@/api/types/halo'
|
||||
|
||||
const appConfigStore = useAppConfigStore()
|
||||
|
||||
const haloConfigs = computed(() => appConfigStore.configs)
|
||||
|
||||
const calcAuditModeEnabled = computed(() => appConfigStore.auditModeEnabled)
|
||||
|
||||
const loading = ref<'loading' | 'success' | 'error'>('loading')
|
||||
const categoryList = ref<ICategory[]>([])
|
||||
|
||||
const calcIsShowCategory = computed(() => {
|
||||
if (calcAuditModeEnabled.value) {
|
||||
return false;
|
||||
}
|
||||
return !!haloConfigs.value.pageConfig?.homeConfig?.useCategory
|
||||
})
|
||||
|
||||
/** 精选分类 */
|
||||
async function handleGetCategoryList() {
|
||||
if (calcAuditModeEnabled.value || !calcIsShowCategory.value) {
|
||||
loading.value = 'success'
|
||||
return
|
||||
}
|
||||
try {
|
||||
loading.value = 'loading'
|
||||
const res = await getCategoryList({ fieldSelector: ['spec.hideFromList=false'], size: 3 })
|
||||
categoryList.value = res.data.items
|
||||
.map(item => {
|
||||
item.spec.cover = checkThumbnailUrl(item.spec.cover)
|
||||
return {
|
||||
...item,
|
||||
postCount: item.postCount ?? 0
|
||||
}
|
||||
})
|
||||
.sort((a, b) => (b.postCount || 0) - (a.postCount || 0))
|
||||
loading.value = 'success'
|
||||
}
|
||||
catch (err) {
|
||||
console.error('获取分类失败', err)
|
||||
loading.value = 'error'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function handleToCategoryPage() {
|
||||
uni.switchTab({ url: '/pages/tabbar/category/category' })
|
||||
}
|
||||
|
||||
|
||||
function handleToCategoryBy(category : ICategory) {
|
||||
if (calcAuditModeEnabled.value)
|
||||
return
|
||||
uni.navigateTo({
|
||||
url: `/pages-blog/category-detail/category-detail?name=${category.metadata.name}&title=${category.spec.displayName}`,
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
handleGetCategoryList()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view v-if="calcIsShowCategory" class="mb-6">
|
||||
<uh-section-title class="mb-4 px-3 box-border">
|
||||
精选分类
|
||||
<template #right>
|
||||
<view class="flex items-center justify-center rounded-md bg-white p-1.5 text-gray-400" @click="handleToCategoryPage">
|
||||
<wd-icon name="arrow-right" size="12px" />
|
||||
</view>
|
||||
</template>
|
||||
</uh-section-title>
|
||||
|
||||
<view class="w-full grid grid-cols-2 grid-rows-auto h-42 box-border px-3 gap-2">
|
||||
<view v-if="categoryList.length === 0"
|
||||
class="cate-empty text-grey w-full flex items-center justify-center">
|
||||
还没有任何分类~
|
||||
</view>
|
||||
<block v-else>
|
||||
<view v-for="(category,index) in categoryList" :key="category.metadata.name"
|
||||
class="uh-global-card-glass relative w-full h-full overflow-hidden rounded-xl text-center text-white"
|
||||
:class="{'grid-row-span-2':index===0 }" @click="handleToCategoryBy(category)">
|
||||
<image :src="category.spec.cover" class="w-full h-full" mode="aspectFill" lazy-load />
|
||||
<view
|
||||
class="absolute bottom-0 left-0 h-[140rpx] w-full bg-gradient-to-b from-black/0 to-black/30" />
|
||||
<view class="absolute left-2 bottom-2 flex z-2 flex-col text-left">
|
||||
<text class="text-sm font-bold">
|
||||
{{ category.spec.displayName }}
|
||||
</text>
|
||||
<text class="mt-1 text-xs text-gray-200">共 {{ category.postCount ?? 0 }} 篇</text>
|
||||
</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -0,0 +1,88 @@
|
||||
<script setup lang="ts">
|
||||
import { useAppConfigStore } from '@/store/appConfig'
|
||||
|
||||
const appConfigStore = useAppConfigStore()
|
||||
|
||||
const haloConfigs = computed(() => appConfigStore.configs)
|
||||
|
||||
const calcAuditModeEnabled = computed(() => appConfigStore.auditModeEnabled)
|
||||
const calcIsShowQuickNavigationEnabled = computed(() => haloConfigs.value.pageConfig?.homeConfig?.useQuickNavigation)
|
||||
const calcVotePluginEnabled = computed(() => !!haloConfigs.value.pluginConfig?.votePlugin?.enabled)
|
||||
const calcLinksPluginEnabled = computed(() => !!haloConfigs.value.pluginConfig?.linksPlugin?.enabled)
|
||||
|
||||
/** 快捷导航列表(由配置控制显隐) */
|
||||
const navList = computed(() => {
|
||||
const loveEnabled = !!(haloConfigs.value.loveConfig as { loveEnabled ?: boolean })?.loveEnabled
|
||||
const socialEnabled = !!(haloConfigs.value.authorConfig?.social as { enabled ?: boolean } | undefined)?.enabled
|
||||
return [
|
||||
{
|
||||
key: 'archives',
|
||||
title: calcAuditModeEnabled.value ? '内容归档' : '文章归档',
|
||||
bgColor: 'rgba(3, 169, 244, 0.95)',
|
||||
icon: 'news',
|
||||
path: '/pages-blog/archives/archives',
|
||||
show: true,
|
||||
},
|
||||
{
|
||||
key: 'vote',
|
||||
title: '投票中心',
|
||||
bgColor: 'rgba(0, 188, 212, 0.95)',
|
||||
icon: 'box',
|
||||
path: '/pages-blog/votes/votes',
|
||||
// show: !calcAuditModeEnabled.value && calcVotePluginEnabled.value,
|
||||
show: true,
|
||||
},
|
||||
{
|
||||
key: 'disclaimers',
|
||||
title: '友情链接',
|
||||
bgColor: 'rgba(0, 150, 136, 0.95)',
|
||||
icon: 'link',
|
||||
path: '/pages-blog/friend-links/friend-links',
|
||||
// show: calcLinksPluginEnabled.value,
|
||||
show: true,
|
||||
},
|
||||
{
|
||||
key: 'love',
|
||||
title: '恋爱日记',
|
||||
bgColor: 'rgba(255, 76, 103, 0.95)',
|
||||
icon: 'heart',
|
||||
path: '/pages-blog/love/love',
|
||||
// show: loveEnabled,
|
||||
show: true,
|
||||
},
|
||||
{
|
||||
key: 'contact-blogger',
|
||||
title: '联系博主',
|
||||
bgColor: 'rgba(255, 152, 0, 0.95)',
|
||||
icon: 'message',
|
||||
path: '/pages-blog/contact/contact',
|
||||
show: socialEnabled,
|
||||
},
|
||||
].filter(item => item.show)
|
||||
})
|
||||
|
||||
|
||||
function handleClickNav(item : { path : string }) {
|
||||
uni.navigateTo({ url: item.path })
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view v-if="navList.length" class="overflow-hidden rounded-xl p-3 px-4 mb-3">
|
||||
<uh-section-title class="mb-4">
|
||||
快捷导航
|
||||
</uh-section-title>
|
||||
<view class="grid grid-cols-5 gap-4">
|
||||
<view v-for="item in navList" :key="item.key" class="flex flex-col items-center gap-2"
|
||||
@click="handleClickNav(item)">
|
||||
<view class="uh-global-card-glass border h-12 w-12 flex items-center justify-center rounded-2xl"
|
||||
:style="{ backgroundColor: item.bgColor }">
|
||||
<wd-icon :name="item.icon" size="24px" color="#fff" />
|
||||
</view>
|
||||
<view class="text-xs text-gray-900 font-bold">
|
||||
{{ item.title }}
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -0,0 +1,85 @@
|
||||
<script setup lang="ts">
|
||||
import { onPageScroll } from '@dcloudio/uni-app'
|
||||
import { ref, computed, useSlots, onMounted } from 'vue'
|
||||
|
||||
interface IProps {
|
||||
useBack : boolean;
|
||||
useTitle : boolean;
|
||||
defaultTitle ?: string;
|
||||
scrollTitle ?: string;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<IProps>(), {
|
||||
useBack: true,
|
||||
useTitle: true,
|
||||
})
|
||||
|
||||
const slots = useSlots()
|
||||
|
||||
const scrollY = ref(0)
|
||||
const maxAlpha = ref(0.65)
|
||||
|
||||
const customStyle = computed(() => {
|
||||
const alpha = Math.min(scrollY.value / 360, maxAlpha.value)
|
||||
return {
|
||||
backgroundColor: `rgba(255, 255, 255, ${alpha})`,
|
||||
}
|
||||
})
|
||||
const scrollThreshold = computed(() => {
|
||||
return scrollY.value / 360 <= 0.5;
|
||||
})
|
||||
|
||||
const customCalss = computed(() => {
|
||||
const _class = []
|
||||
if (scrollThreshold.value) {
|
||||
_class.push('text-white')
|
||||
}
|
||||
else {
|
||||
_class.push('text-gray-900')
|
||||
}
|
||||
return _class;
|
||||
})
|
||||
|
||||
const visibleTitle = computed(() => {
|
||||
if (!props.scrollTitle) {
|
||||
return props.defaultTitle;
|
||||
}
|
||||
if (scrollThreshold.value) {
|
||||
return props.defaultTitle;
|
||||
}
|
||||
return props.scrollTitle;
|
||||
})
|
||||
|
||||
// todo:注意:如果是从分享进来的,我们需要处理为返回 home页面
|
||||
function handleBack(){
|
||||
uni.navigateBack({ delta: 1 })
|
||||
}
|
||||
|
||||
onPageScroll((e : any) => {
|
||||
scrollY.value = e.scrollTop
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="box-border pt-safe w-full fixed left-0 top-0 z-50" :class="customCalss" :style="[customStyle]">
|
||||
<view class="w-full h-[46px] flex items-center gap-x-4 box-border px-3 backdrop-blur-[2rpx]">
|
||||
<!-- 左边 -->
|
||||
<view class="shrink-0" @click="handleBack()">
|
||||
<view
|
||||
class="uh-global-card-glass h-7 px-3 rounded-full border flex items-center gap-x-2 text-gray-900 text-sm">
|
||||
<wd-icon name="arrow-left" size="32rpx"></wd-icon>
|
||||
<view class="w-[1px] h-4 bg-white/60" />
|
||||
<text class="text-xs font-bold">返回</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 中间 -->
|
||||
<view class="flex-1 truncate text-center font-bold transition-colors duration-300">
|
||||
<slot> {{visibleTitle}} </slot>
|
||||
</view>
|
||||
<!-- 右边 -->
|
||||
<view class="shrink-0 min-w-18">
|
||||
<slot name="right"></slot>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -0,0 +1,22 @@
|
||||
<script setup lang="ts">
|
||||
interface IProps {
|
||||
customClass : Array<string>;
|
||||
}
|
||||
const props = defineProps({
|
||||
customClass: () => {
|
||||
return []
|
||||
},
|
||||
})
|
||||
|
||||
function handleScrollTop() {
|
||||
uni.pageScrollTo({ scrollTop: 0, duration: 500 })
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view
|
||||
class="uh-global-card-glass border fixed bottom-24 right-4 z-90 h-10 w-10 flex items-center justify-center rounded-full text-primary"
|
||||
:class="props.customClass" @click="handleScrollTop">
|
||||
<wd-icon name="arrow-up" size="20px" />
|
||||
</view>
|
||||
</template>
|
||||
@@ -0,0 +1,20 @@
|
||||
<script setup lang="ts">
|
||||
import { useSlots } from 'vue'
|
||||
const slots = useSlots();
|
||||
const hasRightSlot = computed(() => !!slots.right?.())
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="w-full flex items-center justify-between">
|
||||
<view class="shrink-0 relative">
|
||||
<text class="font-bold relative z-2">
|
||||
<slot></slot>
|
||||
</text>
|
||||
<view class="absolute z-1 -right-1 -bottom-0.5 rounded-xl bg-secondary h-4 w-4/5"></view>
|
||||
</view>
|
||||
<view v-if="hasRightSlot" class="flex-1 flex items-center justify-end">
|
||||
<slot name="right"></slot>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -1,421 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
/**
|
||||
* 轮播组件(源自旧项目 components/e-swiper,新建复刻)
|
||||
* 数据高内聚:默认内部请求 plugin-uni-halo 公开 banners 接口(getBanners),支持外部 list 覆盖
|
||||
* 支持:图片轮播、日期角标(useTop,显示当前条目 date 快照)、标题浮层(useTitle)、
|
||||
* 作者/日期信息浮层(useUser)、底部小图指示器(useDot)
|
||||
*/
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { getBanners } from '@/api/uni-halo'
|
||||
import { checkAvatarUrl, checkThumbnailUrl } from '@/utils/url'
|
||||
import type { IBannerPublicItem } from '@/api/types/uni-halo'
|
||||
|
||||
export interface IBannerItem {
|
||||
/** 条目标识(Banner 为 metadata.name;兼容旧数据) */
|
||||
id?: string | number
|
||||
/** Banner 条目 metadata.name(custom 详情页跳转用) */
|
||||
name?: string
|
||||
title?: string
|
||||
image?: string
|
||||
src?: string
|
||||
/** 来源:post=文章快照 / custom=自定义 */
|
||||
type?: string
|
||||
/** 文章 id(source=post 时跳转文章详情) */
|
||||
postId?: string
|
||||
content?: string
|
||||
url?: string
|
||||
/** 展示日期(ISO 快照) */
|
||||
date?: string
|
||||
authorName?: string
|
||||
authorAvatar?: string
|
||||
[key: string]: unknown
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
title?: string
|
||||
height?: string
|
||||
dotPosition?: string
|
||||
/** 日期角标(显示当前条目 date) */
|
||||
useTop?: boolean
|
||||
/** 底部小图指示器 */
|
||||
useDot?: boolean
|
||||
/** 标题浮层 */
|
||||
useTitle?: boolean
|
||||
/** 作者/日期信息浮层 */
|
||||
useUser?: boolean
|
||||
/** 轮播数据列表(可选;不传时组件内部调公开 banners 接口拉取) */
|
||||
list?: IBannerItem[]
|
||||
/** 当前选中的项(指示器坐标位置) */
|
||||
current?: number
|
||||
/** 是否自动轮播 */
|
||||
autoplay?: boolean
|
||||
}>(), {
|
||||
title: '',
|
||||
height: '450rpx',
|
||||
dotPosition: 'bottom',
|
||||
useTop: true,
|
||||
useDot: true,
|
||||
useTitle: true,
|
||||
useUser: true,
|
||||
current: 0,
|
||||
autoplay: false,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'on-click', item: IBannerItem): void
|
||||
(e: 'on-more'): void
|
||||
(e: 'change', event: { current: number }): void
|
||||
}>()
|
||||
|
||||
/* ---------------- 状态 ---------------- */
|
||||
const currentIndex = ref(props.current)
|
||||
/** 是否禁止用户 touch 操作 */
|
||||
const disableTouch = ref(false)
|
||||
|
||||
/* ---------------- 数据(高内聚:内部请求公开接口) ---------------- */
|
||||
const internalList = ref<IBannerItem[]>([])
|
||||
|
||||
/** 展示列表:外部传入(list)优先,否则使用内部拉取数据 */
|
||||
const displayItems = computed<IBannerItem[]>(() =>
|
||||
props.list && props.list.length > 0 ? props.list : internalList.value,
|
||||
)
|
||||
|
||||
/** 公开 Banner 条目 → 轮播展示项 */
|
||||
function mapBanners(items: IBannerPublicItem[]): IBannerItem[] {
|
||||
return items.map(item => ({
|
||||
id: item.name,
|
||||
name: item.name,
|
||||
title: item.title || '',
|
||||
image: checkThumbnailUrl(item.cover),
|
||||
src: checkThumbnailUrl(item.cover),
|
||||
type: item.source,
|
||||
postId: item.postId,
|
||||
url: item.link,
|
||||
date: item.date,
|
||||
authorName: item.authorName,
|
||||
authorAvatar: item.authorAvatar ? checkAvatarUrl(item.authorAvatar) : '',
|
||||
}))
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
// 外部已传数据时不再重复请求
|
||||
if (props.list && props.list.length > 0) {
|
||||
return
|
||||
}
|
||||
try {
|
||||
const res = await getBanners()
|
||||
internalList.value = mapBanners(res.data || [])
|
||||
}
|
||||
catch (err) {
|
||||
console.error('获取轮播图失败', err)
|
||||
}
|
||||
})
|
||||
|
||||
// 列表变化(外部覆盖/接口返回)后索引越界时归零
|
||||
watch(displayItems, (val) => {
|
||||
if (currentIndex.value >= val.length) {
|
||||
currentIndex.value = 0
|
||||
}
|
||||
})
|
||||
|
||||
/* ---------------- 计算属性 ---------------- */
|
||||
const currentItem = computed<IBannerItem>(() =>
|
||||
displayItems.value[currentIndex.value] || {},
|
||||
)
|
||||
|
||||
/** 日期角标(useTop):当前条目 date 快照转换(年/月/日) */
|
||||
const dateParts = computed(() => {
|
||||
const dateStr = currentItem.value.date as string | undefined
|
||||
if (!dateStr) {
|
||||
return null
|
||||
}
|
||||
const d = new Date(dateStr)
|
||||
if (Number.isNaN(d.getTime())) {
|
||||
return null
|
||||
}
|
||||
const monthArray = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
|
||||
return {
|
||||
day: String(d.getDate()).padStart(2, '0'),
|
||||
month: String(d.getMonth() + 1).padStart(2, '0'),
|
||||
monthEn: monthArray[d.getMonth()],
|
||||
year: String(d.getFullYear()),
|
||||
}
|
||||
})
|
||||
|
||||
const currentTitle = computed(() => currentItem.value.title || props.title || '')
|
||||
|
||||
/** 作者日期展示(useUser 用) */
|
||||
const authorDateText = computed(() => {
|
||||
const dateStr = currentItem.value.date as string | undefined
|
||||
if (!dateStr) {
|
||||
return ''
|
||||
}
|
||||
const d = new Date(dateStr)
|
||||
if (Number.isNaN(d.getTime())) {
|
||||
return ''
|
||||
}
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
|
||||
})
|
||||
|
||||
/* ---------------- 交互 ---------------- */
|
||||
/** current 改变时会触发 change 事件,event.detail = {current, source} */
|
||||
function change(e: { detail: { current: number, source: string } }) {
|
||||
const { current, source } = e.detail
|
||||
// 只有页面自动切换、手动切换时才轮播,其他不允许
|
||||
if (source === 'autoplay' || source === 'touch') {
|
||||
const event = { current }
|
||||
currentIndex.value = current
|
||||
emit('change', event)
|
||||
}
|
||||
}
|
||||
|
||||
/** 手动点击了指示器[小图模式] */
|
||||
function swiperIndTap(index: number) {
|
||||
const event = { current: index }
|
||||
currentIndex.value = index
|
||||
emit('change', event)
|
||||
}
|
||||
|
||||
function handleOnClick(item: IBannerItem) {
|
||||
emit('on-click', item)
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view v-if="displayItems.length > 0" class="uh-e-swiper">
|
||||
<view class="swiper-box" :class="[dotPosition]">
|
||||
<swiper
|
||||
class="swiper"
|
||||
:style="{ height }"
|
||||
:circular="true"
|
||||
:indicator-dots="false"
|
||||
:autoplay="autoplay"
|
||||
:interval="3000"
|
||||
:duration="1000"
|
||||
:current="currentIndex"
|
||||
:disable-touch="disableTouch"
|
||||
@change="change"
|
||||
>
|
||||
<swiper-item v-for="(item, index) in displayItems" :key="index" class="swiper-mfw-item">
|
||||
<image
|
||||
:src="item.image || item.src"
|
||||
class="image h-full w-full"
|
||||
mode="aspectFill"
|
||||
@click.stop="handleOnClick(item)"
|
||||
/>
|
||||
</swiper-item>
|
||||
</swiper>
|
||||
|
||||
<!-- 指示器 [Top 日期角标]:显示当前条目 date(年/月/日) -->
|
||||
<view v-if="useTop && dateParts" class="indicator-box indicator-top-box">
|
||||
<view class="top-date-hot">
|
||||
<view class="left-date-ri">
|
||||
<text class="date-ri-text">{{ dateParts.day }}</text>
|
||||
</view>
|
||||
<view class="center-date-nianyue">
|
||||
<view class="left-width-bgcolor" />
|
||||
<view class="right-date-nianyue">
|
||||
<text class="top-yue-usa">{{ dateParts.monthEn }}</text>
|
||||
<text class="bottom-nian">{{ dateParts.year }}</text>
|
||||
</view>
|
||||
</view>
|
||||
<view class="right-hot-ttf">
|
||||
<text class="hot-text text-overflow-2">{{ title }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 指示器 标题区域 + 作者/日期信息(useUser) -->
|
||||
<view v-if="useTitle" class="indicator-top" :class="{ 'no-dot': !useDot }">
|
||||
<view v-if="useUser && (currentItem.authorName || authorDateText)" class="author-line">
|
||||
<view v-if="currentItem.authorAvatar" class="author-avatar">
|
||||
<image :src="currentItem.authorAvatar" class="h-full w-full" mode="aspectFill" />
|
||||
</view>
|
||||
<text class="author-name">{{ currentItem.authorName }}</text>
|
||||
<text v-if="authorDateText" class="author-date">{{ authorDateText }}</text>
|
||||
</view>
|
||||
<view v-if="currentTitle" class="top-title">
|
||||
<text class="title-text text-overflow-2">{{ currentTitle }}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 指示器 [左边图片列表] -->
|
||||
<view v-if="useDot" class="indicator-bottom">
|
||||
<view class="bottom-left-imagelist">
|
||||
<view
|
||||
v-for="(item, index) in displayItems"
|
||||
:key="index"
|
||||
class="bottom-item"
|
||||
:class="currentIndex === index ? 'current' : 'no'"
|
||||
@click="swiperIndTap(index)"
|
||||
>
|
||||
<image :src="item.image || item.src" class="image h-full w-full" mode="aspectFill" />
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss">
|
||||
.uh-e-swiper {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
|
||||
.swiper-box {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
|
||||
.swiper {
|
||||
width: 100%;
|
||||
border-radius: 12rpx;
|
||||
}
|
||||
}
|
||||
|
||||
/* 日期角标(顶部) */
|
||||
.indicator-top-box {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 5;
|
||||
padding: 16rpx 24rpx;
|
||||
|
||||
.top-date-hot {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.left-date-ri {
|
||||
.date-ri-text {
|
||||
font-size: 40rpx;
|
||||
font-weight: bold;
|
||||
color: #fff;
|
||||
text-shadow: 0 2rpx 8rpx rgb(0 0 0 / 40%);
|
||||
}
|
||||
}
|
||||
|
||||
.center-date-nianyue {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
margin-left: 12rpx;
|
||||
|
||||
.left-width-bgcolor {
|
||||
width: 2rpx;
|
||||
height: 40rpx;
|
||||
background-color: rgb(255 255 255 / 50%);
|
||||
margin-right: 12rpx;
|
||||
}
|
||||
|
||||
.right-date-nianyue {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.top-yue-usa {
|
||||
font-size: 20rpx;
|
||||
color: #fff;
|
||||
text-shadow: 0 2rpx 8rpx rgb(0 0 0 / 40%);
|
||||
}
|
||||
|
||||
.bottom-nian {
|
||||
font-size: 16rpx;
|
||||
color: rgb(255 255 255 / 80%);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.right-hot-ttf {
|
||||
flex: 1;
|
||||
margin-left: 20rpx;
|
||||
|
||||
.hot-text {
|
||||
display: block;
|
||||
font-size: 24rpx;
|
||||
color: #fff;
|
||||
text-shadow: 0 2rpx 8rpx rgb(0 0 0 / 40%);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 底部标题/作者浮层 */
|
||||
.indicator-top {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 5;
|
||||
padding: 48rpx 24rpx 20rpx;
|
||||
background: linear-gradient(to top, rgb(0 0 0 / 45%), transparent);
|
||||
|
||||
.author-line {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8rpx;
|
||||
margin-bottom: 8rpx;
|
||||
|
||||
.author-avatar {
|
||||
width: 36rpx;
|
||||
height: 36rpx;
|
||||
border-radius: 50%;
|
||||
overflow: hidden;
|
||||
border: 1rpx solid rgb(255 255 255 / 60%);
|
||||
}
|
||||
|
||||
.author-name {
|
||||
font-size: 22rpx;
|
||||
color: rgb(255 255 255 / 92%);
|
||||
text-shadow: 0 1rpx 4rpx rgb(0 0 0 / 40%);
|
||||
}
|
||||
|
||||
.author-date {
|
||||
font-size: 20rpx;
|
||||
color: rgb(255 255 255 / 70%);
|
||||
text-shadow: 0 1rpx 4rpx rgb(0 0 0 / 40%);
|
||||
}
|
||||
}
|
||||
|
||||
.top-title {
|
||||
.title-text {
|
||||
display: block;
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
color: #fff;
|
||||
text-shadow: 0 2rpx 8rpx rgb(0 0 0 / 40%);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 底部小图指示器 */
|
||||
.indicator-bottom {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 16rpx;
|
||||
z-index: 5;
|
||||
padding: 0 24rpx;
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
|
||||
.bottom-left-imagelist {
|
||||
display: flex;
|
||||
gap: 12rpx;
|
||||
|
||||
.bottom-item {
|
||||
width: 96rpx;
|
||||
height: 64rpx;
|
||||
border-radius: 8rpx;
|
||||
overflow: hidden;
|
||||
opacity: 0.6;
|
||||
border: 2rpx solid transparent;
|
||||
|
||||
&.current {
|
||||
opacity: 1;
|
||||
border-color: #fff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user