mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-11-13 22:11:42 +08:00
refactor: 优化代码结构与功能,修复细节问题
1. 新增首页精选分类配置类型定义与逻辑,支持自定义首页分类展示顺序 2. 移除冗余的qs导入与注释代码,简化请求参数处理 3. 修复瞬间详情页悬浮操作的渲染问题与收藏按钮样式 4. 优化文章卡片的头像处理与分类跳转逻辑 5. 重构数据加载组件,新增尺寸配置与样式优化 6. 为分类文章页添加排序切换功能,支持默认/置顶/最新/最旧排序 7. 优化首页分类模块的加载状态与数据获取逻辑,添加延迟模拟 8. 统一API文件的导入格式与代码风格
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed } from 'vue'
|
||||
import { checkThumbnailUrl } from '@/utils/url'
|
||||
import { checkAvatarUrl, checkThumbnailUrl } from '@/utils/url'
|
||||
import { useSettingStore } from '@/store/setting'
|
||||
import { formatTime } from '@/utils/formatTime'
|
||||
import type { ICategory, IPost } from '@/api/types/halo'
|
||||
@@ -139,16 +139,7 @@
|
||||
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>
|
||||
@@ -171,7 +162,7 @@
|
||||
<view v-if="!isGrid" class="my-1 box-border flex flex-wrap gap-2" :class="cardLayout.tagCategory">
|
||||
<template v-if="article.categories && article.categories.length !== 0">
|
||||
<text v-for="cate in article.categories" :key="cate.metadata.name"
|
||||
class="box-border uh-global-card-glass border uh-shadow-xs rounded-xl bg-secondary px-2 py-0.5 text-xs" @click.stop="handleToCategory(cate)">
|
||||
class="box-border uh-global-card-glass border uh-shadow-xs rounded-xl bg-secondary px-2 py-0.5 text-xs">
|
||||
{{ cate.spec.displayName }}
|
||||
</text>
|
||||
</template>
|
||||
@@ -184,7 +175,7 @@
|
||||
</view>
|
||||
<view class="flex items-center text-xs text-gray-500" :class="cardLayout.footer">
|
||||
<view class="flex items-center" :class="cardLayout.authorGroup">
|
||||
<image :src="article.owner.avatar" class="uh-global-card-glass h-5 w-5 rounded-full"
|
||||
<image :src="checkAvatarUrl(article.owner?.avatar || '')" class="uh-global-card-glass h-5 w-5 rounded-full"
|
||||
:class="cardLayout.avatar" mode="aspectFill" />
|
||||
<template v-if="isSocialCard">
|
||||
<view :class="cardLayout.infoCol">
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { checkUrl } from '@/utils/url'
|
||||
import { useAppConfigStore } from '@/store/appConfig'
|
||||
import type { DataLoadingStatus } from '@/hooks/useDataLoading'
|
||||
|
||||
interface IProps {
|
||||
/** 加载状态(取值同 useDataLoading 返回的 status) */
|
||||
loadingStatus ?: DataLoadingStatus
|
||||
/** 占位区最小高度 */
|
||||
size ?: 'mini' | 'small' | 'large'
|
||||
minHeight ?: string
|
||||
loadingText ?: string
|
||||
errorText ?: string
|
||||
emptyText ?: string
|
||||
/** 各态副文案(留空则不显示副行) */
|
||||
loadingSubText ?: string
|
||||
errorSubText ?: string
|
||||
emptySubText ?: string
|
||||
@@ -21,6 +18,7 @@
|
||||
|
||||
const props = withDefaults(defineProps<IProps>(), {
|
||||
loadingStatus: 'loading',
|
||||
size: 'large',
|
||||
minHeight: '80vh',
|
||||
loadingText: '稍等,正在加载中哦',
|
||||
errorText: '哎呀,加载失败了呢~',
|
||||
@@ -33,16 +31,28 @@
|
||||
|
||||
const emit = defineEmits<{ (e : 'refresh') : void }>()
|
||||
|
||||
const appConfigStore = useAppConfigStore()
|
||||
|
||||
const appInfo = computed(() => {
|
||||
const _appInfo = (appConfigStore.configs?.appConfig?.appInfo as any)
|
||||
return {
|
||||
name: _appInfo.name ?? 'UniHalo',
|
||||
logo: checkUrl(_appInfo?.logo ?? 'https://uni-halo.925i.cn/logo.png')
|
||||
}
|
||||
const SizeClasses = {
|
||||
mini: {
|
||||
icon: '60rpx',
|
||||
stage: 'h-16 w-16',
|
||||
glow: 'h-12 w-12'
|
||||
},
|
||||
small: {
|
||||
icon: '100rpx',
|
||||
stage: 'h-22 w-22',
|
||||
glow: 'h-18 w-18'
|
||||
},
|
||||
large: {
|
||||
icon: '120rpx',
|
||||
stage: 'h-32 w-32',
|
||||
glow: 'h-28 w-28'
|
||||
},
|
||||
}
|
||||
|
||||
const sizeClasses = computed(() => {
|
||||
return SizeClasses[props.size] ?? SizeClasses.large
|
||||
})
|
||||
|
||||
|
||||
const isLoading = computed(() => props.loadingStatus === 'loading')
|
||||
|
||||
const statusScene = computed(() => {
|
||||
@@ -76,20 +86,17 @@
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view class="relative w-full flex flex-col items-center justify-center gap-y-4 text-sm"
|
||||
<view class="relative w-full flex flex-col items-center justify-center gap-y-3 text-sm"
|
||||
:style="{ minHeight: props.minHeight }">
|
||||
|
||||
<!-- logo背景 -->
|
||||
<image v-if="false" :src="appInfo.logo" class="absolute left-1/2 top-1/2 -translate-1/2 z-0 opacity-10 w-46 h-46"></image>
|
||||
|
||||
<view class="scene relative z-1 h-[250rpx] w-[250rpx] flex items-center justify-center"
|
||||
:class="statusScene.stageClass">
|
||||
<view class="glow absolute inset-0 m-auto h-[220rpx] w-[220rpx] rounded-full" />
|
||||
|
||||
<view class="scene relative z-1 flex items-center justify-center"
|
||||
:class="[statusScene.stageClass,sizeClasses.stage]">
|
||||
<view class="glow absolute inset-0 m-auto rounded-full" :class="sizeClasses.glow" />
|
||||
<view class="deco-dot dot-a absolute rounded-full" />
|
||||
<view class="deco-dot dot-b absolute rounded-full" />
|
||||
<view class="bubble relative h-[150rpx] w-[150rpx] flex items-center justify-center rounded-full">
|
||||
<view class="bubble">
|
||||
<text class="bubble-icon">
|
||||
<wd-icon class-prefix="uhemoji-icon" :name="statusScene.icon" size="120rpx" />
|
||||
<wd-icon class-prefix="uhemoji-icon" :name="statusScene.icon" :size="sizeClasses.icon" />
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
@@ -103,11 +110,12 @@
|
||||
:style="{ animationDelay: `${(n - 1) * 0.15}s` }" />
|
||||
</view>
|
||||
</view>
|
||||
<text v-if="statusScene.subText" class="mt-3 text-xs text-gray-500">
|
||||
<text v-if="statusScene.subText" class="mt-2 text-xs text-gray-500">
|
||||
{{ statusScene.subText }}
|
||||
</text>
|
||||
<view v-if="props.useRefreshButton" class="mt-5">
|
||||
<uh-button custom-class="!rounded-lg uh-global-card-glass uh-shadow-xs border rounded-lg" @click="emit('refresh')">
|
||||
<view v-if="props.useRefreshButton" class="mt-4">
|
||||
<uh-button custom-class="!rounded-lg uh-global-card-glass uh-shadow-xs border"
|
||||
@click="emit('refresh')">
|
||||
刷新试试
|
||||
</uh-button>
|
||||
</view>
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
import { checkThumbnailUrl } from '@/utils/url'
|
||||
import { useAppConfigStore } from '@/store/appConfig'
|
||||
import type { ICategory } from '@/api/types/halo'
|
||||
import { sleep } from '@/utils/common'
|
||||
|
||||
const appConfigStore = useAppConfigStore()
|
||||
|
||||
@@ -14,23 +15,34 @@
|
||||
const loading = ref<'loading' | 'success' | 'error'>('loading')
|
||||
const categoryList = ref<ICategory[]>([])
|
||||
|
||||
const calcIsShowCategory = computed(() => {
|
||||
if (calcAuditModeEnabled.value) {
|
||||
return false;
|
||||
}
|
||||
const isEnableCategoryModule = computed(() => {
|
||||
return !!haloConfigs.value.pageConfig?.homeConfig?.useCategory
|
||||
})
|
||||
|
||||
/** 精选分类 */
|
||||
async function handleGetCategoryList() {
|
||||
if (calcAuditModeEnabled.value || !calcIsShowCategory.value) {
|
||||
loading.value = 'success'
|
||||
return
|
||||
}
|
||||
try {
|
||||
loading.value = 'loading'
|
||||
const res = await getCategoryList({ fieldSelector: ['spec.hideFromList=false'], size: 3 })
|
||||
categoryList.value = res.data.items
|
||||
const configured = haloConfigs.value.pageConfig?.homeConfig?.categories
|
||||
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)
|
||||
}
|
||||
else {
|
||||
// 默认模式(老部署无配置):保持原有取数与排序
|
||||
const res = await getCategoryList({ fieldSelector: ['spec.hideFromList=false'], size: 3 })
|
||||
categoryListRaw = res.data.items
|
||||
}
|
||||
categoryList.value = categoryListRaw
|
||||
.map(item => {
|
||||
item.spec.cover = checkThumbnailUrl(item.spec.cover)
|
||||
return {
|
||||
@@ -38,7 +50,14 @@
|
||||
postCount: item.postCount ?? 0
|
||||
}
|
||||
})
|
||||
.sort((a, b) => (b.postCount || 0) - (a.postCount || 0))
|
||||
.sort((a, b) => {
|
||||
if (configured && configured.length) {
|
||||
return 0
|
||||
}
|
||||
return (b.postCount || 0) - (a.postCount || 0)
|
||||
})
|
||||
|
||||
await sleep(600)
|
||||
loading.value = 'success'
|
||||
}
|
||||
catch (err) {
|
||||
@@ -54,8 +73,6 @@
|
||||
|
||||
|
||||
function handleToCategoryBy(category : ICategory) {
|
||||
if (calcAuditModeEnabled.value)
|
||||
return
|
||||
uni.navigateTo({
|
||||
url: `/pages-blog/category-articles/category-articles?name=${category.metadata.name}&title=${category.spec.displayName}`,
|
||||
})
|
||||
@@ -67,36 +84,37 @@
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view v-if="calcIsShowCategory" class="mb-6">
|
||||
<view v-if="isEnableCategoryModule" class="mb-6">
|
||||
<uh-section-title class="mb-4 px-3 box-border">
|
||||
精选分类
|
||||
<template #right>
|
||||
<view class="flex items-center justify-center rounded-md bg-white p-1.5 text-gray-400" @click="handleToCategoryPage">
|
||||
<wd-icon name="arrow-right" size="12px" />
|
||||
<view class="box-border flex items-center justify-center rounded-md bg-white p-1.5 text-gray-400"
|
||||
@click="handleToCategoryPage">
|
||||
<wd-icon name="arrow-right" size="24rpx" />
|
||||
</view>
|
||||
</template>
|
||||
</uh-section-title>
|
||||
|
||||
<view class="w-full grid grid-cols-2 grid-rows-auto h-42 box-border px-3 gap-2">
|
||||
<view v-if="categoryList.length === 0"
|
||||
class="cate-empty text-grey w-full flex items-center justify-center">
|
||||
还没有任何分类~
|
||||
|
||||
<view v-if="loading!=='success'" class="box-border px-3">
|
||||
<view class="uh-global-card-glass shadow-none rounded-xl">
|
||||
<uh-data-loading :loading-status="loading" min-height="28vh" size="small" :use-refresh-button="true"
|
||||
@refresh="handleGetCategoryList()" />
|
||||
</view>
|
||||
<block v-else>
|
||||
<view v-for="(category,index) in categoryList" :key="category.metadata.name"
|
||||
class="uh-global-card-glass relative w-full h-full overflow-hidden rounded-xl text-center text-white"
|
||||
:class="{'grid-row-span-2':index===0 }" @click="handleToCategoryBy(category)">
|
||||
<image :src="category.spec.cover" class="w-full h-full" mode="aspectFill" lazy-load />
|
||||
<view
|
||||
class="absolute bottom-0 left-0 h-[140rpx] w-full bg-gradient-to-b from-black/0 to-black/30" />
|
||||
<view class="absolute left-2 bottom-2 flex z-2 flex-col text-left">
|
||||
<text class="text-sm font-bold">
|
||||
{{ category.spec.displayName }}
|
||||
</text>
|
||||
<text class="mt-1 text-xs text-gray-200">共 {{ category.postCount ?? 0 }} 篇</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view v-else class="w-full grid grid-cols-2 grid-rows-auto h-42 box-border px-3 gap-2">
|
||||
<view v-for="(category,index) in categoryList" :key="category.metadata.name"
|
||||
class="uh-global-card-glass relative w-full h-full overflow-hidden rounded-xl text-center text-white"
|
||||
:class="{'grid-row-span-2':index===0 }" @click="handleToCategoryBy(category)">
|
||||
<image :src="category.spec.cover" class="w-full h-full" mode="aspectFill" lazy-load />
|
||||
<view class="absolute bottom-0 left-0 h-[140rpx] w-full bg-gradient-to-b from-black/0 to-black/30" />
|
||||
<view class="absolute left-2 bottom-2 flex z-2 flex-col text-left">
|
||||
<text class="text-sm font-bold">
|
||||
{{ category.spec.displayName }}
|
||||
</text>
|
||||
<text class="mt-1 text-xs text-gray-200">共 {{ category.postCount ?? 0 }} 篇</text>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
Reference in New Issue
Block a user