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

feat: 新增收藏功能与多项体验优化

- 新增本地收藏store与工具函数,支持文章/瞬间收藏持久化
- 重构插件可用性检查hook,统一管理依赖插件状态
- 替换旧数据加载hook为新的状态管理方案
- 优化首页布局与加载逻辑,调整公告组件样式
- 为瞬间详情页添加点赞、评论与收藏功能
- 新增文本处理工具,支持HTML/Markdown转纯文本与摘要截断
- 修复评论弹窗适配瞬间类型的参数问题
This commit is contained in:
小莫唐尼
2026-09-04 17:17:18 +08:00
parent 629b1f9219
commit 62b604644c
28 changed files with 1548 additions and 1387 deletions
@@ -10,9 +10,12 @@
isComment ?: boolean
title ?: string
postName : string
/** 评论目标 kind(文章 Post / 瞬间 Moment) */
subjectKind ?: string
}>(), {
isComment: false,
title: '',
subjectKind: 'Post',
})
const emit = defineEmits<{
@@ -189,7 +192,7 @@
},
subjectRef: {
group: 'content.halo.run',
kind: 'Post',
kind: props.subjectKind,
name: form.value.postName,
version: 'v1alpha1',
},
@@ -18,8 +18,8 @@ interface IProps {
const props = withDefaults(defineProps<IProps>(), {
loadingStatus: 'loading',
minHeight: '60vh',
loadingText: '稍等,正在加载中哦...',
minHeight: '75vh',
loadingText: '稍等,正在加载中哦',
errorText: '哎呀,加载失败了呢~',
emptyText: '啊偶,暂时没有数据呢~',
loadingSubText: '',
@@ -63,7 +63,7 @@ const statusScene = computed(() => {
<template>
<view
class="w-full flex flex-col items-center justify-center gap-y-8 text-sm"
class="w-full flex flex-col items-center justify-center gap-y-4 text-sm"
:style="{ minHeight: props.minHeight }"
>
<!-- 状态舞台:光晕 + 漂浮装饰点 + 毛玻璃表情珠 -->
@@ -83,8 +83,8 @@ const statusScene = computed(() => {
<view class="flex items-center justify-center text-[28rpx] font-bold" :class="statusScene.mainTextClass">
<text>{{ statusScene.mainText }}</text>
<!-- 加载中三点跳动 -->
<view v-if="isLoading" class="ml-3 flex items-end gap-1">
<view v-for="n in 3" :key="n" class="typing-dot" />
<view v-if="isLoading" class="ml-1 flex items-end gap-1">
<view v-for="n in 3" :key="n" class="typing-dot bg-primary" />
</view>
</view>
<text v-if="statusScene.subText" class="mt-3 text-[24rpx] text-gray-400">
@@ -98,9 +98,6 @@ const statusScene = computed(() => {
</template>
<style scoped lang="scss">
/* 氛围化状态占位:keyframes/状态配色无法用原子类表达,保留 scoped 样式 */
/* —— 毛玻璃表情珠(三态共用,缓慢上下漂浮) —— */
.bubble {
animation: bubble-float 2s ease-in-out infinite;
}
@@ -109,7 +106,6 @@ const statusScene = computed(() => {
display: inline-block;
}
/* —— 光晕(状态色,缓慢呼吸) —— */
.glow {
animation: glow-pulse 2.4s ease-in-out infinite;
}
@@ -126,7 +122,6 @@ const statusScene = computed(() => {
background: rgba(217, 249, 157, 0.5);
}
/* —— 漂浮装饰点(品牌双色,错峰漂浮) —— */
.deco-dot {
animation: deco-float 2s ease-in-out infinite;
}
@@ -167,8 +162,7 @@ const statusScene = computed(() => {
.typing-dot {
width: 10rpx;
height: 10rpx;
border-radius: 50%;
background: rgba(163, 230, 53, 0.95);
border-radius: 50%;
animation: dot-jump 1s ease-in-out infinite;
&:nth-child(2) {
@@ -1,269 +0,0 @@
<script lang="ts" setup>
/**
* 轮播组件(源自旧项目 components/e-swiper,新建复刻)
* 数据高内聚:默认内部请求 plugin-uni-halo 公开 banners 接口(getBanners),支持外部 list 覆盖
* 支持:图片轮播、日期角标(useTop,显示当前条目 date 快照)、标题浮层(useTitle)、
* 作者/日期信息浮层(useUser)、底部小图指示器(useDot)
*/
import { computed, onMounted, ref, watch } from 'vue'
import { getBanners } from '@/api/uni-halo'
import { useAppConfigStore } from '@/store/appConfig'
import { checkAvatarUrl, checkThumbnailUrl } from '@/utils/url'
import type { IBannerPublicItem } from '@/api/types/uni-halo'
export interface IBannerItem {
/** 条目标识(Banner 为 metadata.name;兼容旧数据) */
id ?: string | number
/** Banner 条目 metadata.name(custom 详情页跳转用) */
name ?: string
title ?: string
image ?: string
src ?: string
/** 来源:post=文章快照 / custom=自定义 */
type ?: string
/** 文章 id(source=post 时跳转文章详情) */
postId ?: string
content ?: string
url ?: string
/** 展示日期(ISO 快照) */
date ?: string
authorName ?: string
authorAvatar ?: string
[key : string] : unknown
}
const props = withDefaults(defineProps<{
title ?: string
height ?: string
dotPosition ?: string
/** 日期角标(显示当前条目 date) */
useTop ?: boolean
/** 底部小图指示器 */
useDot ?: boolean
/** 标题浮层 */
useTitle ?: boolean
/** 作者/日期信息浮层 */
useUser ?: boolean
/** 轮播数据列表(可选;不传时组件内部调公开 banners 接口拉取) */
list ?: IBannerItem[]
/** 当前选中的项(指示器坐标位置) */
current ?: number
/** 是否自动轮播 */
autoplay ?: boolean
}>(), {
title: '',
height: '450rpx',
dotPosition: 'bottom',
useTop: true,
useDot: true,
useTitle: true,
useUser: true,
current: 0,
autoplay: false,
})
const appConfigStore = useAppConfigStore()
const haloConfigs = computed(() => appConfigStore.configs)
const bannerConfig = computed(() => haloConfigs.value.pageConfig?.homeConfig?.bannerConfig)
/* ---------------- 状态 ---------------- */
const currentIndex = ref(props.current)
/** 是否禁止用户 touch 操作 */
const disableTouch = ref(false)
/* ---------------- 数据(高内聚:内部请求公开接口) ---------------- */
const internalList = ref<IBannerItem[]>([])
/** 展示列表:外部传入(list)优先,否则使用内部拉取数据 */
const displayItems = computed<IBannerItem[]>(() =>
props.list && props.list.length > 0 ? props.list : internalList.value,
)
/** 公开 Banner 条目 → 轮播展示项 */
function mapBanners(items : IBannerPublicItem[]) : IBannerItem[] {
return items.map(item => ({
id: item.name,
name: item.name,
title: item.title || '',
image: checkThumbnailUrl(item.cover),
src: checkThumbnailUrl(item.cover),
type: item.source,
postId: item.postId,
url: item.link,
date: item.date,
authorName: item.authorName,
authorAvatar: item.authorAvatar ? checkAvatarUrl(item.authorAvatar) : '',
}))
}
onMounted(async () => {
// 外部已传数据时不再重复请求
if (props.list && props.list.length > 0) {
return
}
try {
const res = await getBanners()
internalList.value = mapBanners(res.data || [])
}
catch (err) {
console.error('获取轮播图失败', err)
}
})
// 列表变化(外部覆盖/接口返回)后索引越界时归零
watch(displayItems, (val) => {
if (currentIndex.value >= val.length) {
currentIndex.value = 0
}
})
/* ---------------- 计算属性 ---------------- */
const currentItem = computed<IBannerItem>(() =>
displayItems.value[currentIndex.value] || {},
)
/** 日期角标(useTop):当前条目 date 快照转换(年/月/日) */
const dateParts = computed(() => {
const dateStr = currentItem.value.date as string | undefined
if (!dateStr) {
return null
}
const d = new Date(dateStr)
if (Number.isNaN(d.getTime())) {
return null
}
const monthArray = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
return {
day: String(d.getDate()).padStart(2, '0'),
month: String(d.getMonth() + 1).padStart(2, '0'),
monthEn: monthArray[d.getMonth()],
year: String(d.getFullYear()),
}
})
const currentTitle = computed(() => currentItem.value.title || props.title || '')
/** 作者日期展示(useUser 用) */
const authorDateText = computed(() => {
const dateStr = currentItem.value.date as string | undefined
if (!dateStr) {
return ''
}
const d = new Date(dateStr)
if (Number.isNaN(d.getTime())) {
return ''
}
const pad = (n : number) => String(n).padStart(2, '0')
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`
})
/* ---------------- 交互 ---------------- */
/** current 改变时会触发 change 事件,event.detail = {current, source} */
function change(e : { detail : { current : number, source : string } }) {
const { current, source } = e.detail
// 只有页面自动切换、手动切换时才轮播,其他不允许
if (source === 'autoplay' || source === 'touch') {
const event = { current }
currentIndex.value = current
}
}
/** 手动点击了指示器[小图模式] */
function swiperIndTap(index : number) {
const event = { current: index }
currentIndex.value = index
}
function handleOnClick(item : IBannerItem) {
// 审核模式下照常展示 Banner,点击分发不拦截(详情页自行处理审核限制)
if (item.type === 'custom') {
// 自定义条目:跳转 Banner 详情页,页面内调公开详情接口展示 content/外链
if (item.name) {
uni.navigateTo({
url: `/pages-blog/banner-detail/banner-detail?name=${item.name}`,
animationType: 'slide-in-right',
})
}
return
}
// 文章来源
uni.navigateTo({
url: `/pages-blog/article-detail/article-detail?name=${item.postId}`,
animationType: 'slide-in-right',
})
}
</script>
<template>
<view v-if="displayItems.length > 0" class="relative w-full px-4 pt-12 mb-14 box-border">
<view class="absolute inset-0 blur-[2rpx]">
<image :src="displayItems[currentIndex].src" class="h-full w-full" mode="aspectFill"></image>
</view>
<view class="uh-global-card-glass box-border relative w-full overflow-hidden rounded-xl translate-y-12" :class="[dotPosition]">
<swiper class="w-full" :style="{ height }" :circular="true" :indicator-dots="false"
:autoplay="autoplay" :interval="3000" :duration="1000" :current="currentIndex"
:disable-touch="disableTouch" @change="change">
<swiper-item v-for="(item, index) in displayItems" :key="index">
<image :src="item.image || item.src" class="h-full w-full" mode="aspectFill"
@click.stop="handleOnClick(item)" />
</swiper-item>
</swiper>
<!-- 指示器 [Top 日期角标]:显示当前条目 date(年/月/日) -->
<view v-if="useTop && dateParts"
class="box-border absolute inset-x-0 top-0 z-5 flex items-center px-[24rpx] py-[16rpx]">
<text class="text-[40rpx] text-white font-bold text-shadow-[0_2rpx_8rpx_rgba(0,0,0,0.4)]">
{{ dateParts.day }}
</text>
<view class="ml-[12rpx] h-[40rpx] w-[2rpx] bg-white/50" />
<view class="ml-[12rpx] flex flex-col">
<text class="text-[20rpx] text-white text-shadow-[0_2rpx_8rpx_rgba(0,0,0,0.4)]">
{{ dateParts.monthEn }}
</text>
<text class="text-[16rpx] text-white/80">{{ dateParts.year }}</text>
</view>
<text
class="text-overflow-2 ml-[20rpx] block flex-1 text-[24rpx] text-white text-shadow-[0_2rpx_8rpx_rgba(0,0,0,0.4)]">
{{ title }}
</text>
</view>
<!-- 指示器 标题区域 + 作者/日期信息(useUser) -->
<view v-if="useTitle"
class="absolute inset-x-0 bottom-0 z-5 from-black/45 to-transparent bg-gradient-to-t px-[24rpx] pb-[20rpx] pt-[48rpx]">
<view v-if="useUser && (currentItem.authorName || authorDateText)"
class="mb-[8rpx] flex items-center gap-[8rpx]">
<view v-if="currentItem.authorAvatar"
class="h-[36rpx] w-[36rpx] overflow-hidden border-[1rpx] border-white/60 rounded-full">
<image :src="currentItem.authorAvatar" class="h-full w-full" mode="aspectFill" />
</view>
<text class="text-[22rpx] text-white/92 text-shadow-[0_1rpx_4rpx_rgba(0,0,0,0.4)]">
{{ currentItem.authorName }}
</text>
<text v-if="authorDateText"
class="text-[20rpx] text-white/70 text-shadow-[0_1rpx_4rpx_rgba(0,0,0,0.4)]">
{{ authorDateText }}
</text>
</view>
<text v-if="currentTitle"
class="text-overflow-2 block text-[28rpx] text-white font-bold text-shadow-[0_2rpx_8rpx_rgba(0,0,0,0.4)]">
{{ currentTitle }}
</text>
</view>
<!-- 指示器 [底部小图列表] -->
<view v-if="useDot" class="absolute inset-x-0 bottom-3 z-5 flex justify-end px-[24rpx]">
<view class="flex gap-1">
<view v-for="(item, index) in displayItems" :key="index"
class="uh-global-card-glass h-[64rpx] w-[96rpx] overflow-hidden border-[2rpx] rounded-[8rpx]"
:class="currentIndex === index ? 'opacity-100 border-white' : 'opacity-60 border-transparent'"
@click="swiperIndTap(index)">
<image :src="item.image || item.src" class="h-full w-full" mode="aspectFill" />
</view>
</view>
</view>
</view>
</view>
</template>
@@ -1,11 +1,4 @@
<script lang="ts" setup>
/**
* 首页公告滚动条(plugin-uni-halo 通知公告,2026-09-03 客户端新增)
* 展示最新/置顶公告(公开 GET /notices 服务端默认 priority desc + publishTime desc),
* 取前 6 条标题垂直循环轮播:点击当前标题跳公告详情,右侧「更多」跳公告列表页。
* 无公告(或加载失败)时整条不渲染,不占首页空间。
* UIUX 见 .docs/notice-module-client-design.md
*/
import { computed, onMounted, ref } from 'vue'
import { getNotices } from '@/api/uni-halo'
import type { INoticeListVo } from '@/api/types/uni-halo'
@@ -47,14 +40,14 @@ onMounted(() => {
<template>
<view
v-if="showList.length > 0"
class="mx-3 mb-2 flex items-center rounded-xl bg-white px-3 py-1.5 shadow-sm"
class="uh-global-card-glass box-border mx-3 mt-3 mb-2 flex items-center rounded-xl px-3"
>
<!-- 左侧公告入口 -->
<view class="flex shrink-0 items-center gap-1 py-2 pr-3" @click="handleGoList">
<text class="text-[28rpx]">
<text class="text-sm">
📢
</text>
<text class="text-[24rpx] font-bold text-[#f83856]">
<text class="text-xs font-bold text-red-400">
公告
</text>
</view>
@@ -76,7 +69,7 @@ onMounted(() => {
class="h-full w-full"
>
<view
class="flex h-full w-full items-center truncate text-[24rpx] text-[#555]"
class="flex h-full w-full items-center truncate text-xs text-gray-500"
@click="handleTap(item)"
>
{{ item.title }}
@@ -1,138 +1,127 @@
<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import { getNoticeLatest } from '@/api/uni-halo'
import { getCache, setCache } from '@/utils/storage'
import type { INoticeListVo } from '@/api/types/uni-halo'
import { onMounted, ref } from 'vue'
import { getNoticeLatest } from '@/api/uni-halo'
import { getCache, setCache } from '@/utils/storage'
import { checkImageUrl } from '@/utils/url'
import type { INoticeListVo } from '@/api/types/uni-halo'
const HIDDEN_KEY_PREFIX = 'notice_latest_hidden'
const HIDDEN_KEY_PREFIX = 'notice_latest_hidden'
const isShow = ref(false)
const notice = ref<INoticeListVo | null>(null)
const checking = ref(false)
const isShow = ref(false)
const notice = ref<INoticeListVo | null>(null)
const checking = ref(false)
function todayKey(name: string): string {
const date = new Date()
const pad = (n: number) => String(n).padStart(2, '0')
return `${HIDDEN_KEY_PREFIX}_${name}_${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}`
}
function todayKey(name : string) : string {
const date = new Date()
const pad = (n : number) => String(n).padStart(2, '0')
return `${HIDDEN_KEY_PREFIX}_${name}_${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}`
}
function formatDate(value?: string): string {
if (!value)
return ''
const date = new Date(value)
if (Number.isNaN(date.getTime()))
return ''
const pad = (n: number) => String(n).padStart(2, '0')
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
}
function formatDate(value ?: string) : string {
if (!value)
return ''
const date = new Date(value)
if (Number.isNaN(date.getTime()))
return ''
const pad = (n : number) => String(n).padStart(2, '0')
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
}
async function handleCheckLatest() {
if (checking.value)
return
checking.value = true
try {
const res = await getNoticeLatest()
const latest = res.data
if (!latest?.name || !latest.title)
return
// 今日已看过则不再打扰
if (getCache<string>(todayKey(latest.name)))
return
notice.value = latest
isShow.value = true
}
catch (err) {
console.error('获取最新公告失败', err)
}
finally {
checking.value = false
}
}
async function handleCheckLatest() {
if (checking.value) { return }
checking.value = true
try {
const res = await getNoticeLatest()
const latest = res.data
if (!latest?.name || !latest.title) { return }
// 今日已看过则不再打扰
if (getCache<string>(todayKey(latest.name))) { return }
notice.value = latest
isShow.value = true
}
catch (err) {
console.error('获取最新公告失败', err)
}
finally {
checking.value = false
}
}
/** 仅关闭(不记录,下次进入可再弹) */
function handleClose() {
isShow.value = false
}
/** 仅关闭(不记录,下次进入可再弹) */
function handleClose() {
isShow.value = false
}
/** 今日不再提醒:记录后关闭 */
function handleDismissForever() {
if (notice.value?.name) {
setCache(todayKey(notice.value.name), '1')
}
isShow.value = false
}
/** 今日不再提醒:记录后关闭 */
function handleDismissForever() {
if (notice.value?.name) {
setCache(todayKey(notice.value.name), '1')
}
isShow.value = false
}
/** 查看全文:记录今日已看并跳公告详情页 */
function handleViewAll() {
if (notice.value?.name) {
setCache(todayKey(notice.value.name), '1')
const detailName = notice.value.name
isShow.value = false
uni.navigateTo({ url: `/pages-blog/notice/detail?name=${detailName}` })
}
}
/** 查看全文:记录今日已看并跳公告详情页 */
function handleViewAll() {
if (notice.value?.name) {
setCache(todayKey(notice.value.name), '1')
const detailName = notice.value.name
isShow.value = false
uni.navigateTo({ url: `/pages-blog/notice/detail?name=${detailName}` })
}
}
onMounted(() => {
handleCheckLatest()
})
onMounted(() => {
handleCheckLatest()
})
</script>
<template>
<wd-popup
v-model="isShow"
position="center"
custom-class="rounded-xl"
z-index="9999"
@close="handleClose"
>
<view v-if="notice" class="box-border w-[80vw] p-6">
<!-- 头部:标题 + 关闭 -->
<view class="flex items-center justify-between">
<view class="flex items-center gap-2">
<text class="text-sm">
📢
</text>
<text class="text-md font-bold text-gray-900">
最新公告
</text>
<view
v-if="notice.typeDisplayName"
class="rounded px-1.5 py-0.5 text-xs"
:style="{
color: notice.typeColor || '#f83856',
backgroundColor: notice.typeColor ? `${notice.typeColor}1a` : '#fdeef1',
}"
>
{{ notice.typeDisplayName }}
</view>
</view>
<view class="flex h-8 w-8 items-center justify-center text-gray-500" @click="handleClose">
<wd-icon name="close" size="16px" />
</view>
</view>
<wd-popup v-model="isShow" position="center" custom-class="rounded-xl" :z-index="9999" @close="handleClose">
<view v-if="notice" class="box-border w-[80vw] p-6">
<!-- 头部:标题 + 关闭 -->
<view class="flex items-center justify-between">
<view class="flex items-center gap-2">
<text class="text-sm">
📢
</text>
<text class="text-md font-bold text-gray-900">
最新公告
</text>
<view v-if="notice.typeDisplayName" class="rounded px-1.5 py-0.5 text-xs" :style="{
color: notice.typeColor || '#f83856',
backgroundColor: notice.typeColor ? `${notice.typeColor}1a` : '#fdeef1',
}">
{{ notice.typeDisplayName }}
</view>
</view>
<view class="flex h-8 w-8 items-center justify-end text-gray-500" @click="handleClose">
<wd-icon name="close" size="16px" />
</view>
</view>
<!-- 内容 -->
<view class="mt-4">
<view class="text-[32rpx] font-bold leading-snug text-[#222]">
{{ notice.title }}
</view>
<view v-if="notice.summary" class="mt-3 text-[26rpx] leading-relaxed text-gray-500">
{{ notice.summary }}
</view>
<view v-if="notice.publishTime" class="mt-3 text-[22rpx] text-gray-400">
日期:{{ formatDate(notice.publishTime) }}
</view>
</view>
<!-- 内容 -->
<view class="mt-4">
<image v-if="notice.cover" :src="checkImageUrl(notice.cover)" class="w-full h-34 rounded-lg mb-2"></image>
<view class="text-md font-bold leading-snug text-gray-900">
{{ notice.title }}
</view>
<view v-if="notice.summary" class="mt-3 text-sm leading-relaxed text-gray-500">
{{ notice.summary }}
</view>
<view v-if="notice.publishTime" class="mt-3 text-xs text-gray-400">
日期:{{ formatDate(notice.publishTime) }}
</view>
</view>
<!-- 操作 -->
<view class="box-border mt-4 flex items-center justify-between pt-4">
<view class="text-xs text-gray-600 " @click="handleDismissForever">
今日不再提醒
</view>
<uh-button custom-class="font-semibold text-xs" @click="handleViewAll">
查看全文 →
</uh-button>
</view>
</view>
</wd-popup>
<!-- 操作 -->
<view class="box-border mt-4 flex items-center justify-between pt-4">
<view class="text-xs text-gray-600 " @click="handleDismissForever">
今日不再提醒
</view>
<uh-button custom-class="font-semibold text-xs" @click="handleViewAll">
查看全文 →
</uh-button>
</view>
</view>
</wd-popup>
</template>
@@ -1,135 +1,114 @@
<script lang="ts" setup>
/**
/**
* 插件不可用提示(源自旧项目 components/plugin-unavailable,新建复刻)
* 当依赖的 Halo 插件未安装/未启用时展示:插件 logo、名称、错误标签、描述、插件地址、复制/反馈按钮
*/
import { computed } from 'vue'
import { NeedPlugins } from '@/utils/plugin'
import { computed } from 'vue'
import { NeedPlugins } from '@/hooks/usePluginAvailable'
const props = withDefaults(defineProps<{
/** 插件名称(与 NeedPlugins 中的 id 对应) */
pluginId: string
errorText?: string
useDecoration?: boolean
useBorder?: boolean
customStyle?: Record<string, string>
}>(), {
errorText: '',
useDecoration: true,
useBorder: true,
customStyle: () => ({}),
})
const props = withDefaults(defineProps<{
/** 插件名称(与 NeedPlugins 中的 id 对应) */
pluginId : string
errorText ?: string
useDecoration ?: boolean
useBorder ?: boolean
customStyle ?: Record<string, string>
}>(), {
errorText: '',
useDecoration: true,
useBorder: true,
customStyle: () => ({}),
})
const emit = defineEmits<{
(e: 'on-refresh'): void
}>()
const emit = defineEmits<{
(e : 'on-refresh') : void
}>()
/** 插件信息(未在清单中时兜底) */
const pluginInfo = computed(() => {
const info = NeedPlugins.get(props.pluginId)
return info || {
id: props.pluginId,
name: props.pluginId,
desc: '',
logo: '',
url: '',
}
})
/** 插件信息(未在清单中时兜底) */
const pluginInfo = computed(() => {
const info = NeedPlugins.get(props.pluginId)
return info || {
id: props.pluginId,
name: props.pluginId,
desc: '',
logo: '',
url: '',
}
})
const defaultStyle = {
width: '80vw',
borderRadius: '24rpx',
}
const defaultStyle = {
width: '80vw',
borderRadius: '24rpx',
}
const calcCustomStyle = computed(() => ({
...defaultStyle,
...props.customStyle,
}))
const calcCustomStyle = computed(() => ({
...defaultStyle,
...props.customStyle,
}))
function copy() {
if (!pluginInfo.value.url)
return
uni.setClipboardData({
data: pluginInfo.value.url,
showToast: false,
success: () => {
uni.showToast({ icon: 'none', title: '插件地址已复制' })
},
})
}
function copy() {
if (!pluginInfo.value.url)
return
uni.setClipboardData({
data: pluginInfo.value.url,
showToast: false,
success: () => {
uni.showToast({ icon: 'none', title: '插件地址已复制' })
},
})
}
</script>
<template>
<view
v-if="pluginInfo"
class="uh-plugin-unavailable mx-auto my-auto box-border flex flex-col gap-6 p-10 text-[28rpx]"
:class="{ border: useBorder, decoration: useDecoration }"
:style="[calcCustomStyle]"
>
<!-- 图标 -->
<image class="plugin-logo box-border h-[120rpx] w-[120rpx] rounded-3xl" :src="pluginInfo.logo" mode="scaleToFill" />
<!-- 名称 -->
<view class="plugin-name box-border text-[32rpx] text-[#333] font-bold">
{{ pluginInfo.name }}
</view>
<!-- 错误标签 -->
<view class="plugin-error box-border rounded-[36rpx] px-4 py-1.5 text-[24rpx] font-bold" style="background-color: rgb(255 61 49 / 7.5%); color: rgb(255 61 49);">
未安装/启用插件
</view>
<!-- 描述 -->
<view class="plugin-desc box-border w-[60vw] text-center text-[24rpx] text-[#64748b]">
{{ pluginInfo.desc }}
</view>
<!-- 自定义错误提示 -->
<view v-if="errorText" class="plugin-tip box-border border-2 rounded-xl border-dashed px-5 py-2.5 text-[24rpx]" style="border-color: #f2c97d; color: #f0a020;">
{{ errorText }}
</view>
<!-- 插件地址 -->
<view class="plugin-url box-border w-full overflow-hidden text-ellipsis whitespace-nowrap rounded-xl bg-[#f1f5f9] px-6 py-4 text-[24rpx] text-[#666]">
插件地址:{{ pluginInfo.url }}
</view>
<!-- 反馈按钮/复制地址 -->
<view class="plugin-btns box-border w-full">
<!-- #ifndef MP-WEIXIN -->
<wd-button type="primary" block size="medium" @click="copy">
复制地址
</wd-button>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<view class="flex gap-3">
<wd-button type="primary" plain block size="medium" @click="copy">
复制地址
</wd-button>
<wd-button type="warning" plain block size="medium" open-type="contact">
提交反馈
</wd-button>
</view>
<!-- #endif -->
</view>
<!-- 刷新按钮 -->
<view class="flex justify-center">
<wd-button size="small" plain type="info" @click="emit('on-refresh')">
刷新试试
</wd-button>
</view>
<view v-if="pluginInfo"
class="uh-plugin-unavailable mx-auto my-auto box-border flex flex-col gap-6 p-10 text-[28rpx]"
:class="{ border: useBorder, decoration: useDecoration }" :style="[calcCustomStyle]">
<!-- 图标 -->
<image class="plugin-logo box-border h-[120rpx] w-[120rpx] rounded-3xl" :src="pluginInfo.logo"
mode="scaleToFill" />
<!-- 名称 -->
<view class="plugin-name box-border text-[32rpx] text-[#333] font-bold">
{{ pluginInfo.name }}
</view>
<view class="plugin-copyright text-[20rpx] text-[#999]" style="transform: scale(0.9) translateY(20px);">
提示:请确保 Halo 博客已安装相关插件
</view>
</view>
<!-- 自定义错误提示 -->
<view v-if="errorText" class="plugin-tip box-border border-2 rounded-xl border-dashed px-5 py-2.5 text-[24rpx]"
style="border-color: #f2c97d; color: #f0a020;">
{{ errorText }}
</view>
<!-- 反馈按钮/复制地址 -->
<view class="plugin-btns box-border w-full">
<!-- #ifdef MP-WEIXIN -->
<wd-button type="warning" plain block size="medium" open-type="contact">
提交反馈
</wd-button>
<!-- #endif -->
</view>
<!-- 刷新按钮 -->
<view class="flex justify-center">
<wd-button size="small" plain type="info" @click="emit('on-refresh')">
刷新试试
</wd-button>
</view>
<view class="plugin-copyright text-[20rpx] text-[#999]" style="transform: scale(0.9) translateY(20px);">
提示:请确保 Halo 博客已安装相关插件
</view>
</view>
</template>
<style scoped lang="scss">
.uh-plugin-unavailable {
&.border {
border: 2rpx solid #eee;
}
.uh-plugin-unavailable {
&.border {
border: 2rpx solid #eee;
}
&.decoration {
background-color: rgb(255 255 255 / 95%);
box-shadow: 0 0 12rpx rgb(226 232 240 / 35%);
backdrop-filter: blur(6rpx);
border-top: 12rpx solid rgb(3 169 244);
}
}
</style>
&.decoration {
background-color: rgb(255 255 255 / 95%);
box-shadow: 0 0 12rpx rgb(226 232 240 / 35%);
backdrop-filter: blur(6rpx);
border-top: 12rpx solid rgb(3 169 244);
}
}
</style>
@@ -0,0 +1,135 @@
<script lang="ts" setup>
/**
* 插件不可用提示(源自旧项目 components/plugin-unavailable,新建复刻)
* 当依赖的 Halo 插件未安装/未启用时展示:插件 logo、名称、错误标签、描述、插件地址、复制/反馈按钮
*/
import { computed } from 'vue'
import { NeedPlugins } from '@/utils/plugin'
const props = withDefaults(defineProps<{
/** 插件名称(与 NeedPlugins 中的 id 对应) */
pluginId: string
errorText?: string
useDecoration?: boolean
useBorder?: boolean
customStyle?: Record<string, string>
}>(), {
errorText: '',
useDecoration: true,
useBorder: true,
customStyle: () => ({}),
})
const emit = defineEmits<{
(e: 'on-refresh'): void
}>()
/** 插件信息(未在清单中时兜底) */
const pluginInfo = computed(() => {
const info = NeedPlugins.get(props.pluginId)
return info || {
id: props.pluginId,
name: props.pluginId,
desc: '',
logo: '',
url: '',
}
})
const defaultStyle = {
width: '80vw',
borderRadius: '24rpx',
}
const calcCustomStyle = computed(() => ({
...defaultStyle,
...props.customStyle,
}))
function copy() {
if (!pluginInfo.value.url)
return
uni.setClipboardData({
data: pluginInfo.value.url,
showToast: false,
success: () => {
uni.showToast({ icon: 'none', title: '插件地址已复制' })
},
})
}
</script>
<template>
<view
v-if="pluginInfo"
class="uh-plugin-unavailable mx-auto my-auto box-border flex flex-col gap-6 p-10 text-[28rpx]"
:class="{ border: useBorder, decoration: useDecoration }"
:style="[calcCustomStyle]"
>
<!-- 图标 -->
<image class="plugin-logo box-border h-[120rpx] w-[120rpx] rounded-3xl" :src="pluginInfo.logo" mode="scaleToFill" />
<!-- 名称 -->
<view class="plugin-name box-border text-[32rpx] text-[#333] font-bold">
{{ pluginInfo.name }}
</view>
<!-- 错误标签 -->
<view class="plugin-error box-border rounded-[36rpx] px-4 py-1.5 text-[24rpx] font-bold" style="background-color: rgb(255 61 49 / 7.5%); color: rgb(255 61 49);">
未安装/启用插件
</view>
<!-- 描述 -->
<view class="plugin-desc box-border w-[60vw] text-center text-[24rpx] text-[#64748b]">
{{ pluginInfo.desc }}
</view>
<!-- 自定义错误提示 -->
<view v-if="errorText" class="plugin-tip box-border border-2 rounded-xl border-dashed px-5 py-2.5 text-[24rpx]" style="border-color: #f2c97d; color: #f0a020;">
{{ errorText }}
</view>
<!-- 插件地址 -->
<view class="plugin-url box-border w-full overflow-hidden text-ellipsis whitespace-nowrap rounded-xl bg-[#f1f5f9] px-6 py-4 text-[24rpx] text-[#666]">
插件地址:{{ pluginInfo.url }}
</view>
<!-- 反馈按钮/复制地址 -->
<view class="plugin-btns box-border w-full">
<!-- #ifndef MP-WEIXIN -->
<wd-button type="primary" block size="medium" @click="copy">
复制地址
</wd-button>
<!-- #endif -->
<!-- #ifdef MP-WEIXIN -->
<view class="flex gap-3">
<wd-button type="primary" plain block size="medium" @click="copy">
复制地址
</wd-button>
<wd-button type="warning" plain block size="medium" open-type="contact">
提交反馈
</wd-button>
</view>
<!-- #endif -->
</view>
<!-- 刷新按钮 -->
<view class="flex justify-center">
<wd-button size="small" plain type="info" @click="emit('on-refresh')">
刷新试试
</wd-button>
</view>
<view class="plugin-copyright text-[20rpx] text-[#999]" style="transform: scale(0.9) translateY(20px);">
提示:请确保 Halo 博客已安装相关插件
</view>
</view>
</template>
<style scoped lang="scss">
.uh-plugin-unavailable {
&.border {
border: 2rpx solid #eee;
}
&.decoration {
background-color: rgb(255 255 255 / 95%);
box-shadow: 0 0 12rpx rgb(226 232 240 / 35%);
backdrop-filter: blur(6rpx);
border-top: 12rpx solid rgb(3 169 244);
}
}
</style>