mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-11-13 22:11:42 +08:00
feat: 实现全站布局偏好系统,支持多页面独立配置
本次提交完成了完整的偏好设置体系重构: 1. 新增preferences.md文档说明布局偏好设计与映射规则 2. 重构布局配置结构,按页面分组管理列表布局与卡片样式 3. 实现后端preferences字段到本地配置的自动映射转换 4. 完成首页、文章列表、归档页的布局动态切换逻辑 5. 重构投票组件样式绑定,改用unocss类名实现样式分离 6. 新增偏好设置页面,支持按页面配置布局参数 7. 兼容旧版布局参数的自动归一化转换 8. 补充完整的单元测试用例覆盖新旧数据迁移场景
This commit is contained in:
@@ -22,14 +22,6 @@
|
||||
pinned: string
|
||||
}
|
||||
|
||||
/** 旧版全局 cardType → 新版 layout;未知值(如 only_text)由 effectiveLayout 兜底 image_top */
|
||||
const CARD_TYPE_TO_LAYOUT: Record<string, CardLayout> = {
|
||||
lr_image_text: 'image_left',
|
||||
lr_text_image: 'image_right',
|
||||
tb_image_text: 'image_top',
|
||||
tb_text_image: 'image_bottom',
|
||||
}
|
||||
|
||||
/** 单一事实源:每种布局的完整形态,模板不再有任何 order / 条件分支 */
|
||||
const CARD_LAYOUTS: Record<CardLayout, CardLayoutClasses> = {
|
||||
image_top: {
|
||||
@@ -54,7 +46,7 @@
|
||||
authorGroup: 'items-center gap-x-2',
|
||||
avatar: '!h-9 !w-9 !rounded-xl',
|
||||
nickname: '!text-sm',
|
||||
infoCol: 'flex-col items-start leading-tight',
|
||||
infoCol: 'leading-tight',
|
||||
time: '',
|
||||
tagCategory: '',
|
||||
visits: '',
|
||||
@@ -106,23 +98,26 @@
|
||||
|
||||
const isGrid = computed(() => props.variant === 'grid')
|
||||
|
||||
/** 实际生效布局:显式 layout > home/archives 跟随全局 cardType > image_top;窄列场景左右布局回退上图下文 */
|
||||
/** 实际生效布局:显式 layout > 按页面读取全局 cardType(首页/文章列表/文章归档)> image_top;窄列场景左右布局回退上图下文 */
|
||||
const effectiveLayout = computed<CardLayout>(() => {
|
||||
const followGlobal = props.from === 'home' || props.from === 'archives'
|
||||
const _layout = settingStore.settings.layout
|
||||
const page = props.from === 'home' || props.from === 'articles' || props.from === 'archives'
|
||||
? props.from
|
||||
: null
|
||||
let raw = props.layout
|
||||
if (!raw) {
|
||||
raw = followGlobal
|
||||
? CARD_TYPE_TO_LAYOUT[settingStore.settings.layout.cardType] ?? 'image_top'
|
||||
raw = page
|
||||
? (_layout[page].cardType as CardLayout)
|
||||
: 'image_top'
|
||||
}
|
||||
const narrow = isGrid.value || (props.from === 'home' && settingStore.settings.layout.home === 'h_row_col2')
|
||||
const narrow = isGrid.value || (props.from === 'home' && _layout.home.listLayout === 'double')
|
||||
if (narrow && (raw === 'image_left' || raw === 'image_right')) {
|
||||
return 'image_top'
|
||||
}
|
||||
return raw
|
||||
})
|
||||
|
||||
const cardLayout = computed(() => CARD_LAYOUTS[effectiveLayout.value])
|
||||
const cardLayout = computed(() => CARD_LAYOUTS[effectiveLayout.value] ?? CARD_LAYOUTS.image_bottom)
|
||||
|
||||
/** 社交卡片形态(封面在下):左上用户信息(头像 + 昵称/日期垂直)、右上浏览数 */
|
||||
const isSocialCard = computed(() => effectiveLayout.value === 'image_bottom')
|
||||
@@ -192,8 +187,8 @@
|
||||
<image :src="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="flex" :class="cardLayout.infoCol">
|
||||
<text class="truncate" :class="cardLayout.nickname">{{ article.owner.displayName }}</text>
|
||||
<view :class="cardLayout.infoCol">
|
||||
<text class="block truncate" :class="cardLayout.nickname">{{ article.owner.displayName }}</text>
|
||||
<view class="flex items-center gap-x-2">
|
||||
<text class="text-gray-400" :class="cardLayout.time">{{ publishTimeText }}</text>
|
||||
<view class="visits flex items-center gap-x-1 text-gray-400">
|
||||
|
||||
@@ -200,8 +200,7 @@
|
||||
<text v-if="voteTypeLabel" class="rounded-md bg-primary px-2 py-0.5 text-xs text-gray-900">
|
||||
{{ voteTypeLabel }}
|
||||
</text>
|
||||
<text v-if="voteState" class="rounded-md px-2 py-0.5 text-xs"
|
||||
:style="{ color: voteState.color, backgroundColor: `${voteState.color}1a` }">
|
||||
<text v-if="voteState" class="rounded-md px-2 py-0.5 text-xs" :class="[voteState.color,voteState.bgColor]">
|
||||
{{ voteState.state }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
@@ -20,7 +20,7 @@ interface IVoteCardData {
|
||||
endDate?: string
|
||||
isVoted?: boolean
|
||||
_uh_type?: string
|
||||
_uh_state?: { state: string, color: string }
|
||||
_uh_state?: { state: string, color: string, bgColor: string }
|
||||
options?: IVoteCardOption[]
|
||||
[key: string]: unknown
|
||||
}
|
||||
@@ -59,7 +59,7 @@ function formatTime(date?: string, fmt = 'yyyy-MM-dd HH:mm'): string {
|
||||
<text
|
||||
v-if="vote.spec?._uh_state"
|
||||
class="rounded-md px-1.5 py-0.5 text-[22rpx]"
|
||||
:style="{ color: vote.spec._uh_state.color, backgroundColor: `${vote.spec._uh_state.color}1a` }"
|
||||
:class="[vote.spec._uh_state.color, vote.spec._uh_state.bgColor]"
|
||||
>
|
||||
{{ vote.spec._uh_state.state }}
|
||||
</text>
|
||||
|
||||
Reference in New Issue
Block a user