Compare commits

...

1 Commits

Author SHA1 Message Date
Tim
2b28cb2ac1 feat: add reusable swipeable tabs component 2025-08-27 12:30:56 +08:00
6 changed files with 1083 additions and 1058 deletions

View File

@@ -0,0 +1,91 @@
<template>
<div class="base-tabs">
<div class="base-tabs-header">
<div class="base-tabs-items">
<div
v-for="tab in tabs"
:key="tab.key"
:class="['base-tabs-item', { selected: modelValue === tab.key }]"
@click="$emit('update:modelValue', tab.key)"
>
<i v-if="tab.icon" :class="tab.icon"></i>
<div class="base-tabs-item-label">{{ tab.label }}</div>
</div>
</div>
<div class="base-tabs-header-right">
<slot name="right"></slot>
</div>
</div>
<div class="base-tabs-content" @touchstart="onTouchStart" @touchend="onTouchEnd">
<slot></slot>
</div>
</div>
</template>
<script setup>
const props = defineProps({
modelValue: { type: String, required: true },
tabs: { type: Array, default: () => [] },
})
const emit = defineEmits(['update:modelValue'])
let touchStartX = 0
function onTouchStart(e) {
touchStartX = e.touches[0].clientX
}
function onTouchEnd(e) {
const diffX = e.changedTouches[0].clientX - touchStartX
if (Math.abs(diffX) > 50) {
const index = props.tabs.findIndex((t) => t.key === props.modelValue)
if (diffX < 0 && index < props.tabs.length - 1) {
emit('update:modelValue', props.tabs[index + 1].key)
} else if (diffX > 0 && index > 0) {
emit('update:modelValue', props.tabs[index - 1].key)
}
}
}
</script>
<style scoped>
.base-tabs-header {
display: flex;
border-bottom: 1px solid var(--normal-border-color);
align-items: center;
}
.base-tabs-items {
display: flex;
overflow-x: auto;
scrollbar-width: none;
flex: 1;
}
.base-tabs-item {
padding: 10px 20px;
cursor: pointer;
white-space: nowrap;
display: flex;
align-items: center;
}
.base-tabs-item i {
margin-right: 6px;
}
.base-tabs-item.selected {
color: var(--primary-color);
border-bottom: 2px solid var(--primary-color);
}
.base-tabs-header-right {
display: flex;
flex-shrink: 0;
}
.base-tabs-content {
width: 100%;
}
</style>

View File

@@ -1,30 +1,23 @@
<template> <template>
<div class="about-page"> <div class="about-page">
<div class="about-tabs"> <BaseTabs v-model="selectedTab" :tabs="tabs">
<div <div class="about-loading" v-if="isFetching">
v-for="tab in tabs" <l-hatch-spinner size="100" stroke="10" speed="1" color="var(--primary-color)" />
:key="tab.name"
:class="['about-tabs-item', { selected: selectedTab === tab.name }]"
@click="selectTab(tab.name)"
>
<div class="about-tabs-item-label">{{ tab.label }}</div>
</div> </div>
</div> <div
<div class="about-loading" v-if="isFetching"> v-else
<l-hatch-spinner size="100" stroke="10" speed="1" color="var(--primary-color)" /> class="about-content"
</div> v-html="renderMarkdown(content)"
<div @click="handleContentClick"
v-else ></div>
class="about-content" </BaseTabs>
v-html="renderMarkdown(content)"
@click="handleContentClick"
></div>
</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'
import BaseTabs from '~/components/BaseTabs.vue'
export default { export default {
name: 'AboutPageView', name: 'AboutPageView',
@@ -32,27 +25,27 @@ export default {
const isFetching = ref(false) const isFetching = ref(false)
const tabs = [ const tabs = [
{ {
name: 'about', key: 'about',
label: '关于', label: '关于',
file: 'https://openisle-1307107697.cos.ap-guangzhou.myqcloud.com/assert/about/about.md', file: 'https://openisle-1307107697.cos.ap-guangzhou.myqcloud.com/assert/about/about.md',
}, },
{ {
name: 'agreement', key: 'agreement',
label: '用户协议', label: '用户协议',
file: 'https://openisle-1307107697.cos.ap-guangzhou.myqcloud.com/assert/about/agreement.md', file: 'https://openisle-1307107697.cos.ap-guangzhou.myqcloud.com/assert/about/agreement.md',
}, },
{ {
name: 'guideline', key: 'guideline',
label: '创作准则', label: '创作准则',
file: 'https://openisle-1307107697.cos.ap-guangzhou.myqcloud.com/assert/about/guideline.md', file: 'https://openisle-1307107697.cos.ap-guangzhou.myqcloud.com/assert/about/guideline.md',
}, },
{ {
name: 'privacy', key: 'privacy',
label: '隐私政策', label: '隐私政策',
file: 'https://openisle-1307107697.cos.ap-guangzhou.myqcloud.com/assert/about/privacy.md', file: 'https://openisle-1307107697.cos.ap-guangzhou.myqcloud.com/assert/about/privacy.md',
}, },
] ]
const selectedTab = ref(tabs[0].name) const selectedTab = ref(tabs[0].key)
const content = ref('') const content = ref('')
const loadContent = async (file) => { const loadContent = async (file) => {
@@ -71,21 +64,20 @@ export default {
} }
} }
const selectTab = (name) => {
selectedTab.value = name
const tab = tabs.find((t) => t.name === name)
if (tab) loadContent(tab.file)
}
onMounted(() => { onMounted(() => {
loadContent(tabs[0].file) loadContent(tabs[0].file)
}) })
watch(selectedTab, (name) => {
const tab = tabs.find((t) => t.key === name)
if (tab) loadContent(tab.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>
@@ -97,7 +89,7 @@ export default {
margin: 0 auto; margin: 0 auto;
} }
.about-tabs { :deep(.base-tabs-header) {
top: calc(var(--header-height) + 1px); top: calc(var(--header-height) + 1px);
background-color: var(--background-color-blur); background-color: var(--background-color-blur);
display: flex; display: flex;
@@ -108,13 +100,13 @@ export default {
scrollbar-width: none; scrollbar-width: none;
} }
.about-tabs-item { :deep(.base-tabs-item) {
padding: 10px 20px; padding: 10px 20px;
cursor: pointer; cursor: pointer;
white-space: nowrap; white-space: nowrap;
} }
.about-tabs-item.selected { :deep(.base-tabs-item.selected) {
color: var(--primary-color); color: var(--primary-color);
border-bottom: 2px solid var(--primary-color); border-bottom: 2px solid var(--primary-color);
} }

View File

@@ -7,116 +7,113 @@
<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"> <BaseTabs v-model="activeTab" :tabs="tabs">
<div :class="['tab', { active: activeTab === 'messages' }]" @click="switchToMessage"> <div v-if="activeTab === 'messages'">
站内信 <div v-if="loading" class="loading-message">
</div> <l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
<div :class="['tab', { active: activeTab === 'channels' }]" @click="switchToChannels">
频道
</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>
<div class="conversation-content"> <div v-else-if="error" class="error-container">
<div class="conversation-header"> <div class="error-text">{{ error }}</div>
<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>
</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 v-else>
<div v-if="channels.length === 0" class="empty-container">
<BasePlaceholder text="暂无频道" icon="fas fa-inbox" />
</div> </div>
<div v-if="!loading && conversations.length === 0" class="empty-container">
<BasePlaceholder v-if="conversations.length === 0" text="暂无会话" icon="fas fa-inbox" />
</div>
<div <div
v-for="ch in channels" v-if="!loading"
:key="ch.id" v-for="convo in conversations"
:key="convo.id"
class="conversation-item" class="conversation-item"
@click="goToChannel(ch.id)" @click="goToConversation(convo.id)"
> >
<div class="conversation-avatar"> <div class="conversation-avatar">
<BaseImage <BaseImage
:src="ch.avatar || '/default-avatar.svg'" :src="getOtherParticipant(convo)?.avatar || '/default-avatar.svg'"
:alt="ch.name" :alt="getOtherParticipant(convo)?.username || '用户'"
class="avatar-img" class="avatar-img"
@error="handleAvatarError" @error="handleAvatarError"
/> />
</div> </div>
<div class="conversation-content"> <div class="conversation-content">
<div class="conversation-header"> <div class="conversation-header">
<div class="participant-name"> <div class="participant-name">
{{ ch.name }} {{ getOtherParticipant(convo)?.username || '未知用户' }}
<span v-if="ch.unreadCount > 0" class="unread-dot"></span>
</div> </div>
<div class="message-time"> <div class="message-time">
{{ formatTime(ch.lastMessage?.createdAt || ch.createdAt) }} {{ formatTime(convo.lastMessage?.createdAt || convo.createdAt) }}
</div> </div>
</div> </div>
<div class="last-message-row"> <div class="last-message-row">
<div class="last-message"> <div class="last-message">
{{ {{
ch.lastMessage ? stripMarkdownLength(ch.lastMessage.content, 100) : ch.description convo.lastMessage
? stripMarkdownLength(convo.lastMessage.content, 100)
: '暂无消息'
}} }}
</div> </div>
<div class="member-count">成员 {{ ch.memberCount }}</div> <div v-if="convo.unreadCount > 0" class="unread-count-badge">
{{ convo.unreadCount }}
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
</div>
<div v-else>
<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>
</BaseTabs>
</div> </div>
</template> </template>
@@ -132,6 +129,7 @@ import TimeManager from '~/utils/time'
import { stripMarkdownLength } from '~/utils/markdown' import { stripMarkdownLength } from '~/utils/markdown'
import SearchPersonDropdown from '~/components/SearchPersonDropdown.vue' import SearchPersonDropdown from '~/components/SearchPersonDropdown.vue'
import BasePlaceholder from '~/components/BasePlaceholder.vue' import BasePlaceholder from '~/components/BasePlaceholder.vue'
import BaseTabs from '~/components/BaseTabs.vue'
const config = useRuntimeConfig() const config = useRuntimeConfig()
const conversations = ref([]) const conversations = ref([])
@@ -148,6 +146,10 @@ const { fetchChannelUnread: refreshChannelUnread, setFromList: setChannelUnreadF
let subscription = null let subscription = null
const activeTab = ref('channels') const activeTab = ref('channels')
const tabs = [
{ key: 'messages', label: '站内信' },
{ key: 'channels', label: '频道' },
]
const channels = ref([]) const channels = ref([])
const loadingChannels = ref(false) const loadingChannels = ref(false)
const isFloatMode = computed(() => route.query.float === '1') const isFloatMode = computed(() => route.query.float === '1')
@@ -216,15 +218,13 @@ async function fetchChannels() {
} }
} }
function switchToMessage() { watch(activeTab, (tab) => {
activeTab.value = 'messages' if (tab === '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()
@@ -323,18 +323,18 @@ function minimize() {
cursor: pointer; cursor: pointer;
} }
.tabs { :deep(.base-tabs-header) {
display: flex; display: flex;
border-bottom: 1px solid var(--normal-border-color); border-bottom: 1px solid var(--normal-border-color);
margin-bottom: 16px; margin-bottom: 16px;
} }
.tab { :deep(.base-tabs-item) {
padding: 10px 20px; padding: 10px 20px;
cursor: pointer; cursor: pointer;
} }
.tab.active { :deep(.base-tabs-item.selected) {
border-bottom: 2px solid var(--primary-color); border-bottom: 2px solid var(--primary-color);
color: var(--primary-color); color: var(--primary-color);
} }
@@ -500,7 +500,7 @@ function minimize() {
display: block; display: block;
} }
.tabs, :deep(.base-tabs-header),
.loading-message, .loading-message,
.error-container, .error-container,
.search-container, .search-container,

View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,177 +1,170 @@
<template> <template>
<div class="point-mall-page"> <div class="point-mall-page">
<div class="point-tabs"> <BaseTabs v-model="selectedTab" :tabs="tabs">
<div <template v-if="selectedTab === 'mall'">
:class="['point-tab-item', { selected: selectedTab === 'mall' }]" <div class="point-mall-page-content">
@click="selectedTab = 'mall'" <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 }}
:class="['point-tab-item', { selected: selectedTab === 'history' }]" </div>
@click="selectedTab = 'history'" </div>
> </section>
积分历史
</div>
</div>
<template v-if="selectedTab === 'mall'"> <div class="loading-points-container" v-if="isLoading">
<div class="point-mall-page-content"> <l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
<section class="rules">
<div class="section-title">🎉 积分规则</div>
<div class="section-content">
<div class="section-item" v-for="(rule, idx) in pointRules" :key="idx">{{ rule }}</div>
</div> </div>
</section>
<div class="loading-points-container" v-if="isLoading"> <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
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> <l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch>
</div> </div>
<BasePlaceholder
<div class="point-info"> v-else-if="histories.length === 0"
<p v-if="authState.loggedIn && point !== null"> text="暂无积分记录"
<span><i class="fas fa-coins coin-icon"></i></span>我的积分<span icon="fas fa-inbox"
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
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> <div class="timeline-container" v-else>
</template> <BaseTimeline :items="histories">
<template #item="{ item }">
<template v-else> <div class="history-content">
<div class="loading-points-container" v-if="historyLoading"> <template v-if="item.type === 'POST'">
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)"></l-hatch> 发送帖子
</div> <NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
<BasePlaceholder v-else-if="histories.length === 0" text="暂无积分记录" icon="fas fa-inbox" /> item.postTitle
<div class="timeline-container" v-else> }}</NuxtLink>
<BaseTimeline :items="histories"> 获得{{ item.amount }}积分
<template #item="{ item }"> </template>
<div class="history-content"> <template v-else-if="item.type === 'COMMENT'">
<template v-if="item.type === 'POST'"> 在文章
发送帖子 <NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{ item.postTitle
item.postTitle }}</NuxtLink>
}}</NuxtLink>
获得{{ item.amount }}积分 <template v-if="!item.fromUserId">
</template> 发送评论
<template v-else-if="item.type === 'COMMENT'"> <NuxtLink
在文章 :to="`/posts/${item.postId}#comment-${item.commentId}`"
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{ class="timeline-link"
item.postTitle >{{ stripMarkdownLength(item.commentContent, 100) }}</NuxtLink
}}</NuxtLink> >
获得{{ item.amount }}积分
<template v-if="!item.fromUserId"> </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 <NuxtLink
:to="`/posts/${item.postId}#comment-${item.commentId}`" :to="`/posts/${item.postId}#comment-${item.commentId}`"
class="timeline-link" class="timeline-link"
>{{ stripMarkdownLength(item.commentContent, 100) }}</NuxtLink >{{ stripMarkdownLength(item.commentContent, 100) }}</NuxtLink
> >
获得{{ item.amount }}积分
<NuxtLink :to="`/users/${item.fromUserId}`" class="timeline-link">{{
item.fromUserName
}}</NuxtLink>
按赞获得{{ item.amount }}积分
</template> </template>
<template v-else> <template v-else-if="item.type === 'INVITE' && item.fromUserId">
被评论 邀请了好友
<NuxtLink <NuxtLink :to="`/users/${item.fromUserId}`" class="timeline-link">{{
:to="`/posts/${item.postId}#comment-${item.commentId}`" item.fromUserName
class="timeline-link" }}</NuxtLink>
>{{ stripMarkdownLength(item.commentContent, 100) }}</NuxtLink 加入社区 🎉获得 {{ item.amount }} 积分
>
获得{{ item.amount }}积分
</template> </template>
</template> <template v-else-if="item.type === 'FEATURE'">
<template v-else-if="item.type === 'POST_LIKED' && item.fromUserId"> 文章
帖子 <NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{ item.postTitle
item.postTitle }}</NuxtLink>
}}</NuxtLink> 被收录为精选获得 {{ item.amount }} 积分
</template>
<NuxtLink :to="`/users/${item.fromUserId}`" class="timeline-link">{{ <template v-else-if="item.type === 'REDEEM'">
item.fromUserName 兑换商品消耗 {{ -item.amount }} 积分
}}</NuxtLink> </template>
按赞获得{{ item.amount }}积分 <template v-else-if="item.type === 'LOTTERY_JOIN'">
</template> 参与抽奖帖
<template v-else-if="item.type === 'COMMENT_LIKED' && item.fromUserId"> <NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
评论 item.postTitle
<NuxtLink }}</NuxtLink>
:to="`/posts/${item.postId}#comment-${item.commentId}`" 消耗 {{ -item.amount }} 积分
class="timeline-link" </template>
>{{ stripMarkdownLength(item.commentContent, 100) }}</NuxtLink <template v-else-if="item.type === 'LOTTERY_REWARD'">
> 你的抽奖帖
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{
<NuxtLink :to="`/users/${item.fromUserId}`" class="timeline-link">{{ item.postTitle
item.fromUserName }}</NuxtLink>
}}</NuxtLink>
按赞获得{{ item.amount }}积分 <NuxtLink :to="`/users/${item.fromUserId}`" class="timeline-link">{{
</template> item.fromUserName
<template v-else-if="item.type === 'INVITE' && item.fromUserId"> }}</NuxtLink>
邀请了好友 参与获得 {{ item.amount }} 积分
<NuxtLink :to="`/users/${item.fromUserId}`" class="timeline-link">{{ </template>
item.fromUserName <template v-else-if="item.type === 'SYSTEM_ONLINE'"> 积分历史系统上线 </template>
}}</NuxtLink> <i class="fas fa-coins"></i> 你目前的积分是 {{ item.balance }}
加入社区 🎉获得 {{ item.amount }} 积分 </div>
</template> <div class="history-time">{{ TimeManager.format(item.createdAt) }}</div>
<template v-else-if="item.type === 'FEATURE'"> </template>
文章 </BaseTimeline>
<NuxtLink :to="`/posts/${item.postId}`" class="timeline-link">{{ </div>
item.postTitle </template>
}}</NuxtLink> </BaseTabs>
被收录为精选获得 {{ 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 class="history-time">{{ TimeManager.format(item.createdAt) }}</div>
</template>
</BaseTimeline>
</div>
</template>
</div> </div>
</template> </template>
@@ -184,11 +177,16 @@ import BaseTimeline from '~/components/BaseTimeline.vue'
import BasePlaceholder from '~/components/BasePlaceholder.vue' import BasePlaceholder from '~/components/BasePlaceholder.vue'
import { stripMarkdownLength } from '~/utils/markdown' import { stripMarkdownLength } from '~/utils/markdown'
import TimeManager from '~/utils/time' import TimeManager from '~/utils/time'
import BaseTabs from '~/components/BaseTabs.vue'
const config = useRuntimeConfig() const config = useRuntimeConfig()
const API_BASE_URL = config.public.apiBaseUrl const API_BASE_URL = config.public.apiBaseUrl
const selectedTab = ref('mall') const selectedTab = ref('mall')
const tabs = [
{ key: 'mall', label: '积分兑换' },
{ key: 'history', label: '积分历史' },
]
const point = ref(null) const point = ref(null)
const isLoading = ref(false) const isLoading = ref(false)
const histories = ref([]) const histories = ref([])
@@ -315,17 +313,17 @@ const submitRedeem = async () => {
padding: 0 20px; padding: 0 20px;
} }
.point-tabs { :deep(.base-tabs-header) {
display: flex; display: flex;
border-bottom: 1px solid var(--normal-border-color); border-bottom: 1px solid var(--normal-border-color);
} }
.point-tab-item { :deep(.base-tabs-item) {
padding: 10px 15px; padding: 10px 15px;
cursor: pointer; cursor: pointer;
} }
.point-tab-item.selected { :deep(.base-tabs-item.selected) {
border-bottom: 2px solid var(--primary-color); border-bottom: 2px solid var(--primary-color);
color: var(--primary-color); color: var(--primary-color);
} }

View File

@@ -72,282 +72,246 @@
</div> </div>
</div> </div>
<div class="profile-tabs"> <BaseTabs v-model="selectedTab" :tabs="tabs">
<div <div v-if="tabLoading" class="tab-loading">
:class="['profile-tabs-item', { selected: selectedTab === 'summary' }]" <l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)" />
@click="selectedTab = 'summary'"
>
<i class="fas fa-chart-line"></i>
<div class="profile-tabs-item-label">总结</div>
</div> </div>
<div <template v-else>
:class="['profile-tabs-item', { selected: selectedTab === 'timeline' }]" <div v-if="selectedTab === 'summary'" class="profile-summary">
@click="selectedTab = 'timeline'" <div class="total-summary">
> <div class="summary-title">统计信息</div>
<i class="fas fa-clock"></i> <div class="total-summary-content">
<div class="profile-tabs-item-label">时间线</div> <div class="total-summary-item">
</div> <div class="total-summary-item-label">访问天数</div>
<div <div class="total-summary-item-value">{{ user.visitedDays }}</div>
:class="['profile-tabs-item', { selected: selectedTab === 'following' }]" </div>
@click="selectedTab = 'following'" <div class="total-summary-item">
> <div class="total-summary-item-label">已读帖子</div>
<i class="fas fa-user-plus"></i> <div class="total-summary-item-value">{{ user.readPosts }}</div>
<div class="profile-tabs-item-label">关注</div> </div>
</div> <div class="total-summary-item">
<div <div class="total-summary-item-label">已送出的💗</div>
:class="['profile-tabs-item', { selected: selectedTab === 'favorites' }]" <div class="total-summary-item-value">{{ user.likesSent }}</div>
@click="selectedTab = 'favorites'" </div>
> <div class="total-summary-item">
<i class="fas fa-bookmark"></i> <div class="total-summary-item-label">已收到的💗</div>
<div class="profile-tabs-item-label">收藏</div> <div class="total-summary-item-value">{{ user.likesReceived }}</div>
</div> </div>
<div
:class="['profile-tabs-item', { selected: selectedTab === 'achievements' }]"
@click="selectedTab = 'achievements'"
>
<i class="fas fa-medal"></i>
<div class="profile-tabs-item-label">勋章</div>
</div>
</div>
<div v-if="tabLoading" class="tab-loading">
<l-hatch size="28" stroke="4" speed="3.5" color="var(--primary-color)" />
</div>
<template v-else>
<div v-if="selectedTab === 'summary'" class="profile-summary">
<div class="total-summary">
<div class="summary-title">统计信息</div>
<div class="total-summary-content">
<div class="total-summary-item">
<div class="total-summary-item-label">访问天数</div>
<div class="total-summary-item-value">{{ user.visitedDays }}</div>
</div> </div>
<div class="total-summary-item"> </div>
<div class="total-summary-item-label">已读帖子</div> <div class="summary-divider">
<div class="total-summary-item-value">{{ user.readPosts }}</div> <div class="hot-reply">
<div class="summary-title">热门回复</div>
<div class="summary-content" v-if="hotReplies.length > 0">
<BaseTimeline :items="hotReplies">
<template #item="{ item }">
<NuxtLink :to="`/posts/${item.comment.post.id}`" class="timeline-link">
{{ item.comment.post.title }}
</NuxtLink>
<template v-if="item.comment.parentComment">
下对
<NuxtLink
:to="`/posts/${item.comment.post.id}#comment-${item.comment.parentComment.id}`"
class="timeline-link"
>
{{ stripMarkdownLength(item.comment.parentComment.content, 200) }}
</NuxtLink>
回复了
</template>
<template v-else> 下评论了 </template>
<NuxtLink
:to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`"
class="timeline-link"
>
{{ stripMarkdownLength(item.comment.content, 200) }}
</NuxtLink>
<div class="timeline-date">
{{ formatDate(item.comment.createdAt) }}
</div>
</template>
</BaseTimeline>
</div>
<div v-else>
<div class="summary-empty">暂无热门回复</div>
</div>
</div> </div>
<div class="total-summary-item"> <div class="hot-topic">
<div class="total-summary-item-label">已送出的💗</div> <div class="summary-title">热门话题</div>
<div class="total-summary-item-value">{{ user.likesSent }}</div> <div class="summary-content" v-if="hotPosts.length > 0">
<BaseTimeline :items="hotPosts">
<template #item="{ item }">
<NuxtLink :to="`/posts/${item.post.id}`" class="timeline-link">
{{ item.post.title }}
</NuxtLink>
<div class="timeline-snippet">
{{ stripMarkdown(item.post.snippet) }}
</div>
<div class="timeline-date">
{{ formatDate(item.post.createdAt) }}
</div>
</template>
</BaseTimeline>
</div>
<div v-else>
<div class="summary-empty">暂无热门话题</div>
</div>
</div> </div>
<div class="total-summary-item"> <div class="hot-tag">
<div class="total-summary-item-label">已收到的💗</div> <div class="summary-title">TA创建的tag</div>
<div class="total-summary-item-value">{{ user.likesReceived }}</div> <div class="summary-content" v-if="hotTags.length > 0">
<BaseTimeline :items="hotTags">
<template #item="{ item }">
<span class="timeline-link" @click="gotoTag(item.tag)">
{{ item.tag.name }}<span v-if="item.tag.count"> x{{ item.tag.count }}</span>
</span>
<div class="timeline-snippet" v-if="item.tag.description">
{{ item.tag.description }}
</div>
<div class="timeline-date">
{{ formatDate(item.tag.createdAt) }}
</div>
</template>
</BaseTimeline>
</div>
<div v-else>
<div class="summary-empty">暂无标签</div>
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="summary-divider">
<div class="hot-reply"> <div v-else-if="selectedTab === 'timeline'" class="profile-timeline">
<div class="summary-title">热门回复</div> <div class="timeline-tabs">
<div class="summary-content" v-if="hotReplies.length > 0"> <div
<BaseTimeline :items="hotReplies"> :class="['timeline-tab-item', { selected: timelineFilter === 'all' }]"
<template #item="{ item }"> @click="timelineFilter = 'all'"
>
全部
</div>
<div
:class="['timeline-tab-item', { selected: timelineFilter === 'articles' }]"
@click="timelineFilter = 'articles'"
>
文章
</div>
<div
:class="['timeline-tab-item', { selected: timelineFilter === 'comments' }]"
@click="timelineFilter = 'comments'"
>
评论和回复
</div>
</div>
<BasePlaceholder
v-if="filteredTimelineItems.length === 0"
text="暂无时间线"
icon="fas fa-inbox"
/>
<div class="timeline-list">
<BaseTimeline :items="filteredTimelineItems">
<template #item="{ item }">
<template v-if="item.type === 'post'">
发布了文章
<NuxtLink :to="`/posts/${item.post.id}`" class="timeline-link">
{{ item.post.title }}
</NuxtLink>
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
</template>
<template v-else-if="item.type === 'comment'">
<NuxtLink :to="`/posts/${item.comment.post.id}`" class="timeline-link"> <NuxtLink :to="`/posts/${item.comment.post.id}`" class="timeline-link">
{{ item.comment.post.title }} {{ item.comment.post.title }}
</NuxtLink> </NuxtLink>
<template v-if="item.comment.parentComment"> 下评论了
下对
<NuxtLink
:to="`/posts/${item.comment.post.id}#comment-${item.comment.parentComment.id}`"
class="timeline-link"
>
{{ stripMarkdownLength(item.comment.parentComment.content, 200) }}
</NuxtLink>
回复了
</template>
<template v-else> 下评论了 </template>
<NuxtLink <NuxtLink
:to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`" :to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`"
class="timeline-link" class="timeline-link"
> >
{{ stripMarkdownLength(item.comment.content, 200) }} {{ stripMarkdownLength(item.comment.content, 200) }}
</NuxtLink> </NuxtLink>
<div class="timeline-date"> <div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
{{ formatDate(item.comment.createdAt) }}
</div>
</template> </template>
</BaseTimeline> <template v-else-if="item.type === 'reply'">
</div>
<div v-else> <NuxtLink :to="`/posts/${item.comment.post.id}`" class="timeline-link">
<div class="summary-empty">暂无热门回复</div> {{ item.comment.post.title }}
</div>
</div>
<div class="hot-topic">
<div class="summary-title">热门话题</div>
<div class="summary-content" v-if="hotPosts.length > 0">
<BaseTimeline :items="hotPosts">
<template #item="{ item }">
<NuxtLink :to="`/posts/${item.post.id}`" class="timeline-link">
{{ item.post.title }}
</NuxtLink> </NuxtLink>
<div class="timeline-snippet"> 下对
{{ stripMarkdown(item.post.snippet) }} <NuxtLink
</div> :to="`/posts/${item.comment.post.id}#comment-${item.comment.parentComment.id}`"
<div class="timeline-date"> class="timeline-link"
{{ formatDate(item.post.createdAt) }} >
</div> {{ stripMarkdownLength(item.comment.parentComment.content, 200) }}
</NuxtLink>
回复了
<NuxtLink
:to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`"
class="timeline-link"
>
{{ stripMarkdownLength(item.comment.content, 200) }}
</NuxtLink>
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
</template> </template>
</BaseTimeline> <template v-else-if="item.type === 'tag'">
</div> 创建了标签
<div v-else>
<div class="summary-empty">暂无热门话题</div>
</div>
</div>
<div class="hot-tag">
<div class="summary-title">TA创建的tag</div>
<div class="summary-content" v-if="hotTags.length > 0">
<BaseTimeline :items="hotTags">
<template #item="{ item }">
<span class="timeline-link" @click="gotoTag(item.tag)"> <span class="timeline-link" @click="gotoTag(item.tag)">
{{ item.tag.name }}<span v-if="item.tag.count"> x{{ item.tag.count }}</span> {{ item.tag.name }}<span v-if="item.tag.count"> x{{ item.tag.count }}</span>
</span> </span>
<div class="timeline-snippet" v-if="item.tag.description"> <div class="timeline-snippet" v-if="item.tag.description">
{{ item.tag.description }} {{ item.tag.description }}
</div> </div>
<div class="timeline-date"> <div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
{{ formatDate(item.tag.createdAt) }}
</div>
</template> </template>
</BaseTimeline> </template>
</div> </BaseTimeline>
<div v-else>
<div class="summary-empty">暂无标签</div>
</div>
</div> </div>
</div> </div>
</div>
<div v-else-if="selectedTab === 'timeline'" class="profile-timeline"> <div v-else-if="selectedTab === 'following'" class="follow-container">
<div class="timeline-tabs"> <div class="follow-tabs">
<div <div
:class="['timeline-tab-item', { selected: timelineFilter === 'all' }]" :class="['follow-tab-item', { selected: followTab === 'followers' }]"
@click="timelineFilter = 'all'" @click="followTab = 'followers'"
> >
全部 关注者
</div>
<div
:class="['follow-tab-item', { selected: followTab === 'following' }]"
@click="followTab = 'following'"
>
正在关注
</div>
</div> </div>
<div <div class="follow-list">
:class="['timeline-tab-item', { selected: timelineFilter === 'articles' }]" <UserList v-if="followTab === 'followers'" :users="followers" />
@click="timelineFilter = 'articles'" <UserList v-else :users="followings" />
>
文章
</div>
<div
:class="['timeline-tab-item', { selected: timelineFilter === 'comments' }]"
@click="timelineFilter = 'comments'"
>
评论和回复
</div> </div>
</div> </div>
<BasePlaceholder
v-if="filteredTimelineItems.length === 0" <div v-else-if="selectedTab === 'favorites'" class="favorites-container">
text="暂无时间线" <div v-if="favoritePosts.length > 0">
icon="fas fa-inbox" <BaseTimeline :items="favoritePosts">
/> <template #item="{ item }">
<div class="timeline-list">
<BaseTimeline :items="filteredTimelineItems">
<template #item="{ item }">
<template v-if="item.type === 'post'">
发布了文章
<NuxtLink :to="`/posts/${item.post.id}`" class="timeline-link"> <NuxtLink :to="`/posts/${item.post.id}`" class="timeline-link">
{{ item.post.title }} {{ item.post.title }}
</NuxtLink> </NuxtLink>
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div> <div class="timeline-snippet">
</template> {{ stripMarkdown(item.post.snippet) }}
<template v-else-if="item.type === 'comment'">
<NuxtLink :to="`/posts/${item.comment.post.id}`" class="timeline-link">
{{ item.comment.post.title }}
</NuxtLink>
下评论了
<NuxtLink
:to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`"
class="timeline-link"
>
{{ stripMarkdownLength(item.comment.content, 200) }}
</NuxtLink>
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
</template>
<template v-else-if="item.type === 'reply'">
<NuxtLink :to="`/posts/${item.comment.post.id}`" class="timeline-link">
{{ item.comment.post.title }}
</NuxtLink>
下对
<NuxtLink
:to="`/posts/${item.comment.post.id}#comment-${item.comment.parentComment.id}`"
class="timeline-link"
>
{{ stripMarkdownLength(item.comment.parentComment.content, 200) }}
</NuxtLink>
回复了
<NuxtLink
:to="`/posts/${item.comment.post.id}#comment-${item.comment.id}`"
class="timeline-link"
>
{{ stripMarkdownLength(item.comment.content, 200) }}
</NuxtLink>
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div>
</template>
<template v-else-if="item.type === 'tag'">
创建了标签
<span class="timeline-link" @click="gotoTag(item.tag)">
{{ item.tag.name }}<span v-if="item.tag.count"> x{{ item.tag.count }}</span>
</span>
<div class="timeline-snippet" v-if="item.tag.description">
{{ item.tag.description }}
</div> </div>
<div class="timeline-date">{{ formatDate(item.createdAt) }}</div> <div class="timeline-date">{{ formatDate(item.post.createdAt) }}</div>
</template> </template>
</template> </BaseTimeline>
</BaseTimeline>
</div>
</div>
<div v-else-if="selectedTab === 'following'" class="follow-container">
<div class="follow-tabs">
<div
:class="['follow-tab-item', { selected: followTab === 'followers' }]"
@click="followTab = 'followers'"
>
关注者
</div> </div>
<div <div v-else>
:class="['follow-tab-item', { selected: followTab === 'following' }]" <BasePlaceholder text="暂无收藏文章" icon="fas fa-inbox" />
@click="followTab = 'following'"
>
正在关注
</div> </div>
</div> </div>
<div class="follow-list">
<UserList v-if="followTab === 'followers'" :users="followers" />
<UserList v-else :users="followings" />
</div>
</div>
<div v-else-if="selectedTab === 'favorites'" class="favorites-container"> <div v-else-if="selectedTab === 'achievements'" class="achievements-container">
<div v-if="favoritePosts.length > 0"> <AchievementList :medals="medals" :can-select="isMine" />
<BaseTimeline :items="favoritePosts">
<template #item="{ item }">
<NuxtLink :to="`/posts/${item.post.id}`" class="timeline-link">
{{ item.post.title }}
</NuxtLink>
<div class="timeline-snippet">
{{ stripMarkdown(item.post.snippet) }}
</div>
<div class="timeline-date">{{ formatDate(item.post.createdAt) }}</div>
</template>
</BaseTimeline>
</div> </div>
<div v-else> </template>
<BasePlaceholder text="暂无收藏文章" icon="fas fa-inbox" /> </BaseTabs>
</div>
</div>
<div v-else-if="selectedTab === 'achievements'" class="achievements-container">
<AchievementList :medals="medals" :can-select="isMine" />
</div>
</template>
</div> </div>
</div> </div>
</template> </template>
@@ -358,6 +322,7 @@ import { useRoute } from 'vue-router'
import AchievementList from '~/components/AchievementList.vue' import AchievementList from '~/components/AchievementList.vue'
import BasePlaceholder from '~/components/BasePlaceholder.vue' import BasePlaceholder from '~/components/BasePlaceholder.vue'
import BaseTimeline from '~/components/BaseTimeline.vue' import BaseTimeline from '~/components/BaseTimeline.vue'
import BaseTabs from '~/components/BaseTabs.vue'
import LevelProgress from '~/components/LevelProgress.vue' import LevelProgress from '~/components/LevelProgress.vue'
import UserList from '~/components/UserList.vue' import UserList from '~/components/UserList.vue'
import { toast } from '~/main' import { toast } from '~/main'
@@ -400,6 +365,13 @@ const selectedTab = ref(
? route.query.tab ? route.query.tab
: 'summary', : 'summary',
) )
const tabs = [
{ key: 'summary', label: '总结', icon: 'fas fa-chart-line' },
{ key: 'timeline', label: '时间线', icon: 'fas fa-clock' },
{ key: 'following', label: '关注', icon: 'fas fa-user-plus' },
{ key: 'favorites', label: '收藏', icon: 'fas fa-bookmark' },
{ key: 'achievements', label: '勋章', icon: 'fas fa-medal' },
]
const followTab = ref('followers') const followTab = ref('followers')
const levelInfo = computed(() => { const levelInfo = computed(() => {
@@ -796,7 +768,7 @@ watch(selectedTab, async (val) => {
font-size: 14px; font-size: 14px;
} }
.profile-tabs { :deep(.base-tabs-header) {
position: sticky; position: sticky;
top: calc(var(--header-height) + 1px); top: calc(var(--header-height) + 1px);
z-index: 200; z-index: 200;
@@ -810,7 +782,7 @@ watch(selectedTab, async (val) => {
backdrop-filter: var(--blur-10); backdrop-filter: var(--blur-10);
} }
.profile-tabs-item { :deep(.base-tabs-item) {
display: flex; display: flex;
flex: 0 0 auto; flex: 0 0 auto;
flex-direction: row; flex-direction: row;
@@ -823,7 +795,7 @@ watch(selectedTab, async (val) => {
white-space: nowrap; white-space: nowrap;
} }
.profile-tabs-item.selected { :deep(.base-tabs-item.selected) {
color: var(--primary-color); color: var(--primary-color);
border-bottom: 2px solid var(--primary-color); border-bottom: 2px solid var(--primary-color);
} }
@@ -982,7 +954,7 @@ watch(selectedTab, async (val) => {
height: 100px; height: 100px;
} }
.profile-tabs-item { :deep(.base-tabs-item) {
width: 100px; width: 100px;
} }