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. 为图库页面添加图片标题展示与阴影优化
5. 关闭相册接口缓存,确保数据实时性
6. 重构相册查看组件,改为内部自动请求数据并优化布局
7. 优化投票页面样式与配色
8. 重构搜索页面代码结构与细节样式
9. 优化恋爱相册页面布局与交互体验
This commit is contained in:
小莫唐尼
2026-09-08 23:10:29 +08:00
parent 201354dd14
commit 1ca79b3ad5
12 changed files with 532 additions and 572 deletions
+240 -234
View File
@@ -1,264 +1,270 @@
<script lang="ts" setup>
import { computed, ref } from 'vue'
import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app'
import dayjs from 'dayjs'
import { getLoveAlbumByName, getLoveAlbums } from '@/api/uni-halo'
import { useAppConfigStore } from '@/store/appConfig'
import { checkImageUrl } from '@/utils/url'
import { getCache, setCache } from '@/utils/storage'
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
import type { ILoveAlbum, ILovePhoto } from '@/api/types/uni-halo'
import { computed, ref } from 'vue'
import { onLoad, onPullDownRefresh } from '@dcloudio/uni-app'
import dayjs from 'dayjs'
import { getLoveAlbumByName, getLoveAlbums } from '@/api/uni-halo'
import { useAppConfigStore } from '@/store/appConfig'
import { checkImageUrl } from '@/utils/url'
import { getCache, setCache } from '@/utils/storage'
import { DataLoadingStatusEnum, useDataLoadingStatus } from '@/hooks/useDataLoadingStatus'
import type { ILoveAlbum, ILovePhoto } from '@/api/types/uni-halo'
definePage({
style: {
navigationBarTitleText: '恋爱相册',
navigationStyle: 'custom',
enablePullDownRefresh: true,
},
})
definePage({
style: {
navigationBarTitleText: '恋爱相册',
navigationStyle: 'custom',
enablePullDownRefresh: true,
},
})
const appConfigStore = useAppConfigStore()
const loveConfig = computed(() => appConfigStore.configs.loveConfig)
const appConfigStore = useAppConfigStore()
const loveConfig = computed(() => appConfigStore.configs.loveConfig)
/** 已解锁相册本地缓存 key */
const UNLOCKED_ALBUMS_CACHE_KEY = 'unlocked_albums'
/** 解锁 token 有效期(后端默认 30 分钟) */
const ALBUM_TOKEN_TTL_SECONDS = 30 * 60
/** 已解锁相册本地缓存 key */
const UNLOCKED_ALBUMS_CACHE_KEY = 'unlocked_albums'
/** 解锁 token 有效期(后端默认 30 分钟) */
const ALBUM_TOKEN_TTL_SECONDS = 30 * 60
/* ---------------- 展示层类型 ---------------- */
/** 相册展示卡片(script 预处理后的干净展示数据) */
interface ILoveAlbumCard {
/** 相册 key(metadata.name,用于解锁/详情请求) */
name : string
displayName : string
locked : boolean
photoCount : number
/** 封面图(已预处理 URL) */
image : string
/** 创建时间(格式化展示) */
takeTime : string
/** 相册照片(解锁后填充) */
photos : ILovePhoto[]
}
/* ---------------- 展示层类型 ---------------- */
/** 相册展示卡片(script 预处理后的干净展示数据) */
interface ILoveAlbumCard {
/** 相册 key(metadata.name,用于解锁/详情请求) */
name: string
displayName: string
locked: boolean
photoCount: number
/** 封面图(已预处理 URL) */
image: string
/** 创建时间(格式化展示) */
takeTime: string
/** 相册照片(解锁后填充) */
photos: ILovePhoto[]
}
/** 相册卡片映射:字段取值 + 封面/时间预处理(模板不感知原始接口结构) */
function mapAlbumCard(item : ILoveAlbum) : ILoveAlbumCard {
const creationTimestamp = item.metadata?.creationTimestamp
return {
name: item.name || item.metadata?.name || '',
displayName: item.displayName || item.title || '',
locked: !!item.locked,
photoCount: Number(item.photoCount) || 0,
image: checkImageUrl(item.cover || ''),
takeTime: creationTimestamp ? dayjs(creationTimestamp).format('DD/MM/YYYY') : '',
photos: item.photos || [],
}
}
/** 相册卡片映射:字段取值 + 封面/时间预处理(模板不感知原始接口结构) */
function mapAlbumCard(item: ILoveAlbum): ILoveAlbumCard {
const creationTimestamp = item.metadata?.creationTimestamp
return {
name: item.name || item.metadata?.name || '',
displayName: item.displayName || item.title || '',
locked: !!item.locked,
photoCount: Number(item.photoCount) || 0,
image: checkImageUrl(item.cover || ''),
takeTime: creationTimestamp ? dayjs(creationTimestamp).format('DD/MM/YYYY') : '',
photos: item.photos || [],
}
}
/* ---------------- 状态 ---------------- */
const { loadingStatus, updateLoadingStatus } = useDataLoadingStatus()
const dataList = ref<ILoveAlbumCard[]>([])
const unlockedAlbums = ref<Record<string, string>>({})
/* ---------------- 状态 ---------------- */
const { loadingStatus, updateLoadingStatus } = useDataLoadingStatus()
const dataList = ref<ILoveAlbumCard[]>([])
const unlockedAlbums = ref<Record<string, string>>({})
/** 密码解锁弹窗 */
const showUnlockModal = ref(false)
const currentUnlockAlbum = ref<ILoveAlbumCard | null>(null)
/** 密码解锁弹窗 */
const showUnlockModal = ref(false)
const currentUnlockAlbum = ref<ILoveAlbumCard | null>(null)
/** 图片查看弹窗 */
const showPhotoViewer = ref(false)
const currentViewerAlbum = ref<ILoveAlbumCard | null>(null)
const viewerLoading = ref(false)
/** 图片查看弹窗 */
const showPhotoViewer = ref(false)
const currentViewerAlbum = ref<ILoveAlbumCard | null>(null)
const unlockAlbumName = computed(() => currentUnlockAlbum.value?.displayName || '')
const unlockAlbumKey = computed(() => currentUnlockAlbum.value?.name || '')
const viewerAlbumName = computed(() => currentViewerAlbum.value?.displayName || '')
const viewerPhotos = computed(() => currentViewerAlbum.value?.photos || [])
const unlockAlbumName = computed(() => currentUnlockAlbum.value?.displayName || '')
const unlockAlbumKey = computed(() => currentUnlockAlbum.value?.name || '')
const viewerAlbumName = computed(() => currentViewerAlbum.value?.displayName || '')
const viewerAlbumKey = computed(() => currentViewerAlbum.value?.name || '')
const viewerAlbumToken = computed(() => currentViewerAlbum.value
? (unlockedAlbums.value[currentViewerAlbum.value.name] || '')
: '')
/* ---------------- 缓存 ---------------- */
function handleRestoreUnlockedAlbums() {
try {
const saved = getCache<Record<string, string>>(UNLOCKED_ALBUMS_CACHE_KEY)
if (saved) {
unlockedAlbums.value = saved
}
}
catch (e) {
console.error('恢复解锁状态失败', e)
}
}
/* ---------------- 缓存 ---------------- */
function handleRestoreUnlockedAlbums() {
try {
const saved = getCache<Record<string, string>>(UNLOCKED_ALBUMS_CACHE_KEY)
if (saved) {
unlockedAlbums.value = saved
}
}
catch (e) {
console.error('恢复解锁状态失败', e)
}
}
function handleSaveUnlockedAlbums() {
try {
setCache(UNLOCKED_ALBUMS_CACHE_KEY, unlockedAlbums.value, ALBUM_TOKEN_TTL_SECONDS)
}
catch (e) {
console.error('保存解锁状态失败', e)
}
}
function handleSaveUnlockedAlbums() {
try {
setCache(UNLOCKED_ALBUMS_CACHE_KEY, unlockedAlbums.value, ALBUM_TOKEN_TTL_SECONDS)
}
catch (e) {
console.error('保存解锁状态失败', e)
}
}
/* ---------------- 数据加载 ---------------- */
async function handleGetData() {
updateLoadingStatus(DataLoadingStatusEnum.Loading)
try {
const res = await getLoveAlbums({})
const items = res.data?.items || []
dataList.value = items.map(mapAlbumCard)
updateLoadingStatus(dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success)
if (dataList.value.length > 0)
handleLoadUnlockedAlbumPhotos()
}
catch (e) {
console.error('获取相册失败', e)
updateLoadingStatus(DataLoadingStatusEnum.Error)
}
finally {
setTimeout(() => {
uni.stopPullDownRefresh()
}, 200)
}
}
/* ---------------- 数据加载 ---------------- */
async function handleGetData() {
updateLoadingStatus(DataLoadingStatusEnum.Loading)
try {
const res = await getLoveAlbums({})
const items = res.data?.items || []
dataList.value = items.map(mapAlbumCard)
updateLoadingStatus(dataList.value.length === 0 ? DataLoadingStatusEnum.Empty : DataLoadingStatusEnum.Success)
if (dataList.value.length > 0)
handleLoadUnlockedAlbumPhotos()
}
catch (e) {
console.error('获取相册失败', e)
updateLoadingStatus(DataLoadingStatusEnum.Error)
}
finally {
setTimeout(() => {
uni.stopPullDownRefresh()
}, 200)
}
}
/** 加载已解锁相册的照片 */
async function handleLoadUnlockedAlbumPhotos() {
for (const item of dataList.value) {
const token = unlockedAlbums.value[item.name]
if (item.locked && token) {
try {
const detail = await getLoveAlbumByName(item.name, { token })
if (detail.locked) {
delete unlockedAlbums.value[item.name]
handleSaveUnlockedAlbums()
}
else if (detail.photos) {
item.photos = detail.photos
item.locked = false
}
}
catch (e) {
console.error('加载相册照片失败', e)
}
}
}
}
/** 加载已解锁相册的照片 */
async function handleLoadUnlockedAlbumPhotos() {
for (const item of dataList.value) {
const token = unlockedAlbums.value[item.name]
if (item.locked && token) {
try {
const detail = await getLoveAlbumByName(item.name, { token })
if (detail.locked) {
delete unlockedAlbums.value[item.name]
handleSaveUnlockedAlbums()
}
else if (detail.photos) {
item.photos = detail.photos
item.locked = false
}
}
catch (e) {
console.error('加载相册照片失败', e)
}
}
}
}
/* ---------------- 交互 ---------------- */
function handleOnAlbumClick(item : ILoveAlbumCard) {
if (item.locked && !unlockedAlbums.value[item.name]) {
currentUnlockAlbum.value = item
showUnlockModal.value = true
return
}
handleOpenPhotoViewer(item)
}
/* ---------------- 交互 ---------------- */
function handleOnAlbumClick(item: ILoveAlbumCard) {
if (item.locked && !unlockedAlbums.value[item.name]) {
currentUnlockAlbum.value = item
showUnlockModal.value = true
return
}
handleOpenPhotoViewer(item)
}
async function handleOpenPhotoViewer(item : ILoveAlbumCard) {
currentViewerAlbum.value = item
showPhotoViewer.value = true
if (item.photos.length > 0) { return }
viewerLoading.value = true
try {
const token = unlockedAlbums.value[item.name] || ''
const detail = await getLoveAlbumByName(item.name, { token })
if (detail) {
if (detail.locked) {
delete unlockedAlbums.value[item.name]
handleSaveUnlockedAlbums()
}
else if (detail.photos) {
item.photos = detail.photos
item.locked = false
}
}
}
catch (e) {
console.error('获取相册照片失败', e)
uni.showToast({ icon: 'none', title: '照片加载失败,请稍后重试' })
}
finally {
viewerLoading.value = false
}
}
function handleOpenPhotoViewer(item: ILoveAlbumCard) {
currentViewerAlbum.value = item
showPhotoViewer.value = true
// 照片数据由 uh-album-photo-viewer 内部自请求(见组件 handleLoadPhotos)
}
function handleOnUnlockSuccess(data : { albumKey : string, token : string, photos : unknown[] }) {
unlockedAlbums.value[data.albumKey] = data.token
handleSaveUnlockedAlbums()
function handleOnUnlockSuccess(data: { albumKey: string, token: string, photos: unknown[] }) {
unlockedAlbums.value[data.albumKey] = data.token
handleSaveUnlockedAlbums()
const albumIndex = dataList.value.findIndex(a => a.name === data.albumKey)
if (albumIndex !== -1) {
dataList.value[albumIndex].photos = data.photos as ILovePhoto[]
dataList.value[albumIndex].locked = false
}
currentUnlockAlbum.value = null
if (albumIndex !== -1) {
handleOpenPhotoViewer(dataList.value[albumIndex])
}
}
const albumIndex = dataList.value.findIndex(a => a.name === data.albumKey)
if (albumIndex !== -1) {
dataList.value[albumIndex].photos = data.photos as ILovePhoto[]
dataList.value[albumIndex].locked = false
}
currentUnlockAlbum.value = null
if (albumIndex !== -1) {
handleOpenPhotoViewer(dataList.value[albumIndex])
}
}
function handleToTopPage(duration = 500) {
uni.pageScrollTo({
scrollTop: 0,
duration,
fail: (err) => {
console.error('回顶失败', err)
},
})
}
function handleToTopPage(duration = 500) {
uni.pageScrollTo({
scrollTop: 0,
duration,
fail: (err) => {
console.error('回顶失败', err)
},
})
}
/* ---------------- 生命周期 ---------------- */
onLoad(() => {
handleRestoreUnlockedAlbums()
handleGetData()
})
/* ---------------- 生命周期 ---------------- */
onLoad(() => {
handleRestoreUnlockedAlbums()
handleGetData()
})
onPullDownRefresh(() => {
handleGetData()
})
onPullDownRefresh(() => {
handleGetData()
})
</script>
<template>
<view class="app-page box-border min-h-screen w-screen flex flex-col pb-safe">
<!-- 自定义导航 -->
<uh-navbar default-title="恋爱相册" title-color="text-love" back-class="text-love" />
<view class="app-page box-border min-h-screen w-screen flex flex-col pb-safe">
<!-- 自定义导航 -->
<uh-navbar default-title="恋爱相册" title-color="text-love" back-class="text-love" />
<!-- 加载/错误/空占位(状态机) -->
<uh-data-loading v-if="loadingStatus !== DataLoadingStatusEnum.Success" :loading-status="loadingStatus"
min-height="75vh" empty-text="相册暂时还没有数据~" @refresh="handleGetData" />
<!-- 加载/错误/空占位(状态机) -->
<uh-data-loading
v-if="loadingStatus !== DataLoadingStatusEnum.Success" :loading-status="loadingStatus"
min-height="75vh" empty-text="相册暂时还没有数据~" @refresh="handleGetData"
/>
<!-- 相册列表(两列网格) -->
<view v-else class="box-border grid grid-cols-2 p-3 pt-2 gap-3">
<view v-for="(item) in dataList" :key="item.name"
class="uh-global-card-glass box-border overflow-hidden rounded-xl" @click="handleOnAlbumClick(item)">
<view class="relative h-24 w-full">
<image class="h-full w-full" :src="item.image" mode="aspectFill" lazy-load />
<view v-if="item.locked && !unlockedAlbums[item.name]"
class="absolute left-0 top-0 h-full w-full flex flex-col items-center justify-center gap-1 bg-black/45">
<wd-icon name="lock" size="52rpx" class="text-white" />
<view class="text-xs text-white"> 已加密 </view>
</view>
</view>
<view class="album-info box-border p-3">
<view
class="album-name overflow-hidden text-ellipsis whitespace-nowrap text-[30rpx] text-[#333] font-bold">
{{ item.displayName }}
</view>
<view class="album-count mt-1 text-xs text-gray-500">
{{ item.photoCount }} 张照片
</view>
</view>
</view>
</view>
<!-- 密码解锁弹窗 -->
<uh-album-unlock-popup v-if="currentUnlockAlbum" v-model="showUnlockModal" :show="showUnlockModal" :album-name="unlockAlbumName"
:album-key="unlockAlbumKey" @update:show="showUnlockModal = $event" @success="handleOnUnlockSuccess" />
<!-- 相册列表(两列网格) -->
<view v-else class="grid grid-cols-2 box-border gap-3 p-3 pt-2">
<view
v-for="(item) in dataList" :key="item.name"
class="uh-global-card-glass box-border overflow-hidden rounded-xl" @click="handleOnAlbumClick(item)"
>
<view class="relative h-36 w-full">
<image class="h-full w-full" :src="item.image" mode="aspectFill" lazy-load />
<view
v-if="item.locked && !unlockedAlbums[item.name]"
class="absolute right-0 top-0 px-2 py-1 rounded-lb-md flex items-center justify-center gap-1 bg-black/30"
>
<wd-icon name="lock" size="30rpx" class="text-white" />
<view class="text-xs text-white">
已加密
</view>
</view>
</view>
<view class="absolute left-0 right-0 bottom-0 box-border p-3 pt-6 bg-gradient-to-b from-white/0 to-white/60">
<view
class="truncate text-sm text-love font-bold"
>
{{ item.displayName }}
</view>
<view class="album-count mt-1 text-xs text-white">
{{ item.photoCount }} 张照片
</view>
</view>
</view>
</view>
<!-- 密码解锁弹窗 -->
<uh-album-unlock-popup
v-if="currentUnlockAlbum" v-model="showUnlockModal" :show="showUnlockModal" :album-name="unlockAlbumName"
:album-key="unlockAlbumKey" @update:show="showUnlockModal = $event" @success="handleOnUnlockSuccess"
/>
<!-- 相册图片查看弹窗 -->
<uh-album-photo-viewer v-if="currentViewerAlbum" v-model="showPhotoViewer" :show="showPhotoViewer" :album-name="viewerAlbumName"
:photos="viewerPhotos" :loading="viewerLoading" @update:show="showPhotoViewer = $event" />
</view>
<!-- 相册图片查看弹窗(数据在组件内部自请求) -->
<uh-album-photo-viewer
v-if="currentViewerAlbum" v-model="showPhotoViewer" :show="showPhotoViewer"
:album-name="viewerAlbumName" :album-key="viewerAlbumKey" :token="viewerAlbumToken"
@update:show="showPhotoViewer = $event"
/>
</view>
</template>
<style scoped>
.app-page {
background: linear-gradient(-135deg, rgb(247 149 51 / 10%), rgb(243 112 85 / 10%) 15%, rgb(239 78 123 / 10%) 30%, rgb(161 102 171 / 10%) 44%, rgb(80 115 184 / 10%) 58%, rgb(16 152 173 / 10%) 72%, rgb(7 179 155 / 10%) 86%, rgb(109 186 130 / 10%));
}
</style>
.app-page {
background: linear-gradient(
-135deg,
rgb(247 149 51 / 10%),
rgb(243 112 85 / 10%) 15%,
rgb(239 78 123 / 10%) 30%,
rgb(161 102 171 / 10%) 44%,
rgb(80 115 184 / 10%) 58%,
rgb(16 152 173 / 10%) 72%,
rgb(7 179 155 / 10%) 86%,
rgb(109 186 130 / 10%)
);
}
</style>
+1 -1
View File
@@ -350,7 +350,7 @@
</view>
<uh-data-loading v-if="showList.length === 0" :loading-status="DataLoadingStatusEnum.Empty"
min-height="42vh" empty-text="该筛选条件下暂无清单~" :use-loading-button="false" />
min-height="42vh" empty-text="该筛选条件下暂无清单~" :use-refresh-button="false" />
</view>
<!-- 筛选弹层(状态/排序;排序附方向选择) -->