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:
@@ -64,10 +64,14 @@ export interface IPageConfig {
|
|||||||
useQuickNavigation?: boolean
|
useQuickNavigation?: boolean
|
||||||
bannerConfig?: IBannerConfig
|
bannerConfig?: IBannerConfig
|
||||||
/** 首页精选分类引用(插件端「通用配置 → 页面设置 → 首页」配置,固定最多 3 个,
|
/** 首页精选分类引用(插件端「通用配置 → 页面设置 → 首页」配置,固定最多 3 个,
|
||||||
* 数组顺序 = 展示顺序;未配置/为空时客户端回退默认取数) */
|
* 快照含名称/封面/排序权重,数组顺序 = 展示顺序;配置模式下直接映射渲染不发请求,
|
||||||
|
* 未配置/为空时回退默认取数) */
|
||||||
categories?: Array<{
|
categories?: Array<{
|
||||||
name: string
|
name: string
|
||||||
displayName?: string
|
displayName?: string
|
||||||
|
cover?: string
|
||||||
|
/** 分类排序权重(Halo Category.spec.priority,越大越靠前) */
|
||||||
|
priority?: number
|
||||||
}>
|
}>
|
||||||
}
|
}
|
||||||
categoryConfig?: { type?: string }
|
categoryConfig?: { type?: string }
|
||||||
|
|||||||
@@ -35,17 +35,20 @@
|
|||||||
mini: {
|
mini: {
|
||||||
icon: '60rpx',
|
icon: '60rpx',
|
||||||
stage: 'h-16 w-16',
|
stage: 'h-16 w-16',
|
||||||
glow: 'h-12 w-12'
|
glow: 'h-12 w-12',
|
||||||
|
button: '!rounded-lg py-0.5'
|
||||||
},
|
},
|
||||||
small: {
|
small: {
|
||||||
icon: '100rpx',
|
icon: '100rpx',
|
||||||
stage: 'h-22 w-22',
|
stage: 'h-22 w-22',
|
||||||
glow: 'h-18 w-18'
|
glow: 'h-18 w-18',
|
||||||
|
button: '!rounded-lg py-1'
|
||||||
},
|
},
|
||||||
large: {
|
large: {
|
||||||
icon: '120rpx',
|
icon: '120rpx',
|
||||||
stage: 'h-32 w-32',
|
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-a absolute rounded-full" />
|
||||||
<view class="deco-dot dot-b absolute rounded-full" />
|
<view class="deco-dot dot-b absolute rounded-full" />
|
||||||
<view class="bubble">
|
<view class="bubble">
|
||||||
<text class="bubble-icon">
|
<view class="bubble-icon">
|
||||||
<wd-icon class-prefix="uhemoji-icon" :name="statusScene.icon" :size="sizeClasses.icon" />
|
<wd-icon class-prefix="uhemoji-icon" :name="statusScene.icon" :size="sizeClasses.icon" />
|
||||||
</text>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
@@ -114,7 +117,7 @@
|
|||||||
{{ statusScene.subText }}
|
{{ statusScene.subText }}
|
||||||
</text>
|
</text>
|
||||||
<view v-if="props.useRefreshButton" class="mt-4">
|
<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')">
|
@click="emit('refresh')">
|
||||||
刷新试试
|
刷新试试
|
||||||
</uh-button>
|
</uh-button>
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
import { getCategoryList } from '@/api/halo'
|
import { getCategoryList } from '@/api/halo'
|
||||||
import { checkThumbnailUrl } from '@/utils/url'
|
import { checkThumbnailUrl } from '@/utils/url'
|
||||||
import { useAppConfigStore } from '@/store/appConfig'
|
import { useAppConfigStore } from '@/store/appConfig'
|
||||||
import type { ICategory } from '@/api/types/halo'
|
|
||||||
import { sleep } from '@/utils/common'
|
import { sleep } from '@/utils/common'
|
||||||
|
import type { ICategory } from '@/api/types/halo'
|
||||||
|
|
||||||
const appConfigStore = useAppConfigStore()
|
const appConfigStore = useAppConfigStore()
|
||||||
|
|
||||||
@@ -23,22 +23,22 @@
|
|||||||
try {
|
try {
|
||||||
loading.value = 'loading'
|
loading.value = 'loading'
|
||||||
const configured = haloConfigs.value.pageConfig?.homeConfig?.categories
|
const configured = haloConfigs.value.pageConfig?.homeConfig?.categories
|
||||||
|
console.log('configured',configured)
|
||||||
let categoryListRaw : ICategory[] = []
|
let categoryListRaw : ICategory[] = []
|
||||||
if (configured && configured.length) {
|
if (configured && configured.length) {
|
||||||
// 配置模式:按 name 用 in 查询(Halo fieldSelector 数组为 AND 语义,多 name 需 in 语法)
|
// 配置模式
|
||||||
const names = configured.map(c => c.name)
|
categoryListRaw = configured.map(c => ({
|
||||||
const res = await getCategoryList({
|
metadata: { name: c.name },
|
||||||
fieldSelector: [`metadata.name in (${names.join(',')})`],
|
spec: {
|
||||||
size: 3,
|
displayName: c.displayName || '',
|
||||||
})
|
slug: '',
|
||||||
// 按配置顺序排列;配置的 name 查不到(分类已删除)则跳过
|
cover: checkThumbnailUrl(c.cover),
|
||||||
const byName = new Map(res.data.items.map(item => [item.metadata.name, item]))
|
priority: c.priority,
|
||||||
categoryListRaw = names
|
}
|
||||||
.map(name => byName.get(name))
|
} as ICategory))
|
||||||
.filter((item) : item is ICategory => !!item)
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// 默认模式(老部署无配置):保持原有取数与排序
|
// 默认模式
|
||||||
const res = await getCategoryList({ fieldSelector: ['spec.hideFromList=false'], size: 3 })
|
const res = await getCategoryList({ fieldSelector: ['spec.hideFromList=false'], size: 3 })
|
||||||
categoryListRaw = res.data.items
|
categoryListRaw = res.data.items
|
||||||
}
|
}
|
||||||
@@ -50,13 +50,7 @@
|
|||||||
postCount: item.postCount ?? 0
|
postCount: item.postCount ?? 0
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.sort((a, b) => {
|
.sort((a, b) => b.spec.priority - a.spec.priority)
|
||||||
if (configured && configured.length) {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
return (b.postCount || 0) - (a.postCount || 0)
|
|
||||||
})
|
|
||||||
|
|
||||||
await sleep(600)
|
await sleep(600)
|
||||||
loading.value = 'success'
|
loading.value = 'success'
|
||||||
}
|
}
|
||||||
@@ -66,21 +60,17 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function handleToCategoryPage() {
|
function handleToCategoryPage() {
|
||||||
uni.switchTab({ url: '/pages/tabbar/category/category' })
|
uni.switchTab({ url: '/pages/tabbar/category/category' })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function handleToCategoryBy(category : ICategory) {
|
function handleToCategoryBy(category : ICategory) {
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: `/pages-blog/category-articles/category-articles?name=${category.metadata.name}&title=${category.spec.displayName}`,
|
url: `/pages-blog/category-articles/category-articles?name=${category.metadata.name}&title=${category.spec.displayName}`,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(handleGetCategoryList)
|
||||||
handleGetCategoryList()
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -20,23 +20,28 @@
|
|||||||
emit('update:modelValue', value)
|
emit('update:modelValue', value)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
emit('update:modelValue', false)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<wd-popup v-model="show" position="bottom" :z-index="200" :safe-area-inset-bottom="true" closable
|
<uh-glass-popup v-model="show" position="bottom" :z-index="100" :safe-area-inset-bottom="true"
|
||||||
custom-class="rounded-lt-4 rounded-rt-4">
|
custom-class="rounded-xl">
|
||||||
<view class="flex flex-col bg-white">
|
|
||||||
<view class="box-border px-4 py-4 text-center">
|
<view class="box-border px-4 py-4 text-center">
|
||||||
<text class="text-[30rpx] text-[#17181a] font-bold">
|
<text class="text-md text-gray-900 font-bold">
|
||||||
维护详情
|
维护详情
|
||||||
</text>
|
</text>
|
||||||
</view>
|
</view>
|
||||||
<scroll-view scroll-y
|
<scroll-view scroll-y :show-scrollbar="false"
|
||||||
class="box-border max-h-[60vh] px-[32rpx] pb-4 text-[26rpx] text-[#3a3e44] leading-[1.8]">
|
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
|
<mp-html :content="content" lazy-load :domain="markdownConfig.domain" scroll-table selectable
|
||||||
:tag-style="markdownConfig.tagStyle" :container-style="markdownConfig.containStyle"
|
:tag-style="markdownConfig.tagStyle" :container-style="markdownConfig.containStyle"
|
||||||
copy-by-long-press />
|
copy-by-long-press />
|
||||||
</scroll-view>
|
</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>
|
</view>
|
||||||
</wd-popup>
|
</uh-glass-popup>
|
||||||
</template>
|
</template>
|
||||||
+1
-1
@@ -9,9 +9,9 @@ const messages = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const i18n = createI18n({
|
const i18n = createI18n({
|
||||||
|
legacy: false, // 组合式 API 模式:不再注入每组件 legacy mixin,避免 mounted 阶段访问 $i18n.__composer 报错
|
||||||
locale: uni.getLocale(), // 获取已设置的语言,fallback 语言需要再 manifest.config.ts 中设置
|
locale: uni.getLocale(), // 获取已设置的语言,fallback 语言需要再 manifest.config.ts 中设置
|
||||||
messages,
|
messages,
|
||||||
allowComposition: true,
|
|
||||||
})
|
})
|
||||||
|
|
||||||
console.log(uni.getLocale())
|
console.log(uni.getLocale())
|
||||||
|
|||||||
Reference in New Issue
Block a user