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
+55 -50
View File
@@ -7,6 +7,7 @@ import { computed, ref } from 'vue'
import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app'
import { getPostListByKeyword } from '@/api/halo'
import { useAppConfigStore } from '@/store/appConfig'
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
import { markdownConfig } from '@/config/markdown'
import { formatTime as formatTimeUtil } from '@/utils/formatTime'
import { debounce } from '@/utils/debounce'
@@ -15,6 +16,7 @@ definePage({
style: {
navigationBarTitleText: '内容搜索',
enablePullDownRefresh: true,
navigationStyle: 'custom',
},
})
@@ -26,7 +28,7 @@ const uniHaloPluginId = 'plugin-search-widget'
const { available: uniHaloPluginAvailable, check: checkPluginAvailable } = usePluginAvailable(uniHaloPluginId)
/* ---------------- 状态 ---------------- */
const loading = ref<'loading' | 'success' | 'error'>('loading')
const { loadingStatus, updateLoadingStatus } = useDataLoadingStatus()
const queryParams = ref({
keyword: '',
limit: 50,
@@ -52,19 +54,26 @@ const calcAniDelays = computed(() => {
})
})
/** 空态文案(无关键词提示输入;有关键词提示未搜到) */
const emptyText = computed(() =>
queryParams.value.keyword ? `未搜到 ${queryParams.value.keyword} 相关内容` : '请输入关键词搜索',
)
/* ---------------- 搜索 ---------------- */
async function handleGetData() {
if (calcAuditModeEnabled.value)
return
loading.value = 'loading'
updateLoadingStatus(DataLoadingStatusEnum.Loading)
try {
const res = await getPostListByKeyword({ ...queryParams.value })
loading.value = 'success'
dataList.value = (res.data as unknown as { hits?: typeof dataList.value }).hits || []
updateLoadingStatus(
dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success,
)
}
catch (err) {
console.error(err)
loading.value = 'error'
updateLoadingStatus(DataLoadingStatusEnum.Error)
}
finally {
setTimeout(() => {
@@ -76,7 +85,7 @@ async function handleGetData() {
function handleOnSearch() {
if (!queryParams.value.keyword) {
dataList.value = []
loading.value = 'success'
updateLoadingStatus(DataLoadingStatusEnum.Empty)
}
else {
handleGetData()
@@ -128,7 +137,7 @@ onLoad(async () => {
}
// 关键词非空(如带参进入)时自动搜索,否则展示空态
if (!queryParams.value.keyword) {
loading.value = 'success'
updateLoadingStatus(DataLoadingStatusEnum.Empty)
}
else {
handleGetData()
@@ -145,64 +154,67 @@ onPullDownRefresh(() => {
</script>
<template>
<view class="app-page min-h-screen w-screen flex flex-col bg-page pb-6">
<view class="box-border min-h-screen w-screen flex flex-col bg-page pb-6">
<!-- 自定义导航 -->
<uh-navbar default-title="内容搜索" title-color="text-gray-900" />
<uh-plugin-unavailable
v-if="!uniHaloPluginAvailable"
:plugin-id="uniHaloPluginId"
error-text="检测到当前插件没有安装或者启用,无法使用搜索功能哦,请联系管理员"
@on-refresh="handleOnSearch"
/>
<template v-else>
<!-- 顶部搜索框(玻璃吸顶,呼应首页搜索条) -->
<view class="search-bar uh-global-card-glass sticky top-0 z-10 px-3 py-2">
<view class="search-input h-[72rpx] flex items-center gap-3 rounded-full bg-[#f6f3ee] px-5">
<wd-icon name="search" size="16px" color="#a8a294" />
<input
v-model="queryParams.keyword"
class="search-field flex-1 text-[26rpx] text-gray-900"
placeholder="哈喽,想看些什么呢~"
placeholder-class="text-gray-400"
confirm-type="search"
@input="handleOnInput"
@confirm="handleOnSearch"
>
<view v-if="queryParams.keyword" class="clear-btn flex items-center" @click="queryParams.keyword = ''; handleOnSearch()">
<wd-icon name="close" size="14px" color="#a8a294" />
<!-- 顶部搜索框-->
<wd-sticky class="">
<view class="w-screen box-border px-3 py-2">
<view class="uh-global-card-glass h-9 flex items-center gap-3 rounded-full px-5">
<wd-icon name="search" size="16px" />
<input
v-model="queryParams.keyword"
class="flex-1 text-[26rpx] text-gray-900"
placeholder="哈喽,想看些什么呢~"
placeholder-class="text-gray-400"
confirm-type="search"
@input="handleOnInput"
@confirm="handleOnSearch"
>
<view v-if="queryParams.keyword" class="clear-btn flex items-center" @click="queryParams.keyword = ''; handleOnSearch()">
<wd-icon name="close" size="14px" />
</view>
</view>
</view>
</view>
</wd-sticky>
<!-- 骨架屏 -->
<view v-if="loading === 'loading'" class="loading-wrap p-3">
<wd-skeleton :row="4" :animated="true" />
</view>
<view v-else-if="loading === 'error'" class="min-h-[60vh] flex items-center justify-center content-empty">
<wd-empty description="搜索异常" />
</view>
<!-- 加载/错误/空占位(状态机) -->
<uh-data-loading
v-if="loadingStatus !== 'success'"
:loading-status="loadingStatus"
min-height="65vh"
error-text="搜索异常"
:empty-text="emptyText"
@refresh="handleOnSearch"
/>
<!-- 内容区域 -->
<view v-else class="content pt-4">
<view v-if="dataList.length === 0" class="min-h-[60vh] flex items-center justify-center content-empty">
<wd-empty v-if="!queryParams.keyword" description="请输入关键词搜索" />
<wd-empty v-else :description="`未搜到 ${queryParams.keyword} 相关内容`" />
</view>
<block v-else>
<!-- 内容区域(成功态) -->
<view v-else class="box-border pt-2 px-3 flex flex-col gap-y-3">
<block v-if="dataList.length !== 0">
<view
v-for="(item, index) in dataList"
:key="index"
class="article-card fade-up uh-global-card-glass mx-4 mb-4 flex flex-col overflow-hidden rounded-2xl p-4"
class="uh-global-card-glass uh-shadow-xs border flex flex-col overflow-hidden rounded-2xl p-4"
:style="{ animationDelay: `${calcAniDelays[index]}ms` }"
@click="handleToDetail(item)"
>
<view class="card-head mb-3 flex items-center">
<view
class="type-tag mr-3 shrink-0 rounded-md px-1.5 py-0.5 text-[20rpx] leading-none"
:class="isArticle(item) ? 'bg-secondary text-[#4d7c0f]' : 'bg-[#e8e3d8] text-gray-600'"
class="type-tag mr-3 shrink-0 rounded-md px-1.5 py-1 text-xs leading-none"
:class="isArticle(item) ? 'bg-secondary text-gray-900' : 'bg-blue-500 text-gray-50'"
>
{{ isArticle(item) ? '文章' : '瞬间' }}
</view>
<text class="card-title flex-1 overflow-hidden text-ellipsis whitespace-nowrap text-[28rpx] text-gray-900 font-bold">{{ item.title }}</text>
<text class="flex-1 overflow-hidden text-ellipsis whitespace-nowrap text-sm text-gray-900 font-bold">{{ item.title }}</text>
</view>
<mp-html
class="evan-markdown"
@@ -219,14 +231,7 @@ onPullDownRefresh(() => {
:show-language-name="true"
copy-by-long-press
/>
<view class="card-foot mt-3 flex items-center">
<text class="text-[24rpx] text-gray-400">{{ item.updateTimestamp ? `最近更新:${formatTimeUtil({ d: item.updateTimestamp, f: 'yyyy年MM月dd日 HH点mm分ss秒' })}` : '' }}</text>
</view>
</view>
<view class="to-top-btn uh-global-card-glass fixed bottom-[100rpx] right-6 z-6 h-[72rpx] w-[72rpx] flex items-center justify-center rounded-full" @click="handleToTopPage()">
<wd-icon name="arrow-up" size="20px" color="#6b7280" />
</view>
</view>
</block>
</view>
</template>