1
0
mirror of https://github.com/ialley-workshop-open/uni-halo.git synced 2026-09-12 16:40:40 +08:00

refactor(uni-halo): 优化多处代码逻辑与样式

1. 开启i18n组合式API模式修复$i18n.__composer报错
2. 完善分类配置类型定义,新增封面和排序权重字段
3. 重构数据加载组件样式与结构,优化按钮样式
4. 替换底部弹窗组件为玻璃弹窗,新增关闭按钮并调整样式
5. 简化首页分类模块逻辑,直接使用配置数据排序而非接口查询
6. 移除多余代码与日志,调整代码格式与注释
This commit is contained in:
小莫唐尼
2026-09-09 22:46:46 +08:00
parent eb44980484
commit b0f101c96c
5 changed files with 51 additions and 49 deletions
+5 -1
View File
@@ -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 }
@@ -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 @@
<view class="deco-dot dot-a absolute rounded-full" />
<view class="deco-dot dot-b absolute rounded-full" />
<view class="bubble">
<text class="bubble-icon">
<view class="bubble-icon">
<wd-icon class-prefix="uhemoji-icon" :name="statusScene.icon" :size="sizeClasses.icon" />
</text>
</view>
</view>
</view>
@@ -114,7 +117,7 @@
{{ statusScene.subText }}
</text>
<view v-if="props.useRefreshButton" class="mt-4">
<uh-button custom-class="!rounded-lg uh-global-card-glass uh-shadow-xs border"
<uh-button :custom-class="'uh-global-card-glass uh-shadow-xs border' + sizeClasses.button"
@click="emit('refresh')">
刷新试试
</uh-button>
@@ -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()
@@ -23,22 +23,22 @@
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)
</script>
<template>
@@ -20,23 +20,28 @@
emit('update:modelValue', value)
},
})
function close() {
emit('update:modelValue', false)
}
</script>
<template>
<wd-popup v-model="show" position="bottom" :z-index="200" :safe-area-inset-bottom="true" closable
custom-class="rounded-lt-4 rounded-rt-4">
<view class="flex flex-col bg-white">
<view class="box-border px-4 py-4 text-center">
<text class="text-[30rpx] text-[#17181a] font-bold">
维护详情
</text>
</view>
<scroll-view scroll-y
class="box-border max-h-[60vh] px-[32rpx] pb-4 text-[26rpx] text-[#3a3e44] leading-[1.8]">
<mp-html :content="content" lazy-load :domain="markdownConfig.domain ?? ''" scroll-table selectable
:tag-style="markdownConfig.tagStyle" :container-style="markdownConfig.containStyle"
copy-by-long-press />
</scroll-view>
<uh-glass-popup v-model="show" position="bottom" :z-index="100" :safe-area-inset-bottom="true"
custom-class="rounded-xl">
<view class="box-border px-4 py-4 text-center">
<text class="text-md text-gray-900 font-bold">
维护详情
</text>
</view>
</wd-popup>
<scroll-view scroll-y :show-scrollbar="false"
class="box-border max-h-[60vh] px-4 text-sm text-gray-900 leading-5">
<mp-html :content="content" lazy-load :domain="markdownConfig.domain" scroll-table selectable
:tag-style="markdownConfig.tagStyle" :container-style="markdownConfig.containStyle"
copy-by-long-press />
</scroll-view>
<view class="w-full box-border flex items-center p-3">
<uh-button custom-class="flex-1 shadow-none bg-white text-primary" @click="close()">关闭</uh-button>
</view>
</uh-glass-popup>
</template>
+1 -1
View File
@@ -9,9 +9,9 @@ const messages = {
}
const i18n = createI18n({
legacy: false, // 组合式 API 模式:不再注入每组件 legacy mixin,避免 mounted 阶段访问 $i18n.__composer 报错
locale: uni.getLocale(), // 获取已设置的语言,fallback 语言需要再 manifest.config.ts 中设置
messages,
allowComposition: true,
})
console.log(uni.getLocale())