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

refactor: 统一加载状态组件,重构投票相关类型与逻辑,新增维护拦截功能

1. 替换所有页面的wd-skeleton与空状态为uh-data-loading组件
2. 重构投票相关API类型与列表/详情逻辑,适配Halo扩展对象结构
3. 新增维护拦截hook与维护页,统一插件可用性与维护模式检查跳转
4. 优化多个页面的代码结构与样式细节
This commit is contained in:
小莫唐尼
2026-09-04 04:19:50 +08:00
parent d0dd7d7a46
commit 2fbd3fb19a
15 changed files with 987 additions and 178 deletions
+3 -3
View File
@@ -258,9 +258,9 @@ onReachBottom(() => {
</wd-tabs>
</view>
<!-- 骨架屏 -->
<view v-if="loading !== 'success'" class="loading-wrap p-3">
<wd-skeleton :row="3" :animated="true" />
<!-- 加载/错误占位 -->
<view v-if="loading !== 'success'">
<uh-data-loading :loading-status="loading" @refresh="handleGetData" />
</view>
<!-- 内容区域 -->
+8 -12
View File
@@ -102,15 +102,9 @@ function handleOpenLink() {
<template>
<view class="app-page">
<!-- 加载骨架 -->
<view v-if="loading === 'loading'" class="p-4">
<wd-skeleton :row="3" :animated="true" />
</view>
<!-- 加载失败 -->
<view v-else-if="loading === 'error'" class="flex flex-col items-center gap-4 py-20">
<wd-empty description="详情加载失败" />
<wd-button size="small" @click="handleRetry">重新加载</wd-button>
<!-- 加载/错误占位 -->
<view v-if="loading !== 'success'">
<uh-data-loading :loading-status="loading" @refresh="handleRetry" />
</view>
<!-- 详情内容 -->
@@ -120,7 +114,7 @@ function handleOpenLink() {
<view class="px-4">
<!-- 标题 -->
<view class="mt-6 text-[34rpx] font-bold leading-snug text-[#303133]">
<view class="mt-6 text-[34rpx] text-[#303133] font-bold leading-snug">
{{ detail.title }}
</view>
@@ -143,8 +137,10 @@ function handleOpenLink() {
<!-- 外链(平台差异,条件编译) -->
<view v-if="detail.link" class="link-card mt-8 rounded-xl bg-[#f7f7f9] p-4">
<view class="mb-3 text-[24rpx] text-[#909399]">相关链接</view>
<text class="link-text block break-all text-[26rpx] leading-relaxed text-[#606266]">
<view class="mb-3 text-[24rpx] text-[#909399]">
相关链接
</view>
<text class="link-text block break-all text-[26rpx] text-[#606266] leading-relaxed">
{{ detail.link }}
</text>
<!-- #ifndef APP-PLUS -->
@@ -107,8 +107,9 @@ onShareTimeline(() => ({
<template>
<view class="app-page min-h-screen w-screen flex flex-col py-6" style="background-color: #fafafd;">
<view v-if="loading !== 'success'" class="loading-wrap min-h-screen px-6">
<wd-skeleton :row="4" :animated="true" />
<!-- 加载/错误占位 -->
<view v-if="loading !== 'success'">
<uh-data-loading :loading-status="loading" @refresh="handleGetData" />
</view>
<block v-else>
+3 -6
View File
@@ -167,12 +167,9 @@ init()
@on-refresh="handleGetData"
/>
<template v-else>
<!-- 加载/错误 -->
<view v-if="loading === 'loading'" class="loading-wrap p-3">
<wd-skeleton :row="4" :animated="true" />
</view>
<view v-else-if="loading === 'error'" class="h-[60vh] flex items-center justify-center content-empty">
<wd-empty description="加载异常" />
<!-- 加载/错误占位 -->
<view v-if="loading !== 'success'">
<uh-data-loading :loading-status="loading" @refresh="handleGetData" />
</view>
<!-- 内容区域 -->
+6 -4
View File
@@ -338,8 +338,9 @@ onReachBottom(() => {
@on-refresh="handleGetLinkGroupData"
/>
<template v-else>
<view v-if="loading !== 'success'" class="loading-wrap min-h-screen p-3">
<wd-skeleton :row="5" :animated="true" />
<!-- 加载/错误占位 -->
<view v-if="loading !== 'success'">
<uh-data-loading :loading-status="loading" @refresh="handleGetData" />
</view>
<view v-else class="content pt-4">
@@ -435,8 +436,9 @@ onReachBottom(() => {
@on-refresh="handleGetMiniProgramLinks"
/>
<template v-else>
<view v-if="miniLoading !== 'success'" class="loading-wrap min-h-screen p-3">
<wd-skeleton :row="5" :animated="true" />
<!-- 加载/错误占位 -->
<view v-if="miniLoading !== 'success'">
<uh-data-loading :loading-status="miniLoading" @refresh="handleGetMiniProgramLinks" />
</view>
<view v-else class="content flex flex-1 flex-col">
+3 -2
View File
@@ -97,8 +97,9 @@ onReachBottom(() => {
<template>
<view class="app-page min-h-screen w-screen flex flex-col py-6" style="background-color: #fafafd;">
<view v-if="loading !== 'success'" class="loading-wrap min-h-screen px-6">
<wd-skeleton :row="4" :animated="true" />
<!-- 加载/错误占位 -->
<view v-if="loading !== 'success'">
<uh-data-loading :loading-status="loading" @refresh="handleGetData" />
</view>
<block v-else>
+22 -9
View File
@@ -5,11 +5,10 @@
*/
import { computed, ref } from 'vue'
import { onLoad, onPullDownRefresh, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import dayjs from 'dayjs'
import { getVoteDetail, submitVote } from '@/api/uni-halo'
import { calcVotePercent, VOTE_TYPES, voteCacheUtil } from '@/utils/vote'
import { formatTime as formatTimeUtil } from '@/utils/formatTime'
import type { IVote, IVoteOption } from '@/api/types/uni-halo'
import type { IVote, IVoteDetail, IVoteOption } from '@/api/types/uni-halo'
definePage({
style: {
@@ -81,13 +80,15 @@ async function handleGetData() {
pageTitle.value = '加载中...'
try {
const res = await getVoteDetail(name.value)
const tempVote = res.data as typeof vote.value
const detailRes = res.data as IVoteDetail
const tempVote = detailRes.vote as typeof vote.value
if (tempVote) {
pageTitle.value = `投票详情(${VOTE_TYPES[(tempVote.spec?.type || 'SINGLE') as keyof typeof VOTE_TYPES] || tempVote.spec?.type})`
const typeKey = ((tempVote.spec?.type || 'SINGLE') as string).toUpperCase()
pageTitle.value = `投票详情(${VOTE_TYPES[typeKey as keyof typeof VOTE_TYPES] || tempVote.spec?.type})`
tempVote.spec = tempVote.spec || {}
tempVote.spec.isVoted = isVoted.value
tempVote.spec.disabled = isVoted.value
tempVote.spec._uh_type = VOTE_TYPES[(tempVote.spec.type || 'SINGLE') as keyof typeof VOTE_TYPES] || tempVote.spec.type
tempVote.spec._uh_type = VOTE_TYPES[typeKey as keyof typeof VOTE_TYPES] || tempVote.spec.type
// 计算状态
const startTime = tempVote.spec.startDate ? new Date(tempVote.spec.startDate).getTime() : Date.now()
@@ -105,16 +106,27 @@ async function handleGetData() {
}
// 选项计算
// 插件选项为 {id,title},票数在 VoteDetail.voteDataList / Vote.stats.voteDataList
const countList = (detailRes.voteDataList || tempVote.stats?.voteDataList || []) as { id?: string, voteCount?: number }[]
const countMap: Record<string, number> = {}
countList.forEach((item) => {
if (item.id)
countMap[item.id] = item.voteCount || 0
})
tempVote.spec.options = (tempVote.spec.options || []).map((option) => {
const checked = handleCalcIsChecked(option)
return {
const optionWithCount = {
...option,
value: option.id,
label: option.title,
count: countMap[option.id || ''] || 0,
isVoted: isVoted.value,
checked,
disabled: isVoted.value,
_uh_percent: calcVotePercent(tempVote, option),
}
return {
...optionWithCount,
_uh_percent: calcVotePercent(tempVote, optionWithCount),
}
})
}
@@ -258,8 +270,9 @@ onShareTimeline(() => ({
<template>
<view class="app-page box-border min-h-screen w-screen flex flex-col py-6 pb-[160rpx]" style="background-color: #fafafd;">
<view v-if="loading !== 'success'" class="loading-wrap min-h-screen px-6">
<wd-skeleton :row="4" :animated="true" />
<!-- 加载/错误占位 -->
<view v-if="loading !== 'success'">
<uh-data-loading :loading-status="loading" @refresh="handleGetData" />
</view>
<block v-else>
+8 -7
View File
@@ -49,10 +49,10 @@ async function handleGetData() {
try {
const res = await getVoteList({ ...queryParams.value })
loading.value = 'success'
hasNext.value = (res.data as unknown as { hasNext?: boolean }).hasNext || false
hasNext.value = res.data.hasNext || false
dataList.value = isLoadMore.value
? dataList.value.concat(res.data as IVoteItem[])
: (res.data as IVoteItem[])
? dataList.value.concat(res.data.items)
: res.data.items
loadMoreText.value = hasNext.value ? '上拉加载更多' : '呜呜,没有更多数据啦~'
}
catch (err) {
@@ -125,8 +125,9 @@ onReachBottom(() => {
@on-refresh="handleGetData"
/>
<template v-else>
<view v-if="loading !== 'success'" class="loading-wrap p-3">
<wd-skeleton :row="3" :animated="true" />
<!-- 加载/错误占位 -->
<view v-if="loading !== 'success'">
<uh-data-loading :loading-status="loading" @refresh="handleGetData" />
</view>
<view v-else class="content flex flex-col gap-4 p-3">
@@ -136,8 +137,8 @@ onReachBottom(() => {
<block v-else>
<uh-vote-card
v-for="vote in dataList"
:key="vote.name"
:vote-name="vote.name"
:key="vote.metadata?.name"
:vote-name="vote.metadata?.name || ''"
@on-vote-success="handleOnVoteSuccess"
/>
<view class="load-text py-5 text-center text-[24rpx] text-gray-400">