style: 统一代码格式和行尾
This commit is contained in:
1036
frontend/src/views/AccountView.vue
vendored
1036
frontend/src/views/AccountView.vue
vendored
File diff suppressed because it is too large
Load Diff
144
frontend/src/views/ChangePasswordView.vue
vendored
144
frontend/src/views/ChangePasswordView.vue
vendored
@@ -1,72 +1,72 @@
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
import AppShell from '../components/AppShell.vue'
|
||||
import { ApiError } from '../api/client'
|
||||
import * as accountApi from '../api/account'
|
||||
import { useToastStore } from '../stores/toast'
|
||||
|
||||
const router = useRouter()
|
||||
const toast = useToastStore()
|
||||
|
||||
const busy = ref(false)
|
||||
const form = reactive({ username: '', oldPassword: '', newPassword: '' })
|
||||
|
||||
async function submit() {
|
||||
if (busy.value) return
|
||||
const username = form.username.trim()
|
||||
const oldPassword = form.oldPassword.trim()
|
||||
const newPassword = form.newPassword.trim()
|
||||
if (!username || !oldPassword || !newPassword) {
|
||||
toast.error('请把信息填完整')
|
||||
return
|
||||
}
|
||||
|
||||
busy.value = true
|
||||
try {
|
||||
await accountApi.changePassword(username, oldPassword, newPassword)
|
||||
toast.success('密码已修改,请重新登录')
|
||||
await router.push('/account')
|
||||
} catch (e) {
|
||||
const msg = e instanceof ApiError ? e.message : String(e)
|
||||
toast.error(msg)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppShell>
|
||||
<div class="grid two">
|
||||
<div class="card">
|
||||
<p class="title">修改密码</p>
|
||||
<p class="subtle">不需要登录(对应后端 `/account/changePassword`)。</p>
|
||||
<div class="grid" style="margin-top: 12px">
|
||||
<div>
|
||||
<label>username</label>
|
||||
<input v-model.trim="form.username" autocomplete="username" />
|
||||
</div>
|
||||
<div>
|
||||
<label>old_password</label>
|
||||
<input v-model.trim="form.oldPassword" type="password" autocomplete="current-password" />
|
||||
</div>
|
||||
<div>
|
||||
<label>new_password</label>
|
||||
<input v-model.trim="form.newPassword" type="password" autocomplete="new-password" />
|
||||
</div>
|
||||
<div class="row" style="justify-content: flex-end">
|
||||
<button class="primary" type="button" :disabled="busy" @click="submit">提交</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<p class="title">提示</p>
|
||||
<p class="muted">改密成功后后端会让旧 token 失效;请在「账号」页重新登录。</p>
|
||||
</div>
|
||||
</div>
|
||||
</AppShell>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
import AppShell from '../components/AppShell.vue'
|
||||
import { ApiError } from '../api/client'
|
||||
import * as accountApi from '../api/account'
|
||||
import { useToastStore } from '../stores/toast'
|
||||
|
||||
const router = useRouter()
|
||||
const toast = useToastStore()
|
||||
|
||||
const busy = ref(false)
|
||||
const form = reactive({ username: '', oldPassword: '', newPassword: '' })
|
||||
|
||||
async function submit() {
|
||||
if (busy.value) return
|
||||
const username = form.username.trim()
|
||||
const oldPassword = form.oldPassword.trim()
|
||||
const newPassword = form.newPassword.trim()
|
||||
if (!username || !oldPassword || !newPassword) {
|
||||
toast.error('请把信息填完整')
|
||||
return
|
||||
}
|
||||
|
||||
busy.value = true
|
||||
try {
|
||||
await accountApi.changePassword(username, oldPassword, newPassword)
|
||||
toast.success('密码已修改,请重新登录')
|
||||
await router.push('/account')
|
||||
} catch (e) {
|
||||
const msg = e instanceof ApiError ? e.message : String(e)
|
||||
toast.error(msg)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppShell>
|
||||
<div class="grid two">
|
||||
<div class="card">
|
||||
<p class="title">修改密码</p>
|
||||
<p class="subtle">不需要登录(对应后端 `/account/changePassword`)。</p>
|
||||
<div class="grid" style="margin-top: 12px">
|
||||
<div>
|
||||
<label>username</label>
|
||||
<input v-model.trim="form.username" autocomplete="username" />
|
||||
</div>
|
||||
<div>
|
||||
<label>old_password</label>
|
||||
<input v-model.trim="form.oldPassword" type="password" autocomplete="current-password" />
|
||||
</div>
|
||||
<div>
|
||||
<label>new_password</label>
|
||||
<input v-model.trim="form.newPassword" type="password" autocomplete="new-password" />
|
||||
</div>
|
||||
<div class="row" style="justify-content: flex-end">
|
||||
<button class="primary" type="button" :disabled="busy" @click="submit">提交</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<p class="title">提示</p>
|
||||
<p class="muted">改密成功后后端会让旧 token 失效;请在「账号」页重新登录。</p>
|
||||
</div>
|
||||
</div>
|
||||
</AppShell>
|
||||
</template>
|
||||
|
||||
|
||||
524
frontend/src/views/FeedView.vue
vendored
524
frontend/src/views/FeedView.vue
vendored
@@ -1,262 +1,262 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, watch } from 'vue'
|
||||
|
||||
import AppShell from '../components/AppShell.vue'
|
||||
import JsonBox from '../components/JsonBox.vue'
|
||||
import FeedVideoCard from '../components/FeedVideoCard.vue'
|
||||
import { ApiError } from '../api/client'
|
||||
import * as feedApi from '../api/feed'
|
||||
import * as likeApi from '../api/like'
|
||||
import type { FeedVideoItem } from '../api/types'
|
||||
import { useAuthStore } from '../stores/auth'
|
||||
|
||||
const auth = useAuthStore()
|
||||
|
||||
type ListState = {
|
||||
loading: boolean
|
||||
error: string
|
||||
items: FeedVideoItem[]
|
||||
has_more: boolean
|
||||
}
|
||||
|
||||
const latest = reactive<ListState & { limit: number; next_time: number }>({
|
||||
loading: false,
|
||||
error: '',
|
||||
items: [],
|
||||
has_more: false,
|
||||
limit: 10,
|
||||
next_time: 0,
|
||||
})
|
||||
|
||||
const likesCount = reactive<ListState & { limit: number; next_likes_count_before?: number; next_id_before?: number }>({
|
||||
loading: false,
|
||||
error: '',
|
||||
items: [],
|
||||
has_more: false,
|
||||
limit: 10,
|
||||
next_likes_count_before: undefined,
|
||||
next_id_before: undefined,
|
||||
})
|
||||
|
||||
const following = reactive<ListState & { limit: number; next_time: number }>({
|
||||
loading: false,
|
||||
error: '',
|
||||
items: [],
|
||||
has_more: false,
|
||||
limit: 10,
|
||||
next_time: 0,
|
||||
})
|
||||
|
||||
const action = reactive<{ loading: boolean; error: string; payload: unknown; name: string }>({
|
||||
loading: false,
|
||||
error: '',
|
||||
payload: null,
|
||||
name: '',
|
||||
})
|
||||
|
||||
const canLike = computed(() => auth.isLoggedIn)
|
||||
|
||||
async function runAction(name: string, fn: () => Promise<unknown>) {
|
||||
action.name = name
|
||||
action.loading = true
|
||||
action.error = ''
|
||||
action.payload = null
|
||||
try {
|
||||
action.payload = await fn()
|
||||
} catch (e) {
|
||||
action.error = e instanceof ApiError ? e.message : String(e)
|
||||
action.payload = e instanceof ApiError ? e.payload : null
|
||||
} finally {
|
||||
action.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadLatest(reset: boolean) {
|
||||
latest.loading = true
|
||||
latest.error = ''
|
||||
try {
|
||||
const latest_time = reset ? 0 : latest.next_time
|
||||
const res = await feedApi.listLatest({ limit: latest.limit, latest_time })
|
||||
latest.has_more = res.has_more
|
||||
latest.next_time = res.next_time
|
||||
latest.items = reset ? res.video_list : latest.items.concat(res.video_list)
|
||||
} catch (e) {
|
||||
latest.error = e instanceof ApiError ? e.message : String(e)
|
||||
} finally {
|
||||
latest.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadLikesCount(reset: boolean) {
|
||||
likesCount.loading = true
|
||||
likesCount.error = ''
|
||||
try {
|
||||
const res = await feedApi.listLikesCount({
|
||||
limit: likesCount.limit,
|
||||
likes_count_before: reset ? undefined : likesCount.next_likes_count_before,
|
||||
id_before: reset ? undefined : likesCount.next_id_before,
|
||||
})
|
||||
likesCount.has_more = res.has_more
|
||||
likesCount.next_likes_count_before = res.next_likes_count_before
|
||||
likesCount.next_id_before = res.next_id_before
|
||||
likesCount.items = reset ? res.video_list : likesCount.items.concat(res.video_list)
|
||||
} catch (e) {
|
||||
likesCount.error = e instanceof ApiError ? e.message : String(e)
|
||||
} finally {
|
||||
likesCount.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadFollowing(reset: boolean) {
|
||||
following.loading = true
|
||||
following.error = ''
|
||||
try {
|
||||
const latest_time = reset ? 0 : following.next_time
|
||||
const res = await feedApi.listByFollowing({ limit: following.limit, latest_time })
|
||||
following.has_more = res.has_more
|
||||
following.next_time = res.next_time
|
||||
following.items = reset ? res.video_list : following.items.concat(res.video_list)
|
||||
} catch (e) {
|
||||
following.error = e instanceof ApiError ? e.message : String(e)
|
||||
} finally {
|
||||
following.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleLike(item: FeedVideoItem) {
|
||||
if (!auth.isLoggedIn) return
|
||||
|
||||
await runAction(item.is_liked ? '取消点赞' : '点赞', async () => {
|
||||
if (item.is_liked) await likeApi.unlike(item.id)
|
||||
else await likeApi.like(item.id)
|
||||
|
||||
item.is_liked = !item.is_liked
|
||||
item.likes_count = Math.max(0, item.likes_count + (item.is_liked ? 1 : -1))
|
||||
return { ok: true, is_liked: item.is_liked, likes_count: item.likes_count }
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadLatest(true)
|
||||
await loadLikesCount(true)
|
||||
if (auth.isLoggedIn) {
|
||||
await loadFollowing(true)
|
||||
}
|
||||
})
|
||||
|
||||
watch(
|
||||
() => auth.isLoggedIn,
|
||||
async (v) => {
|
||||
if (v && following.items.length === 0) {
|
||||
await loadFollowing(true)
|
||||
}
|
||||
},
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppShell>
|
||||
<div class="grid two">
|
||||
<div class="card">
|
||||
<p class="title">Feed</p>
|
||||
<p class="subtle">`/feed/listLatest` 与 `/feed/listLikesCount` 支持匿名(可选 JWT);`/feed/listByFollowing` 需要 JWT。</p>
|
||||
|
||||
<div class="card" style="margin-top: 12px">
|
||||
<div class="row" style="justify-content: space-between">
|
||||
<div>
|
||||
<p class="title">最新流(listLatest)</p>
|
||||
<div class="subtle">limit:{{ latest.limit }} · next_time:{{ latest.next_time }} · has_more:{{ latest.has_more }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label class="subtle" style="margin: 0">limit</label>
|
||||
<input v-model.number="latest.limit" type="number" min="1" max="50" style="width: 90px" />
|
||||
<button class="primary" type="button" :disabled="latest.loading" @click="loadLatest(true)">刷新</button>
|
||||
<button type="button" :disabled="latest.loading || !latest.has_more" @click="loadLatest(false)">加载更多</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="latest.error" class="pill bad" style="margin-top: 10px">错误:{{ latest.error }}</div>
|
||||
<div class="grid" style="gap: 10px; margin-top: 12px">
|
||||
<FeedVideoCard
|
||||
v-for="item in latest.items"
|
||||
:key="`latest-${item.id}`"
|
||||
:item="item"
|
||||
:can-like="canLike"
|
||||
:busy="action.loading"
|
||||
@toggle-like="toggleLike"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-top: 12px">
|
||||
<div class="row" style="justify-content: space-between">
|
||||
<div>
|
||||
<p class="title">点赞数流(listLikesCount)</p>
|
||||
<div class="subtle">
|
||||
limit:{{ likesCount.limit }} · next=(likes={{ likesCount.next_likes_count_before }}, id={{ likesCount.next_id_before }})
|
||||
· has_more:{{ likesCount.has_more }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label class="subtle" style="margin: 0">limit</label>
|
||||
<input v-model.number="likesCount.limit" type="number" min="1" max="50" style="width: 90px" />
|
||||
<button class="primary" type="button" :disabled="likesCount.loading" @click="loadLikesCount(true)">刷新</button>
|
||||
<button type="button" :disabled="likesCount.loading || !likesCount.has_more" @click="loadLikesCount(false)">
|
||||
加载更多
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="likesCount.error" class="pill bad" style="margin-top: 10px">错误:{{ likesCount.error }}</div>
|
||||
<div class="grid" style="gap: 10px; margin-top: 12px">
|
||||
<FeedVideoCard
|
||||
v-for="item in likesCount.items"
|
||||
:key="`likes-${item.id}`"
|
||||
:item="item"
|
||||
:can-like="canLike"
|
||||
:busy="action.loading"
|
||||
@toggle-like="toggleLike"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-top: 12px">
|
||||
<div class="row" style="justify-content: space-between">
|
||||
<div>
|
||||
<p class="title">关注流(listByFollowing,JWT)</p>
|
||||
<div class="subtle">
|
||||
limit:{{ following.limit }} · next_time:{{ following.next_time }} · has_more:{{ following.has_more }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label class="subtle" style="margin: 0">limit</label>
|
||||
<input v-model.number="following.limit" type="number" min="1" max="50" style="width: 90px" />
|
||||
<button class="primary" type="button" :disabled="following.loading" @click="loadFollowing(true)">刷新</button>
|
||||
<button type="button" :disabled="following.loading || !following.has_more" @click="loadFollowing(false)">加载更多</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!auth.isLoggedIn" class="pill bad" style="margin-top: 10px">未登录:无法访问关注流</div>
|
||||
<div v-if="following.error" class="pill bad" style="margin-top: 10px">错误:{{ following.error }}</div>
|
||||
<div class="grid" style="gap: 10px; margin-top: 12px">
|
||||
<FeedVideoCard
|
||||
v-for="item in following.items"
|
||||
:key="`following-${item.id}`"
|
||||
:item="item"
|
||||
:can-like="canLike"
|
||||
:busy="action.loading"
|
||||
@toggle-like="toggleLike"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<p class="title">动作输出(点赞等)</p>
|
||||
<div class="row" style="margin-bottom: 10px">
|
||||
<span class="pill">动作:{{ action.name || '-' }}</span>
|
||||
<span v-if="action.loading" class="pill">请求中…</span>
|
||||
<span v-if="action.error" class="pill bad">错误:{{ action.error }}</span>
|
||||
</div>
|
||||
<JsonBox :value="action.payload" />
|
||||
</div>
|
||||
</div>
|
||||
</AppShell>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, watch } from 'vue'
|
||||
|
||||
import AppShell from '../components/AppShell.vue'
|
||||
import JsonBox from '../components/JsonBox.vue'
|
||||
import FeedVideoCard from '../components/FeedVideoCard.vue'
|
||||
import { ApiError } from '../api/client'
|
||||
import * as feedApi from '../api/feed'
|
||||
import * as likeApi from '../api/like'
|
||||
import type { FeedVideoItem } from '../api/types'
|
||||
import { useAuthStore } from '../stores/auth'
|
||||
|
||||
const auth = useAuthStore()
|
||||
|
||||
type ListState = {
|
||||
loading: boolean
|
||||
error: string
|
||||
items: FeedVideoItem[]
|
||||
has_more: boolean
|
||||
}
|
||||
|
||||
const latest = reactive<ListState & { limit: number; next_time: number }>({
|
||||
loading: false,
|
||||
error: '',
|
||||
items: [],
|
||||
has_more: false,
|
||||
limit: 10,
|
||||
next_time: 0,
|
||||
})
|
||||
|
||||
const likesCount = reactive<ListState & { limit: number; next_likes_count_before?: number; next_id_before?: number }>({
|
||||
loading: false,
|
||||
error: '',
|
||||
items: [],
|
||||
has_more: false,
|
||||
limit: 10,
|
||||
next_likes_count_before: undefined,
|
||||
next_id_before: undefined,
|
||||
})
|
||||
|
||||
const following = reactive<ListState & { limit: number; next_time: number }>({
|
||||
loading: false,
|
||||
error: '',
|
||||
items: [],
|
||||
has_more: false,
|
||||
limit: 10,
|
||||
next_time: 0,
|
||||
})
|
||||
|
||||
const action = reactive<{ loading: boolean; error: string; payload: unknown; name: string }>({
|
||||
loading: false,
|
||||
error: '',
|
||||
payload: null,
|
||||
name: '',
|
||||
})
|
||||
|
||||
const canLike = computed(() => auth.isLoggedIn)
|
||||
|
||||
async function runAction(name: string, fn: () => Promise<unknown>) {
|
||||
action.name = name
|
||||
action.loading = true
|
||||
action.error = ''
|
||||
action.payload = null
|
||||
try {
|
||||
action.payload = await fn()
|
||||
} catch (e) {
|
||||
action.error = e instanceof ApiError ? e.message : String(e)
|
||||
action.payload = e instanceof ApiError ? e.payload : null
|
||||
} finally {
|
||||
action.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadLatest(reset: boolean) {
|
||||
latest.loading = true
|
||||
latest.error = ''
|
||||
try {
|
||||
const latest_time = reset ? 0 : latest.next_time
|
||||
const res = await feedApi.listLatest({ limit: latest.limit, latest_time })
|
||||
latest.has_more = res.has_more
|
||||
latest.next_time = res.next_time
|
||||
latest.items = reset ? res.video_list : latest.items.concat(res.video_list)
|
||||
} catch (e) {
|
||||
latest.error = e instanceof ApiError ? e.message : String(e)
|
||||
} finally {
|
||||
latest.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadLikesCount(reset: boolean) {
|
||||
likesCount.loading = true
|
||||
likesCount.error = ''
|
||||
try {
|
||||
const res = await feedApi.listLikesCount({
|
||||
limit: likesCount.limit,
|
||||
likes_count_before: reset ? undefined : likesCount.next_likes_count_before,
|
||||
id_before: reset ? undefined : likesCount.next_id_before,
|
||||
})
|
||||
likesCount.has_more = res.has_more
|
||||
likesCount.next_likes_count_before = res.next_likes_count_before
|
||||
likesCount.next_id_before = res.next_id_before
|
||||
likesCount.items = reset ? res.video_list : likesCount.items.concat(res.video_list)
|
||||
} catch (e) {
|
||||
likesCount.error = e instanceof ApiError ? e.message : String(e)
|
||||
} finally {
|
||||
likesCount.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
async function loadFollowing(reset: boolean) {
|
||||
following.loading = true
|
||||
following.error = ''
|
||||
try {
|
||||
const latest_time = reset ? 0 : following.next_time
|
||||
const res = await feedApi.listByFollowing({ limit: following.limit, latest_time })
|
||||
following.has_more = res.has_more
|
||||
following.next_time = res.next_time
|
||||
following.items = reset ? res.video_list : following.items.concat(res.video_list)
|
||||
} catch (e) {
|
||||
following.error = e instanceof ApiError ? e.message : String(e)
|
||||
} finally {
|
||||
following.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleLike(item: FeedVideoItem) {
|
||||
if (!auth.isLoggedIn) return
|
||||
|
||||
await runAction(item.is_liked ? '取消点赞' : '点赞', async () => {
|
||||
if (item.is_liked) await likeApi.unlike(item.id)
|
||||
else await likeApi.like(item.id)
|
||||
|
||||
item.is_liked = !item.is_liked
|
||||
item.likes_count = Math.max(0, item.likes_count + (item.is_liked ? 1 : -1))
|
||||
return { ok: true, is_liked: item.is_liked, likes_count: item.likes_count }
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadLatest(true)
|
||||
await loadLikesCount(true)
|
||||
if (auth.isLoggedIn) {
|
||||
await loadFollowing(true)
|
||||
}
|
||||
})
|
||||
|
||||
watch(
|
||||
() => auth.isLoggedIn,
|
||||
async (v) => {
|
||||
if (v && following.items.length === 0) {
|
||||
await loadFollowing(true)
|
||||
}
|
||||
},
|
||||
)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppShell>
|
||||
<div class="grid two">
|
||||
<div class="card">
|
||||
<p class="title">Feed</p>
|
||||
<p class="subtle">`/feed/listLatest` 与 `/feed/listLikesCount` 支持匿名(可选 JWT);`/feed/listByFollowing` 需要 JWT。</p>
|
||||
|
||||
<div class="card" style="margin-top: 12px">
|
||||
<div class="row" style="justify-content: space-between">
|
||||
<div>
|
||||
<p class="title">最新流(listLatest)</p>
|
||||
<div class="subtle">limit:{{ latest.limit }} · next_time:{{ latest.next_time }} · has_more:{{ latest.has_more }}</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label class="subtle" style="margin: 0">limit</label>
|
||||
<input v-model.number="latest.limit" type="number" min="1" max="50" style="width: 90px" />
|
||||
<button class="primary" type="button" :disabled="latest.loading" @click="loadLatest(true)">刷新</button>
|
||||
<button type="button" :disabled="latest.loading || !latest.has_more" @click="loadLatest(false)">加载更多</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="latest.error" class="pill bad" style="margin-top: 10px">错误:{{ latest.error }}</div>
|
||||
<div class="grid" style="gap: 10px; margin-top: 12px">
|
||||
<FeedVideoCard
|
||||
v-for="item in latest.items"
|
||||
:key="`latest-${item.id}`"
|
||||
:item="item"
|
||||
:can-like="canLike"
|
||||
:busy="action.loading"
|
||||
@toggle-like="toggleLike"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-top: 12px">
|
||||
<div class="row" style="justify-content: space-between">
|
||||
<div>
|
||||
<p class="title">点赞数流(listLikesCount)</p>
|
||||
<div class="subtle">
|
||||
limit:{{ likesCount.limit }} · next=(likes={{ likesCount.next_likes_count_before }}, id={{ likesCount.next_id_before }})
|
||||
· has_more:{{ likesCount.has_more }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label class="subtle" style="margin: 0">limit</label>
|
||||
<input v-model.number="likesCount.limit" type="number" min="1" max="50" style="width: 90px" />
|
||||
<button class="primary" type="button" :disabled="likesCount.loading" @click="loadLikesCount(true)">刷新</button>
|
||||
<button type="button" :disabled="likesCount.loading || !likesCount.has_more" @click="loadLikesCount(false)">
|
||||
加载更多
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="likesCount.error" class="pill bad" style="margin-top: 10px">错误:{{ likesCount.error }}</div>
|
||||
<div class="grid" style="gap: 10px; margin-top: 12px">
|
||||
<FeedVideoCard
|
||||
v-for="item in likesCount.items"
|
||||
:key="`likes-${item.id}`"
|
||||
:item="item"
|
||||
:can-like="canLike"
|
||||
:busy="action.loading"
|
||||
@toggle-like="toggleLike"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-top: 12px">
|
||||
<div class="row" style="justify-content: space-between">
|
||||
<div>
|
||||
<p class="title">关注流(listByFollowing,JWT)</p>
|
||||
<div class="subtle">
|
||||
limit:{{ following.limit }} · next_time:{{ following.next_time }} · has_more:{{ following.has_more }}
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<label class="subtle" style="margin: 0">limit</label>
|
||||
<input v-model.number="following.limit" type="number" min="1" max="50" style="width: 90px" />
|
||||
<button class="primary" type="button" :disabled="following.loading" @click="loadFollowing(true)">刷新</button>
|
||||
<button type="button" :disabled="following.loading || !following.has_more" @click="loadFollowing(false)">加载更多</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!auth.isLoggedIn" class="pill bad" style="margin-top: 10px">未登录:无法访问关注流</div>
|
||||
<div v-if="following.error" class="pill bad" style="margin-top: 10px">错误:{{ following.error }}</div>
|
||||
<div class="grid" style="gap: 10px; margin-top: 12px">
|
||||
<FeedVideoCard
|
||||
v-for="item in following.items"
|
||||
:key="`following-${item.id}`"
|
||||
:item="item"
|
||||
:can-like="canLike"
|
||||
:busy="action.loading"
|
||||
@toggle-like="toggleLike"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<p class="title">动作输出(点赞等)</p>
|
||||
<div class="row" style="margin-bottom: 10px">
|
||||
<span class="pill">动作:{{ action.name || '-' }}</span>
|
||||
<span v-if="action.loading" class="pill">请求中…</span>
|
||||
<span v-if="action.error" class="pill bad">错误:{{ action.error }}</span>
|
||||
</div>
|
||||
<JsonBox :value="action.payload" />
|
||||
</div>
|
||||
</div>
|
||||
</AppShell>
|
||||
</template>
|
||||
|
||||
314
frontend/src/views/HotView.vue
vendored
314
frontend/src/views/HotView.vue
vendored
@@ -1,157 +1,157 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive } from 'vue'
|
||||
|
||||
import { ApiError } from '../api/client'
|
||||
import * as feedApi from '../api/feed'
|
||||
import * as likeApi from '../api/like'
|
||||
import type { FeedVideoItem } from '../api/types'
|
||||
import AppShell from '../components/AppShell.vue'
|
||||
import FeedVideoCard from '../components/FeedVideoCard.vue'
|
||||
import { useAuthStore } from '../stores/auth'
|
||||
import { useToastStore } from '../stores/toast'
|
||||
|
||||
const auth = useAuthStore()
|
||||
const toast = useToastStore()
|
||||
|
||||
const canLike = computed(() => auth.isLoggedIn)
|
||||
|
||||
const state = reactive({
|
||||
loading: false,
|
||||
error: '',
|
||||
items: [] as FeedVideoItem[],
|
||||
hasMore: false,
|
||||
limit: 10,
|
||||
asOf: 0,
|
||||
nextOffset: 0,
|
||||
})
|
||||
|
||||
const likeBusy = reactive<Record<string, boolean>>({})
|
||||
|
||||
async function loadHot(reset: boolean) {
|
||||
if (state.loading) return
|
||||
state.loading = true
|
||||
state.error = ''
|
||||
try {
|
||||
const res = await feedApi.listByPopularity({
|
||||
limit: state.limit,
|
||||
as_of: reset ? 0 : state.asOf,
|
||||
offset: reset ? 0 : state.nextOffset,
|
||||
})
|
||||
state.hasMore = res.has_more
|
||||
state.asOf = res.as_of
|
||||
state.nextOffset = res.next_offset
|
||||
state.items = reset ? res.video_list : state.items.concat(res.video_list)
|
||||
} catch (e) {
|
||||
state.error = e instanceof ApiError ? e.message : String(e)
|
||||
} finally {
|
||||
state.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleLike(item: FeedVideoItem) {
|
||||
if (!auth.isLoggedIn) {
|
||||
toast.error('请先登录')
|
||||
return
|
||||
}
|
||||
const key = String(item.id)
|
||||
if (likeBusy[key]) return
|
||||
likeBusy[key] = true
|
||||
try {
|
||||
if (item.is_liked) await likeApi.unlike(item.id)
|
||||
else await likeApi.like(item.id)
|
||||
item.is_liked = !item.is_liked
|
||||
item.likes_count = Math.max(0, item.likes_count + (item.is_liked ? 1 : -1))
|
||||
} catch (e) {
|
||||
const msg = e instanceof ApiError ? e.message : String(e)
|
||||
toast.error(msg)
|
||||
} finally {
|
||||
likeBusy[key] = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadHot(true)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppShell>
|
||||
<div class="card">
|
||||
<div class="row" style="justify-content: space-between; align-items: baseline">
|
||||
<div>
|
||||
<p class="title" style="margin: 0">热榜</p>
|
||||
<p class="subtle" style="margin: 6px 0 0">按热度排序(/feed/listByPopularity)</p>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label class="subtle" style="margin: 0">limit</label>
|
||||
<input v-model.number="state.limit" type="number" min="1" max="50" style="width: 90px" :disabled="state.loading" />
|
||||
<button class="primary" type="button" :disabled="state.loading" @click="loadHot(true)">刷新</button>
|
||||
<button type="button" :disabled="state.loading || !state.hasMore" @click="loadHot(false)">加载更多</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="state.error" class="pill bad" style="margin-top: 12px">错误:{{ state.error }}</div>
|
||||
<div v-else-if="state.loading && state.items.length === 0" class="subtle" style="margin-top: 12px">加载中…</div>
|
||||
<div v-else-if="state.items.length === 0" class="subtle" style="margin-top: 12px">暂无内容</div>
|
||||
|
||||
<div v-if="state.items.length" class="rank-list" style="margin-top: 14px">
|
||||
<div v-for="(item, idx) in state.items" :key="`hot-${item.id}`" class="rank-row">
|
||||
<div class="rank-num" :class="idx < 3 ? 'top' : ''">{{ idx + 1 }}</div>
|
||||
<FeedVideoCard
|
||||
:item="item"
|
||||
:can-like="canLike"
|
||||
:busy="!!likeBusy[String(item.id)]"
|
||||
@toggle-like="toggleLike"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AppShell>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.rank-list {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.rank-row {
|
||||
display: grid;
|
||||
grid-template-columns: 44px minmax(0, 1fr);
|
||||
gap: 12px;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.rank-num {
|
||||
height: 44px;
|
||||
width: 44px;
|
||||
border-radius: 16px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
font-weight: 900;
|
||||
letter-spacing: 0.2px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
color: rgba(255, 255, 255, 0.86);
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.rank-num.top {
|
||||
border-color: rgba(254, 44, 85, 0.55);
|
||||
background: rgba(254, 44, 85, 0.18);
|
||||
color: rgba(255, 255, 255, 0.96);
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.rank-row {
|
||||
grid-template-columns: 38px minmax(0, 1fr);
|
||||
gap: 10px;
|
||||
}
|
||||
.rank-num {
|
||||
height: 38px;
|
||||
width: 38px;
|
||||
border-radius: 14px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive } from 'vue'
|
||||
|
||||
import { ApiError } from '../api/client'
|
||||
import * as feedApi from '../api/feed'
|
||||
import * as likeApi from '../api/like'
|
||||
import type { FeedVideoItem } from '../api/types'
|
||||
import AppShell from '../components/AppShell.vue'
|
||||
import FeedVideoCard from '../components/FeedVideoCard.vue'
|
||||
import { useAuthStore } from '../stores/auth'
|
||||
import { useToastStore } from '../stores/toast'
|
||||
|
||||
const auth = useAuthStore()
|
||||
const toast = useToastStore()
|
||||
|
||||
const canLike = computed(() => auth.isLoggedIn)
|
||||
|
||||
const state = reactive({
|
||||
loading: false,
|
||||
error: '',
|
||||
items: [] as FeedVideoItem[],
|
||||
hasMore: false,
|
||||
limit: 10,
|
||||
asOf: 0,
|
||||
nextOffset: 0,
|
||||
})
|
||||
|
||||
const likeBusy = reactive<Record<string, boolean>>({})
|
||||
|
||||
async function loadHot(reset: boolean) {
|
||||
if (state.loading) return
|
||||
state.loading = true
|
||||
state.error = ''
|
||||
try {
|
||||
const res = await feedApi.listByPopularity({
|
||||
limit: state.limit,
|
||||
as_of: reset ? 0 : state.asOf,
|
||||
offset: reset ? 0 : state.nextOffset,
|
||||
})
|
||||
state.hasMore = res.has_more
|
||||
state.asOf = res.as_of
|
||||
state.nextOffset = res.next_offset
|
||||
state.items = reset ? res.video_list : state.items.concat(res.video_list)
|
||||
} catch (e) {
|
||||
state.error = e instanceof ApiError ? e.message : String(e)
|
||||
} finally {
|
||||
state.loading = false
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleLike(item: FeedVideoItem) {
|
||||
if (!auth.isLoggedIn) {
|
||||
toast.error('请先登录')
|
||||
return
|
||||
}
|
||||
const key = String(item.id)
|
||||
if (likeBusy[key]) return
|
||||
likeBusy[key] = true
|
||||
try {
|
||||
if (item.is_liked) await likeApi.unlike(item.id)
|
||||
else await likeApi.like(item.id)
|
||||
item.is_liked = !item.is_liked
|
||||
item.likes_count = Math.max(0, item.likes_count + (item.is_liked ? 1 : -1))
|
||||
} catch (e) {
|
||||
const msg = e instanceof ApiError ? e.message : String(e)
|
||||
toast.error(msg)
|
||||
} finally {
|
||||
likeBusy[key] = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
await loadHot(true)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppShell>
|
||||
<div class="card">
|
||||
<div class="row" style="justify-content: space-between; align-items: baseline">
|
||||
<div>
|
||||
<p class="title" style="margin: 0">热榜</p>
|
||||
<p class="subtle" style="margin: 6px 0 0">按热度排序(/feed/listByPopularity)</p>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<label class="subtle" style="margin: 0">limit</label>
|
||||
<input v-model.number="state.limit" type="number" min="1" max="50" style="width: 90px" :disabled="state.loading" />
|
||||
<button class="primary" type="button" :disabled="state.loading" @click="loadHot(true)">刷新</button>
|
||||
<button type="button" :disabled="state.loading || !state.hasMore" @click="loadHot(false)">加载更多</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="state.error" class="pill bad" style="margin-top: 12px">错误:{{ state.error }}</div>
|
||||
<div v-else-if="state.loading && state.items.length === 0" class="subtle" style="margin-top: 12px">加载中…</div>
|
||||
<div v-else-if="state.items.length === 0" class="subtle" style="margin-top: 12px">暂无内容</div>
|
||||
|
||||
<div v-if="state.items.length" class="rank-list" style="margin-top: 14px">
|
||||
<div v-for="(item, idx) in state.items" :key="`hot-${item.id}`" class="rank-row">
|
||||
<div class="rank-num" :class="idx < 3 ? 'top' : ''">{{ idx + 1 }}</div>
|
||||
<FeedVideoCard
|
||||
:item="item"
|
||||
:can-like="canLike"
|
||||
:busy="!!likeBusy[String(item.id)]"
|
||||
@toggle-like="toggleLike"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AppShell>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.rank-list {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.rank-row {
|
||||
display: grid;
|
||||
grid-template-columns: 44px minmax(0, 1fr);
|
||||
gap: 12px;
|
||||
align-items: start;
|
||||
}
|
||||
|
||||
.rank-num {
|
||||
height: 44px;
|
||||
width: 44px;
|
||||
border-radius: 16px;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
font-weight: 900;
|
||||
letter-spacing: 0.2px;
|
||||
border: 1px solid rgba(255, 255, 255, 0.12);
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
color: rgba(255, 255, 255, 0.86);
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.rank-num.top {
|
||||
border-color: rgba(254, 44, 85, 0.55);
|
||||
background: rgba(254, 44, 85, 0.18);
|
||||
color: rgba(255, 255, 255, 0.96);
|
||||
}
|
||||
|
||||
@media (max-width: 900px) {
|
||||
.rank-row {
|
||||
grid-template-columns: 38px minmax(0, 1fr);
|
||||
gap: 10px;
|
||||
}
|
||||
.rank-num {
|
||||
height: 38px;
|
||||
width: 38px;
|
||||
border-radius: 14px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
134
frontend/src/views/RegisterView.vue
vendored
134
frontend/src/views/RegisterView.vue
vendored
@@ -1,67 +1,67 @@
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
import AppShell from '../components/AppShell.vue'
|
||||
import { ApiError } from '../api/client'
|
||||
import * as accountApi from '../api/account'
|
||||
import { useToastStore } from '../stores/toast'
|
||||
|
||||
const router = useRouter()
|
||||
const toast = useToastStore()
|
||||
|
||||
const busy = ref(false)
|
||||
const form = reactive({ username: '', password: '' })
|
||||
|
||||
async function submit() {
|
||||
if (busy.value) return
|
||||
const username = form.username.trim()
|
||||
const password = form.password.trim()
|
||||
if (!username || !password) {
|
||||
toast.error('请输入 username 和 password')
|
||||
return
|
||||
}
|
||||
|
||||
busy.value = true
|
||||
try {
|
||||
await accountApi.register(username, password)
|
||||
toast.success('注册成功,请登录')
|
||||
await router.push('/account')
|
||||
} catch (e) {
|
||||
const msg = e instanceof ApiError ? e.message : String(e)
|
||||
toast.error(msg)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppShell>
|
||||
<div class="grid two">
|
||||
<div class="card">
|
||||
<p class="title">注册</p>
|
||||
<p class="subtle">创建新账号(对应后端 `/account/register`)。</p>
|
||||
<div class="grid" style="margin-top: 12px">
|
||||
<div>
|
||||
<label>username</label>
|
||||
<input v-model.trim="form.username" autocomplete="username" />
|
||||
</div>
|
||||
<div>
|
||||
<label>password</label>
|
||||
<input v-model.trim="form.password" type="password" autocomplete="new-password" />
|
||||
</div>
|
||||
<div class="row" style="justify-content: flex-end">
|
||||
<button class="primary" type="button" :disabled="busy" @click="submit">注册</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<p class="title">提示</p>
|
||||
<p class="muted">注册成功后会跳回「账号」页进行登录。</p>
|
||||
</div>
|
||||
</div>
|
||||
</AppShell>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
import AppShell from '../components/AppShell.vue'
|
||||
import { ApiError } from '../api/client'
|
||||
import * as accountApi from '../api/account'
|
||||
import { useToastStore } from '../stores/toast'
|
||||
|
||||
const router = useRouter()
|
||||
const toast = useToastStore()
|
||||
|
||||
const busy = ref(false)
|
||||
const form = reactive({ username: '', password: '' })
|
||||
|
||||
async function submit() {
|
||||
if (busy.value) return
|
||||
const username = form.username.trim()
|
||||
const password = form.password.trim()
|
||||
if (!username || !password) {
|
||||
toast.error('请输入 username 和 password')
|
||||
return
|
||||
}
|
||||
|
||||
busy.value = true
|
||||
try {
|
||||
await accountApi.register(username, password)
|
||||
toast.success('注册成功,请登录')
|
||||
await router.push('/account')
|
||||
} catch (e) {
|
||||
const msg = e instanceof ApiError ? e.message : String(e)
|
||||
toast.error(msg)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppShell>
|
||||
<div class="grid two">
|
||||
<div class="card">
|
||||
<p class="title">注册</p>
|
||||
<p class="subtle">创建新账号(对应后端 `/account/register`)。</p>
|
||||
<div class="grid" style="margin-top: 12px">
|
||||
<div>
|
||||
<label>username</label>
|
||||
<input v-model.trim="form.username" autocomplete="username" />
|
||||
</div>
|
||||
<div>
|
||||
<label>password</label>
|
||||
<input v-model.trim="form.password" type="password" autocomplete="new-password" />
|
||||
</div>
|
||||
<div class="row" style="justify-content: flex-end">
|
||||
<button class="primary" type="button" :disabled="busy" @click="submit">注册</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<p class="title">提示</p>
|
||||
<p class="muted">注册成功后会跳回「账号」页进行登录。</p>
|
||||
</div>
|
||||
</div>
|
||||
</AppShell>
|
||||
</template>
|
||||
|
||||
|
||||
336
frontend/src/views/SettingsView.vue
vendored
336
frontend/src/views/SettingsView.vue
vendored
@@ -1,168 +1,168 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, reactive, ref } from 'vue'
|
||||
import { 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 { useAuthStore } from '../stores/auth'
|
||||
import { useToastStore } from '../stores/toast'
|
||||
|
||||
const router = useRouter()
|
||||
const auth = useAuthStore()
|
||||
const toast = useToastStore()
|
||||
|
||||
const busy = ref(false)
|
||||
|
||||
const me = computed(() => ({
|
||||
id: auth.claims?.account_id ?? 0,
|
||||
username: auth.claims?.username ?? '',
|
||||
}))
|
||||
|
||||
const rename = reactive({
|
||||
open: false,
|
||||
newUsername: '',
|
||||
})
|
||||
|
||||
async function openRename() {
|
||||
if (!auth.isLoggedIn) return
|
||||
rename.open = true
|
||||
rename.newUsername = me.value.username
|
||||
await nextTick()
|
||||
}
|
||||
|
||||
async function submitRename() {
|
||||
if (!auth.isLoggedIn) return
|
||||
if (busy.value) return
|
||||
const newUsername = rename.newUsername.trim()
|
||||
if (!newUsername) {
|
||||
toast.error('请输入新用户名')
|
||||
return
|
||||
}
|
||||
|
||||
busy.value = true
|
||||
try {
|
||||
const res = await accountApi.rename(newUsername)
|
||||
auth.setToken(res.token)
|
||||
rename.open = false
|
||||
toast.success('改名成功(已刷新 token)')
|
||||
} catch (e) {
|
||||
const msg = e instanceof ApiError ? e.message : String(e)
|
||||
toast.error(msg)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function goLogin() {
|
||||
await router.push('/account')
|
||||
}
|
||||
|
||||
async function goChangePassword() {
|
||||
await router.push('/account/change-password')
|
||||
}
|
||||
|
||||
async function onLogout() {
|
||||
if (!auth.isLoggedIn) return
|
||||
if (busy.value) return
|
||||
if (!window.confirm('确认退出登录?')) return
|
||||
|
||||
busy.value = true
|
||||
try {
|
||||
await accountApi.logout()
|
||||
} catch (e) {
|
||||
const msg = e instanceof ApiError ? e.message : String(e)
|
||||
toast.error(`登出失败:${msg}`)
|
||||
} finally {
|
||||
auth.clearTokens()
|
||||
rename.open = false
|
||||
toast.info('已退出登录')
|
||||
busy.value = false
|
||||
await router.push('/')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppShell>
|
||||
<div v-if="!auth.isLoggedIn" class="grid two">
|
||||
<div class="card">
|
||||
<p class="title">设置</p>
|
||||
<p class="subtle">需要先登录后才能进行改名/退出等操作。</p>
|
||||
<div class="row" style="margin-top: 12px; justify-content: flex-end">
|
||||
<button class="primary" type="button" @click="goLogin">去登录</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<p class="title">提示</p>
|
||||
<p class="muted">登录入口在「账号」页。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="grid two">
|
||||
<div class="card">
|
||||
<div class="row" style="justify-content: space-between; align-items: flex-start">
|
||||
<div class="row" style="gap: 12px; align-items: center">
|
||||
<UserAvatar :username="me.username" :id="me.id" :size="56" />
|
||||
<div>
|
||||
<div class="title" style="margin: 0">@{{ me.username }}</div>
|
||||
<div class="subtle mono">#{{ me.id }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-top: 14px">
|
||||
<div class="row" style="justify-content: space-between; align-items: center">
|
||||
<p class="title" style="margin: 0">账号设置</p>
|
||||
<button class="ghost" type="button" :disabled="busy" @click="openRename">改名</button>
|
||||
</div>
|
||||
|
||||
<div v-if="rename.open" class="grid" style="margin-top: 12px">
|
||||
<div>
|
||||
<label>new_username</label>
|
||||
<input v-model.trim="rename.newUsername" @keydown.enter="submitRename" />
|
||||
</div>
|
||||
<div class="row" style="justify-content: flex-end">
|
||||
<button type="button" :disabled="busy" @click="rename.open = false">取消</button>
|
||||
<button class="primary" type="button" :disabled="busy" @click="submitRename">提交</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-top: 14px">
|
||||
<p class="title">账号安全</p>
|
||||
<div class="row">
|
||||
<button class="ghost" type="button" :disabled="busy" @click="goChangePassword">修改密码</button>
|
||||
<button class="danger" type="button" :disabled="busy" @click="onLogout">退出登录</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<p class="title">说明</p>
|
||||
<div class="grid" style="margin-top: 10px">
|
||||
<div class="pill ok">改名后会返回新 token,旧 token 立即失效</div>
|
||||
<div class="pill ok">退出登录会清空本地 token</div>
|
||||
<div class="pill">修改密码无需登录,但成功后会让旧 token 失效</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AppShell>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.ghost {
|
||||
border: 1px solid rgba(255, 255, 255, 0.14);
|
||||
background: rgba(0, 0, 0, 0.18);
|
||||
color: rgba(255, 255, 255, 0.86);
|
||||
border-radius: 12px;
|
||||
padding: 10px 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ghost:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
</style>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, reactive, ref } from 'vue'
|
||||
import { 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 { useAuthStore } from '../stores/auth'
|
||||
import { useToastStore } from '../stores/toast'
|
||||
|
||||
const router = useRouter()
|
||||
const auth = useAuthStore()
|
||||
const toast = useToastStore()
|
||||
|
||||
const busy = ref(false)
|
||||
|
||||
const me = computed(() => ({
|
||||
id: auth.claims?.account_id ?? 0,
|
||||
username: auth.claims?.username ?? '',
|
||||
}))
|
||||
|
||||
const rename = reactive({
|
||||
open: false,
|
||||
newUsername: '',
|
||||
})
|
||||
|
||||
async function openRename() {
|
||||
if (!auth.isLoggedIn) return
|
||||
rename.open = true
|
||||
rename.newUsername = me.value.username
|
||||
await nextTick()
|
||||
}
|
||||
|
||||
async function submitRename() {
|
||||
if (!auth.isLoggedIn) return
|
||||
if (busy.value) return
|
||||
const newUsername = rename.newUsername.trim()
|
||||
if (!newUsername) {
|
||||
toast.error('请输入新用户名')
|
||||
return
|
||||
}
|
||||
|
||||
busy.value = true
|
||||
try {
|
||||
const res = await accountApi.rename(newUsername)
|
||||
auth.setToken(res.token)
|
||||
rename.open = false
|
||||
toast.success('改名成功(已刷新 token)')
|
||||
} catch (e) {
|
||||
const msg = e instanceof ApiError ? e.message : String(e)
|
||||
toast.error(msg)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function goLogin() {
|
||||
await router.push('/account')
|
||||
}
|
||||
|
||||
async function goChangePassword() {
|
||||
await router.push('/account/change-password')
|
||||
}
|
||||
|
||||
async function onLogout() {
|
||||
if (!auth.isLoggedIn) return
|
||||
if (busy.value) return
|
||||
if (!window.confirm('确认退出登录?')) return
|
||||
|
||||
busy.value = true
|
||||
try {
|
||||
await accountApi.logout()
|
||||
} catch (e) {
|
||||
const msg = e instanceof ApiError ? e.message : String(e)
|
||||
toast.error(`登出失败:${msg}`)
|
||||
} finally {
|
||||
auth.clearTokens()
|
||||
rename.open = false
|
||||
toast.info('已退出登录')
|
||||
busy.value = false
|
||||
await router.push('/')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppShell>
|
||||
<div v-if="!auth.isLoggedIn" class="grid two">
|
||||
<div class="card">
|
||||
<p class="title">设置</p>
|
||||
<p class="subtle">需要先登录后才能进行改名/退出等操作。</p>
|
||||
<div class="row" style="margin-top: 12px; justify-content: flex-end">
|
||||
<button class="primary" type="button" @click="goLogin">去登录</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card">
|
||||
<p class="title">提示</p>
|
||||
<p class="muted">登录入口在「账号」页。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="grid two">
|
||||
<div class="card">
|
||||
<div class="row" style="justify-content: space-between; align-items: flex-start">
|
||||
<div class="row" style="gap: 12px; align-items: center">
|
||||
<UserAvatar :username="me.username" :id="me.id" :size="56" />
|
||||
<div>
|
||||
<div class="title" style="margin: 0">@{{ me.username }}</div>
|
||||
<div class="subtle mono">#{{ me.id }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-top: 14px">
|
||||
<div class="row" style="justify-content: space-between; align-items: center">
|
||||
<p class="title" style="margin: 0">账号设置</p>
|
||||
<button class="ghost" type="button" :disabled="busy" @click="openRename">改名</button>
|
||||
</div>
|
||||
|
||||
<div v-if="rename.open" class="grid" style="margin-top: 12px">
|
||||
<div>
|
||||
<label>new_username</label>
|
||||
<input v-model.trim="rename.newUsername" @keydown.enter="submitRename" />
|
||||
</div>
|
||||
<div class="row" style="justify-content: flex-end">
|
||||
<button type="button" :disabled="busy" @click="rename.open = false">取消</button>
|
||||
<button class="primary" type="button" :disabled="busy" @click="submitRename">提交</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-top: 14px">
|
||||
<p class="title">账号安全</p>
|
||||
<div class="row">
|
||||
<button class="ghost" type="button" :disabled="busy" @click="goChangePassword">修改密码</button>
|
||||
<button class="danger" type="button" :disabled="busy" @click="onLogout">退出登录</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<p class="title">说明</p>
|
||||
<div class="grid" style="margin-top: 10px">
|
||||
<div class="pill ok">改名后会返回新 token,旧 token 立即失效</div>
|
||||
<div class="pill ok">退出登录会清空本地 token</div>
|
||||
<div class="pill">修改密码无需登录,但成功后会让旧 token 失效</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AppShell>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.ghost {
|
||||
border: 1px solid rgba(255, 255, 255, 0.14);
|
||||
background: rgba(0, 0, 0, 0.18);
|
||||
color: rgba(255, 255, 255, 0.86);
|
||||
border-radius: 12px;
|
||||
padding: 10px 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ghost:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
790
frontend/src/views/UserProfileView.vue
vendored
790
frontend/src/views/UserProfileView.vue
vendored
@@ -1,107 +1,107 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, 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 socialApi from '../api/social'
|
||||
import type { Account, Video } from '../api/types'
|
||||
import * as videoApi from '../api/video'
|
||||
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 userId = computed(() => Number(route.params.id))
|
||||
const myId = computed(() => auth.claims?.account_id ?? 0)
|
||||
const isMe = computed(() => myId.value > 0 && myId.value === userId.value)
|
||||
|
||||
const state = reactive({
|
||||
loading: false,
|
||||
error: '',
|
||||
user: null as Account | null,
|
||||
videos: [] as Video[],
|
||||
followers: [] as Account[],
|
||||
vloggers: [] as Account[],
|
||||
socialLoading: false,
|
||||
socialError: '',
|
||||
})
|
||||
|
||||
const isFollowing = computed(() => (auth.isLoggedIn ? social.isFollowing(userId.value) : false))
|
||||
|
||||
async function loadProfile() {
|
||||
if (!Number.isFinite(userId.value) || userId.value <= 0) {
|
||||
state.error = '无效的用户 id'
|
||||
return
|
||||
}
|
||||
|
||||
state.loading = true
|
||||
state.error = ''
|
||||
try {
|
||||
const [u, vids] = await Promise.all([accountApi.findById(userId.value), videoApi.listByAuthorId(userId.value)])
|
||||
state.user = u
|
||||
state.videos = vids
|
||||
} catch (e) {
|
||||
state.error = e instanceof ApiError ? e.message : String(e)
|
||||
state.user = null
|
||||
state.videos = []
|
||||
} finally {
|
||||
state.loading = false
|
||||
}
|
||||
|
||||
await loadSocialCounts()
|
||||
}
|
||||
|
||||
async function loadSocialCounts() {
|
||||
state.socialError = ''
|
||||
state.followers = []
|
||||
state.vloggers = []
|
||||
|
||||
if (!auth.isLoggedIn) return
|
||||
if (!Number.isFinite(userId.value) || userId.value <= 0) return
|
||||
|
||||
state.socialLoading = true
|
||||
try {
|
||||
const [followersRes, vloggersRes] = await Promise.all([
|
||||
socialApi.getAllFollowers(userId.value),
|
||||
socialApi.getAllVloggers(userId.value),
|
||||
])
|
||||
state.followers = followersRes.followers
|
||||
state.vloggers = vloggersRes.vloggers
|
||||
} catch (e) {
|
||||
state.socialError = e instanceof ApiError ? e.message : String(e)
|
||||
} finally {
|
||||
state.socialLoading = false
|
||||
}
|
||||
}
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, 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 socialApi from '../api/social'
|
||||
import type { Account, Video } from '../api/types'
|
||||
import * as videoApi from '../api/video'
|
||||
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 userId = computed(() => Number(route.params.id))
|
||||
const myId = computed(() => auth.claims?.account_id ?? 0)
|
||||
const isMe = computed(() => myId.value > 0 && myId.value === userId.value)
|
||||
|
||||
const state = reactive({
|
||||
loading: false,
|
||||
error: '',
|
||||
user: null as Account | null,
|
||||
videos: [] as Video[],
|
||||
followers: [] as Account[],
|
||||
vloggers: [] as Account[],
|
||||
socialLoading: false,
|
||||
socialError: '',
|
||||
})
|
||||
|
||||
const isFollowing = computed(() => (auth.isLoggedIn ? social.isFollowing(userId.value) : false))
|
||||
|
||||
async function loadProfile() {
|
||||
if (!Number.isFinite(userId.value) || userId.value <= 0) {
|
||||
state.error = '无效的用户 id'
|
||||
return
|
||||
}
|
||||
|
||||
state.loading = true
|
||||
state.error = ''
|
||||
try {
|
||||
const [u, vids] = await Promise.all([accountApi.findById(userId.value), videoApi.listByAuthorId(userId.value)])
|
||||
state.user = u
|
||||
state.videos = vids
|
||||
} catch (e) {
|
||||
state.error = e instanceof ApiError ? e.message : String(e)
|
||||
state.user = null
|
||||
state.videos = []
|
||||
} finally {
|
||||
state.loading = false
|
||||
}
|
||||
|
||||
await loadSocialCounts()
|
||||
}
|
||||
|
||||
async function loadSocialCounts() {
|
||||
state.socialError = ''
|
||||
state.followers = []
|
||||
state.vloggers = []
|
||||
|
||||
if (!auth.isLoggedIn) return
|
||||
if (!Number.isFinite(userId.value) || userId.value <= 0) return
|
||||
|
||||
state.socialLoading = true
|
||||
try {
|
||||
const [followersRes, vloggersRes] = await Promise.all([
|
||||
socialApi.getAllFollowers(userId.value),
|
||||
socialApi.getAllVloggers(userId.value),
|
||||
])
|
||||
state.followers = followersRes.followers
|
||||
state.vloggers = vloggersRes.vloggers
|
||||
} catch (e) {
|
||||
state.socialError = e instanceof ApiError ? e.message : String(e)
|
||||
} finally {
|
||||
state.socialLoading = false
|
||||
}
|
||||
}
|
||||
|
||||
async function toggleFollow() {
|
||||
if (isMe.value) return
|
||||
if (!auth.isLoggedIn) {
|
||||
toast.error('请先登录')
|
||||
await router.push('/account')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
if (isFollowing.value) {
|
||||
await social.unfollow(userId.value)
|
||||
toast.info('已取关')
|
||||
} else {
|
||||
await social.follow(userId.value)
|
||||
toast.success('已关注')
|
||||
}
|
||||
await loadSocialCounts()
|
||||
} catch (e) {
|
||||
const msg = e instanceof ApiError ? e.message : String(e)
|
||||
toast.error(msg)
|
||||
toast.error('请先登录')
|
||||
await router.push('/account')
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
if (isFollowing.value) {
|
||||
await social.unfollow(userId.value)
|
||||
toast.info('已取关')
|
||||
} else {
|
||||
await social.follow(userId.value)
|
||||
toast.success('已关注')
|
||||
}
|
||||
await loadSocialCounts()
|
||||
} catch (e) {
|
||||
const msg = e instanceof ApiError ? e.message : String(e)
|
||||
toast.error(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,69 +114,69 @@ async function goMessage() {
|
||||
}
|
||||
await router.push(`/messages/${userId.value}`)
|
||||
}
|
||||
|
||||
type ListTab = 'followers' | 'following'
|
||||
const drawer = reactive({
|
||||
open: false,
|
||||
tab: 'followers' as ListTab,
|
||||
})
|
||||
|
||||
function openFollowers() {
|
||||
drawer.tab = 'followers'
|
||||
drawer.open = true
|
||||
}
|
||||
|
||||
function openFollowing() {
|
||||
drawer.tab = 'following'
|
||||
drawer.open = true
|
||||
}
|
||||
|
||||
function closeDrawer() {
|
||||
drawer.open = false
|
||||
}
|
||||
|
||||
const listTitle = computed(() => (drawer.tab === 'followers' ? '粉丝' : '关注'))
|
||||
const listItems = computed(() => (drawer.tab === 'followers' ? state.followers : state.vloggers))
|
||||
|
||||
async function goUser(id: number) {
|
||||
drawer.open = false
|
||||
await router.push(`/u/${id}`)
|
||||
}
|
||||
|
||||
async function goVideo(videoId: number) {
|
||||
await router.push(`/video/${videoId}`)
|
||||
}
|
||||
|
||||
watch(
|
||||
() => route.params.id,
|
||||
async () => {
|
||||
drawer.open = false
|
||||
await loadProfile()
|
||||
},
|
||||
)
|
||||
|
||||
watch(
|
||||
() => auth.isLoggedIn,
|
||||
async () => {
|
||||
await loadSocialCounts()
|
||||
},
|
||||
)
|
||||
|
||||
onMounted(loadProfile)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppShell>
|
||||
<div class="card">
|
||||
<div class="row" style="justify-content: space-between; align-items: flex-start">
|
||||
<div class="row" style="gap: 12px; align-items: center">
|
||||
<UserAvatar :username="state.user?.username ?? 'User'" :id="state.user?.id ?? userId" :size="64" />
|
||||
<div>
|
||||
<div class="title" style="margin: 0">@{{ state.user?.username ?? '-' }}</div>
|
||||
<div class="subtle mono">#{{ state.user?.id ?? userId }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
type ListTab = 'followers' | 'following'
|
||||
const drawer = reactive({
|
||||
open: false,
|
||||
tab: 'followers' as ListTab,
|
||||
})
|
||||
|
||||
function openFollowers() {
|
||||
drawer.tab = 'followers'
|
||||
drawer.open = true
|
||||
}
|
||||
|
||||
function openFollowing() {
|
||||
drawer.tab = 'following'
|
||||
drawer.open = true
|
||||
}
|
||||
|
||||
function closeDrawer() {
|
||||
drawer.open = false
|
||||
}
|
||||
|
||||
const listTitle = computed(() => (drawer.tab === 'followers' ? '粉丝' : '关注'))
|
||||
const listItems = computed(() => (drawer.tab === 'followers' ? state.followers : state.vloggers))
|
||||
|
||||
async function goUser(id: number) {
|
||||
drawer.open = false
|
||||
await router.push(`/u/${id}`)
|
||||
}
|
||||
|
||||
async function goVideo(videoId: number) {
|
||||
await router.push(`/video/${videoId}`)
|
||||
}
|
||||
|
||||
watch(
|
||||
() => route.params.id,
|
||||
async () => {
|
||||
drawer.open = false
|
||||
await loadProfile()
|
||||
},
|
||||
)
|
||||
|
||||
watch(
|
||||
() => auth.isLoggedIn,
|
||||
async () => {
|
||||
await loadSocialCounts()
|
||||
},
|
||||
)
|
||||
|
||||
onMounted(loadProfile)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<AppShell>
|
||||
<div class="card">
|
||||
<div class="row" style="justify-content: space-between; align-items: flex-start">
|
||||
<div class="row" style="gap: 12px; align-items: center">
|
||||
<UserAvatar :username="state.user?.username ?? 'User'" :id="state.user?.id ?? userId" :size="64" />
|
||||
<div>
|
||||
<div class="title" style="margin: 0">@{{ state.user?.username ?? '-' }}</div>
|
||||
<div class="subtle mono">#{{ state.user?.id ?? userId }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<button v-if="isMe" class="ghost" type="button" @click="router.push('/account')">我的账号</button>
|
||||
<template v-else>
|
||||
@@ -187,72 +187,72 @@ onMounted(loadProfile)
|
||||
</template>
|
||||
</div>
|
||||
</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 class="row" style="margin-top: 14px">
|
||||
<button class="metric" type="button" :disabled="!auth.isLoggedIn || state.socialLoading" @click="openFollowers">
|
||||
<div class="metric-num">{{ auth.isLoggedIn ? (state.socialLoading ? '…' : state.followers.length) : '—' }}</div>
|
||||
<div class="metric-label">粉丝</div>
|
||||
</button>
|
||||
<button class="metric" type="button" :disabled="!auth.isLoggedIn || state.socialLoading" @click="openFollowing">
|
||||
<div class="metric-num">{{ auth.isLoggedIn ? (state.socialLoading ? '…' : state.vloggers.length) : '—' }}</div>
|
||||
<div class="metric-label">关注</div>
|
||||
</button>
|
||||
<div class="metric static">
|
||||
<div class="metric-num">{{ state.videos.length }}</div>
|
||||
<div class="metric-label">作品</div>
|
||||
</div>
|
||||
<div v-if="!auth.isLoggedIn" class="subtle" style="margin-left: 8px">登录后可查看粉丝/关注列表</div>
|
||||
<div v-else-if="state.socialError" class="subtle" style="margin-left: 8px">社交信息加载失败:{{ state.socialError }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-top: 14px">
|
||||
<div class="row" style="justify-content: space-between">
|
||||
<p class="title" style="margin: 0">作品</p>
|
||||
<div class="subtle">点击封面进入播放页</div>
|
||||
</div>
|
||||
|
||||
<div v-if="state.videos.length === 0" class="hint" style="margin-top: 12px">暂无作品</div>
|
||||
|
||||
<div v-else class="video-grid" style="margin-top: 12px">
|
||||
<button v-for="v in state.videos" :key="v.id" class="video-card" type="button" @click="goVideo(v.id)">
|
||||
<img class="video-cover" :src="v.cover_url" :alt="v.title" loading="lazy" />
|
||||
<div class="video-meta">
|
||||
<div class="video-title">{{ v.title }}</div>
|
||||
<div class="video-sub subtle">❤️ {{ v.likes_count }} · {{ new Date(v.create_time).toLocaleDateString() }}</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="drawer.open" class="drawer-backdrop" @click.self="closeDrawer">
|
||||
<div class="drawer">
|
||||
<div class="drawer-head">
|
||||
<div class="drawer-title">{{ listTitle }}</div>
|
||||
<button class="drawer-x" type="button" @click="closeDrawer">×</button>
|
||||
</div>
|
||||
<div class="drawer-body">
|
||||
<div v-if="state.socialLoading" class="drawer-hint">加载中…</div>
|
||||
<div v-else-if="state.socialError" class="drawer-hint bad">{{ state.socialError }}</div>
|
||||
<div v-else-if="listItems.length === 0" class="drawer-hint">暂无</div>
|
||||
|
||||
<button v-for="u in listItems" :key="u.id" class="user-row" type="button" @click="goUser(u.id)">
|
||||
<UserAvatar :username="u.username" :id="u.id" :size="40" />
|
||||
<div class="user-meta">
|
||||
<div class="user-name">@{{ u.username }}</div>
|
||||
<div class="user-id mono">#{{ u.id }}</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AppShell>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
<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 class="row" style="margin-top: 14px">
|
||||
<button class="metric" type="button" :disabled="!auth.isLoggedIn || state.socialLoading" @click="openFollowers">
|
||||
<div class="metric-num">{{ auth.isLoggedIn ? (state.socialLoading ? '…' : state.followers.length) : '—' }}</div>
|
||||
<div class="metric-label">粉丝</div>
|
||||
</button>
|
||||
<button class="metric" type="button" :disabled="!auth.isLoggedIn || state.socialLoading" @click="openFollowing">
|
||||
<div class="metric-num">{{ auth.isLoggedIn ? (state.socialLoading ? '…' : state.vloggers.length) : '—' }}</div>
|
||||
<div class="metric-label">关注</div>
|
||||
</button>
|
||||
<div class="metric static">
|
||||
<div class="metric-num">{{ state.videos.length }}</div>
|
||||
<div class="metric-label">作品</div>
|
||||
</div>
|
||||
<div v-if="!auth.isLoggedIn" class="subtle" style="margin-left: 8px">登录后可查看粉丝/关注列表</div>
|
||||
<div v-else-if="state.socialError" class="subtle" style="margin-left: 8px">社交信息加载失败:{{ state.socialError }}</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card" style="margin-top: 14px">
|
||||
<div class="row" style="justify-content: space-between">
|
||||
<p class="title" style="margin: 0">作品</p>
|
||||
<div class="subtle">点击封面进入播放页</div>
|
||||
</div>
|
||||
|
||||
<div v-if="state.videos.length === 0" class="hint" style="margin-top: 12px">暂无作品</div>
|
||||
|
||||
<div v-else class="video-grid" style="margin-top: 12px">
|
||||
<button v-for="v in state.videos" :key="v.id" class="video-card" type="button" @click="goVideo(v.id)">
|
||||
<img class="video-cover" :src="v.cover_url" :alt="v.title" loading="lazy" />
|
||||
<div class="video-meta">
|
||||
<div class="video-title">{{ v.title }}</div>
|
||||
<div class="video-sub subtle">❤️ {{ v.likes_count }} · {{ new Date(v.create_time).toLocaleDateString() }}</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="drawer.open" class="drawer-backdrop" @click.self="closeDrawer">
|
||||
<div class="drawer">
|
||||
<div class="drawer-head">
|
||||
<div class="drawer-title">{{ listTitle }}</div>
|
||||
<button class="drawer-x" type="button" @click="closeDrawer">×</button>
|
||||
</div>
|
||||
<div class="drawer-body">
|
||||
<div v-if="state.socialLoading" class="drawer-hint">加载中…</div>
|
||||
<div v-else-if="state.socialError" class="drawer-hint bad">{{ state.socialError }}</div>
|
||||
<div v-else-if="listItems.length === 0" class="drawer-hint">暂无</div>
|
||||
|
||||
<button v-for="u in listItems" :key="u.id" class="user-row" type="button" @click="goUser(u.id)">
|
||||
<UserAvatar :username="u.username" :id="u.id" :size="40" />
|
||||
<div class="user-meta">
|
||||
<div class="user-name">@{{ u.username }}</div>
|
||||
<div class="user-id mono">#{{ u.id }}</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AppShell>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.ghost {
|
||||
border: 1px solid var(--border);
|
||||
background: rgba(255, 255, 255, 0.055);
|
||||
@@ -261,42 +261,42 @@ onMounted(loadProfile)
|
||||
padding: 10px 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ghost:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
|
||||
.ghost:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.metric {
|
||||
border: 1px solid var(--border);
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
border-radius: 8px;
|
||||
padding: 12px 14px;
|
||||
min-width: 120px;
|
||||
cursor: pointer;
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.metric.static {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.metric:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.metric:disabled {
|
||||
opacity: 0.55;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.metric-num {
|
||||
font-size: 18px;
|
||||
font-weight: 900;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
|
||||
cursor: pointer;
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.metric.static {
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
.metric:hover {
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.metric:disabled {
|
||||
opacity: 0.55;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.metric-num {
|
||||
font-size: 18px;
|
||||
font-weight: 900;
|
||||
letter-spacing: 0.2px;
|
||||
}
|
||||
|
||||
.metric-label {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
@@ -309,160 +309,160 @@ onMounted(loadProfile)
|
||||
.hint.bad {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.video-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.video-grid {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 800px) {
|
||||
.video-grid {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.video-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 1100px) {
|
||||
.video-grid {
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 800px) {
|
||||
.video-grid {
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
.video-card {
|
||||
border: 1px solid var(--border);
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.video-card:hover {
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
|
||||
.video-cover {
|
||||
width: 100%;
|
||||
aspect-ratio: 9/12;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
background: rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
|
||||
.video-meta {
|
||||
padding: 10px 10px;
|
||||
}
|
||||
|
||||
.video-title {
|
||||
font-weight: 800;
|
||||
font-size: 13px;
|
||||
overflow: hidden;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.video-sub {
|
||||
margin-top: 6px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.drawer-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.55);
|
||||
backdrop-filter: blur(10px);
|
||||
z-index: 120;
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
align-items: center;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.video-card:hover {
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
|
||||
.video-cover {
|
||||
width: 100%;
|
||||
aspect-ratio: 9/12;
|
||||
object-fit: cover;
|
||||
display: block;
|
||||
background: rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
|
||||
.video-meta {
|
||||
padding: 10px 10px;
|
||||
}
|
||||
|
||||
.video-title {
|
||||
font-weight: 800;
|
||||
font-size: 13px;
|
||||
overflow: hidden;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
}
|
||||
|
||||
.video-sub {
|
||||
margin-top: 6px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.drawer-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.55);
|
||||
backdrop-filter: blur(10px);
|
||||
z-index: 120;
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
align-items: center;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.drawer {
|
||||
width: min(520px, calc(100vw - 18px));
|
||||
max-height: min(78vh, 720px);
|
||||
width: min(520px, calc(100vw - 18px));
|
||||
max-height: min(78vh, 720px);
|
||||
background: rgba(13, 18, 29, 0.92);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
display: grid;
|
||||
grid-template-rows: auto 1fr;
|
||||
}
|
||||
|
||||
.drawer-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 14px 14px;
|
||||
overflow: hidden;
|
||||
display: grid;
|
||||
grid-template-rows: auto 1fr;
|
||||
}
|
||||
|
||||
.drawer-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 14px 14px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.drawer-title {
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.drawer-x {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
}
|
||||
|
||||
.drawer-title {
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.drawer-x {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--border);
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
cursor: pointer;
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.drawer-body {
|
||||
overflow: auto;
|
||||
padding: 12px 14px;
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
background: rgba(255, 255, 255, 0.06);
|
||||
color: rgba(255, 255, 255, 0.9);
|
||||
cursor: pointer;
|
||||
font-size: 20px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.drawer-body {
|
||||
overflow: auto;
|
||||
padding: 12px 14px;
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.drawer-hint {
|
||||
color: var(--muted);
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
padding: 12px 0;
|
||||
}
|
||||
|
||||
.drawer-hint.bad {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.user-row {
|
||||
text-align: left;
|
||||
display: grid;
|
||||
grid-template-columns: auto 1fr;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
padding: 10px 10px;
|
||||
|
||||
.user-row {
|
||||
text-align: left;
|
||||
display: grid;
|
||||
grid-template-columns: auto 1fr;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
padding: 10px 10px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--border);
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.user-row:hover {
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
|
||||
.user-meta {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.user-name {
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.user-row:hover {
|
||||
background: rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
|
||||
.user-meta {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.user-name {
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.user-id {
|
||||
font-size: 12px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.mono {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
.mono {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
1372
frontend/src/views/VideoDetailView.vue
vendored
1372
frontend/src/views/VideoDetailView.vue
vendored
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user