Compare commits

...

1 Commits

Author SHA1 Message Date
Tim
e8a162d859 feat: add reusable multi-tabs component 2025-08-27 12:22:22 +08:00
5 changed files with 908 additions and 836 deletions

View File

@@ -0,0 +1,82 @@
<template>
<div class="multi-tabs">
<div class="multi-tabs-header" :class="headerClass">
<div
v-for="tab in tabs"
:key="tab.name"
:class="[itemClass, { selected: current === tab.name }]"
@click="select(tab.name)"
>
<div :class="labelClass">
<i v-if="tab.icon" :class="tab.icon"></i>
{{ tab.label }}
</div>
</div>
<slot name="header-extra" />
</div>
<div class="multi-tabs-content" @touchstart="onTouchStart" @touchend="onTouchEnd">
<slot :selected="current" />
</div>
</div>
</template>
<script setup>
import { computed, ref } from 'vue'
const props = defineProps({
tabs: { type: Array, required: true },
modelValue: { type: String, required: true },
headerClass: { type: String, default: '' },
itemClass: { type: String, default: '' },
labelClass: { type: String, default: '' },
})
const emit = defineEmits(['update:modelValue'])
const current = computed({
get: () => props.modelValue,
set: (val) => emit('update:modelValue', val),
})
const select = (name) => {
current.value = name
}
const startX = ref(0)
const startY = ref(0)
const onTouchStart = (e) => {
const t = e.touches[0]
startX.value = t.clientX
startY.value = t.clientY
}
const onTouchEnd = (e) => {
const t = e.changedTouches[0]
const dx = t.clientX - startX.value
const dy = t.clientY - startY.value
if (Math.abs(dx) > Math.abs(dy) && Math.abs(dx) > 50) {
const idx = props.tabs.findIndex((t) => t.name === current.value)
if (dx < 0 && idx < props.tabs.length - 1) {
current.value = props.tabs[idx + 1].name
} else if (dx > 0 && idx > 0) {
current.value = props.tabs[idx - 1].name
}
}
}
</script>
<style scoped>
.multi-tabs-header {
display: flex;
flex-direction: row;
overflow-x: auto;
scrollbar-width: none;
}
.multi-tabs-header::-webkit-scrollbar {
display: none;
}
.multi-tabs-content {
width: 100%;
}
</style>

View File

@@ -1,29 +1,29 @@
<template> <template>
<div class="about-page"> <div class="about-page">
<div class="about-tabs"> <MultiTabs
<div :tabs="tabs"
v-for="tab in tabs" v-model="selectedTab"
:key="tab.name" header-class="about-tabs"
:class="['about-tabs-item', { selected: selectedTab === tab.name }]" item-class="about-tabs-item"
@click="selectTab(tab.name)" label-class="about-tabs-item-label"
> >
<div class="about-tabs-item-label">{{ tab.label }}</div> <template #default>
</div> <div class="about-loading" v-if="isFetching">
</div> <l-hatch-spinner size="100" stroke="10" speed="1" color="var(--primary-color)" />
<div class="about-loading" v-if="isFetching"> </div>
<l-hatch-spinner size="100" stroke="10" speed="1" color="var(--primary-color)" /> <div
</div> v-else
<div class="about-content"
v-else v-html="renderMarkdown(content)"
class="about-content" @click="handleContentClick"
v-html="renderMarkdown(content)" ></div>
@click="handleContentClick" </template>
></div> </MultiTabs>
</div> </div>
</template> </template>
<script> <script>
import { onMounted, ref } from 'vue' import { onMounted, ref, watch } from 'vue'
import { handleMarkdownClick, renderMarkdown } from '~/utils/markdown' import { handleMarkdownClick, renderMarkdown } from '~/utils/markdown'
export default { export default {
@@ -71,21 +71,21 @@ export default {
} }
} }
const selectTab = (name) => { watch(selectedTab, (name) => {
selectedTab.value = name
const tab = tabs.find((t) => t.name === name) const tab = tabs.find((t) => t.name === name)
if (tab) loadContent(tab.file) if (tab) loadContent(tab.file)
} })
onMounted(() => { onMounted(() => {
loadContent(tabs[0].file) const first = tabs[0]
if (first) loadContent(first.file)
}) })
const handleContentClick = (e) => { const handleContentClick = (e) => {
handleMarkdownClick(e) handleMarkdownClick(e)
} }
return { tabs, selectedTab, content, renderMarkdown, selectTab, isFetching, handleContentClick } return { tabs, selectedTab, content, renderMarkdown, isFetching, handleContentClick }
}, },
} }
</script> </script>

View File

@@ -7,116 +7,118 @@
<div v-if="!isFloatMode" class="float-control"> <div v-if="!isFloatMode" class="float-control">
<i class="fas fa-compress" @click="minimize" title="最小化"></i> <i class="fas fa-compress" @click="minimize" title="最小化"></i>
</div> </div>
<div class="tabs"> <MultiTabs :tabs="tabs" v-model="activeTab" header-class="tabs" item-class="tab">
<div :class="['tab', { active: activeTab === 'messages' }]" @click="switchToMessage"> <template #default="{ selected }">
站内信 <div v-if="selected === 'messages'">
</div> <div v-if="loading" class="loading-message">
<div :class="['tab', { active: activeTab === 'channels' }]" @click="switchToChannels"> <l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
频道
</div>
</div>
<div v-if="activeTab === 'messages'">
<div v-if="loading" class="loading-message">
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
</div>
<div v-else-if="error" class="error-container">
<div class="error-text">{{ error }}</div>
</div>
<div v-if="!loading && !isFloatMode" class="search-container">
<SearchPersonDropdown />
</div>
<div v-if="!loading && conversations.length === 0" class="empty-container">
<BasePlaceholder v-if="conversations.length === 0" text="暂无会话" icon="fas fa-inbox" />
</div>
<div
v-if="!loading"
v-for="convo in conversations"
:key="convo.id"
class="conversation-item"
@click="goToConversation(convo.id)"
>
<div class="conversation-avatar">
<BaseImage
:src="getOtherParticipant(convo)?.avatar || '/default-avatar.svg'"
:alt="getOtherParticipant(convo)?.username || '用户'"
class="avatar-img"
@error="handleAvatarError"
/>
</div>
<div class="conversation-content">
<div class="conversation-header">
<div class="participant-name">
{{ getOtherParticipant(convo)?.username || '未知用户' }}
</div>
<div class="message-time">
{{ formatTime(convo.lastMessage?.createdAt || convo.createdAt) }}
</div>
</div> </div>
<div class="last-message-row"> <div v-else-if="error" class="error-container">
<div class="last-message"> <div class="error-text">{{ error }}</div>
{{
convo.lastMessage ? stripMarkdownLength(convo.lastMessage.content, 100) : '暂无消息'
}}
</div>
<div v-if="convo.unreadCount > 0" class="unread-count-badge">
{{ convo.unreadCount }}
</div>
</div> </div>
</div>
</div>
</div>
<div v-else> <div v-if="!loading && !isFloatMode" class="search-container">
<div v-if="loadingChannels" class="loading-message"> <SearchPersonDropdown />
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch> </div>
</div>
<div v-else> <div v-if="!loading && conversations.length === 0" class="empty-container">
<div v-if="channels.length === 0" class="empty-container"> <BasePlaceholder
<BasePlaceholder text="暂无频道" icon="fas fa-inbox" /> v-if="conversations.length === 0"
</div> text="暂无会话"
<div icon="fas fa-inbox"
v-for="ch in channels"
:key="ch.id"
class="conversation-item"
@click="goToChannel(ch.id)"
>
<div class="conversation-avatar">
<BaseImage
:src="ch.avatar || '/default-avatar.svg'"
:alt="ch.name"
class="avatar-img"
@error="handleAvatarError"
/> />
</div> </div>
<div class="conversation-content">
<div class="conversation-header"> <div
<div class="participant-name"> v-if="!loading"
{{ ch.name }} v-for="convo in conversations"
<span v-if="ch.unreadCount > 0" class="unread-dot"></span> :key="convo.id"
</div> class="conversation-item"
<div class="message-time"> @click="goToConversation(convo.id)"
{{ formatTime(ch.lastMessage?.createdAt || ch.createdAt) }} >
</div> <div class="conversation-avatar">
<BaseImage
:src="getOtherParticipant(convo)?.avatar || '/default-avatar.svg'"
:alt="getOtherParticipant(convo)?.username || '用户'"
class="avatar-img"
@error="handleAvatarError"
/>
</div> </div>
<div class="last-message-row">
<div class="last-message"> <div class="conversation-content">
{{ <div class="conversation-header">
ch.lastMessage ? stripMarkdownLength(ch.lastMessage.content, 100) : ch.description <div class="participant-name">
}} {{ getOtherParticipant(convo)?.username || '未知用户' }}
</div>
<div class="message-time">
{{ formatTime(convo.lastMessage?.createdAt || convo.createdAt) }}
</div>
</div>
<div class="last-message-row">
<div class="last-message">
{{
convo.lastMessage
? stripMarkdownLength(convo.lastMessage.content, 100)
: '暂无消息'
}}
</div>
<div v-if="convo.unreadCount > 0" class="unread-count-badge">
{{ convo.unreadCount }}
</div>
</div> </div>
<div class="member-count">成员 {{ ch.memberCount }}</div>
</div> </div>
</div> </div>
</div> </div>
</div> <div v-else>
</div> <div v-if="loadingChannels" class="loading-message">
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
</div>
<div v-else>
<div v-if="channels.length === 0" class="empty-container">
<BasePlaceholder text="暂无频道" icon="fas fa-inbox" />
</div>
<div
v-for="ch in channels"
:key="ch.id"
class="conversation-item"
@click="goToChannel(ch.id)"
>
<div class="conversation-avatar">
<BaseImage
:src="ch.avatar || '/default-avatar.svg'"
:alt="ch.name"
class="avatar-img"
@error="handleAvatarError"
/>
</div>
<div class="conversation-content">
<div class="conversation-header">
<div class="participant-name">
{{ ch.name }}
<span v-if="ch.unreadCount > 0" class="unread-dot"></span>
</div>
<div class="message-time">
{{ formatTime(ch.lastMessage?.createdAt || ch.createdAt) }}
</div>
</div>
<div class="last-message-row">
<div class="last-message">
{{
ch.lastMessage
? stripMarkdownLength(ch.lastMessage.content, 100)
: ch.description
}}
</div>
<div class="member-count">成员 {{ ch.memberCount }}</div>
</div>
</div>
</div>
</div>
</div>
</template>
</MultiTabs>
</div> </div>
</template> </template>
@@ -147,6 +149,10 @@ const { fetchChannelUnread: refreshChannelUnread, setFromList: setChannelUnreadF
useChannelsUnreadCount() useChannelsUnreadCount()
let subscription = null let subscription = null
const tabs = [
{ name: 'messages', label: '站内信' },
{ name: 'channels', label: '频道' },
]
const activeTab = ref('channels') const activeTab = ref('channels')
const channels = ref([]) const channels = ref([])
const loadingChannels = ref(false) const loadingChannels = ref(false)
@@ -216,15 +222,13 @@ async function fetchChannels() {
} }
} }
function switchToMessage() { watch(activeTab, (val) => {
activeTab.value = 'messages' if (val === 'messages') {
fetchConversations() fetchConversations()
} } else {
fetchChannels()
function switchToChannels() { }
activeTab.value = 'channels' })
fetchChannels()
}
async function goToChannel(id) { async function goToChannel(id) {
const token = getToken() const token = getToken()

View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,177 +1,166 @@
<template> <template>
<div class="point-mall-page"> <div class="point-mall-page">
<div class="point-tabs"> <MultiTabs
<div :tabs="tabs"
:class="['point-tab-item', { selected: selectedTab === 'mall' }]" v-model="selectedTab"
@click="selectedTab = 'mall'" header-class="point-tabs"
> item-class="point-tab-item"
积分兑换 >
</div> <template #default="{ selected }">
<div <template v-if="selected === 'mall'">
:class="['point-tab-item', { selected: selectedTab === 'history' }]" <div class="point-mall-page-content">
@click="selectedTab = 'history'" <section class="rules">
> <div class="section-title">🎉 积分规则</div>
积分历史 <div class="section-content">
</div> <div class="section-item" v-for="(rule, idx) in pointRules" :key="idx">
</div> {{ rule }}
</div>
<template v-if="selectedTab === 'mall'"> </div>
<div class="point-mall-page-content"> </section>
<section class="rules"> <div class="loading-points-container" v-if="isLoading">
<div class="section-title">🎉 积分规则</div> <l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
<div class="section-content">
<div class="section-item" v-for="(rule, idx) in pointRules" :key="idx">{{ rule }}</div>
</div>
</section>
<div class="loading-points-container" v-if="isLoading">
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
</div>
<div class="point-info">
<p v-if="authState.loggedIn && point !== null">
<span><i class="fas fa-coins coin-icon"></i></span>我的积分<span
class="point-value"
>{{ point }}</span
>
</p>
</div>
<section class="goods">
<div class="goods-item" v-for="(good, idx) in goods" :key="idx">
<BaseImage class="goods-item-image" :src="good.image" alt="good.name" />
<div class="goods-item-name">{{ good.name }}</div>
<div class="goods-item-cost">
<i class="fas fa-coins"></i>
{{ good.cost }} 积分
</div> </div>
<div <div class="point-info">
class="goods-item-button" <p v-if="authState.loggedIn && point !== null">
:class="{ disabled: !authState.loggedIn || point === null || point < good.cost }" <span><i class="fas fa-coins coin-icon"></i></span>我的积分<span
@click="openRedeem(good)" class="point-value"
> >{{ point }}</span
兑换
</div>
</div>
</section>
<RedeemPopup
:visible="dialogVisible"
v-model="contact"
:loading="loading"
@close="closeRedeem"
@submit="submitRedeem"
/>
</div>
</template>
<template v-else>
<div class="loading-points-container" v-if="historyLoading">
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
</div>
<BasePlaceholder v-else-if="histories.length === 0" text="暂无积分记录" icon="fas fa-inbox" />
<div class="timeline-container" v-else>
<BaseTimeline :items="histories">
<template #item="{ item }">
<div class="history-content">
<template v-if="item.type === 'POST'">
发送帖子
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
item.postTitle
}}</NuxtLink>
获得{{ item.amount }}积分
</template>
<template v-else-if="item.type === 'COMMENT'">
在文章
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
item.postTitle
}}</NuxtLink>
<template v-if="!item.fromUserId">
发送评论
<NuxtLink
:to="`/posts/${item.postId}#comment-${item.commentId}`"
class="timeline-link"
>{{ stripMarkdownLength(item.commentContent, 100) }}</NuxtLink
>
获得{{ item.amount }}积分
</template>
<template v-else>
被评论
<NuxtLink
:to="`/posts/${item.postId}#comment-${item.commentId}`"
class="timeline-link"
>{{ stripMarkdownLength(item.commentContent, 100) }}</NuxtLink
>
获得{{ item.amount }}积分
</template>
</template>
<template v-else-if="item.type === 'POST_LIKED' && item.fromUserId">
帖子
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
item.postTitle
}}</NuxtLink>
<NuxtLink :to="`/users/${item.fromUserId}`" class="timeline-link">{{
item.fromUserName
}}</NuxtLink>
按赞获得{{ item.amount }}积分
</template>
<template v-else-if="item.type === 'COMMENT_LIKED' && item.fromUserId">
评论
<NuxtLink
:to="`/posts/${item.postId}#comment-${item.commentId}`"
class="timeline-link"
>{{ stripMarkdownLength(item.commentContent, 100) }}</NuxtLink
> >
</p>
<NuxtLink :to="`/users/${item.fromUserId}`" class="timeline-link">{{
item.fromUserName
}}</NuxtLink>
按赞获得{{ item.amount }}积分
</template>
<template v-else-if="item.type === 'INVITE' && item.fromUserId">
邀请了好友
<NuxtLink :to="`/users/${item.fromUserId}`" class="timeline-link">{{
item.fromUserName
}}</NuxtLink>
加入社区 🎉获得 {{ item.amount }} 积分
</template>
<template v-else-if="item.type === 'FEATURE'">
文章
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
item.postTitle
}}</NuxtLink>
被收录为精选获得 {{ item.amount }} 积分
</template>
<template v-else-if="item.type === 'REDEEM'">
兑换商品消耗 {{ -item.amount }} 积分
</template>
<template v-else-if="item.type === 'LOTTERY_JOIN'">
参与抽奖帖
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
item.postTitle
}}</NuxtLink>
消耗 {{ -item.amount }} 积分
</template>
<template v-else-if="item.type === 'LOTTERY_REWARD'">
你的抽奖帖
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
item.postTitle
}}</NuxtLink>
<NuxtLink :to="`/users/${item.fromUserId}`" class="timeline-link">{{
item.fromUserName
}}</NuxtLink>
参与获得 {{ item.amount }} 积分
</template>
<template v-else-if="item.type === 'SYSTEM_ONLINE'"> 积分历史系统上线 </template>
<i class="fas fa-coins"></i> 你目前的积分是 {{ item.balance }}
</div> </div>
<div class="history-time">{{ TimeManager.format(item.createdAt) }}</div> <section class="goods">
</template> <div class="goods-item" v-for="(good, idx) in goods" :key="idx">
</BaseTimeline> <BaseImage class="goods-item-image" :src="good.image" alt="good.name" />
</div> <div class="goods-item-name">{{ good.name }}</div>
</template> <div class="goods-item-cost">
<i class="fas fa-coins"></i>
{{ good.cost }} 积分
</div>
<div
class="goods-item-button"
:class="{ disabled: !authState.loggedIn || point === null || point < good.cost }"
@click="openRedeem(good)"
>
兑换
</div>
</div>
</section>
<RedeemPopup
:visible="dialogVisible"
v-model="contact"
:loading="loading"
@close="closeRedeem"
@submit="submitRedeem"
/>
</div>
</template>
<template v-else>
<div class="loading-points-container" v-if="historyLoading">
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
</div>
<BasePlaceholder
v-else-if="histories.length === 0"
text="暂无积分记录"
icon="fas fa-inbox"
/>
<div class="timeline-container" v-else>
<BaseTimeline :items="histories">
<template #item="{ item }">
<div class="history-content">
<template v-if="item.type === 'POST'">
发送帖子
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
item.postTitle
}}</NuxtLink>
获得{{ item.amount }}积分
</template>
<template v-else-if="item.type === 'COMMENT'">
在文章
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
item.postTitle
}}</NuxtLink>
<template v-if="!item.fromUserId">
发送评论
<NuxtLink
:to="`/posts/${item.postId}#comment-${item.commentId}`"
class="timeline-link"
>{{ stripMarkdownLength(item.commentContent, 100) }}</NuxtLink
>
获得{{ item.amount }}积分
</template>
<template v-else>
被评论
<NuxtLink
:to="`/posts/${item.postId}#comment-${item.commentId}`"
class="timeline-link"
>{{ stripMarkdownLength(item.commentContent, 100) }}</NuxtLink
>
获得{{ item.amount }}积分
</template>
</template>
<template v-else-if="item.type === 'POST_LIKED' && item.fromUserId">
帖子
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
item.postTitle
}}</NuxtLink>
<NuxtLink :to="`/users/${item.fromUserId}`" class="timeline-link">{{
item.fromUserName
}}</NuxtLink>
按赞获得{{ item.amount }}积分
</template>
<template v-else-if="item.type === 'COMMENT_LIKED' && item.fromUserId">
评论
<NuxtLink
:to="`/posts/${item.postId}#comment-${item.commentId}`"
class="timeline-link"
>{{ stripMarkdownLength(item.commentContent, 100) }}</NuxtLink
>
<NuxtLink :to="`/users/${item.fromUserId}`" class="timeline-link">{{
item.fromUserName
}}</NuxtLink>
按赞获得{{ item.amount }}积分
</template>
<template v-else-if="item.type === 'INVITE' && item.fromUserId">
邀请了好友
<NuxtLink :to="`/users/${item.fromUserId}`" class="timeline-link">{{
item.fromUserName
}}</NuxtLink>
加入社区 🎉获得 {{ item.amount }} 积分
</template>
<template v-else-if="item.type === 'FEATURE'">
文章
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
item.postTitle
}}</NuxtLink>
被收录为精选获得 {{ item.amount }} 积分
</template>
<template v-else-if="item.type === 'REDEEM'">
兑换商品消耗 {{ -item.amount }} 积分
</template>
<template v-else-if="item.type === 'LOTTERY_JOIN'">
参与抽奖帖
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
item.postTitle
}}</NuxtLink>
消耗 {{ -item.amount }} 积分
</template>
<template v-else-if="item.type === 'LOTTERY_REWARD'">
你的抽奖帖
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
item.postTitle
}}</NuxtLink>
被抽中消耗 {{ -item.amount }} 积分
</template>
</div>
</template>
</BaseTimeline>
</div>
</template>
</template>
</MultiTabs>
</div> </div>
</template> </template>
@@ -188,6 +177,11 @@ import TimeManager from '~/utils/time'
const config = useRuntimeConfig() const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl const API_BASE_URL = config.public.apiBaseUrl
const tabs = [
{ name: 'mall', label: '积分兑换' },
{ name: 'history', label: '积分历史' },
]
const selectedTab = ref('mall') const selectedTab = ref('mall')
const point = ref(null) const point = ref(null)
const isLoading = ref(false) const isLoading = ref(false)