1
0
mirror of https://github.com/ialley-workshop-open/uni-halo.git synced 2026-11-13 22:11:42 +08:00

style: 优化多个组件UI细节与归档页代码格式

调整了首页分类、链接操作、横幅、相册查看器、投票详情、评论弹窗等组件的样式、尺寸与文案,统一了文字大小、图标规格,重构归档页代码缩进与格式
This commit is contained in:
小莫唐尼
2026-09-13 03:05:03 +08:00
parent 2177541de3
commit b8887641e1
7 changed files with 331 additions and 348 deletions
@@ -66,7 +66,7 @@
photos.value = [] photos.value = []
handleLoadPhotos() handleLoadPhotos()
} }
}) }, { immediate: true })
function handleClose() { function handleClose() {
isShow.value = false isShow.value = false
@@ -91,7 +91,6 @@
<uh-glass-popup v-model="isShow" position="bottom" :z-index="100" custom-class="!border rounded-2xl" <uh-glass-popup v-model="isShow" position="bottom" :z-index="100" custom-class="!border rounded-2xl"
safe-area-inset-bottom @close="handleClose"> safe-area-inset-bottom @close="handleClose">
<view class="box-border h-full w-full flex flex-col gap-y-3 p-4"> <view class="box-border h-full w-full flex flex-col gap-y-3 p-4">
<!-- 头部 -->
<view class="w-full flex shrink-0 items-center justify-between"> <view class="w-full flex shrink-0 items-center justify-between">
<view class="flex items-center gap-x-1 font-bold"> <view class="flex items-center gap-x-1 font-bold">
{{ albumName }} {{ albumName }}
@@ -99,12 +98,12 @@
<view <view
class="uh-global-card-glass uh-shadow-xs h-6 w-6 flex items-center justify-center border rounded-lg" class="uh-global-card-glass uh-shadow-xs h-6 w-6 flex items-center justify-center border rounded-lg"
@click="handleClose"> @click="handleClose">
<wd-icon name="close" size="32rpx" /> <wd-icon name="close" size="28rpx" />
</view> </view>
</view> </view>
<!-- 照片列表 --> <!-- 照片列表 -->
<scroll-view class="box-border max-h-[50vh] flex-1" scroll-y :show-scrollbar="false"> <scroll-view class="w-full box-border max-h-[50vh] flex-1" scroll-y :show-scrollbar="false">
<!-- 加载/错误/空占位(状态机) --> <!-- 加载/错误/空占位(状态机) -->
<uh-data-loading v-if="loadingStatus !== DataLoadingStatusEnum.Success" :use-refresh-button="false" <uh-data-loading v-if="loadingStatus !== DataLoadingStatusEnum.Success" :use-refresh-button="false"
:loading-status="loadingStatus" error-text="照片加载失败,请点击刷新重试" empty-text="这个相册暂时还没有照片~" :loading-status="loadingStatus" error-text="照片加载失败,请点击刷新重试" empty-text="这个相册暂时还没有照片~"
@@ -122,8 +121,7 @@
<view v-if="photo.description" class="mb-1 text-xs text-white leading-5"> <view v-if="photo.description" class="mb-1 text-xs text-white leading-5">
{{ photo.description }} {{ photo.description }}
</view> </view>
<view v-if="photo.takenDate || photo.location" <view v-if="photo.takenDate || photo.location" class="flex flex-col gap-y-1">
class="flex flex-col gap-y-1">
<text v-if="photo.takenDate" class="text-xs text-white"> <text v-if="photo.takenDate" class="text-xs text-white">
<wd-icon name="time-line"></wd-icon> {{ photo.takenDate }} <wd-icon name="time-line"></wd-icon> {{ photo.takenDate }}
</text> </text>
@@ -139,11 +137,11 @@
<!-- 底部关闭 --> <!-- 底部关闭 -->
<view class="w-full shrink-0 flex items-center justify-center gap-x-2"> <view class="w-full shrink-0 flex items-center justify-center gap-x-2">
<uh-button custom-class="py-2 flex-1 uh-global-card-glass border rounded-xl bg-white/90" <uh-button class="flex-1" custom-class="py-2 flex-1 uh-global-card-glass text-xs border rounded-xl bg-white/90"
@click="handleClose"> @click="handleClose">
关闭 关闭
</uh-button> </uh-button>
<uh-button custom-class="flex-1 py-2 uh-global-card-glass rounded-xl !bg-love/90 text-white border" <uh-button class="flex-1" custom-class="flex-1 py-2 uh-global-card-glass text-xs rounded-xl !bg-love/90 text-white border"
@click="handleLoadPhotos"> @click="handleLoadPhotos">
刷新 刷新
</uh-button> </uh-button>
@@ -176,8 +176,7 @@
} }
async function handleHandle() { async function handleHandle() {
if (!validateForm()) if (!validateForm()) { return }
return
uni.showLoading({ title: '正在提交...' }) uni.showLoading({ title: '正在提交...' })
@@ -269,54 +268,55 @@
</script> </script>
<template> <template>
<uh-glass-popup v-model="isShow" position="bottom" custom-class="!border rounded-2xl" <uh-glass-popup v-model="isShow" position="bottom" custom-class="!border rounded-2xl" :z-index="100"
:z-index="100" @close="handleOnChange(false)"> @close="handleOnChange(false)">
<view class="box-border p-4"> <view class="box-border p-4">
<view <view
class="relative w-full flex items-center justify-around box-border px-12 text-md font-bold text-center"> class="relative w-full flex items-center justify-around box-border px-12 text-md font-bold text-center">
{{ calcTitle }} <text>{{ calcTitle }} </text>
<view class="absolute right-0 top-1 w-6 h-6 uh-global-card-glass shadow-none border rounded-lg" <view
class="absolute right-0 top-0 w-6 h-6 uh-global-card-glass shadow-none border rounded-lg flex items-center justify-center"
@click="handleClose"> @click="handleClose">
<wd-icon name="close" size="32rpx" class="text-gray-500"></wd-icon> <wd-icon name="close" size="28rpx" class="text-gray-500"></wd-icon>
</view> </view>
</view> </view>
<scroll-view :scroll-y="true" class="form mt-6"> <scroll-view :scroll-y="true" class="form mt-6">
<view class="form-item mb-4 flex items-center"> <view class="form-item mb-4 flex items-center">
<textarea v-model="form.content" <textarea v-model="form.content"
class="h-22 uh-global-card-glass shadow-none border box-border w-full rounded-xl p-5 text-sm" class="h-22 uh-global-card-glass shadow-none border box-border w-full rounded-xl px-3 py-2 text-xs"
:placeholder="config.editor?.placeholder || '请输入内容,不超过200字符...'" :maxlength="200" /> :placeholder="config.editor?.placeholder || '请输入内容,不超过200字符...'" :maxlength="200" />
</view> </view>
<view class="form-item mb-4 flex items-center"> <view class="form-item mb-4 flex items-center">
<text class="label w-[140rpx] shrink-0 text-sm text-[#666]">我的昵称</text> <text class="label w-16 shrink-0 text-xs text-gray-500">我的昵称</text>
<input v-model="form.author" <input v-model="form.author"
class="uh-global-card-glass shadow-none border h-9 flex-1 rounded-xl px-5 text-sm" class="uh-global-card-glass shadow-none border h-9 flex-1 rounded-xl px-3 text-xs"
placeholder="请输入您的昵称..."> placeholder="请输入您的昵称...">
</view> </view>
<view class="form-item mb-4 flex items-center"> <view class="form-item mb-4 flex items-center">
<text class="label w-[140rpx] shrink-0 text-sm text-[#666]">我的邮箱</text> <text class="label w-16 shrink-0 text-sm text-gray-500">我的邮箱</text>
<input v-model="form.email" <input v-model="form.email"
class="uh-global-card-glass shadow-none border h-9 flex-1 rounded-xl px-5 text-sm" class="uh-global-card-glass shadow-none border h-9 flex-1 rounded-xl px-3 text-xs"
placeholder="请输入您的邮箱..."> placeholder="请输入您的邮箱...">
</view> </view>
<view class="form-item mb-4 flex items-center"> <view class="form-item mb-4 flex items-center">
<text class="label w-[140rpx] shrink-0 text-sm text-[#666]">我的网站</text> <text class="label w-16 shrink-0 text-sm text-gray-500">我的网站</text>
<input v-model="form.authorUrl" <input v-model="form.authorUrl"
class="uh-global-card-glass shadow-none border h-9 flex-1 rounded-xl px-5 text-sm" class="uh-global-card-glass shadow-none border h-9 flex-1 rounded-xl px-3 text-xs"
placeholder="请输入您的网址..."> placeholder="[ 可选 ] 请输入您的网址...">
</view> </view>
<!-- 匿名评论验证码 --> <!-- 匿名评论验证码 -->
<view v-if="config?.security?.captcha?.anonymousCommentCaptcha" <view v-if="config?.security?.captcha?.anonymousCommentCaptcha"
class="form-item mb-4 flex items-center"> class="form-item mb-4 flex items-center">
<text class="w-[140rpx] shrink-0 text-sm text-[#666]">验证码</text> <text class="w-16 shrink-0 text-sm text-gray-500">验证码</text>
<view class="flex flex-1 items-center gap-4"> <view class="flex flex-1 items-center gap-3">
<input v-model="form.captchaCode" <input v-model="form.captchaCode"
class="uh-global-card-glass shadow-none border h-9 flex-1 rounded-xl px-5 text-sm" class="uh-global-card-glass shadow-none border h-9 flex-1 rounded-xl px-3 text-xs"
placeholder="请输入验证码结果"> placeholder="请输入验证码">
<view class="h-10 w-29 flex shrink-0 items-center justify-center"> <view class="h-10 w-29 flex shrink-0 items-center justify-center">
<uh-button v-if="captchaData.status === 'loading'" <uh-button v-if="captchaData.status === 'loading'"
class="w-full uh-global-card-glass shadow-none border py-2.5 !rounded-xl text-xs text-gray-900">获取中...</uh-button> class="w-full uh-global-card-glass shadow-none border py-2.5 !rounded-xl text-xs text-gray-900">获取中...</uh-button>
@@ -330,7 +330,8 @@
</view> </view>
<view class="submit-btn my-6"> <view class="submit-btn my-6">
<uh-button custom-class="py-2 !rounded-xl uh-global-card-glass border" @click="handleHandle"> <uh-button custom-class="py-2.5 !rounded-xl text-xs uh-global-card-glass border"
@click="handleHandle">
提交 提交
</uh-button> </uh-button>
</view> </view>
@@ -101,8 +101,8 @@
<template> <template>
<view v-if="bannerList.length > 0" class="relative w-full mb-6 box-border "> <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"> <view class="box-border relative w-full h-56 overflow-hidden">
<swiper class="w-full h-52" :circular="true" :indicator-dots="false" :autoplay="true" :interval="3000" <swiper class="w-full h-56" :circular="true" :indicator-dots="false" :autoplay="true" :interval="3000"
:duration="1000" @change="handleBannerChange"> :duration="1000" @change="handleBannerChange">
<swiper-item v-for="(item, index) in bannerList" :key="index" class="relative"> <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" <image :src="item.image || item.src" class="h-full w-full" mode="aspectFill"
@@ -111,9 +111,11 @@
</swiper> </swiper>
<view v-if="currentBanner" <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]"> 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-2xs text-gray-900 font-bold bg-secondary px-3 py-1 rounded-xl"> <view class="box-border mt-3 flex items-center justify-center bg-secondary px-3 py-1 rounded-xl">
{{ currentBanner.title }} <text class="text-2xs text-gray-900 font-semibold">
</text> {{ currentBanner.title }}
</text>
</view>
<text <text
class="text-xs text-white text-shadow-[0_2rpx_8rpx_rgba(0,0,0,0.4)]">{{ currentBanner.date }}</text> class="text-xs text-white text-shadow-[0_2rpx_8rpx_rgba(0,0,0,0.4)]">{{ currentBanner.date }}</text>
</view> </view>
@@ -122,10 +124,10 @@
<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 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 uh-translate-y-n6"> <view class="absolute left-0 right-0 z-10 flex items-center justify-center uh-translate-y-n6">
<view <view
class="uh-global-card-glass border w-4/5 rounded-full px-4 py-2.5 text-2xs text-gray-600 flex items-center justify-center gap-x-2" class="uh-global-card-glass border w-4/5 rounded-full px-4 py-2.5 text-gray-600 flex items-center justify-center gap-x-2"
@click="handleToSearch()"> @click="handleToSearch()">
<wd-icon name="search-line" size="32rpx"></wd-icon> <wd-icon name="search-line" size="32rpx"></wd-icon>
<text>哈喽,想看些什么 <text class="bg-secondary rounded-xl px-1">{ 内容 }</text> 呢~</text> <text class="text-2xs">哈喽,想看些什么 <text class="bg-secondary rounded-xl px-1">{ 内容 }</text> 呢~</text>
</view> </view>
</view> </view>
</view> </view>
@@ -81,7 +81,7 @@
<template #right> <template #right>
<view class="uh-global-card-glass uh-shadow-xs border flex items-center justify-center rounded-md p-1 text-gray-400" <view class="uh-global-card-glass uh-shadow-xs border flex items-center justify-center rounded-md p-1 text-gray-400"
@click="handleToCategoryPage"> @click="handleToCategoryPage">
<wd-icon name="arrow-right" size="28rpx" /> <wd-icon name="arrow-right" size="14px" />
</view> </view>
</template> </template>
</uh-section-title> </uh-section-title>
@@ -19,20 +19,20 @@
</script> </script>
<template> <template>
<view class="fixed bottom-8 left-1/2 z-10 flex items-center justify-center pb-safe uh-translate-x-center"> <view class="fixed bottom-0 left-1/2 z-10 flex items-center justify-center pb-safe uh-translate-x-center">
<view <view
class="uh-global-card-glass box-border flex items-center justify-center gap-2 border rounded-full p-1 text-primary"> class="uh-global-card-glass box-border flex items-center justify-center gap-2 border rounded-full p-1 text-primary">
<view v-if="actions.includes('apply')" <view v-if="actions.includes('apply')"
class="uh-global-card-glass box-border h-9 flex flex-1 items-center justify-center gap-x-1 border rounded-full px-8 shadow-none" class="uh-global-card-glass box-border py-2 flex flex-1 items-center justify-center gap-x-1 border rounded-full px-8 shadow-none"
@click="emit('apply')"> @click="emit('apply')">
<wd-icon name="edit" size="36rpx" /> <wd-icon name="edit" size="32rpx" />
<text class="shrink-0 text-sm text-gray-900 font-semibold">提交申请</text> <text class="shrink-0 text-xs text-gray-900 font-semibold">提交申请</text>
</view> </view>
<view v-if="actions.includes('info')" <view v-if="actions.includes('info')"
class="uh-global-card-glass box-border h-9 flex flex-1 items-center justify-center gap-x-1 border rounded-full px-8 shadow-none" class="uh-global-card-glass box-border py-2 flex flex-1 items-center justify-center gap-x-1 border rounded-full px-8 shadow-none"
@click="emit('info')"> @click="emit('info')">
<wd-icon name="info" size="36rpx" /> <wd-icon name="info" size="32rpx" />
<text class="shrink-0 text-sm text-gray-900 font-semibold">友链信息</text> <text class="shrink-0 text-xs text-gray-900 font-semibold">友链信息</text>
</view> </view>
</view> </view>
</view> </view>
+277 -295
View File
@@ -1,324 +1,306 @@
<script lang="ts" setup> <script lang="ts" setup>
import { computed, ref } from 'vue' import { computed, ref } from 'vue'
import { onPageScroll, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app' import { onPageScroll, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
import { getPostList } from '@/api/halo' import { getPostList } from '@/api/halo'
import { useAppConfigStore } from '@/store/appConfig' import { useAppConfigStore } from '@/store/appConfig'
import { useSettingStore } from '@/store/setting' import { useSettingStore } from '@/store/setting'
import { usePageScroll } from '@/hooks/usePageScroll' import { usePageScroll } from '@/hooks/usePageScroll'
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus' import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
import { sleep } from '@/utils/common' import { sleep } from '@/utils/common'
import type { IPost } from '@/api/types/halo' import type { IPost } from '@/api/types/halo'
definePage({ definePage({
style: { style: {
navigationBarTitleText: '归档', navigationBarTitleText: '归档',
enablePullDownRefresh: true, enablePullDownRefresh: true,
navigationStyle: 'custom', navigationStyle: 'custom',
}, },
}) })
const { scrollY, updatePageScrollValue } = usePageScroll() const { scrollY, updatePageScrollValue } = usePageScroll()
const appConfigStore = useAppConfigStore() const appConfigStore = useAppConfigStore()
const calcAuditModeEnabled = computed(() => appConfigStore.auditModeEnabled) const calcAuditModeEnabled = computed(() => appConfigStore.auditModeEnabled)
const settingStore = useSettingStore() const settingStore = useSettingStore()
/** 归档页列表布局(偏好设置驱动:single=单列 / double=双列) */ /** 归档页列表布局(偏好设置驱动:single=单列 / double=双列) */
const archivesListLayout = computed(() => settingStore.settings.archivesListLayout) const archivesListLayout = computed(() => settingStore.settings.archivesListLayout)
/* ---------------- 状态 ---------------- */ /* ---------------- 状态 ---------------- */
const { loadingStatus, loadMoreStatus, updateLoadingStatus, updateLoadMoreStatus, resetLoadMoreStatus } = useDataLoadingStatus() const { loadingStatus, loadMoreStatus, updateLoadingStatus, updateLoadMoreStatus, resetLoadMoreStatus } = useDataLoadingStatus()
const activeTabIndex = ref(0) const activeTabIndex = ref(0)
const queryParams = ref({ size: 10, page: 1 }) const queryParams = ref({ size: 10, page: 1 })
const cacheDataList = ref<IPost[]>([]) const cacheDataList = ref<IPost[]>([])
const dataList = ref<{ const dataList = ref<{
sort: number sort : number
key: string key : string
year: string year : string
month: string month : string
posts: IPost[] posts : IPost[]
}[]>([]) }[]>([])
const postLabelYearKey = 'content.halo.run/archive-year' const postLabelYearKey = 'content.halo.run/archive-year'
const postLabelMonthKey = 'content.halo.run/archive-month' const postLabelMonthKey = 'content.halo.run/archive-month'
/* ---------------- 数据处理 ---------------- */ /* ---------------- 数据处理 ---------------- */
/** 按 tab 分组文章 */ /** 按 tab 分组文章 */
function handleGetPosts(list: IPost[]): Record<string, IPost[]> { function handleGetPosts(list : IPost[]) : Record<string, IPost[]> {
const posts: Record<string, IPost[]> = {} const posts : Record<string, IPost[]> = {}
list.forEach((item) => { list.forEach((item) => {
const labels = item.metadata.labels || {} const labels = item.metadata.labels || {}
let postItemKey = '' let postItemKey = ''
if (activeTabIndex.value === 0) { if (activeTabIndex.value === 0) {
postItemKey = `${labels[postLabelYearKey]}-${labels[postLabelMonthKey]}` postItemKey = `${labels[postLabelYearKey]}-${labels[postLabelMonthKey]}`
} }
else { else {
postItemKey = `${labels[postLabelYearKey]}` postItemKey = `${labels[postLabelYearKey]}`
} }
if (posts[postItemKey]) { if (posts[postItemKey]) {
posts[postItemKey].push(item) posts[postItemKey].push(item)
} }
else { else {
posts[postItemKey] = [item] posts[postItemKey] = [item]
} }
}) })
return posts return posts
} }
/** 处理成显示数据(分组 + 排序) */ /** 处理成显示数据(分组 + 排序) */
function handleGetShowDataList(posts: Record<string, IPost[]>): typeof dataList.value { function handleGetShowDataList(posts : Record<string, IPost[]>) : typeof dataList.value {
const listResult: typeof dataList.value = [] const listResult : typeof dataList.value = []
Object.keys(posts).forEach((key) => { Object.keys(posts).forEach((key) => {
const postData = { const postData = {
sort: 0, sort: 0,
key, key,
year: key, year: key,
month: '', month: '',
posts: posts[key], posts: posts[key],
} }
if (activeTabIndex.value === 0) { if (activeTabIndex.value === 0) {
const splitDate = key.split('-') const splitDate = key.split('-')
postData.year = splitDate[0] postData.year = splitDate[0]
postData.month = splitDate[1] postData.month = splitDate[1]
postData.sort = Number(key.replace('-', '')) postData.sort = Number(key.replace('-', ''))
} }
else { else {
postData.sort = Number(key) postData.sort = Number(key)
} }
listResult.push(postData) listResult.push(postData)
}) })
listResult.sort((a, b) => Number(b.sort) - Number(a.sort)) listResult.sort((a, b) => Number(b.sort) - Number(a.sort))
return listResult return listResult
} }
/** 去重缓存列表 */ /** 去重缓存列表 */
function handleUniqueCacheDatalist(list: IPost[]): IPost[] { function handleUniqueCacheDatalist(list : IPost[]) : IPost[] {
const seen = new Set<string>() const seen = new Set<string>()
return list.filter((item) => { return list.filter((item) => {
return seen.has(item.metadata.name) ? false : (seen.add(item.metadata.name), true) return seen.has(item.metadata.name) ? false : (seen.add(item.metadata.name), true)
}) })
} }
/* ---------------- 数据加载 ---------------- */ /* ---------------- 数据加载 ---------------- */
async function handleGetData() { async function handleGetData() {
if (calcAuditModeEnabled.value) { if (calcAuditModeEnabled.value) {
// 审核模式:真实文章按 audit-data posts 过滤(数组顺序即展示顺序),一次拉取不分页 // 审核模式:真实文章按 audit-data posts 过滤(数组顺序即展示顺序),一次拉取不分页
resetLoadMoreStatus() resetLoadMoreStatus()
const auditPostNames = appConfigStore.auditData.spec?.posts || [] const auditPostNames = appConfigStore.auditData.spec?.posts || []
try { try {
const res = await getPostList({ page: 1, size: 99999, sort: ['spec.publishTime,desc'] }) const res = await getPostList({ page: 1, size: 99999, sort: ['spec.publishTime,desc'] })
const filtered = res.data.items.filter(item => auditPostNames.includes(item.metadata.name)) const filtered = res.data.items.filter(item => auditPostNames.includes(item.metadata.name))
const orderMap = new Map(auditPostNames.map((name, index) => [name, index])) const orderMap = new Map(auditPostNames.map((name, index) => [name, index]))
filtered.sort((a, b) => (orderMap.get(a.metadata.name) ?? 999) - (orderMap.get(b.metadata.name) ?? 999)) filtered.sort((a, b) => (orderMap.get(a.metadata.name) ?? 999) - (orderMap.get(b.metadata.name) ?? 999))
const posts = handleGetPosts(filtered) const posts = handleGetPosts(filtered)
dataList.value = handleGetShowDataList(posts) dataList.value = handleGetShowDataList(posts)
cacheDataList.value = filtered cacheDataList.value = filtered
updateLoadingStatus( updateLoadingStatus(
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success, dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
) )
updateLoadMoreStatus({ updateLoadMoreStatus({
active: false, active: false,
status: 'noMore', status: 'noMore',
hasNext: false, hasNext: false,
}) })
uni.stopPullDownRefresh() uni.stopPullDownRefresh()
} }
catch (err) { catch (err) {
console.error(err) console.error(err)
updateLoadingStatus(DataLoadingStatusEnum.Error) updateLoadingStatus(DataLoadingStatusEnum.Error)
updateLoadMoreStatus({ updateLoadMoreStatus({
active: false, active: false,
status: 'error', status: 'error',
}) })
} }
return return
} }
if (!loadMoreStatus.value.active) { if (!loadMoreStatus.value.active) {
updateLoadingStatus(DataLoadingStatusEnum.Loading) updateLoadingStatus(DataLoadingStatusEnum.Loading)
} }
try { try {
// getPostList 返回 IResponse<IPostListRes>,数据在 .data 下 // getPostList 返回 IResponse<IPostListRes>,数据在 .data 下
const res = await getPostList({ ...queryParams.value }) const res = await getPostList({ ...queryParams.value })
const posts = handleGetPosts(res.data.items) const posts = handleGetPosts(res.data.items)
const showDataList = handleGetShowDataList(posts) const showDataList = handleGetShowDataList(posts)
if (loadMoreStatus.value.active) { if (loadMoreStatus.value.active) {
cacheDataList.value = handleUniqueCacheDatalist([...cacheDataList.value, ...res.data.items]) cacheDataList.value = handleUniqueCacheDatalist([...cacheDataList.value, ...res.data.items])
// 合并增量数据 // 合并增量数据
showDataList.forEach((item) => { showDataList.forEach((item) => {
const find = dataList.value.find(x => x.key === item.key) const find = dataList.value.find(x => x.key === item.key)
if (find) { if (find) {
item.posts.forEach((post) => { item.posts.forEach((post) => {
if (!find.posts.some(x => x.metadata.name === post.metadata.name)) { if (!find.posts.some(x => x.metadata.name === post.metadata.name)) {
find.posts.push(post) find.posts.push(post)
} }
}) })
} }
}) })
showDataList.forEach((post) => { showDataList.forEach((post) => {
if (!dataList.value.some(x => x.key === post.key)) { if (!dataList.value.some(x => x.key === post.key)) {
dataList.value.push(post) dataList.value.push(post)
} }
}) })
dataList.value.sort((a, b) => Number(b.sort) - Number(a.sort)) dataList.value.sort((a, b) => Number(b.sort) - Number(a.sort))
} }
else { else {
dataList.value = showDataList dataList.value = showDataList
cacheDataList.value = res.data.items cacheDataList.value = res.data.items
} }
if (!loadMoreStatus.value.active) { if (!loadMoreStatus.value.active) {
await sleep(500) await sleep(500)
updateLoadingStatus( updateLoadingStatus(
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success, dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
) )
} }
updateLoadMoreStatus({ updateLoadMoreStatus({
active: false, active: false,
status: res.data.hasNext ? 'loadMore' : 'noMore', status: res.data.hasNext ? 'loadMore' : 'noMore',
hasNext: res.data.hasNext, hasNext: res.data.hasNext,
}) })
} }
catch (err) { catch (err) {
console.error(err) console.error(err)
if (loadMoreStatus.value.active) { if (loadMoreStatus.value.active) {
updateLoadMoreStatus({ updateLoadMoreStatus({
active: false, active: false,
status: 'error', status: 'error',
}) })
} }
else { else {
updateLoadingStatus(DataLoadingStatusEnum.Error) updateLoadingStatus(DataLoadingStatusEnum.Error)
} }
} }
finally { finally {
uni.stopPullDownRefresh() uni.stopPullDownRefresh()
} }
} }
/** 顶部 tab 定义(同收藏页胶囊 chip) */ /** 顶部 tab 定义(同收藏页胶囊 chip) */
const archiveTabs = [ const archiveTabs = [
{ key: 'month', label: '按月份查看' }, { key: 'month', label: '按月份查看' },
{ key: 'year', label: '按年份查看' }, { key: 'year', label: '按年份查看' },
] ]
function handleOnTabChange(e: { index: number }) { function handleOnTabChange(e : { index : number }) {
activeTabIndex.value = e.index activeTabIndex.value = e.index
queryParams.value.page = 1 queryParams.value.page = 1
dataList.value = handleGetShowDataList(handleGetPosts(cacheDataList.value)) dataList.value = handleGetShowDataList(handleGetPosts(cacheDataList.value))
uni.pageScrollTo({ scrollTop: 0, duration: 500 }) uni.pageScrollTo({ scrollTop: 0, duration: 500 })
} }
function handleToTopPage(duration = 500) { function handleToTopPage(duration = 500) {
uni.pageScrollTo({ uni.pageScrollTo({
scrollTop: 0, scrollTop: 0,
duration, duration,
fail: (err) => { fail: (err) => {
console.error('回顶失败', err) console.error('回顶失败', err)
}, },
}) })
} }
/* ---------------- 生命周期 ---------------- */ /* ---------------- 生命周期 ---------------- */
onPageScroll((option: Page.PageScrollOption) => { onPageScroll((option : Page.PageScrollOption) => {
updatePageScrollValue(option.scrollTop) updatePageScrollValue(option.scrollTop)
}) })
handleGetData() handleGetData()
onPullDownRefresh(() => { onPullDownRefresh(() => {
resetLoadMoreStatus() resetLoadMoreStatus()
queryParams.value.page = 1 queryParams.value.page = 1
handleGetData() handleGetData()
}) })
onReachBottom(() => { onReachBottom(() => {
if (calcAuditModeEnabled.value) { if (calcAuditModeEnabled.value) {
uni.showToast({ icon: 'none', title: '没有更多数据了' }) uni.showToast({ icon: 'none', title: '没有更多数据了' })
return return
} }
// 正在加载时阻止重复请求 // 正在加载时阻止重复请求
if (loadMoreStatus.value.active) { if (loadMoreStatus.value.active) {
return return
} }
// 有更多数据时继续加载 // 有更多数据时继续加载
if (loadMoreStatus.value.hasNext) { if (loadMoreStatus.value.hasNext) {
queryParams.value.page += 1 queryParams.value.page += 1
updateLoadMoreStatus({ updateLoadMoreStatus({
active: true, active: true,
status: 'loading', status: 'loading',
}) })
handleGetData() handleGetData()
} }
}) })
</script> </script>
<template> <template>
<view class="min-h-screen w-screen flex flex-col bg-page"> <view class="min-h-screen w-screen flex flex-col bg-page">
<!-- 自定义导航 --> <uh-navbar :scroll-y="scrollY" default-title="内容归档" title-color="text-gray-900" />
<uh-navbar :scroll-y="scrollY" default-title="内容归档" title-color="text-gray-900" />
<!-- 顶部--> <wd-sticky>
<wd-sticky> <scroll-view scroll-x class="w-full whitespace-nowrap">
<scroll-view scroll-x class="w-full whitespace-nowrap"> <view class="box-border flex gap-2 px-3 pb-1">
<view class="box-border flex gap-2 px-3 pb-1 pt-3"> <view v-for="(tab, index) in archiveTabs" :key="tab.key"
<view class="uh-global-card-glass uh-shadow-xs inline-block border rounded-2xl px-5 py-2 text-2xs"
v-for="(tab, index) in archiveTabs" :key="tab.key" :class="activeTabIndex === index ? 'bg-primary font-medium' : 'text-gray-500'"
class="uh-global-card-glass uh-shadow-xs inline-block border rounded-2xl px-5 py-1.5 text-sm" @click="handleOnTabChange({ index })">
:class="activeTabIndex === index ? 'bg-primary font-bold' : 'text-gray-500'" {{ tab.label }}
@click="handleOnTabChange({ index })" </view>
> </view>
{{ tab.label }} </scroll-view>
</view> </wd-sticky>
</view>
</scroll-view>
</wd-sticky>
<uh-data-loading v-if="loadingStatus !== 'success'"
:loading-status="loadingStatus"
:empty-text="calcAuditModeEnabled ? '暂无归档的内容' : '暂无归档的文章'"
@refresh="handleGetData"
/>
<!-- 内容区域 --> <uh-data-loading v-if="loadingStatus !== DataLoadingStatusEnum.Success" :loading-status="loadingStatus"
<block v-else> empty-text="暂无归档的内容" @refresh="handleGetData" />
<!-- 时间线 -->
<view class="timeline px-4 pt-3">
<view v-for="item in dataList" :key="item.key" class="timeline-item flex">
<!-- <view class="timeline-left w-[96rpx] flex shrink-0 flex-col items-center">
<view class="timeline-dot mt-2 h-4 w-4 rounded-full bg-secondary shadow-[0_0_0_8rpx_rgba(215,249,76,0.3)]" />
<view v-if="index !== dataList.length - 1" class="timeline-line mt-2 w-[2rpx] flex-1 bg-black/5" />
</view> -->
<!-- <view class="timeline-content min-w-0 flex-1 pb-10 pl-5"> -->
<view class="flex-1 pb-10">
<view class="mb-3 flex items-center gap-2">
<text class="text-md text-gray-900 font-bold">{{ item.year }}年</text>
<text v-if="activeTabIndex === 0" class="text-md text-gray-900 font-bold">{{ item.month }}月</text>
<text class="rounded-full bg-secondary px-2 py-1 text-xs text-gray-500 leading-none">共 {{ item.posts.length }} 篇{{ calcAuditModeEnabled ? '内容' : '文章' }}</text>
</view>
<view v-if="item.posts.length !== 0" <!-- 内容区域 -->
:class="archivesListLayout === 'double' ? 'grid grid-cols-2 gap-3' : 'flex flex-col gap-y-4'"> <template v-else>
<uh-article-card <view class="px-3 pt-3">
v-for="post in item.posts" <view v-for="item in dataList" :key="item.key" class="flex">
:key="post.metadata.name" <view class="flex-1 pb-4">
from="archives" <view class="mb-3 flex items-center gap-1">
:variant="archivesListLayout === 'double' ? 'grid' : 'list'" <text class="text-md text-gray-900 font-bold">{{ item.year }}年</text>
:article="post" <text v-if="activeTabIndex === 0"
:audit-mode="calcAuditModeEnabled" class="text-md text-gray-900 font-bold">{{ item.month }}月</text>
/> <text class="ml-2 rounded-full bg-secondary px-2 py-1 text-xs text-gray-900 leading-none">共
</view> {{ item.posts.length }} 篇{{ calcAuditModeEnabled ? '内容' : '文章' }}</text>
<view v-else class="post-empty py-6 text-[26rpx] text-gray-400"> </view>
该日期下暂无归档文章!
</view>
</view>
</view>
</view>
<uh-data-loadmore :status="loadMoreStatus.status" :text="loadMoreStatus.text" /> <view v-if="item.posts.length !== 0"
</block> :class="archivesListLayout === 'double' ? 'grid grid-cols-2 gap-3' : 'flex flex-col gap-y-4'">
</view> <uh-article-card v-for="post in item.posts" :key="post.metadata.name" from="archives"
</template> :variant="archivesListLayout === 'double' ? 'grid' : 'list'" :article="post"
:audit-mode="calcAuditModeEnabled" />
</view>
<uh-data-loading v-else :loading-status="DataLoadingStatusEnum.Empty" empty-text="该分类下暂无文章"
@refresh="handleGetData" />
</view>
</view>
</view>
<uh-data-loadmore :status="loadMoreStatus.status" :text="loadMoreStatus.text" />
</template>
</view>
</template>
+9 -9
View File
@@ -275,7 +275,7 @@ onShareTimeline(() => ({
<!-- 投票信息 --> <!-- 投票信息 -->
<view class="uh-global-card-glass box-border flex flex-col gap-y-3 rounded-2xl p-3"> <view class="uh-global-card-glass box-border flex flex-col gap-y-3 rounded-2xl p-3">
<uh-section-title> 投票信息 </uh-section-title> <uh-section-title> 投票信息 </uh-section-title>
<view class="flex flex-col gap-2 rounded-xl bg-gray-100 px-4 py-3 text-sm text-gray-900"> <view class="flex flex-col gap-2 rounded-xl bg-gray-100 px-4 py-3 text-xs text-gray-900">
<view class="info-row"> <view class="info-row">
<text>投票类型:</text> <text>投票类型:</text>
<text class="tag">{{ vote.spec?._uh_type }}</text> <text class="tag">{{ vote.spec?._uh_type }}</text>
@@ -328,7 +328,7 @@ onShareTimeline(() => ({
</text> </text>
</view> </view>
<view class="options flex flex-col gap-3 w-full"> <view class="options flex flex-col gap-3 w-full">
<!-- PK 对抗条(样式需顶层定义,勿嵌套在 .vote-card 下) --> <!-- PK 对抗条 -->
<view v-if="vote.spec?.type === 'pk'" class="pk-container box-border w-full flex"> <view v-if="vote.spec?.type === 'pk'" class="pk-container box-border w-full flex">
<view <view
v-for="(option, optionIndex) in vote.spec?.options" :key="optionIndex" v-for="(option, optionIndex) in vote.spec?.options" :key="optionIndex"
@@ -336,7 +336,7 @@ onShareTimeline(() => ({
:style="{ width: `${option._uh_percent}%` }" :style="{ width: `${option._uh_percent}%` }"
> >
<view <view
class="option-item box-border w-full rounded-xl px-3 py-3" class="option-item box-border w-full rounded-xl px-3 py-2"
:class="optionIndex === 0 ? 'option-item-left' : 'option-item-right'" :class="optionIndex === 0 ? 'option-item-left' : 'option-item-right'"
> >
{{ option._uh_percent }}% {{ option._uh_percent }}%
@@ -390,34 +390,34 @@ onShareTimeline(() => ({
<view <view
class="uh-global-card-glass mb-2 w-full flex items-center justify-center gap-x-2 border rounded-xl" class="uh-global-card-glass mb-2 w-full flex items-center justify-center gap-x-2 border rounded-xl"
> >
<uh-button v-if="isVoted" custom-class="flex-1 py-2 !rounded-xl"> <uh-button v-if="isVoted" class="flex-1" custom-class="flex-1 py-2 !rounded-xl">
您已参与投票 您已参与投票
</uh-button> </uh-button>
<uh-button <uh-button
v-else-if="vote.spec?._uh_state?.state === '未开始'" custom-class="flex-1 py-2 !rounded-xl" v-else-if="vote.spec?._uh_state?.state === '未开始'" class="flex-1" custom-class="flex-1 py-2 !rounded-xl"
@click="handleSubmitTip('投票未开始')" @click="handleSubmitTip('投票未开始')"
> >
投票未开始 投票未开始
</uh-button> </uh-button>
<uh-button <uh-button
v-else-if="vote.spec?._uh_state?.state === '已结束'" custom-class="flex-1 py-2 !rounded-xl" v-else-if="vote.spec?._uh_state?.state === '已结束'" class="flex-1" custom-class="flex-1 py-2 !rounded-xl"
@click="handleSubmitTip('投票已结束')" @click="handleSubmitTip('投票已结束')"
> >
投票已结束 投票已结束
</uh-button> </uh-button>
<uh-button <uh-button
v-else-if="!vote.spec?.canAnonymously" custom-class="flex-1 py-2 !rounded-xl" v-else-if="!vote.spec?.canAnonymously" class="flex-1" custom-class="flex-1 py-2 !rounded-xl"
@click="handleSubmit()" @click="handleSubmit()"
> >
不支持匿名投票 不支持匿名投票
</uh-button> </uh-button>
<uh-button <uh-button
v-else-if="submitForm.voteData.length === 0" custom-class="flex-1 py-2 !rounded-xl" v-else-if="submitForm.voteData.length === 0" class="flex-1" custom-class="flex-1 py-2 !rounded-xl"
@click="handleSubmitTip('请选择选项')" @click="handleSubmitTip('请选择选项')"
> >
提交投票(请选择选项) 提交投票(请选择选项)
</uh-button> </uh-button>
<uh-button v-else custom-class="flex-1 py-2 !rounded-xl" @click="handleSubmit()"> <uh-button v-else class="flex-1" custom-class="flex-1 py-2 !rounded-xl" @click="handleSubmit()">
提交投票 提交投票
</uh-button> </uh-button>
</view> </view>