Add frontend messaging experience

This commit is contained in:
leonincs
2026-04-26 15:47:17 +08:00
parent 0275ad7ea3
commit 624da23a1c
8 changed files with 944 additions and 331 deletions

View File

@@ -0,0 +1,10 @@
import { postJson } from './client'
import type { DirectMessage, ListMessagesResponse } from './types'
export function sendMessage(toId: number, content: string) {
return postJson<DirectMessage>('/message/send', { to_id: toId, content }, { authRequired: true })
}
export function listMessages(peerId: number) {
return postJson<ListMessagesResponse>('/message/list', { peer_id: peerId }, { authRequired: true })
}

View File

@@ -1,6 +1,19 @@
export type MessageResponse = { message: string } export type MessageResponse = { message: string }
export type TokenResponse = { token: string; refresh_token?: string; account_id?: number; username?: string } export type DirectMessage = {
id: number
from_id: number
to_id: number
content: string
is_read: boolean
created_at: string
}
export type ListMessagesResponse = {
messages: DirectMessage[]
}
export type TokenResponse = { token: string; refresh_token?: string; account_id?: number; username?: string }
export type Account = { export type Account = {
id: number id: number

View File

@@ -58,11 +58,12 @@ async function goSettings() {
<nav class="dy-nav"> <nav class="dy-nav">
<RouterLink class="dy-nav-link" to="/">推荐</RouterLink> <RouterLink class="dy-nav-link" to="/">推荐</RouterLink>
<RouterLink class="dy-nav-link" to="/hot">热榜</RouterLink> <RouterLink class="dy-nav-link" to="/hot">热榜</RouterLink>
<RouterLink class="dy-nav-link" to="/video">发布</RouterLink> <RouterLink class="dy-nav-link" to="/video">发布</RouterLink>
<RouterLink class="dy-nav-link" to="/account">账号</RouterLink> <RouterLink class="dy-nav-link" to="/account">账号</RouterLink>
<RouterLink class="dy-nav-link" to="/settings">设置</RouterLink> <RouterLink v-if="auth.isLoggedIn" class="dy-nav-link" to="/messages">私信</RouterLink>
</nav> <RouterLink class="dy-nav-link" to="/settings">设置</RouterLink>
</nav>
<div class="dy-aside-foot"> <div class="dy-aside-foot">
<div class="dy-user"> <div class="dy-user">
@@ -87,10 +88,18 @@ async function goSettings() {
<button class="dy-btn dy-btn-primary" type="button" @click="onSearch">搜索</button> <button class="dy-btn dy-btn-primary" type="button" @click="onSearch">搜索</button>
</div> </div>
<div class="dy-top-right"> <div class="dy-top-right">
<RouterLink class="dy-btn dy-btn-ghost" to="/video">+ 发布视频</RouterLink> <RouterLink class="dy-btn dy-btn-ghost" to="/video">+ 发布视频</RouterLink>
</div> </div>
</header> </header>
<nav class="dy-mobile-nav">
<RouterLink class="dy-mobile-link" to="/">推荐</RouterLink>
<RouterLink class="dy-mobile-link" to="/hot">热榜</RouterLink>
<RouterLink class="dy-mobile-link" to="/video">发布</RouterLink>
<RouterLink v-if="auth.isLoggedIn" class="dy-mobile-link" to="/messages">私信</RouterLink>
<RouterLink class="dy-mobile-link" to="/account">账号</RouterLink>
</nav>
<div class="dy-content" :class="props.full ? 'full' : 'padded'"> <div class="dy-content" :class="props.full ? 'full' : 'padded'">
<template v-if="props.full"> <template v-if="props.full">
@@ -109,57 +118,60 @@ async function goSettings() {
</template> </template>
<style scoped> <style scoped>
.dy-shell { .dy-shell {
height: 100vh; height: 100vh;
display: grid; display: grid;
grid-template-columns: 240px 1fr; grid-template-columns: 232px 1fr;
background: radial-gradient(1200px 900px at 20% -25%, rgba(254, 44, 85, 0.18), transparent 60%), background: transparent;
radial-gradient(900px 700px at 90% 10%, rgba(37, 244, 238, 0.12), transparent 55%), transparent; }
}
.dy-aside {
.dy-aside { border-right: 1px solid var(--border);
border-right: 1px solid rgba(255, 255, 255, 0.08); background: rgba(12, 16, 23, 0.78);
background: rgba(0, 0, 0, 0.35); backdrop-filter: blur(18px);
backdrop-filter: blur(16px); padding: 14px 12px;
padding: 14px 12px; display: flex;
display: flex; flex-direction: column;
flex-direction: column;
gap: 14px; gap: 14px;
} }
.dy-logo { .dy-logo {
font-weight: 900; font-weight: 900;
letter-spacing: 0.4px; letter-spacing: 0;
font-size: 18px; font-size: 18px;
padding: 10px 10px; padding: 10px 10px;
border-radius: 12px; border-radius: 8px;
background: rgba(255, 255, 255, 0.06); background: rgba(43, 161, 255, 0.1);
border: 1px solid rgba(255, 255, 255, 0.1); border: 1px solid rgba(43, 161, 255, 0.22);
} text-decoration: none;
}
.dy-nav { .dy-nav {
display: grid; display: grid;
gap: 8px; gap: 8px;
} }
.dy-nav-link { .dy-nav-link {
padding: 10px 10px; padding: 10px 10px;
border-radius: 12px; border-radius: 8px;
border: 1px solid transparent; border: 1px solid transparent;
background: rgba(255, 255, 255, 0.04); background: rgba(255, 255, 255, 0.04);
} color: rgba(246, 248, 251, 0.86);
text-decoration: none;
.dy-nav-link.router-link-active { }
border-color: rgba(254, 44, 85, 0.42);
background: rgba(254, 44, 85, 0.12); .dy-nav-link.router-link-active {
} border-color: rgba(43, 161, 255, 0.42);
background: rgba(43, 161, 255, 0.14);
color: rgba(246, 248, 251, 0.96);
}
.dy-aside-foot { .dy-aside-foot {
margin-top: auto; margin-top: auto;
display: grid; display: grid;
gap: 10px; gap: 10px;
padding-top: 12px; padding-top: 12px;
border-top: 1px solid rgba(255, 255, 255, 0.08); border-top: 1px solid var(--border);
} }
.dy-user { .dy-user {
@@ -181,14 +193,14 @@ async function goSettings() {
box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.14); box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.14);
} }
.dy-user-dot.bad { .dy-user-dot.bad {
background: rgba(254, 44, 85, 1); background: rgba(255, 93, 115, 1);
box-shadow: 0 0 0 3px rgba(254, 44, 85, 0.14); box-shadow: 0 0 0 3px rgba(255, 93, 115, 0.14);
} }
.dy-user-name { .dy-user-name {
font-size: 13px; font-size: 13px;
color: rgba(255, 255, 255, 0.86); color: var(--text);
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
@@ -199,12 +211,12 @@ async function goSettings() {
gap: 10px; gap: 10px;
} }
.dy-btn { .dy-btn {
appearance: none; appearance: none;
border: 1px solid rgba(255, 255, 255, 0.14); border: 1px solid var(--border);
background: rgba(255, 255, 255, 0.06); background: rgba(255, 255, 255, 0.06);
color: rgba(255, 255, 255, 0.9); color: var(--text);
border-radius: 12px; border-radius: 8px;
padding: 10px 12px; padding: 10px 12px;
cursor: pointer; cursor: pointer;
text-decoration: none; text-decoration: none;
@@ -219,19 +231,19 @@ async function goSettings() {
background: rgba(255, 255, 255, 0.1); background: rgba(255, 255, 255, 0.1);
} }
.dy-btn-primary { .dy-btn-primary {
border-color: rgba(254, 44, 85, 0.5); border-color: rgba(43, 161, 255, 0.5);
background: rgba(254, 44, 85, 0.16); background: rgba(43, 161, 255, 0.16);
} }
.dy-btn-primary:hover { .dy-btn-primary:hover {
background: rgba(254, 44, 85, 0.24); background: rgba(43, 161, 255, 0.24);
} }
.dy-btn-ghost { .dy-btn-ghost {
border-color: rgba(255, 255, 255, 0.14); border-color: var(--border);
background: rgba(0, 0, 0, 0.15); background: rgba(255, 255, 255, 0.045);
} }
.dy-main { .dy-main {
height: 100vh; height: 100vh;
@@ -240,11 +252,11 @@ async function goSettings() {
min-width: 0; min-width: 0;
} }
.dy-topbar { .dy-topbar {
height: 56px; height: 56px;
border-bottom: 1px solid rgba(255, 255, 255, 0.08); border-bottom: 1px solid var(--border);
background: rgba(0, 0, 0, 0.28); background: rgba(12, 16, 23, 0.68);
backdrop-filter: blur(16px); backdrop-filter: blur(18px);
display: grid; display: grid;
grid-template-columns: 180px 1fr 180px; grid-template-columns: 180px 1fr 180px;
gap: 12px; gap: 12px;
@@ -252,12 +264,12 @@ async function goSettings() {
padding: 0 14px; padding: 0 14px;
} }
.dy-tabs-hint { .dy-tabs-hint {
font-size: 12px; font-size: 12px;
color: rgba(255, 255, 255, 0.55); color: var(--muted);
text-transform: uppercase; text-transform: uppercase;
letter-spacing: 0.16em; letter-spacing: 0;
} }
.dy-search { .dy-search {
display: grid; display: grid;
@@ -269,20 +281,20 @@ async function goSettings() {
justify-self: center; justify-self: center;
} }
.dy-search-input { .dy-search-input {
width: 100%; width: 100%;
background: rgba(255, 255, 255, 0.06); background: rgba(255, 255, 255, 0.055);
border: 1px solid rgba(255, 255, 255, 0.12); border: 1px solid var(--border);
border-radius: 999px; border-radius: 8px;
color: rgba(255, 255, 255, 0.9); color: var(--text);
padding: 10px 14px; padding: 10px 14px;
outline: none; outline: none;
} }
.dy-search-input:focus { .dy-search-input:focus {
border-color: rgba(37, 244, 238, 0.42); border-color: rgba(43, 161, 255, 0.52);
box-shadow: 0 0 0 3px rgba(37, 244, 238, 0.14); box-shadow: 0 0 0 3px rgba(43, 161, 255, 0.14);
} }
.dy-top-right { .dy-top-right {
display: flex; display: flex;
@@ -298,25 +310,54 @@ async function goSettings() {
overflow: auto; overflow: auto;
} }
.dy-content.full { .dy-content.full {
overflow: hidden; overflow: hidden;
} }
@media (max-width: 900px) { .dy-mobile-nav {
.dy-shell { display: none;
}
@media (max-width: 900px) {
.dy-shell {
grid-template-columns: 1fr; grid-template-columns: 1fr;
} }
.dy-aside { .dy-aside {
display: none; display: none;
} }
.dy-topbar { .dy-topbar {
grid-template-columns: 1fr auto; grid-template-columns: 1fr;
} padding: 0 10px;
}
.dy-top-left { .dy-top-left {
display: none; display: none;
} }
.dy-top-right { .dy-top-right {
display: none; display: none;
} }
} .dy-mobile-nav {
</style> height: 48px;
display: grid;
grid-auto-flow: column;
grid-auto-columns: 1fr;
border-bottom: 1px solid var(--border);
background: rgba(12, 16, 23, 0.74);
backdrop-filter: blur(18px);
}
.dy-mobile-link {
display: grid;
place-items: center;
color: var(--muted);
font-size: 13px;
text-decoration: none;
border-bottom: 2px solid transparent;
}
.dy-mobile-link.router-link-active {
color: var(--text);
border-bottom-color: var(--primary);
}
.dy-search {
max-width: none;
}
}
</style>

View File

@@ -6,10 +6,11 @@ import VideoView from '../views/VideoView.vue'
import VideoDetailView from '../views/VideoDetailView.vue' import VideoDetailView from '../views/VideoDetailView.vue'
import AccountView from '../views/AccountView.vue' import AccountView from '../views/AccountView.vue'
import ChangePasswordView from '../views/ChangePasswordView.vue' import ChangePasswordView from '../views/ChangePasswordView.vue'
import RegisterView from '../views/RegisterView.vue' import RegisterView from '../views/RegisterView.vue'
import SettingsView from '../views/SettingsView.vue' import SettingsView from '../views/SettingsView.vue'
import UserProfileView from '../views/UserProfileView.vue' import UserProfileView from '../views/UserProfileView.vue'
import { useAuthStore } from '../stores/auth' import MessageView from '../views/MessageView.vue'
import { useAuthStore } from '../stores/auth'
const router = createRouter({ const router = createRouter({
history: createWebHistory(), history: createWebHistory(),
@@ -22,10 +23,12 @@ const router = createRouter({
{ path: '/account', name: 'account', component: AccountView }, { path: '/account', name: 'account', component: AccountView },
{ path: '/account/register', name: 'account-register', component: RegisterView }, { path: '/account/register', name: 'account-register', component: RegisterView },
{ path: '/account/change-password', name: 'account-change-password', component: ChangePasswordView }, { path: '/account/change-password', name: 'account-change-password', component: ChangePasswordView },
{ path: '/settings', name: 'settings', component: SettingsView, meta: { requiresAuth: true } }, { path: '/settings', name: 'settings', component: SettingsView, meta: { requiresAuth: true } },
{ path: '/u/:id', name: 'user-profile', component: UserProfileView, props: true }, { path: '/u/:id', name: 'user-profile', component: UserProfileView, props: true },
], { path: '/messages', name: 'message-list', component: MessageView, meta: { requiresAuth: true } },
}) { path: '/messages/:peerId', name: 'messages', component: MessageView, meta: { requiresAuth: true } },
],
})
router.beforeEach((to, _from, next) => { router.beforeEach((to, _from, next) => {
const auth = useAuthStore() const auth = useAuthStore()

View File

@@ -1,17 +1,19 @@
:root { :root {
color-scheme: dark; color-scheme: dark;
--bg: #0b0b0f; --bg: #0e1117;
--panel: rgba(255, 255, 255, 0.06); --bg-soft: #141922;
--panel-2: rgba(255, 255, 255, 0.1); --panel: rgba(22, 27, 37, 0.82);
--text: rgba(255, 255, 255, 0.92); --panel-2: rgba(35, 42, 55, 0.78);
--muted: rgba(255, 255, 255, 0.64); --text: rgba(246, 248, 251, 0.94);
--border: rgba(255, 255, 255, 0.12); --muted: rgba(205, 214, 226, 0.68);
--primary: #fe2c55; --border: rgba(155, 171, 195, 0.18);
--primary-2: #25f4ee; --primary: #2ba1ff;
--danger: #fe2c55; --primary-2: #22c55e;
--ok: #22c55e; --danger: #ff5d73;
font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, 'Apple Color Emoji', --ok: #22c55e;
'Segoe UI Emoji'; --shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, 'Apple Color Emoji',
'Segoe UI Emoji';
line-height: 1.5; line-height: 1.5;
font-synthesis: none; font-synthesis: none;
text-rendering: optimizeLegibility; text-rendering: optimizeLegibility;
@@ -25,55 +27,65 @@
box-sizing: border-box; box-sizing: border-box;
} }
/* Hide scrollbars globally (still scrollable). */ * {
* { scrollbar-width: thin;
scrollbar-width: none; /* Firefox */ scrollbar-color: rgba(155, 171, 195, 0.35) transparent;
-ms-overflow-style: none; /* IE/Edge legacy */ }
}
*::-webkit-scrollbar {
*::-webkit-scrollbar { width: 8px;
width: 0; height: 8px;
height: 0; }
}
*::-webkit-scrollbar-thumb {
html, background: rgba(155, 171, 195, 0.28);
body { border-radius: 999px;
height: 100%; }
}
*::-webkit-scrollbar-track {
body { background: transparent;
margin: 0; }
background: radial-gradient(1200px 900px at 20% -25%, rgba(254, 44, 85, 0.18), transparent 60%),
radial-gradient(900px 700px at 90% 10%, rgba(37, 244, 238, 0.12), transparent 55%), var(--bg); html,
color: var(--text); body {
} height: 100%;
}
body {
margin: 0;
background:
radial-gradient(1000px 720px at 10% -20%, rgba(43, 161, 255, 0.14), transparent 58%),
linear-gradient(180deg, #10141d 0%, var(--bg) 42%, #0b0e14 100%);
color: var(--text);
}
a { a {
color: inherit; color: inherit;
text-decoration: none; text-decoration: none;
} }
a:hover { a:hover {
text-decoration: underline; color: #dceeff;
} }
.container { .container {
max-width: 1100px; max-width: 1180px;
margin: 0 auto; margin: 0 auto;
padding: 24px 16px 56px; padding: 22px 18px 56px;
} }
.card { .card {
background: var(--panel); background: var(--panel);
border: 1px solid var(--border); border: 1px solid var(--border);
border-radius: 16px; border-radius: 8px;
padding: 16px; padding: 18px;
backdrop-filter: blur(10px); backdrop-filter: blur(14px);
} box-shadow: var(--shadow);
}
.card + .card {
margin-top: 14px; .card + .card {
} margin-top: 16px;
}
.grid { .grid {
display: grid; display: grid;
@@ -106,11 +118,12 @@ a:hover {
color: var(--muted); color: var(--muted);
} }
.title { .title {
font-size: 18px; font-size: 18px;
font-weight: 700; font-weight: 800;
margin: 0 0 6px; margin: 0 0 6px;
} letter-spacing: 0;
}
.subtle { .subtle {
font-size: 13px; font-size: 13px;
@@ -124,53 +137,56 @@ label {
margin-bottom: 6px; margin-bottom: 6px;
} }
input, input,
textarea, textarea,
select { select {
width: 100%; width: 100%;
background: rgba(255, 255, 255, 0.06); background: rgba(255, 255, 255, 0.055);
border: 1px solid var(--border); border: 1px solid var(--border);
border-radius: 12px; border-radius: 8px;
color: var(--text); color: var(--text);
padding: 10px 12px; padding: 11px 12px;
outline: none; outline: none;
} transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}
textarea { textarea {
min-height: 88px; min-height: 88px;
resize: vertical; resize: vertical;
} }
input:focus, input:focus,
textarea:focus, textarea:focus,
select:focus { select:focus {
border-color: rgba(124, 92, 255, 0.8); border-color: rgba(43, 161, 255, 0.72);
box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.22); box-shadow: 0 0 0 3px rgba(43, 161, 255, 0.18);
} background: rgba(255, 255, 255, 0.075);
}
button {
appearance: none; button {
border: 1px solid var(--border); appearance: none;
background: rgba(255, 255, 255, 0.08); border: 1px solid var(--border);
color: var(--text); background: rgba(255, 255, 255, 0.08);
border-radius: 12px; color: var(--text);
padding: 10px 14px; border-radius: 8px;
cursor: pointer; padding: 10px 14px;
transition: 120ms ease; cursor: pointer;
} transition: 120ms ease;
font: inherit;
}
button:hover { button:hover {
background: rgba(255, 255, 255, 0.12); background: rgba(255, 255, 255, 0.12);
} }
button.primary { button.primary {
border-color: rgba(254, 44, 85, 0.55); border-color: rgba(43, 161, 255, 0.55);
background: rgba(254, 44, 85, 0.18); background: rgba(43, 161, 255, 0.18);
} }
button.primary:hover { button.primary:hover {
background: rgba(254, 44, 85, 0.26); background: rgba(43, 161, 255, 0.26);
} }
button.danger { button.danger {
border-color: rgba(255, 77, 109, 0.65); border-color: rgba(255, 77, 109, 0.65);
@@ -186,12 +202,12 @@ button:disabled {
cursor: not-allowed; cursor: not-allowed;
} }
.pill { .pill {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
gap: 8px; gap: 8px;
padding: 6px 10px; padding: 6px 10px;
border-radius: 999px; border-radius: 8px;
border: 1px solid var(--border); border: 1px solid var(--border);
background: rgba(255, 255, 255, 0.06); background: rgba(255, 255, 255, 0.06);
font-size: 13px; font-size: 13px;
@@ -211,14 +227,28 @@ button:disabled {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
} }
.pre { .pre {
white-space: pre-wrap; white-space: pre-wrap;
word-break: break-word; word-break: break-word;
font-size: 13px; font-size: 13px;
line-height: 1.45; line-height: 1.45;
background: rgba(0, 0, 0, 0.25); background: rgba(0, 0, 0, 0.25);
border: 1px solid rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 12px; border-radius: 8px;
padding: 12px; padding: 12px;
margin: 0; margin: 0;
} }
@media (max-width: 760px) {
.container {
padding: 14px 12px 76px;
}
.card {
padding: 14px;
}
.row {
gap: 8px;
}
}

View File

@@ -349,23 +349,23 @@ watch(
width: min(420px, 100%); width: min(420px, 100%);
} }
.ghost { .ghost {
border: 1px solid rgba(255, 255, 255, 0.14); border: 1px solid var(--border);
background: rgba(0, 0, 0, 0.18); background: rgba(255, 255, 255, 0.055);
color: rgba(255, 255, 255, 0.86); color: var(--text);
border-radius: 12px; border-radius: 8px;
padding: 10px 12px; padding: 10px 12px;
cursor: pointer; cursor: pointer;
} }
.ghost:hover { .ghost:hover {
background: rgba(255, 255, 255, 0.1); background: rgba(255, 255, 255, 0.1);
} }
.metric { .metric {
border: 1px solid rgba(255, 255, 255, 0.12); border: 1px solid var(--border);
background: rgba(255, 255, 255, 0.06); background: rgba(255, 255, 255, 0.06);
border-radius: 16px; border-radius: 8px;
padding: 12px 14px; padding: 12px 14px;
min-width: 120px; min-width: 120px;
cursor: pointer; cursor: pointer;
@@ -378,10 +378,10 @@ watch(
background: rgba(255, 255, 255, 0.1); background: rgba(255, 255, 255, 0.1);
} }
.metric.active { .metric.active {
background: rgba(254, 44, 85, 0.14); background: rgba(43, 161, 255, 0.14);
border-color: rgba(254, 44, 85, 0.55); border-color: rgba(43, 161, 255, 0.55);
} }
.metric.static { .metric.static {
cursor: default; cursor: default;
@@ -398,18 +398,18 @@ watch(
letter-spacing: 0.2px; letter-spacing: 0.2px;
} }
.metric-label { .metric-label {
font-size: 12px; font-size: 12px;
color: rgba(255, 255, 255, 0.65); color: var(--muted);
} }
.hint { .hint {
color: rgba(255, 255, 255, 0.78); color: var(--muted);
} }
.hint.bad { .hint.bad {
color: rgba(254, 44, 85, 0.92); color: var(--danger);
} }
.drawer-backdrop { .drawer-backdrop {
position: fixed; position: fixed;
@@ -423,12 +423,12 @@ watch(
padding: 16px; padding: 16px;
} }
.drawer { .drawer {
width: min(520px, calc(100vw - 18px)); width: min(520px, calc(100vw - 18px));
max-height: min(78vh, 720px); max-height: min(78vh, 720px);
background: rgba(0, 0, 0, 0.65); background: rgba(13, 18, 29, 0.92);
border: 1px solid rgba(255, 255, 255, 0.12); border: 1px solid var(--border);
border-radius: 18px; border-radius: 8px;
overflow: hidden; overflow: hidden;
display: grid; display: grid;
grid-template-rows: auto 1fr; grid-template-rows: auto 1fr;
@@ -439,7 +439,7 @@ watch(
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
padding: 14px 14px; padding: 14px 14px;
border-bottom: 1px solid rgba(255, 255, 255, 0.1); border-bottom: 1px solid var(--border);
} }
.drawer-title { .drawer-title {
@@ -449,8 +449,8 @@ watch(
.drawer-x { .drawer-x {
width: 34px; width: 34px;
height: 34px; height: 34px;
border-radius: 12px; border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.14); border: 1px solid var(--border);
background: rgba(255, 255, 255, 0.06); background: rgba(255, 255, 255, 0.06);
color: rgba(255, 255, 255, 0.9); color: rgba(255, 255, 255, 0.9);
cursor: pointer; cursor: pointer;
@@ -465,14 +465,14 @@ watch(
gap: 10px; gap: 10px;
} }
.drawer-hint { .drawer-hint {
color: rgba(255, 255, 255, 0.78); color: var(--muted);
padding: 12px 0; padding: 12px 0;
} }
.drawer-hint.bad { .drawer-hint.bad {
color: rgba(254, 44, 85, 0.92); color: var(--danger);
} }
.video-grid { .video-grid {
display: grid; display: grid;
@@ -492,10 +492,10 @@ watch(
} }
} }
.video-card { .video-card {
border: 1px solid rgba(255, 255, 255, 0.12); border: 1px solid var(--border);
background: rgba(255, 255, 255, 0.05); background: rgba(255, 255, 255, 0.05);
border-radius: 16px; border-radius: 8px;
overflow: hidden; overflow: hidden;
cursor: pointer; cursor: pointer;
padding: 0; padding: 0;
@@ -539,8 +539,8 @@ watch(
gap: 12px; gap: 12px;
align-items: center; align-items: center;
padding: 10px 10px; padding: 10px 10px;
border-radius: 14px; border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.1); border: 1px solid var(--border);
background: rgba(255, 255, 255, 0.05); background: rgba(255, 255, 255, 0.05);
cursor: pointer; cursor: pointer;
} }
@@ -557,10 +557,10 @@ watch(
font-weight: 800; font-weight: 800;
} }
.user-id { .user-id {
font-size: 12px; font-size: 12px;
color: rgba(255, 255, 255, 0.6); color: var(--muted);
} }
.mono { .mono {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;

503
frontend/src/views/MessageView.vue vendored Normal file
View File

@@ -0,0 +1,503 @@
<script setup lang="ts">
import { computed, nextTick, onMounted, reactive, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import AppShell from '../components/AppShell.vue'
import UserAvatar from '../components/UserAvatar.vue'
import { ApiError } from '../api/client'
import * as accountApi from '../api/account'
import * as messageApi from '../api/message'
import type { Account, DirectMessage } from '../api/types'
import { useAuthStore } from '../stores/auth'
import { useSocialStore } from '../stores/social'
import { useToastStore } from '../stores/toast'
const route = useRoute()
const router = useRouter()
const auth = useAuthStore()
const social = useSocialStore()
const toast = useToastStore()
const peerId = computed(() => {
const raw = route.params.peerId
return typeof raw === 'string' ? Number(raw) : 0
})
const myId = computed(() => auth.claims?.account_id ?? 0)
const hasPeer = computed(() => Number.isFinite(peerId.value) && peerId.value > 0)
const listEl = ref<HTMLDivElement | null>(null)
const content = ref('')
const state = reactive({
loading: false,
sending: false,
error: '',
peer: null as Account | null,
messages: [] as DirectMessage[],
})
const orderedMessages = computed(() => [...state.messages].sort((a, b) => new Date(a.created_at).getTime() - new Date(b.created_at).getTime()))
const canSend = computed(() => content.value.trim().length > 0 && !state.sending && !!state.peer && peerId.value > 0)
const contactItems = computed(() => {
const map = new Map<number, Account>()
for (const user of social.vloggers) map.set(user.id, user)
for (const user of social.followers) map.set(user.id, user)
return [...map.values()].filter((user) => user.id !== myId.value)
})
const contactLoading = computed(() => social.vloggersLoading || social.followersLoading)
const contactError = computed(() => social.vloggersError || social.followersError)
function formatTime(value: string) {
const date = new Date(value)
if (Number.isNaN(date.getTime())) return ''
return date.toLocaleString([], { month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit' })
}
async function scrollToBottom() {
await nextTick()
if (listEl.value) listEl.value.scrollTop = listEl.value.scrollHeight
}
async function loadChat() {
if (!auth.isLoggedIn) {
await router.push({ path: '/account', query: { redirect: route.fullPath } })
return
}
if (!hasPeer.value) {
await social.refreshMine()
state.loading = false
state.error = ''
state.peer = null
state.messages = []
return
}
if (!Number.isFinite(peerId.value) || peerId.value <= 0) {
state.error = '无效的用户 id'
return
}
if (peerId.value === myId.value) {
state.error = '请选择其他用户发送私信'
return
}
state.loading = true
state.error = ''
try {
const [peer, res] = await Promise.all([accountApi.findById(peerId.value), messageApi.listMessages(peerId.value)])
state.peer = peer
state.messages = res.messages ?? []
await scrollToBottom()
} catch (e) {
state.error = e instanceof ApiError ? e.message : String(e)
state.peer = null
state.messages = []
} finally {
state.loading = false
}
}
async function send() {
const text = content.value.trim()
if (!text || state.sending || !state.peer) return
state.sending = true
try {
const msg = await messageApi.sendMessage(peerId.value, text)
state.messages = [msg, ...state.messages]
content.value = ''
await scrollToBottom()
} catch (e) {
const msg = e instanceof ApiError ? e.message : String(e)
toast.error(msg)
} finally {
state.sending = false
}
}
async function goPeerProfile() {
if (state.peer) await router.push(`/u/${state.peer.id}`)
}
async function openChat(userId: number) {
await router.push(`/messages/${userId}`)
}
watch(
() => route.params.peerId,
() => {
state.peer = null
state.messages = []
content.value = ''
void loadChat()
},
)
onMounted(loadChat)
</script>
<template>
<AppShell>
<section class="chat-shell">
<div v-if="!hasPeer" class="contact-panel">
<div class="contact-head">
<div>
<p class="title">私信</p>
<p class="subtle">选择关注或粉丝里的用户开始聊天</p>
</div>
<button class="ghost small" type="button" :disabled="contactLoading" @click="social.refreshMine">刷新</button>
</div>
<div class="contact-body">
<div v-if="contactLoading" class="chat-hint">加载中</div>
<div v-else-if="contactError" class="chat-hint bad">{{ contactError }}</div>
<div v-else-if="contactItems.length === 0" class="empty">
<div class="empty-title">暂无可聊天用户</div>
<div class="empty-text">关注别人或拥有粉丝后可以从这里开始私信</div>
</div>
<button v-for="user in contactItems" :key="user.id" class="contact-row" type="button" @click="openChat(user.id)">
<UserAvatar :username="user.username" :id="user.id" :size="42" />
<span class="contact-meta">
<span class="contact-name">@{{ user.username }}</span>
<span class="contact-id mono">#{{ user.id }}</span>
</span>
<span class="contact-action">聊天</span>
</button>
</div>
</div>
<div v-else class="chat-panel">
<header class="chat-head">
<button class="icon-btn" type="button" title="返回" @click="router.back()"></button>
<button class="peer" type="button" :disabled="!state.peer" @click="goPeerProfile">
<UserAvatar :username="state.peer?.username ?? 'User'" :id="state.peer?.id ?? peerId" :size="44" />
<span class="peer-meta">
<span class="peer-name">@{{ state.peer?.username ?? '加载中' }}</span>
<span class="peer-id mono">#{{ state.peer?.id ?? peerId }}</span>
</span>
</button>
<button class="ghost small" type="button" :disabled="state.loading" @click="loadChat">刷新</button>
</header>
<div ref="listEl" class="message-list">
<div v-if="state.loading" class="chat-hint">加载中</div>
<div v-else-if="state.error" class="chat-hint bad">{{ state.error }}</div>
<div v-else-if="orderedMessages.length === 0" class="empty">
<div class="empty-title">开始聊天</div>
<div class="empty-text"> @{{ state.peer?.username ?? '对方' }} 发第一条消息</div>
</div>
<div
v-for="msg in orderedMessages"
:key="msg.id"
class="bubble-row"
:class="{ mine: msg.from_id === myId }"
>
<UserAvatar
v-if="msg.from_id !== myId"
:username="state.peer?.username ?? 'User'"
:id="state.peer?.id ?? msg.from_id"
:size="32"
/>
<div class="bubble-wrap">
<div class="bubble">{{ msg.content }}</div>
<div class="bubble-time">{{ formatTime(msg.created_at) }}</div>
</div>
</div>
</div>
<footer class="composer">
<textarea
v-model="content"
placeholder="输入私信内容"
:disabled="!!state.error || state.loading || state.sending"
@keydown.enter.exact.prevent="send"
/>
<button class="primary send-btn" type="button" :disabled="!canSend" @click="send">
{{ state.sending ? '发送中' : '发送' }}
</button>
</footer>
</div>
</section>
</AppShell>
</template>
<style scoped>
.chat-shell {
min-height: calc(100vh - 104px);
display: grid;
}
.contact-panel,
.chat-panel {
height: min(760px, calc(100vh - 136px));
min-height: 560px;
overflow: hidden;
border: 1px solid var(--border);
background: rgba(13, 18, 29, 0.78);
border-radius: 8px;
box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}
.contact-panel,
.chat-panel {
display: grid;
}
.contact-panel {
grid-template-rows: auto 1fr;
}
.chat-panel {
grid-template-rows: auto 1fr auto;
}
.contact-head,
.chat-head {
min-height: 68px;
display: grid;
gap: 10px;
align-items: center;
padding: 12px 14px;
border-bottom: 1px solid var(--border);
background: rgba(255, 255, 255, 0.035);
}
.contact-head {
grid-template-columns: 1fr auto;
}
.contact-head .title {
margin: 0 0 4px;
}
.chat-head {
grid-template-columns: auto 1fr auto;
}
.contact-body {
min-height: 0;
overflow: auto;
padding: 14px;
display: grid;
gap: 10px;
align-content: start;
}
.contact-row {
display: grid;
grid-template-columns: auto minmax(0, 1fr) auto;
gap: 12px;
align-items: center;
text-align: left;
padding: 10px;
border: 1px solid var(--border);
background: rgba(255, 255, 255, 0.05);
border-radius: 8px;
}
.contact-row:hover {
background: rgba(255, 255, 255, 0.08);
}
.contact-meta {
min-width: 0;
display: grid;
gap: 2px;
}
.contact-name {
font-weight: 800;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.contact-id,
.contact-action {
color: var(--muted);
font-size: 12px;
}
.contact-action {
color: rgba(190, 223, 255, 0.92);
}
.icon-btn {
width: 40px;
height: 40px;
padding: 0;
border-radius: 8px;
font-size: 28px;
line-height: 1;
}
.peer {
min-width: 0;
display: inline-grid;
grid-template-columns: auto minmax(0, 1fr);
gap: 10px;
align-items: center;
justify-self: start;
padding: 4px 8px 4px 4px;
border-radius: 8px;
background: transparent;
border-color: transparent;
text-align: left;
}
.peer:disabled {
opacity: 0.72;
cursor: default;
}
.peer-meta {
min-width: 0;
display: grid;
gap: 2px;
}
.peer-name {
font-weight: 800;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.peer-id {
color: var(--muted);
font-size: 12px;
}
.message-list {
min-height: 0;
overflow: auto;
padding: 18px 16px;
display: flex;
flex-direction: column;
gap: 12px;
}
.chat-hint {
margin: auto;
color: var(--muted);
}
.chat-hint.bad {
color: var(--danger);
}
.empty {
margin: auto;
text-align: center;
color: var(--muted);
}
.empty-title {
color: var(--text);
font-weight: 900;
margin-bottom: 6px;
}
.empty-text {
font-size: 13px;
}
.bubble-row {
display: grid;
grid-template-columns: auto minmax(0, 1fr);
gap: 10px;
align-items: end;
}
.bubble-row.mine {
grid-template-columns: minmax(0, 1fr);
justify-items: end;
}
.bubble-wrap {
max-width: min(68%, 560px);
display: grid;
gap: 4px;
}
.bubble {
padding: 10px 12px;
border: 1px solid rgba(255, 255, 255, 0.12);
background: rgba(255, 255, 255, 0.08);
border-radius: 8px;
line-height: 1.5;
white-space: pre-wrap;
word-break: break-word;
}
.mine .bubble {
border-color: rgba(43, 161, 255, 0.42);
background: rgba(43, 161, 255, 0.22);
}
.bubble-time {
color: var(--muted);
font-size: 11px;
}
.mine .bubble-time {
text-align: right;
}
.composer {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
gap: 10px;
align-items: end;
padding: 12px 14px;
border-top: 1px solid var(--border);
background: rgba(255, 255, 255, 0.035);
}
.composer textarea {
min-height: 44px;
max-height: 132px;
resize: vertical;
}
.send-btn {
min-width: 86px;
height: 44px;
}
.ghost.small {
padding: 8px 12px;
}
@media (max-width: 760px) {
.chat-shell {
min-height: calc(100vh - 56px);
}
.chat-panel {
min-height: calc(100vh - 92px);
height: calc(100vh - 92px);
}
.contact-panel {
min-height: calc(100vh - 92px);
height: calc(100vh - 92px);
}
.contact-head {
grid-template-columns: 1fr;
}
.bubble-wrap {
max-width: 86%;
}
.composer {
grid-template-columns: 1fr;
}
.send-btn {
width: 100%;
}
}
</style>

View File

@@ -82,9 +82,9 @@ async function loadSocialCounts() {
} }
} }
async function toggleFollow() { async function toggleFollow() {
if (isMe.value) return if (isMe.value) return
if (!auth.isLoggedIn) { if (!auth.isLoggedIn) {
toast.error('请先登录') toast.error('请先登录')
await router.push('/account') await router.push('/account')
return return
@@ -102,8 +102,18 @@ async function toggleFollow() {
} catch (e) { } catch (e) {
const msg = e instanceof ApiError ? e.message : String(e) const msg = e instanceof ApiError ? e.message : String(e)
toast.error(msg) toast.error(msg)
} }
} }
async function goMessage() {
if (isMe.value) return
if (!auth.isLoggedIn) {
toast.error('请先登录')
await router.push({ path: '/account', query: { redirect: route.fullPath } })
return
}
await router.push(`/messages/${userId.value}`)
}
type ListTab = 'followers' | 'following' type ListTab = 'followers' | 'following'
const drawer = reactive({ const drawer = reactive({
@@ -167,13 +177,16 @@ onMounted(loadProfile)
</div> </div>
</div> </div>
<div class="row"> <div class="row">
<button v-if="isMe" class="ghost" type="button" @click="router.push('/account')">我的账号</button> <button v-if="isMe" class="ghost" type="button" @click="router.push('/account')">我的账号</button>
<button v-else class="primary" type="button" :disabled="!state.user || state.loading" @click="toggleFollow"> <template v-else>
{{ isFollowing ? '已关注' : '关注' }} <button class="ghost" type="button" :disabled="!state.user || state.loading" @click="goMessage">私信</button>
</button> <button class="primary" type="button" :disabled="!state.user || state.loading" @click="toggleFollow">
</div> {{ isFollowing ? '已关注' : '关注' }}
</div> </button>
</template>
</div>
</div>
<div v-if="state.loading" class="hint" style="margin-top: 12px">加载中</div> <div v-if="state.loading" class="hint" style="margin-top: 12px">加载中</div>
<div v-else-if="state.error" class="hint bad" style="margin-top: 12px">{{ state.error }}</div> <div v-else-if="state.error" class="hint bad" style="margin-top: 12px">{{ state.error }}</div>
@@ -240,25 +253,25 @@ onMounted(loadProfile)
</template> </template>
<style scoped> <style scoped>
.ghost { .ghost {
border: 1px solid rgba(255, 255, 255, 0.14); border: 1px solid var(--border);
background: rgba(0, 0, 0, 0.18); background: rgba(255, 255, 255, 0.055);
color: rgba(255, 255, 255, 0.86); color: var(--text);
border-radius: 12px; border-radius: 8px;
padding: 10px 12px; padding: 10px 12px;
cursor: pointer; cursor: pointer;
} }
.ghost:hover { .ghost:hover {
background: rgba(255, 255, 255, 0.1); background: rgba(255, 255, 255, 0.1);
} }
.metric { .metric {
border: 1px solid rgba(255, 255, 255, 0.12); border: 1px solid var(--border);
background: rgba(255, 255, 255, 0.06); background: rgba(255, 255, 255, 0.06);
border-radius: 16px; border-radius: 8px;
padding: 12px 14px; padding: 12px 14px;
min-width: 120px; min-width: 120px;
cursor: pointer; cursor: pointer;
display: grid; display: grid;
gap: 4px; gap: 4px;
@@ -284,18 +297,18 @@ onMounted(loadProfile)
letter-spacing: 0.2px; letter-spacing: 0.2px;
} }
.metric-label { .metric-label {
font-size: 12px; font-size: 12px;
color: rgba(255, 255, 255, 0.65); color: var(--muted);
} }
.hint { .hint {
color: rgba(255, 255, 255, 0.78); color: var(--muted);
} }
.hint.bad { .hint.bad {
color: rgba(254, 44, 85, 0.92); color: var(--danger);
} }
.video-grid { .video-grid {
display: grid; display: grid;
@@ -315,10 +328,10 @@ onMounted(loadProfile)
} }
} }
.video-card { .video-card {
border: 1px solid rgba(255, 255, 255, 0.12); border: 1px solid var(--border);
background: rgba(255, 255, 255, 0.05); background: rgba(255, 255, 255, 0.05);
border-radius: 16px; border-radius: 8px;
overflow: hidden; overflow: hidden;
cursor: pointer; cursor: pointer;
padding: 0; padding: 0;
@@ -367,12 +380,12 @@ onMounted(loadProfile)
padding: 16px; padding: 16px;
} }
.drawer { .drawer {
width: min(520px, calc(100vw - 18px)); width: min(520px, calc(100vw - 18px));
max-height: min(78vh, 720px); max-height: min(78vh, 720px);
background: rgba(0, 0, 0, 0.65); background: rgba(13, 18, 29, 0.92);
border: 1px solid rgba(255, 255, 255, 0.12); border: 1px solid var(--border);
border-radius: 18px; border-radius: 8px;
overflow: hidden; overflow: hidden;
display: grid; display: grid;
grid-template-rows: auto 1fr; grid-template-rows: auto 1fr;
@@ -383,7 +396,7 @@ onMounted(loadProfile)
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
padding: 14px 14px; padding: 14px 14px;
border-bottom: 1px solid rgba(255, 255, 255, 0.1); border-bottom: 1px solid var(--border);
} }
.drawer-title { .drawer-title {
@@ -393,8 +406,8 @@ onMounted(loadProfile)
.drawer-x { .drawer-x {
width: 34px; width: 34px;
height: 34px; height: 34px;
border-radius: 12px; border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.14); border: 1px solid var(--border);
background: rgba(255, 255, 255, 0.06); background: rgba(255, 255, 255, 0.06);
color: rgba(255, 255, 255, 0.9); color: rgba(255, 255, 255, 0.9);
cursor: pointer; cursor: pointer;
@@ -409,14 +422,14 @@ onMounted(loadProfile)
gap: 10px; gap: 10px;
} }
.drawer-hint { .drawer-hint {
color: rgba(255, 255, 255, 0.78); color: var(--muted);
padding: 12px 0; padding: 12px 0;
} }
.drawer-hint.bad { .drawer-hint.bad {
color: rgba(254, 44, 85, 0.92); color: var(--danger);
} }
.user-row { .user-row {
text-align: left; text-align: left;
@@ -425,8 +438,8 @@ onMounted(loadProfile)
gap: 12px; gap: 12px;
align-items: center; align-items: center;
padding: 10px 10px; padding: 10px 10px;
border-radius: 14px; border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.1); border: 1px solid var(--border);
background: rgba(255, 255, 255, 0.05); background: rgba(255, 255, 255, 0.05);
cursor: pointer; cursor: pointer;
} }
@@ -443,10 +456,10 @@ onMounted(loadProfile)
font-weight: 800; font-weight: 800;
} }
.user-id { .user-id {
font-size: 12px; font-size: 12px;
color: rgba(255, 255, 255, 0.6); color: var(--muted);
} }
.mono { .mono {
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;