1
0
mirror of https://github.com/ialley-workshop-open/uni-halo.git synced 2026-11-13 22:11:42 +08:00

refactor: 重构页面导航与样式,清理冗余代码

1.  移除快捷导航组件多余注释与本地导航开关
2.  重构关于页样式与静态资源路径
3.  简化个人页导航逻辑,移除旧版配置判断与冗余函数
4.  统一导航项样式与属性命名,修复文案与图标颜色问题
This commit is contained in:
小莫唐尼
2026-09-11 04:05:24 +08:00
parent b85c69b3ec
commit 8bb76fcd08
3 changed files with 36 additions and 245 deletions
@@ -8,11 +8,9 @@
const calcAuditModeEnabled = computed(() => appConfigStore.auditModeEnabled)
const calcIsShowQuickNavigationEnabled = computed(() => haloConfigs.value.pageConfig?.homeConfig?.useQuickNavigation)
/** 快捷导航项(字段命名与插件端 quickNavigation 一致:key/title/subTitle/color/bgColor/iconPrefix/icon/path/visible,无 borderColor) */
interface QuickNavItem {
key : string
title ?: string
/** 副标题(对标 about 页 rightText,如「全部文章」;2026-09-10 插件端新增可空字段) */
subTitle ?: string
color ?: string
bgColor ?: string
@@ -22,9 +20,7 @@
visible ?: boolean
}
// 是否使用本地的快捷导航数据(本地的可以任意修改图标、路径,插件端的无法修改图标)
const useLocalNav = false
/** 内置默认项(未配置时回退;字段命名与插件端一致,可作配置缺失字段的兜底;颜色统一 hex8) */
const DEFAULT_NAV_LIST : QuickNavItem[] = [
{
key: 'archives',
@@ -79,12 +75,10 @@
},
]
/** 快捷导航列表:优先读插件端配置(零映射,visible 过滤);未配置/为空回退内置默认(保留原显隐推导) */
const navList = computed(() => {
const configured = haloConfigs.value.pageConfig?.homeConfig?.quickNavigation
let list : QuickNavItem[]
if (!useLocalNav && configured && configured.length) {
// 配置模式:以配置项为准,缺失字段(icon/iconPrefix/color/path 等)按 key 从默认项兜底
list = configured.map(item => {
const fallback = DEFAULT_NAV_LIST.find(d => d.key === item.key) || DEFAULT_NAV_LIST[0]
return { ...fallback, ...item }
@@ -120,14 +114,11 @@
<wd-icon :class-prefix="item.iconPrefix" :name="item.icon" size="64rpx" />
</view>
<view class="flex flex-col items-center gap-0.5">
<text class="max-w-16 truncate text-xs text-gray-900">
<text class="max-w-16 truncate text-xs text-gray-900" :style="{color:item.color}">
{{ item.title }}
</text>
<text v-if="item.subTitle" class="max-w-16 truncate text-[10rpx] text-gray-400">
{{ item.subTitle }}
</text>
</view>
</view>
</view>
</view>
</template>
</template>
+19 -23
View File
@@ -11,12 +11,11 @@
})
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')
name: 'UniHalo',
logo: checkUrl('/plugins/plugin-uni-halo/assets/static/logo.png')
}
})
@@ -49,18 +48,18 @@
<!-- 自定义导航 -->
<uh-navbar default-title="关于项目" title-color="text-gray-900" />
<view class="fixed -right-8 top-8 h-28 w-28 rounded-full bg-[rgba(185,228,36,0.32)] blur-xl" />
<view class="fixed -left-10 top-36 h-24 w-24 rounded-full bg-[rgba(215,249,76,0.45)] blur-xl" />
<view class="relative">
<view class="absolute h-[220rpx] w-[220rpx] rounded-full bg-[rgba(185,228,36,0.32)] -right-8 -top-8" />
<view
class="absolute top-[150rpx] h-[180rpx] w-[180rpx] rounded-full bg-[rgba(215,249,76,0.45)] -left-10" />
<view class="uh-global-card-glass relative flex flex-col items-center rounded-2xl px-6 pb-7 pt-10">
<image class="h-[140rpx] w-[140rpx] rounded-3xl shadow-lg" :src="appInfo.logo" mode="aspectFill" />
<view class="mt-4 text-xl text-gray-900 font-bold">
<image class="uh-global-card-glass uh-shadow-xs border h-18 w-18 rounded-2xl" :src="appInfo.logo" mode="aspectFill" />
<view class="mt-4 text-xl text- font-bold">
{{appInfo.name}}
</view>
<view class="mt-3 flex items-center gap-2">
<text class="rounded-full bg-secondary px-3 py-1 text-[20rpx] text-[#4d7c0f]">AGPL-3.0 开源协议</text>
<text class="rounded-full bg-[#f6f3ee] px-3 py-1 text-[20rpx] text-gray-500">UniApp × Halo</text>
<text class="rounded-full bg-secondary px-3 py-1 text-[20rpx] text-gray-900">AGPL-3.0 开源协议</text>
<text class="rounded-full bg-gray-100 px-3 py-1 text-[20rpx] text-gray-900">UniApp × Halo</text>
</view>
<view class="mt-4 text-center text-xs text-gray-500 leading-relaxed">
基于 uni-app 打造的 Halo 博客跨端客户端
@@ -68,26 +67,23 @@
</view>
</view>
<!-- 相关链接 -->
<uh-section-title class="mb-3 mt-6">
相关链接
</uh-section-title>
<view class="link-list uh-global-card-glass overflow-hidden rounded-2xl">
<view v-for="(link, index) in links" :key="link.title" class="link-item flex items-center gap-3 px-4 py-4"
:class="index < links.length - 1 ? 'border-b border-black/5' : ''"
<uh-section-title class="mb-3 mt-6"> 相关链接 </uh-section-title>
<view class="box-border uh-global-card-glass flex flex-col gap-y-6 rounded-2xl py-4">
<view v-for="(link) in links" :key="link.title" class="flex items-center gap-3 px-4"
@click="copyText(link.copy, link.tip)">
<view
class="tile h-[76rpx] w-[76rpx] flex shrink-0 items-center justify-center rounded-xl border border-black/5"
class="uh-global-card-glass uh-shadow-xs border h-10 w-10 flex shrink-0 items-center justify-center rounded-xl"
:style="{ backgroundColor: `${link.tileColor}1A` }">
<text class="text-[30rpx] font-bold" :style="{ color: link.tileColor }">{{ link.tileLetter }}</text>
<text class="text-sm font-bold" :style="{ color: link.tileColor }">{{ link.tileLetter }}</text>
</view>
<view class="min-w-0 flex flex-1 flex-col">
<text class="text-[28rpx] text-gray-900 font-bold">{{ link.title }}</text>
<view class="mt-1 overflow-hidden text-ellipsis whitespace-nowrap text-[24rpx] text-gray-400">
<text class="text-sm text-gray-900 font-bold">{{ link.title }}</text>
<view class="truncate text-xs text-gray-400">
{{ link.value }}
</view>
</view>
<wd-icon name="copy" size="28rpx" color="#c8c2b4" class="shrink-0" />
<wd-icon name="copy" size="28rpx" class="shrink-0 text-gray-500" />
</view>
</view>
+15 -211
View File
@@ -62,32 +62,12 @@
const calcWaveUrl = computed(() => checkImageUrl(pageConfig.value?.waveImageUrl))
/** 免责声明(2026-09-10 起插件端从 basicConfig 迁入 pageConfig.disclaimers,无 enabled 开关,按内容判定入口显隐) */
const pageDisclaimers = computed(() => (haloConfigs.value.pageConfig as { disclaimers ?: { content ?: string } } | undefined)?.disclaimers)
/** 页脚版权(2026-09-10 起插件端从 basicConfig.copyrightConfig 迁入 pageConfig.aboutConfig.copyrightConfig) */
const copyrightConfig = computed(() => pageConfig.value?.copyrightConfig)
/** 恋爱入口:总开关 loveEnabled 2026-09-10 下线,改按模块入口开关判定(任一开启即展示) */
const loveEnabled = computed(() => {
const love = haloConfigs.value.loveConfig as
| { ourStory ?: { enabled ?: boolean }, lovePhoto ?: { enabled ?: boolean }, loveDaily ?: { enabled ?: boolean } }
| undefined
return !!(love?.ourStory?.enabled || love?.lovePhoto?.enabled || love?.loveDaily?.enabled)
})
/** 社交信息入口:2026-09-10 起去 enabled 开关,改按社交项列表判定(存在可见且有内容的社交项即展示) */
const socialEnabled = computed(() => {
const social = haloConfigs.value.authorConfig?.social as
| { items ?: Array<{ visible ?: boolean, content ?: string }> }
| undefined
return !!(social?.items?.some(item => item.visible !== false && !!item.content))
})
/* ---------------- 状态 ---------------- */
const statisticsShowMore = ref(false)
const statistics = ref<IBlogStats>({ post: 0, comment: 0, category: 0, visit: 0, upvote: 0 })
/** 主行统计(常驻展示) */
/** 主行统计*/
const allStats = computed(() => [
{ key: 'post', label: '内容', value: statistics.value.post },
{ key: 'visit', label: '访客', value: statistics.value.visit },
@@ -101,21 +81,15 @@
title : string
iconPrefix ?: string
icon : string
/** 图标块背景色(与首页快捷导航同色板,同一功能同色) */
bgColor : string
/** 图标颜色(插件端 myPageConfig 条目 color;本地默认缺省由 toSolidColor(bgColor) 派生) */
color ?: string
rightText : string
subTitle ?: string
path : string | null
isAdmin ?: boolean
openType ?: string
show : boolean
/** 分组:blog=博客功能 more=更多信息 */
group : 'blog' | 'more'
}
/** 插件端 myPageConfig 条目(pageConfig.myPageConfig.commonFeatures/otherFeatures;
* 字段命名与插件端一致:key/title/subTitle/color/bgColor/iconPrefix/icon/path/visible) */
interface IMyPageEntry {
key ?: string
title ?: string
@@ -128,15 +102,11 @@
visible ?: boolean
}
// 是否使用本地的功能入口数据(true=忽略插件端 myPageConfig,用内置默认;便于二次开发本地定制)
const useLocalNav = false
/** 插件端 myPageConfig(additive:未配置/为空返回 null,回退本地内置默认) */
const configuredFeatures = computed(() => {
const mp = haloConfigs.value.pageConfig?.myPageConfig as
| { commonFeatures ?: IMyPageEntry[], otherFeatures ?: IMyPageEntry[] }
| undefined
if (useLocalNav || !mp || (!mp.commonFeatures?.length && !mp.otherFeatures?.length)) {
if (!mp || (!mp.commonFeatures?.length && !mp.otherFeatures?.length)) {
return null
}
return mp
@@ -157,23 +127,6 @@
})
/* ---------------- 功能导航 ---------------- */
/** 图标块浅色背景:品牌深色 hex8 降透明度 → 轻量底色(#rrggbbaa 后两位替换为 26,≈0.15 透明度) */
function toLightBg(hex8 : string) {
return (hex8 || '').replace(/(#[0-9a-fA-F]{6})[0-9a-fA-F]{2}$/, (_m, base) => `${base}26`)
}
/** 图标颜色:品牌深色实色(#rrggbbaa 后两位替换为 FF,不透明) */
function toSolidColor(hex8 : string) {
return (hex8 || '').replace(/(#[0-9a-fA-F]{6})[0-9a-fA-F]{2}$/, (_m, base) => `${base}FF`)
}
/** 收藏导航项右侧文案跟随收藏总数(收藏页返回/切回时刷新) */
function syncFavoritesNavText() {
const nav = navList.value.find(n => n.key === 'favorites')
if (nav) {
nav.rightText = `共 ${favoritesStore.counts.total} 条收藏`
}
}
async function handleGetNavList() {
// 配置模式:插件端 myPageConfig 两组(常用功能→blog、其他功能→more),
@@ -181,8 +134,7 @@
const mp = configuredFeatures.value
if (mp) {
const mapEntry = (e : IMyPageEntry, group : 'blog' | 'more') : INavItem | null => {
if (!e.key)
return null
if (!e.key) { return null }
return {
key: e.key,
title: e.title || '',
@@ -190,17 +142,16 @@
icon: e.icon || '',
bgColor: e.bgColor || '#969696F2',
color: e.color,
rightText: e.subTitle || '',
subTitle: e.subTitle || '',
path: e.path || null,
show: e.visible !== false,
group,
}
}
navList.value = [
...(mp.commonFeatures || []).map(e => mapEntry(e, 'blog')).filter((n): n is INavItem => n !== null),
...(mp.otherFeatures || []).map(e => mapEntry(e, 'more')).filter((n): n is INavItem => n !== null),
...(mp.commonFeatures || []).map(e => mapEntry(e, 'blog')).filter((n) : n is INavItem => n !== null),
...(mp.otherFeatures || []).map(e => mapEntry(e, 'more')).filter((n) : n is INavItem => n !== null),
]
syncFavoritesNavText()
return
}
@@ -209,128 +160,6 @@
checkVotePluginAvailable(),
checkLinksPluginAvailable(),
])
navList.value = [
{
key: 'favorites',
title: '我的收藏',
iconPrefix: 'uhemoji2-icon',
icon: '-smiling',
bgColor: '#FFB300F2',
rightText: '',
path: '/pages-blog/favorites/favorites',
show: true,
group: 'blog',
},
{
key: 'data-visual',
title: '数据看板',
iconPrefix: 'uhemoji2-icon',
icon: '-surprised',
bgColor: '#663CC9F2',
rightText: '站点数据可视化',
path: '/pages-blog/data-visual/data-visual',
show: dataVisualAvailable,
group: 'blog',
},
{
key: 'archives',
title: calcAuditModeEnabled.value ? '内容归档' : '文章归档',
iconPrefix: 'uhemoji2-icon',
icon: '-mask',
bgColor: '#03A9F4F2',
rightText: calcAuditModeEnabled.value ? '全部已归档内容' : '全部已归档文章',
path: '/pages-blog/archives/archives',
show: true,
group: 'blog',
},
{
key: 'love',
title: '恋爱日记',
iconPrefix: 'uhemoji2-icon',
icon: '-in-love',
bgColor: '#FF4C67F2',
rightText: '博主的恋爱日记',
path: '/pages-blog/love/love',
show: loveEnabled.value,
// show: true,
group: 'blog',
},
{
key: 'vote',
title: '投票中心',
iconPrefix: 'uhemoji2-icon',
icon: '-confused',
bgColor: '#00BCD4F2',
rightText: '查看和进行投票',
path: '/pages-blog/votes/votes',
show: !calcAuditModeEnabled.value && voteAvailable,
// show: true,
group: 'blog',
},
{
key: 'friend-links',
title: '友情链接',
iconPrefix: 'uhemoji2-icon',
icon: '-cool',
bgColor: '#009688F2',
rightText: '看看博主朋友们吧',
path: '/pages-blog/friend-links/friend-links',
show: linksAvailable,
// show: true,
group: 'blog',
},
{
key: 'disclaimers',
title: '免责声明',
iconPrefix: 'uhemoji2-icon',
icon: '-smirking',
bgColor: '#795548F2',
rightText: '博客内容免责声明',
path: '/pages-blog/disclaimers/disclaimers',
// 2026-09-10 起无 enabled 开关,按内容非空判定入口显隐
show: !!pageDisclaimers.value?.content,
// show: true,
group: 'more',
},
{
key: 'contact-blogger',
title: '联系博主',
iconPrefix: 'uhemoji2-icon',
icon: '-wink',
bgColor: '#FF9800F2',
rightText: '博主常用联系方式',
path: '/pages-blog/contact/contact',
show: socialEnabled.value,
// show: true,
group: 'more',
},
{
key: 'about',
title: '关于项目',
iconPrefix: 'uhemoji2-icon',
icon: '-happy-',
bgColor: '#607D8BF2',
rightText: '小莫唐尼开源项目',
path: '/pages-blog/about/about',
// showAboutSystem 2026-09-10 下线(入口由插件端功能入口 myPageConfig 统一管理),默认展示
show: true,
// show: true,
group: 'more',
},
{
key: 'setting',
title: '偏好设置',
iconPrefix: 'uhemoji2-icon',
icon: '-tired',
bgColor: '#7986CBF2',
rightText: '首页布局、卡片样式等本地偏好',
path: '/pages-blog/setting/setting',
show: true,
group: 'more',
},
]
syncFavoritesNavText()
}
/* ---------------- 数据加载 ---------------- */
@@ -354,24 +183,6 @@
if (!path)
return
// 拦截后台管理页面(需超管登录)
if (isAdmin && !checkHasAdminLogin()) {
uni.showModal({
title: '提示',
content: '未登录超管账号或登录状态已过期,是否立即登录?',
showCancel: true,
cancelText: '否',
cancelColor: '#999999',
confirmText: '是',
confirmColor: '#03a9f4',
success: (res) => {
if (res.confirm) {
uni.navigateTo({ url: '/pages/auth/login' })
}
},
})
return
}
uni.navigateTo({ url: path })
}
@@ -383,11 +194,6 @@
handleGetData()
// 从收藏页返回/切回时刷新收藏数文案
onShow(() => {
syncFavoritesNavText()
})
onPullDownRefresh(() => {
handleGetData()
})
@@ -417,10 +223,8 @@
<!-- 站点统计 -->
<view class="uh-global-card-glass uh-shadow-xs relative z-100 mx-4 flex border rounded-2xl -mt-12">
<view v-for="item in allStats" :key="item.key" class="flex-1 py-4 text-center">
<wd-count-to
:key="`${item.key}-${item.value}`" :start-val="0" :end-val="item.value"
:duration="900" separator="" color="#111827" custom-class="text-lg font-bold"
/>
<wd-count-to :key="`${item.key}-${item.value}`" :start-val="0" :end-val="item.value" :duration="900"
separator="" color="#111827" custom-class="text-lg font-bold" />
<view class="mt-1 text-xs text-gray-500">
{{ item.label }}
</view>
@@ -440,15 +244,15 @@
<view class="nav-left flex items-center gap-3 py-3">
<view
class="uh-global-card-glass border uh-shadow-xs h-8 w-8 flex items-center justify-center rounded-xl"
:style="{ backgroundColor: toLightBg(nav.bgColor) }">
<wd-icon :class-prefix="nav.iconPrefix" :name="nav.icon" size="36rpx"
:color="nav.color || toSolidColor(nav.bgColor)" />
:style="{ backgroundColor: nav.bgColor }">
<wd-icon :class-prefix="nav.iconPrefix" :name="nav.icon" size="36rpx" />
</view>
<text class="nav-title text-sm text-gray-900 font-bold">{{ nav.title }}</text>
<text class="nav-title text-sm text-gray-900 font-bold"
:style="{color:nav.color}">{{ nav.title }}</text>
</view>
<view class="nav-right flex items-center gap-2">
<text class="nav-right-text text-xs text-gray-400">{{ nav.rightText }}</text>
<wd-icon name="arrow-right" size="12px" color="#c8c2b4" />
<text class="nav-right-text text-xs text-gray-400">{{ nav.subTitle }}</text>
<wd-icon name="arrow-right" size="24rpx" class="text-gray-400" />
</view>
</view>
</view>