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

refactor: 重构项目页面与组件,优化整体结构与体验

1.  重构分类页面路由与实现,替换旧分类详情页为文章列表页
2.  统一使用自定义导航栏,替换原有原生导航配置
3.  重构加载状态管理,统一使用useDataLoadingStatus hook
4.  优化插件可用性检查逻辑与组件展示
5.  调整数据加载占位与空状态样式
6.  优化文章卡片样式与交互,新增分类跳转功能
7.  重构设置页枚举选择弹窗,使用wd-picker替换自定义实现
8.  删除废弃的IPluginAvailable类型与相关代码
This commit is contained in:
小莫唐尼
2026-09-04 20:31:46 +08:00
parent 56ce29e69e
commit 02fa9e4294
27 changed files with 727 additions and 630 deletions
@@ -1,79 +1,105 @@
<script lang="ts" setup>
import { computed } from 'vue'
import { checkThumbnailUrl } from '@/utils/url'
import { useSettingStore } from '@/store/setting'
import { formatTime} from '@/utils/formatTime'
import type { IPost } from '@/api/types/halo'
import { computed } from 'vue'
import { checkThumbnailUrl } from '@/utils/url'
import { useSettingStore } from '@/store/setting'
import { formatTime } from '@/utils/formatTime'
import type { IPost,ICategory } from '@/api/types/halo'
const props = withDefaults(defineProps<{
/** 来源页面(home 时跟随首页布局) */
from?: string
article: IPost
}>(), {
from: '',
})
const props = withDefaults(defineProps<{
from ?: string
auditMode?: boolean
article : IPost
}>(), {
auditMode: false,
from: '',
})
const emit = defineEmits<{
(e: 'on-click', article: IPost): void
}>()
const settingStore = useSettingStore()
const settingStore = useSettingStore()
/** 卡片布局 class(由全局设置 layout 决定) */
const cardType = computed(() => {
const layout = settingStore.settings.layout
// 首页双列时强制上图下文布局,除非显式指定其他
if (props.from === 'home' && layout.home === 'h_row_col2') {
if (!['tb_image_text', 'tb_text_image', 'only_text'].includes(layout.cardType)) {
return [props.from, layout.home, 'tb_image_text']
}
return [props.from, layout.home, layout.cardType]
}
return [layout.home, layout.cardType]
})
/** 卡片布局 class(由全局设置 layout 决定) */
const cardType = computed(() => {
const layout = settingStore.settings.layout
// 首页双列时强制上图下文布局,除非显式指定其他
if (props.from === 'home' && layout.home === 'h_row_col2') {
if (!['tb_image_text', 'tb_text_image', 'only_text'].includes(layout.cardType)) {
return [props.from, layout.home, 'tb_image_text']
}
return [props.from, layout.home, layout.cardType]
}
return [layout.home, layout.cardType]
})
/** 发布时间格式化 yyyy-MM-dd */
const publishTimeText = computed(() => {
const time = props.article.spec.publishTime
return time ? formatTime({ d: time, f: 'yyyy-MM-dd' }) : ''
})
/** 发布时间格式化 yyyy-MM-dd */
const publishTimeText = computed(() => {
const time = props.article.spec.publishTime
return time ? formatTime({d:time,f:'yyyy-MM-dd'}) : ''
})
/** 阅读数(兼容 status.stats.visits 与旧版顶层 stats.visit) */
const visitCount = computed(() => {
return props.article.status?.stats?.visits ?? props.article.stats?.visit ?? 0
})
/** 阅读数(兼容 status.stats.visits 与旧版顶层 stats.visit) */
const visitCount = computed(() => {
return props.article.status?.stats?.visits ?? props.article.stats?.visit ?? 0
})
function handleClick() {
emit('on-click', props.article)
}
function handleToArticleDetail() {
uni.navigateTo({
url: `/pages-blog/article-detail/article-detail?name=${props.article.metadata.name}`,
animationType: 'slide-in-right',
})
}
function handleToCategory(category : ICategory) {
if (props.auditMode) {
return
}
uni.navigateTo({
url: `/pages-blog/category-articles/category-articles?name=${category.metadata.name}&title=${category.spec.displayName}`,
})
}
</script>
<template>
<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 line-clamp-2 text-gray-600">
{{ article.status?.excerpt }}
</view>
<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 class="uh-global-card-glass uh-shadow-xs overflow-hidden relative rounded-xl p-3"
@click.stop="handleToArticleDetail()">
<text v-if="article.spec.pinned"
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 line-clamp-2 text-gray-600">
{{ article.status?.excerpt }}
</view>
<view class="my-1 box-border flex flex-wrap gap-2">
<template v-if="article.categories && article.categories.length !== 0">
<text v-for="cate in article.categories" :key="cate.metadata.name"
class="py-1 px-2 text-xs rounded-xl bg-secondary" @click.stop="handleToCategory(cate)">
{{ cate.spec.displayName }}
</text>
</template>
<template v-if="article.tags && article.tags.length !== 0">
<text v-for="tag in article.tags" :key="tag.metadata.name"
class="py-1 px-2 text-xs rounded-xl bg-secondary">
# {{ tag.spec.displayName }}
</text>
</template>
</view>
<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">
浏览
<text class="number">{{ visitCount }}</text>
次
</view>
</view>
</view>
<view class="flex items-center gap-x-2">
{{ publishTimeText }}
</view>
<view class="visits">
浏览
<text class="number">{{ visitCount }}</text>
次
</view>
</view>
</view>
</view>
</template>
</view>
</template>
@@ -18,7 +18,7 @@ interface IProps {
const props = withDefaults(defineProps<IProps>(), {
loadingStatus: 'loading',
minHeight: '75vh',
minHeight: '80vh',
loadingText: '稍等,正在加载中哦',
errorText: '哎呀,加载失败了呢~',
emptyText: '啊偶,暂时没有数据呢~',
@@ -57,7 +57,7 @@
if (calcAuditModeEnabled.value)
return
uni.navigateTo({
url: `/pages-blog/category-detail/category-detail?name=${category.metadata.name}&title=${category.spec.displayName}`,
url: `/pages-blog/category-articles/category-articles?name=${category.metadata.name}&title=${category.spec.displayName}`,
})
}
@@ -3,17 +3,11 @@
import { NeedPlugins } from '@/hooks/usePluginAvailable'
const props = withDefaults(defineProps<{
/** 插件名称(与 NeedPlugins 中的 id 对应) */
pluginId : string
errorText ?: string
useDecoration ?: boolean
useBorder ?: boolean
customStyle ?: Record<string, string>
checking : boolean
}>(), {
errorText: '',
useDecoration: true,
useBorder: true,
customStyle: () => ({}),
})
const emit = defineEmits<{
@@ -25,75 +19,40 @@
const info = NeedPlugins.get(props.pluginId)
return info || {
id: props.pluginId,
name: props.pluginId,
name: props.name,
desc: '',
logo: '',
url: '',
}
})
const defaultStyle = {
width: '80vw',
borderRadius: '24rpx',
function handleRefresh() {
if (props.checking) { return }
emit('on-refresh')
}
const calcCustomStyle = computed(() => ({
...defaultStyle,
...props.customStyle,
}))
</script>
<template>
<view v-if="pluginInfo"
class="uh-plugin-unavailable mx-auto my-auto box-border flex flex-col gap-6 p-10 text-[28rpx]"
:class="{ border: useBorder, decoration: useDecoration }" :style="[calcCustomStyle]">
<!-- 图标 -->
<image class="plugin-logo box-border h-[120rpx] w-[120rpx] rounded-3xl" :src="pluginInfo.logo"
mode="scaleToFill" />
<!-- 名称 -->
<view class="plugin-name box-border text-[32rpx] text-[#333] font-bold">
<view v-if="pluginInfo" class="mx-auto my-auto box-border flex flex-col items-center justify-center gap-6 text-sm">
<wd-icon class-prefix="uhemoji-icon" name="-cry" size="160rpx"></wd-icon>
<view class="box-border text-lg text-gray-900 font-bold">
{{ pluginInfo.name }}
</view>
<!-- 自定义错误提示 -->
<view v-if="errorText" class="plugin-tip box-border border-2 rounded-xl border-dashed px-5 py-2.5 text-[24rpx]"
style="border-color: #f2c97d; color: #f0a020;">
<view v-if="errorText" class=" text-yellow-500 text-sm">
{{ errorText }}
</view>
<!-- 反馈按钮/复制地址 -->
<view class="plugin-btns box-border w-full">
<view class="w-full flex flex-col gap-y-4">
<uh-button custom-class="!rounded-full py-2 !uh-shadow-xs" @click="handleRefresh()">
{{props.checking?'正在刷新':'刷新试试'}}
</uh-button>
<!-- #ifdef MP-WEIXIN -->
<wd-button type="warning" plain block size="medium" open-type="contact">
<uh-button custom-class="bg-white py-2 !rounded-full" open-type="contact">
提交反馈
</wd-button>
</uh-button>
<!-- #endif -->
</view>
<!-- 刷新按钮 -->
<view class="flex justify-center">
<wd-button size="small" plain type="info" @click="emit('on-refresh')">
刷新试试
</wd-button>
</view>
<view class="plugin-copyright text-[20rpx] text-[#999]" style="transform: scale(0.9) translateY(20px);">
提示:请确保 Halo 博客已安装相关插件
</view>
</view>
</template>
<style scoped lang="scss">
.uh-plugin-unavailable {
&.border {
border: 2rpx solid #eee;
}
&.decoration {
background-color: rgb(255 255 255 / 95%);
box-shadow: 0 0 12rpx rgb(226 232 240 / 35%);
backdrop-filter: blur(6rpx);
border-top: 12rpx solid rgb(3 169 244);
}
}
</style>
</template>