From b0f101c96c2f51067b529fd6b85782c9ca9f356e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=8E=AB=E5=94=90=E5=B0=BC?= Date: Wed, 9 Sep 2026 22:46:46 +0800 Subject: [PATCH] =?UTF-8?q?refactor(uni-halo):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=A4=9A=E5=A4=84=E4=BB=A3=E7=A0=81=E9=80=BB=E8=BE=91=E4=B8=8E?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 开启i18n组合式API模式修复$i18n.__composer报错 2. 完善分类配置类型定义,新增封面和排序权重字段 3. 重构数据加载组件样式与结构,优化按钮样式 4. 替换底部弹窗组件为玻璃弹窗,新增关闭按钮并调整样式 5. 简化首页分类模块逻辑,直接使用配置数据排序而非接口查询 6. 移除多余代码与日志,调整代码格式与注释 --- src/api/types/uni-halo.ts | 6 ++- .../uh-data-loading/uh-data-loading.vue | 15 ++++--- .../uh-home-category/uh-home-category.vue | 42 +++++++------------ .../uh-maintenance-detail.vue | 35 +++++++++------- src/locale/index.ts | 2 +- 5 files changed, 51 insertions(+), 49 deletions(-) diff --git a/src/api/types/uni-halo.ts b/src/api/types/uni-halo.ts index c26be20..f48c8f9 100644 --- a/src/api/types/uni-halo.ts +++ b/src/api/types/uni-halo.ts @@ -64,10 +64,14 @@ export interface IPageConfig { useQuickNavigation?: boolean bannerConfig?: IBannerConfig /** 首页精选分类引用(插件端「通用配置 → 页面设置 → 首页」配置,固定最多 3 个, - * 数组顺序 = 展示顺序;未配置/为空时客户端回退默认取数) */ + * 快照含名称/封面/排序权重,数组顺序 = 展示顺序;配置模式下直接映射渲染不发请求, + * 未配置/为空时回退默认取数) */ categories?: Array<{ name: string displayName?: string + cover?: string + /** 分类排序权重(Halo Category.spec.priority,越大越靠前) */ + priority?: number }> } categoryConfig?: { type?: string } diff --git a/src/components/uh-data-loading/uh-data-loading.vue b/src/components/uh-data-loading/uh-data-loading.vue index e07ad9b..82fba98 100644 --- a/src/components/uh-data-loading/uh-data-loading.vue +++ b/src/components/uh-data-loading/uh-data-loading.vue @@ -35,17 +35,20 @@ mini: { icon: '60rpx', stage: 'h-16 w-16', - glow: 'h-12 w-12' + glow: 'h-12 w-12', + button: '!rounded-lg py-0.5' }, small: { icon: '100rpx', stage: 'h-22 w-22', - glow: 'h-18 w-18' + glow: 'h-18 w-18', + button: '!rounded-lg py-1' }, large: { icon: '120rpx', stage: 'h-32 w-32', - glow: 'h-28 w-28' + glow: 'h-28 w-28', + button: '!rounded-lg' }, } @@ -95,9 +98,9 @@ - + - + @@ -114,7 +117,7 @@ {{ statusScene.subText }} - 刷新试试 diff --git a/src/components/uh-home-category/uh-home-category.vue b/src/components/uh-home-category/uh-home-category.vue index b9b5012..fb3b6f0 100644 --- a/src/components/uh-home-category/uh-home-category.vue +++ b/src/components/uh-home-category/uh-home-category.vue @@ -3,8 +3,8 @@ import { getCategoryList } from '@/api/halo' import { checkThumbnailUrl } from '@/utils/url' import { useAppConfigStore } from '@/store/appConfig' - import type { ICategory } from '@/api/types/halo' import { sleep } from '@/utils/common' + import type { ICategory } from '@/api/types/halo' const appConfigStore = useAppConfigStore() @@ -18,27 +18,27 @@ const isEnableCategoryModule = computed(() => { return !!haloConfigs.value.pageConfig?.homeConfig?.useCategory }) - + async function handleGetCategoryList() { try { loading.value = 'loading' const configured = haloConfigs.value.pageConfig?.homeConfig?.categories + console.log('configured',configured) let categoryListRaw : ICategory[] = [] if (configured && configured.length) { - // 配置模式:按 name 用 in 查询(Halo fieldSelector 数组为 AND 语义,多 name 需 in 语法) - const names = configured.map(c => c.name) - const res = await getCategoryList({ - fieldSelector: [`metadata.name in (${names.join(',')})`], - size: 3, - }) - // 按配置顺序排列;配置的 name 查不到(分类已删除)则跳过 - const byName = new Map(res.data.items.map(item => [item.metadata.name, item])) - categoryListRaw = names - .map(name => byName.get(name)) - .filter((item) : item is ICategory => !!item) + // 配置模式 + categoryListRaw = configured.map(c => ({ + metadata: { name: c.name }, + spec: { + displayName: c.displayName || '', + slug: '', + cover: checkThumbnailUrl(c.cover), + priority: c.priority, + } + } as ICategory)) } else { - // 默认模式(老部署无配置):保持原有取数与排序 + // 默认模式 const res = await getCategoryList({ fieldSelector: ['spec.hideFromList=false'], size: 3 }) categoryListRaw = res.data.items } @@ -50,13 +50,7 @@ postCount: item.postCount ?? 0 } }) - .sort((a, b) => { - if (configured && configured.length) { - return 0 - } - return (b.postCount || 0) - (a.postCount || 0) - }) - + .sort((a, b) => b.spec.priority - a.spec.priority) await sleep(600) loading.value = 'success' } @@ -66,21 +60,17 @@ } } - function handleToCategoryPage() { uni.switchTab({ url: '/pages/tabbar/category/category' }) } - function handleToCategoryBy(category : ICategory) { uni.navigateTo({ url: `/pages-blog/category-articles/category-articles?name=${category.metadata.name}&title=${category.spec.displayName}`, }) } - onMounted(() => { - handleGetCategoryList() - }) + onMounted(handleGetCategoryList)