mirror of
https://github.com/ialley-workshop-open/uni-halo.git
synced 2026-11-13 22:11:42 +08:00
refactor: 重构插件可用性检测逻辑,统一传参和状态管理
1. 抽离统一的插件ID枚举NeedPluginIds,替换硬编码的插件ID字符串 2. 修改usePluginAvailable调用方式,改为对象传参模式 3. 统一插件不可用页面的提示文本和刷新逻辑,新增检测状态绑定 4. 优化uh-plugin-unavailable组件的兜底数据和样式
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
import { getBlogStatistics } from '@/api/halo'
|
||||
import { useAppConfigStore } from '@/store/appConfig'
|
||||
import { useFavoritesStore } from '@/store/favorites'
|
||||
import { NeedPluginIds } from '@/hooks/usePluginAvailable'
|
||||
import { checkAvatarUrl, checkImageUrl } from '@/utils/url'
|
||||
import { checkHasAdminLogin } from '@/utils/auth'
|
||||
import { t } from '@/locale'
|
||||
@@ -28,8 +29,10 @@
|
||||
const calcAuditModeEnabled = computed(() => appConfigStore.auditModeEnabled)
|
||||
const calcVotePluginEnabled = computed(() => !!haloConfigs.value.pluginConfig?.votePlugin?.enabled)
|
||||
const calcLinksPluginEnabled = computed(() => !!haloConfigs.value.pluginConfig?.linksPlugin?.enabled)
|
||||
/** 数据看板插件可用性(供导航项显隐判断) */
|
||||
const { check: checkDataVisualPlugin } = usePluginAvailable('plugin-data-statistics')
|
||||
/** 数据看板插件可用性(供导航项显隐判断,参考 gallery 对象传参模式) */
|
||||
const { check: checkDataVisualPlugin } = usePluginAvailable({
|
||||
pluginId: NeedPluginIds.PluginDataStatistics,
|
||||
})
|
||||
|
||||
/* ---------------- 计算属性 ---------------- */
|
||||
const bloggerInfo = computed(() => {
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
import { onLoad, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
|
||||
import { getMomentList } from '@/api/halo'
|
||||
import { useAppConfigStore } from '@/store/appConfig'
|
||||
import { NeedPluginIds } from '@/hooks/usePluginAvailable'
|
||||
import { useFavoritesStore } from '@/store/favorites'
|
||||
import { checkAvatarUrl, checkThumbnailUrl } from '@/utils/url'
|
||||
import { buildMomentFavoriteItem } from '@/utils/favorite'
|
||||
@@ -46,9 +47,17 @@
|
||||
return appInfo?.name || bloggerInfo.value.nickname || 'uni-halo'
|
||||
})
|
||||
|
||||
/** 依赖插件(plugin-moments) */
|
||||
const uniHaloPluginId = 'plugin-moments'
|
||||
const { available: uniHaloPluginAvailable, check: checkPluginAvailable } = usePluginAvailable(uniHaloPluginId)
|
||||
/** 依赖插件(plugin-moments,参考 gallery 对象传参模式) */
|
||||
const { pluginId, checking, tips, available: uniHaloPluginAvailable, check: checkPluginAvailable } = usePluginAvailable({
|
||||
pluginId: NeedPluginIds.PluginMoments,
|
||||
tips: '检测到当前插件没有安装或者启用,无法使用瞬间功能哦,请联系管理员',
|
||||
})
|
||||
|
||||
/** 重新检测插件:可用则拉取数据(供 uh-plugin-unavailable 刷新按钮) */
|
||||
async function handlePluginRefresh() {
|
||||
if (await checkPluginAvailable())
|
||||
handleGetData()
|
||||
}
|
||||
|
||||
/* ---------------- 状态 ---------------- */
|
||||
const { loadingStatus, updateLoadingStatus } = useDataLoadingStatus()
|
||||
@@ -279,8 +288,8 @@
|
||||
|
||||
<template>
|
||||
<view class="box-border min-h-screen w-screen flex flex-col bg-page py-3">
|
||||
<uh-plugin-unavailable v-if="!uniHaloPluginAvailable" :plugin-id="uniHaloPluginId"
|
||||
error-text="检测到当前插件没有安装或者启用,无法使用瞬间功能哦,请联系管理员" @on-refresh="handleGetData" />
|
||||
<uh-plugin-unavailable v-if="!uniHaloPluginAvailable" :plugin-id="pluginId" :error-text="tips"
|
||||
:checking="checking" @on-refresh="handlePluginRefresh" />
|
||||
<template v-else>
|
||||
<!-- 加载失败(可重试) -->
|
||||
<uh-data-loading v-if="loadingStatus !== DataLoadingStatusEnum.Success" :loading-status="loadingStatus"
|
||||
|
||||
Reference in New Issue
Block a user