Compare commits

..

3 Commits

Author SHA1 Message Date
Tim
7701d359dc fix: 允许窗口收起 2025-08-25 20:35:33 +08:00
Tim
ffd9ef8a32 fix: 新增交互 2025-08-25 19:25:06 +08:00
Tim
36cd5ab171 Merge pull request #722 from nagisa77/codex/add-floating-window-support-for-message-box-a7msu4
feat: add floating message box window
2025-08-25 17:20:30 +08:00
4 changed files with 137 additions and 31 deletions

View File

@@ -1,8 +1,23 @@
<template>
<div v-if="floatRoute" class="message-float-window">
<div v-if="floatRoute" class="message-float-window" :style="{ height: floatHeight }">
<iframe :src="iframeSrc" frameborder="0"></iframe>
<div class="float-actions">
<i class="fas fa-expand" @click="expand"></i>
<i
class="fas fa-chevron-down"
v-if="floatHeight !== MINI_HEIGHT"
title="收起至 100px"
@click="collapseToMini"
></i>
<!-- 回弹60vh -->
<i
class="fas fa-chevron-up"
v-if="floatHeight !== DEFAULT_HEIGHT"
title="回弹至 60vh"
@click="reboundToDefault"
></i>
<!-- 全屏打开原有逻辑 -->
<i class="fas fa-expand" title="在页面中打开" @click="expand"></i>
</div>
</div>
</template>
@@ -10,17 +25,37 @@
<script setup>
const floatRoute = useState('messageFloatRoute')
const DEFAULT_HEIGHT = '60vh'
const MINI_HEIGHT = '45px'
const floatHeight = ref(DEFAULT_HEIGHT)
const iframeSrc = computed(() => {
if (!floatRoute.value) return ''
return floatRoute.value + (floatRoute.value.includes('?') ? '&' : '?') + 'float=1'
})
function collapseToMini() {
floatHeight.value = MINI_HEIGHT
}
function reboundToDefault() {
floatHeight.value = DEFAULT_HEIGHT
}
function expand() {
if (!floatRoute.value) return
const target = floatRoute.value
floatRoute.value = null
navigateTo(target)
}
// 当浮窗重新出现时,恢复默认高度
watch(
() => floatRoute.value,
(v) => {
if (v) floatHeight.value = DEFAULT_HEIGHT
},
)
</script>
<style scoped>
@@ -29,7 +64,7 @@ function expand() {
bottom: 0;
right: 0;
width: 400px;
height: 60vh;
/* 高度由内联样式绑定控制60vh / 100px */
max-height: 90vh;
background-color: var(--background-color);
border: 1px solid var(--normal-border-color);
@@ -37,6 +72,7 @@ function expand() {
z-index: 2000;
display: flex;
flex-direction: column;
transition: height 0.25s ease; /* 平滑过渡 */
}
.message-float-window iframe {
@@ -48,18 +84,18 @@ function expand() {
position: absolute;
top: 4px;
right: 8px;
padding: 12px;
display: flex;
gap: 10px;
}
.float-actions i {
cursor: pointer;
font-size: 14px;
opacity: 0.9;
}
@media (max-width: 480px) {
.message-float-window {
width: 100%;
right: 0;
left: 0;
height: 100vh;
}
.float-actions i:hover {
opacity: 1;
}
</style>

View File

@@ -125,6 +125,7 @@
<script setup>
import { computed, onMounted, onBeforeUnmount, nextTick, ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import ArticleCategory from '~/components/ArticleCategory.vue'
import ArticleTags from '~/components/ArticleTags.vue'
import CategorySelect from '~/components/CategorySelect.vue'

View File

@@ -2,15 +2,15 @@
<div class="chat-container" :class="{ float: isFloatMode }">
<div v-if="!loading" class="chat-header">
<div class="header-main">
<NuxtLink to="/message-box" class="back-button">
<div class="back-button" @click="goBack">
<i class="fas fa-arrow-left"></i>
</NuxtLink>
</div>
<h2 class="participant-name">
{{ isChannel ? conversationName : otherParticipant?.username }}
</h2>
</div>
<div v-if="!isFloatMode" class="header-actions" @click="minimize">
<i class="fas fa-window-minimize"></i>
<div v-if="!isFloatMode" class="float-control">
<i class="fas fa-compress" @click="minimize" title="最小化"></i>
</div>
</div>
@@ -415,12 +415,21 @@ function minimize() {
}
function openUser(id) {
if (isFloatMode.value && typeof window !== 'undefined') {
window.top.location.href = `/users/${id}`
if (isFloatMode.value) {
// 先不处理...
// navigateTo(`/users/${id}?float=1`)
} else {
navigateTo(`/users/${id}`, { replace: true })
}
}
function goBack() {
if (isFloatMode.value) {
navigateTo('/message-box?float=1')
} else {
navigateTo('/message-box')
}
}
</script>
<style scoped>
@@ -455,7 +464,16 @@ function openUser(id) {
align-items: center;
}
.header-actions i {
.float-control {
position: absolute;
top: 0;
right: 0;
text-align: right;
padding: 12px 12px;
cursor: pointer;
}
.float-control i {
cursor: pointer;
}
@@ -573,12 +591,6 @@ function openUser(id) {
color: var(--text-color-secondary);
}
@media (max-width: 768px) {
.messages-list {
padding: 10px;
}
}
.message-input-area {
margin-left: 10px;
margin-right: 10px;
@@ -619,4 +631,17 @@ function openUser(id) {
margin-left: 8px;
cursor: pointer;
}
@media (max-height: 200px) {
.messages-list,
.message-input-area {
display: none;
}
}
@media (max-width: 768px) {
.messages-list {
padding: 10px;
}
}
</style>

View File

@@ -1,7 +1,11 @@
<template>
<div class="messages-container">
<div class="page-title">
<i class="fas fa-comments"></i>
<span class="page-title-text">选择聊天</span>
</div>
<div v-if="!isFloatMode" class="float-control">
<i class="fas fa-window-minimize" @click="minimize"></i>
<i class="fas fa-compress" @click="minimize" title="最小化"></i>
</div>
<div class="tabs">
<div :class="['tab', { active: activeTab === 'messages' }]" @click="activeTab = 'messages'">
@@ -21,7 +25,7 @@
<div class="error-text">{{ error }}</div>
</div>
<div v-if="!loading" class="search-container">
<div v-if="!loading && !isFloatMode" class="search-container">
<SearchPersonDropdown />
</div>
@@ -146,8 +150,7 @@ let subscription = null
const activeTab = ref('messages')
const channels = ref([])
const loadingChannels = ref(false)
const route = useRoute()
const isFloatMode = computed(() => route.query.float !== undefined)
const isFloatMode = computed(() => route.query.float === '1')
const floatRoute = useState('messageFloatRoute')
async function fetchConversations() {
@@ -230,7 +233,11 @@ async function goToChannel(id) {
method: 'POST',
headers: { Authorization: `Bearer ${token}` },
})
navigateTo(`/message-box/${id}`)
if (isFloatMode.value) {
navigateTo(`/message-box/${id}?float=1`)
} else {
navigateTo(`/message-box/${id}`)
}
} catch (e) {
toast.error(e.message)
}
@@ -279,7 +286,11 @@ onUnmounted(() => {
})
function goToConversation(id) {
navigateTo(`/message-box/${id}`)
if (isFloatMode.value) {
navigateTo(`/message-box/${id}?float=1`)
} else {
navigateTo(`/message-box/${id}`)
}
}
function minimize() {
@@ -290,11 +301,15 @@ function minimize() {
<style scoped>
.messages-container {
position: relative;
}
.float-control {
position: absolute;
top: 0;
right: 0;
text-align: right;
padding: 8px 12px;
padding: 12px 12px;
}
.float-control i {
@@ -334,6 +349,21 @@ function minimize() {
margin-bottom: 24px;
}
.page-title {
padding: 12px;
display: none;
flex-direction: row;
gap: 10px;
}
.page-title-text {
margin-left: 10px;
}
.page-title-text:hover {
text-decoration: underline;
}
.messages-title {
font-size: 28px;
font-weight: 600;
@@ -458,7 +488,21 @@ function minimize() {
margin-left: 4px;
}
/* 响应式设计 */
@media (max-height: 200px) {
.page-title {
display: block;
}
.tabs,
.loading-message,
.error-container,
.search-container,
.empty-container,
.conversation-item {
display: none;
}
}
@media (max-width: 768px) {
.conversation-item {
margin-left: 10px;