hanbinsite commited on
Commit
dfa6264
·
1 Parent(s): d003a1c

feat: implement all web pages with player, search, favorites, auth, useApi composable

Browse files
components/VodCard.vue ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <template>
2
+ <NuxtLink :to="`/vod/${vod.id}`" class="group block cursor-pointer">
3
+ <div class="aspect-[2/3] rounded-lg overflow-hidden bg-gray-800 relative">
4
+ <img
5
+ v-if="vod.cover"
6
+ :src="vod.cover"
7
+ :alt="vod.name"
8
+ loading="lazy"
9
+ class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300"
10
+ />
11
+ <div v-else class="w-full h-full flex items-center justify-center text-gray-600 text-xs">
12
+ {{ vod.name }}
13
+ </div>
14
+ <span
15
+ v-if="vod.remarks"
16
+ class="absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/80 to-transparent px-2 py-1 text-xs text-white truncate"
17
+ >
18
+ {{ vod.remarks }}
19
+ </span>
20
+ </div>
21
+ <div class="mt-2 px-0.5">
22
+ <p class="text-sm text-white truncate group-hover:text-emerald-400 transition">{{ vod.name }}</p>
23
+ <p class="text-xs text-gray-500 mt-0.5">
24
+ <span v-if="vod.score" class="text-amber-400">{{ vod.score }}分</span>
25
+ <span v-if="vod.year" class="ml-1">{{ vod.year }}</span>
26
+ </p>
27
+ </div>
28
+ </NuxtLink>
29
+ </template>
30
+
31
+ <script setup lang="ts">
32
+ import type { VodUserItem } from '~/types/vod'
33
+ defineProps<{ vod: VodUserItem }>()
34
+ </script>
components/VodGrid.vue ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <template>
2
+ <div :class="gridClass">
3
+ <VodCard v-for="vod in list" :key="vod.id" :vod="vod" />
4
+ </div>
5
+ </template>
6
+
7
+ <script setup lang="ts">
8
+ import type { VodUserItem } from '~/types/vod'
9
+ defineProps<{ list: VodUserItem[] }>()
10
+
11
+ const gridClass = 'grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 2xl:grid-cols-6 gap-3 sm:gap-4'
12
+ </script>
components/VodPlayer.vue ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <template>
2
+ <div ref="containerRef" class="w-full aspect-video bg-black rounded-lg overflow-hidden relative">
3
+ <div v-if="mode === 'iframe'" class="w-full h-full">
4
+ <iframe
5
+ :src="iframeSrc"
6
+ class="w-full h-full border-0"
7
+ allowfullscreen
8
+ allow="autoplay; encrypted-media; fullscreen; picture-in-picture"
9
+ />
10
+ </div>
11
+ <div v-else ref="artRef" class="w-full h-full" />
12
+ </div>
13
+ </template>
14
+
15
+ <script setup lang="ts">
16
+ import Artplayer from "artplayer"
17
+ import Hls from "hls.js"
18
+
19
+ type PlayType = "m3u8" | "iframe"
20
+
21
+ const props = defineProps<{
22
+ url: string
23
+ type?: PlayType
24
+ poster?: string
25
+ parseUrl?: string | null
26
+ }>()
27
+
28
+ const emit = defineEmits<{
29
+ (e: "time-update", payload: { currentTime: number; duration: number }): void
30
+ }>()
31
+
32
+ const containerRef = ref<HTMLElement>()
33
+ const artRef = ref<HTMLElement>()
34
+ const artInstance = shallowRef<Artplayer | null>(null)
35
+
36
+ const mode = computed<PlayType>(() => {
37
+ if (props.type === "iframe") return "iframe"
38
+ const url = props.url.toLowerCase()
39
+ if (url.includes(".m3u8") || url.includes("m3u8")) return "m3u8"
40
+ if (url.startsWith("http") && !url.includes(".mp4") && !url.includes(".mkv") && props.parseUrl) return "iframe"
41
+ return "m3u8"
42
+ })
43
+
44
+ const iframeSrc = computed(() => {
45
+ if (mode.value !== "iframe") return ""
46
+ if (props.parseUrl) return `${props.parseUrl}${props.url}`
47
+ return props.url
48
+ })
49
+
50
+ function initArtplayer() {
51
+ if (!artRef.value) return
52
+ if (artInstance.value) {
53
+ artInstance.value.destroy()
54
+ artInstance.value = null
55
+ }
56
+
57
+ const url = props.url
58
+ const isM3u8 = url.toLowerCase().includes(".m3u8") || url.toLowerCase().includes("m3u8")
59
+
60
+ artInstance.value = new Artplayer({
61
+ container: artRef.value,
62
+ url,
63
+ poster: props.poster || "",
64
+ autoplay: false,
65
+ volume: 0.8,
66
+ autoSize: false,
67
+ fullscreen: true,
68
+ fullscreenWeb: true,
69
+ miniProgressBar: true,
70
+ playsInline: true,
71
+ autoPlayback: true,
72
+ setting: true,
73
+ hotkey: true,
74
+ pip: true,
75
+ lock: true,
76
+ fastForward: true,
77
+ playbackRate: true,
78
+ customType: isM3u8
79
+ ? {
80
+ m3u8: (video: HTMLVideoElement, src: string) => {
81
+ if (Hls.isSupported()) {
82
+ const hls = new Hls()
83
+ hls.loadSource(src)
84
+ hls.attachMedia(video)
85
+ } else if (video.canPlayType("application/vnd.apple.mpegurl")) {
86
+ video.src = src
87
+ }
88
+ },
89
+ }
90
+ : undefined,
91
+ })
92
+
93
+ artInstance.value.on("video:timeupdate", () => {
94
+ if (!artInstance.value) return
95
+ emit("time-update", {
96
+ currentTime: artInstance.value.currentTime,
97
+ duration: artInstance.value.duration,
98
+ })
99
+ })
100
+ }
101
+
102
+ watch(
103
+ () => [props.url, props.type, props.parseUrl],
104
+ () => {
105
+ if (mode.value === "iframe") {
106
+ if (artInstance.value) {
107
+ artInstance.value.destroy()
108
+ artInstance.value = null
109
+ }
110
+ } else {
111
+ nextTick(() => initArtplayer())
112
+ }
113
+ }
114
+ )
115
+
116
+ onMounted(() => {
117
+ if (mode.value !== "iframe") {
118
+ nextTick(() => initArtplayer())
119
+ }
120
+ })
121
+
122
+ onBeforeUnmount(() => {
123
+ if (artInstance.value) {
124
+ artInstance.value.destroy()
125
+ artInstance.value = null
126
+ }
127
+ })
128
+ </script>
composables/useApi.ts CHANGED
@@ -1,37 +1,52 @@
 
 
1
  export function useApi() {
2
- const userStore = useUserStore();
3
- const config = useRuntimeConfig();
4
 
5
  function getHeaders(): Record<string, string> {
6
- const headers: Record<string, string> = {};
7
  if (userStore.token) {
8
- headers.Authorization = `Bearer ${userStore.token}`;
 
 
 
 
 
 
 
 
 
 
9
  }
10
- return headers;
11
  }
12
 
13
- async function get<T>(path: string, params?: Record<string, any>) {
14
- return $fetch<T>(`${config.public.apiBase}${path}`, {
15
  method: "GET",
16
  params,
17
  headers: getHeaders(),
18
- });
 
19
  }
20
 
21
- async function post<T>(path: string, body?: Record<string, any>) {
22
- return $fetch<T>(`${config.public.apiBase}${path}`, {
23
  method: "POST",
24
  body,
25
  headers: getHeaders(),
26
- });
 
27
  }
28
 
29
- async function del<T>(path: string) {
30
- return $fetch<T>(`${config.public.apiBase}${path}`, {
31
  method: "DELETE",
32
  headers: getHeaders(),
33
- });
 
34
  }
35
 
36
- return { get, post, del };
37
  }
 
1
+ import type { ApiResponse } from "~/types/api"
2
+
3
  export function useApi() {
4
+ const userStore = useUserStore()
5
+ const config = useRuntimeConfig()
6
 
7
  function getHeaders(): Record<string, string> {
8
+ const headers: Record<string, string> = {}
9
  if (userStore.token) {
10
+ headers.Authorization = `Bearer ${userStore.token}`
11
+ }
12
+ return headers
13
+ }
14
+
15
+ async function unwrap<T>(raw: any): Promise<T> {
16
+ if (raw && typeof raw === "object" && "code" in raw) {
17
+ if (raw.code !== 0) {
18
+ throw createError({ statusCode: raw.code, statusMessage: raw.msg || "Error" })
19
+ }
20
+ return raw.data as T
21
  }
22
+ return raw as T
23
  }
24
 
25
+ async function get<T>(path: string, params?: Record<string, any>): Promise<T> {
26
+ const raw = await $fetch<any>(`${config.public.apiBase}${path}`, {
27
  method: "GET",
28
  params,
29
  headers: getHeaders(),
30
+ })
31
+ return unwrap<T>(raw)
32
  }
33
 
34
+ async function post<T>(path: string, body?: Record<string, any>): Promise<T> {
35
+ const raw = await $fetch<any>(`${config.public.apiBase}${path}`, {
36
  method: "POST",
37
  body,
38
  headers: getHeaders(),
39
+ })
40
+ return unwrap<T>(raw)
41
  }
42
 
43
+ async function del<T>(path: string): Promise<T> {
44
+ const raw = await $fetch<any>(`${config.public.apiBase}${path}`, {
45
  method: "DELETE",
46
  headers: getHeaders(),
47
+ })
48
+ return unwrap<T>(raw)
49
  }
50
 
51
+ return { get, post, del }
52
  }
layouts/default.vue CHANGED
@@ -2,18 +2,69 @@
2
  <div class="min-h-screen flex flex-col bg-gray-950 text-white">
3
  <header class="sticky top-0 z-50 bg-gray-900/95 backdrop-blur border-b border-gray-800">
4
  <div class="max-w-7xl mx-auto px-4 h-14 flex items-center justify-between">
5
- <NuxtLink to="/" class="text-lg font-bold text-emerald-400">BinV</NuxtLink>
6
- <div class="flex items-center gap-4">
7
- <NuxtLink to="/search" class="text-gray-400 hover:text-white text-sm">搜索</NuxtLink>
8
- <NuxtLink to="/login" class="text-gray-400 hover:text-white text-sm">登录</NuxtLink>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  </div>
10
  </div>
11
  </header>
12
  <main class="flex-1">
13
  <slot />
14
  </main>
15
- <footer class="py-6 text-center text-gray-500 text-sm border-t border-gray-800">
16
  &copy; {{ new Date().getFullYear() }} BinV
17
  </footer>
18
  </div>
19
- </template>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  <div class="min-h-screen flex flex-col bg-gray-950 text-white">
3
  <header class="sticky top-0 z-50 bg-gray-900/95 backdrop-blur border-b border-gray-800">
4
  <div class="max-w-7xl mx-auto px-4 h-14 flex items-center justify-between">
5
+ <div class="flex items-center gap-6">
6
+ <NuxtLink to="/" class="text-lg font-bold text-emerald-400">BinV</NuxtLink>
7
+ <nav class="hidden sm:flex gap-1">
8
+ <NuxtLink
9
+ v-for="cat in topCategories"
10
+ :key="cat.id"
11
+ :to="`/category/${cat.id}`"
12
+ class="px-3 py-1.5 rounded-md text-sm text-gray-400 hover:text-white hover:bg-gray-800 transition"
13
+ >
14
+ {{ cat.name }}
15
+ </NuxtLink>
16
+ </nav>
17
+ </div>
18
+ <div class="flex items-center gap-3">
19
+ <NuxtLink to="/search" class="text-gray-400 hover:text-white">
20
+ <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" /></svg>
21
+ </NuxtLink>
22
+ <NuxtLink v-if="!userStore.isLoggedIn" to="/login" class="text-sm text-gray-400 hover:text-white">登录</NuxtLink>
23
+ <NDropdown v-else :options="userMenuOptions" @select="onUserMenuSelect">
24
+ <NButton quaternary size="small" class="text-sm text-gray-300">{{ userStore.userInfo?.nickname || '用户' }}</NButton>
25
+ </NDropdown>
26
  </div>
27
  </div>
28
  </header>
29
  <main class="flex-1">
30
  <slot />
31
  </main>
32
+ <footer class="py-6 text-center text-gray-600 text-sm border-t border-gray-800">
33
  &copy; {{ new Date().getFullYear() }} BinV
34
  </footer>
35
  </div>
36
+ </template>
37
+
38
+ <script setup lang="ts">
39
+ import type { CategoryUserNode } from '~/types/category'
40
+
41
+ const userStore = useUserStore()
42
+ const { get } = useApi()
43
+
44
+ const topCategories = ref<CategoryUserNode[]>([])
45
+ const { data: catData } = await useAsyncData('categories', () => get<CategoryUserNode[]>('/user/category'))
46
+ topCategories.value = catData.value ?? []
47
+
48
+ const userMenuOptions = [
49
+ { label: '我的收藏', key: 'favorite' },
50
+ { label: '播放历史', key: 'history' },
51
+ { label: '退出登录', key: 'logout' },
52
+ ]
53
+
54
+ function onUserMenuSelect(key: string) {
55
+ if (key === 'logout') {
56
+ userStore.logout()
57
+ navigateTo('/')
58
+ } else if (key === 'favorite') {
59
+ navigateTo('/favorite')
60
+ } else if (key === 'history') {
61
+ navigateTo('/history')
62
+ }
63
+ }
64
+
65
+ onMounted(() => {
66
+ if (userStore.isLoggedIn && !userStore.userInfo) {
67
+ userStore.fetchProfile()
68
+ }
69
+ })
70
+ </script>
nuxt.config.ts CHANGED
@@ -7,7 +7,7 @@ export default defineNuxtConfig({
7
  ],
8
  css: ["~/assets/css/main.css"],
9
  runtimeConfig: {
10
- apiBaseUrl: process.env.NUXT_API_BASE_URL || "http://localhost:9999",
11
  public: {
12
  apiBase: process.env.NUXT_PUBLIC_API_BASE || "/api",
13
  siteName: "BinV",
 
7
  ],
8
  css: ["~/assets/css/main.css"],
9
  runtimeConfig: {
10
+ apiBaseUrl: process.env.NUXT_API_BASE_URL || "http://127.0.0.1:9999",
11
  public: {
12
  apiBase: process.env.NUXT_PUBLIC_API_BASE || "/api",
13
  siteName: "BinV",
pages/category/[id].vue CHANGED
@@ -1 +1,67 @@
1
- <template><div class="container mx-auto p-4"><h1 class="text-2xl font-bold">分类列表</h1><p>分类ID: {{ $route.params.id }}</p></div></template>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <template>
2
+ <div class="max-w-7xl mx-auto px-4 py-6">
3
+ <h1 class="text-2xl font-bold mb-6">{{ categoryName }}</h1>
4
+
5
+ <div class="flex flex-wrap gap-2 mb-6">
6
+ <NuxtLink
7
+ v-for="cat in categories"
8
+ :key="cat.id"
9
+ :to="`/category/${cat.id}`"
10
+ :class="[
11
+ 'px-3 py-1 rounded-full text-sm transition',
12
+ cat.id === categoryId ? 'bg-emerald-600 text-white' : 'bg-gray-800 text-gray-400 hover:text-white'
13
+ ]"
14
+ >
15
+ {{ cat.name }}
16
+ </NuxtLink>
17
+ </div>
18
+
19
+ <div v-if="pending" class="text-center text-gray-500 py-12">加载中...</div>
20
+ <template v-else>
21
+ <VodGrid v-if="list.length" :list="list" />
22
+ <div v-else class="text-center text-gray-500 py-12">暂无数据</div>
23
+ </template>
24
+
25
+ <div v-if="total > pageSize" class="flex justify-center mt-8">
26
+ <NPagination v-model:page="page" :page-count="Math.ceil(total / pageSize)" />
27
+ </div>
28
+ </div>
29
+ </template>
30
+
31
+ <script setup lang="ts">
32
+ import type { VodUserItem } from '~/types/vod'
33
+ import type { CategoryUserNode } from '~/types/category'
34
+ import type { PaginatedData } from '~/types/api'
35
+
36
+ const route = useRoute()
37
+ const { get } = useApi()
38
+
39
+ const categoryId = computed(() => Number(route.params.id))
40
+ const page = ref(1)
41
+ const pageSize = 24
42
+
43
+ const { data: catData } = await useAsyncData('categories', () => get<CategoryUserNode[]>('/user/category'))
44
+ const categories = computed(() => {
45
+ const all = catData.value ?? []
46
+ return [{ id: 0, name: '全部', children: null }, ...all]
47
+ })
48
+ const categoryName = computed(() => {
49
+ const found = categories.value.find(c => c.id === categoryId.value)
50
+ return found?.name ?? '分类'
51
+ })
52
+
53
+ const { data, pending } = await useAsyncData(
54
+ () => `category-${categoryId.value}-${page.value}`,
55
+ () => get<PaginatedData<VodUserItem>>('/user/vod', {
56
+ category_id: categoryId.value || undefined,
57
+ page: page.value,
58
+ page_size: pageSize,
59
+ }),
60
+ { watch: [categoryId, page] }
61
+ )
62
+
63
+ const list = computed(() => data.value?.list ?? [])
64
+ const total = computed(() => data.value?.total ?? 0)
65
+
66
+ useHead({ title: `${categoryName.value} - BinV` })
67
+ </script>
pages/favorite.vue CHANGED
@@ -1 +1,73 @@
1
- <script setup>definePageMeta({ middleware: "auth" })</script><template><div class="container mx-auto p-4"><h1 class="text-2xl font-bold">我的收藏</h1></div></template>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <template>
2
+ <div class="max-w-7xl mx-auto px-4 py-6">
3
+ <h1 class="text-2xl font-bold mb-6">我的收藏</h1>
4
+ <div v-if="loading" class="text-center text-gray-500 py-12">加载中...</div>
5
+ <template v-else>
6
+ <div v-if="list.length" class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-6 gap-4">
7
+ <NuxtLink
8
+ v-for="item in list"
9
+ :key="item.id"
10
+ :to="`/vod/${item.vod_id}`"
11
+ class="group block"
12
+ >
13
+ <div class="aspect-[2/3] rounded-lg overflow-hidden bg-gray-800 relative">
14
+ <img
15
+ v-if="item.vod_cover"
16
+ :src="item.vod_cover"
17
+ :alt="item.vod_name"
18
+ loading="lazy"
19
+ class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300"
20
+ />
21
+ <div v-else class="w-full h-full flex items-center justify-center text-gray-600 text-xs">
22
+ {{ item.vod_name }}
23
+ </div>
24
+ <span
25
+ v-if="item.vod_remarks"
26
+ class="absolute bottom-0 left-0 right-0 bg-gradient-to-t from-black/80 to-transparent px-2 py-1 text-xs text-white truncate"
27
+ >
28
+ {{ item.vod_remarks }}
29
+ </span>
30
+ <button
31
+ class="absolute top-2 right-2 w-7 h-7 bg-black/60 rounded-full flex items-center justify-center opacity-0 group-hover:opacity-100 transition"
32
+ @click.prevent="removeFav(item.vod_id)"
33
+ >
34
+ <svg xmlns="http://www.w3.org/2000/svg" class="w-4 h-4 text-red-400" fill="currentColor" viewBox="0 0 24 24"><path d="M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z"/></svg>
35
+ </button>
36
+ </div>
37
+ <p class="mt-2 text-sm text-white truncate group-hover:text-emerald-400 transition">{{ item.vod_name }}</p>
38
+ </NuxtLink>
39
+ </div>
40
+ <div v-else class="text-center text-gray-500 py-12">暂无收藏</div>
41
+ </template>
42
+ </div>
43
+ </template>
44
+
45
+ <script setup lang="ts">
46
+ definePageMeta({ middleware: "auth" })
47
+
48
+ import type { PaginatedData } from '~/types/api'
49
+
50
+ const { get, del } = useApi()
51
+ const list = ref<any[]>([])
52
+ const loading = ref(true)
53
+
54
+ async function fetchFavorites() {
55
+ loading.value = true
56
+ try {
57
+ const data = await get<PaginatedData<any>>('/user/favorite', { page: 1, page_size: 100 })
58
+ list.value = data?.list ?? []
59
+ } catch {} finally {
60
+ loading.value = false
61
+ }
62
+ }
63
+
64
+ async function removeFav(vodId: number) {
65
+ try {
66
+ await del(`/user/favorite/${vodId}`)
67
+ list.value = list.value.filter(item => item.vod_id !== vodId)
68
+ } catch {}
69
+ }
70
+
71
+ onMounted(() => fetchFavorites())
72
+ useHead({ title: '我的收藏 - BinV' })
73
+ </script>
pages/history.vue CHANGED
@@ -1 +1,70 @@
1
- <script setup>definePageMeta({ middleware: "auth" })</script><template><div class="container mx-auto p-4"><h1 class="text-2xl font-bold">播放历史</h1></div></template>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <template>
2
+ <div class="max-w-7xl mx-auto px-4 py-6">
3
+ <h1 class="text-2xl font-bold mb-6">播放历史</h1>
4
+ <div v-if="loading" class="text-center text-gray-500 py-12">加载中...</div>
5
+ <template v-else>
6
+ <div v-if="list.length" class="space-y-3">
7
+ <div
8
+ v-for="item in list"
9
+ :key="item.id"
10
+ class="flex gap-4 bg-gray-900 rounded-lg p-4 group hover:bg-gray-800/80 transition"
11
+ >
12
+ <NuxtLink :to="`/vod/${item.vod_id}`" class="flex-shrink-0 w-24 aspect-[2/3] rounded overflow-hidden bg-gray-800">
13
+ <img v-if="item.vod_cover" :src="item.vod_cover" :alt="item.vod_name" loading="lazy" class="w-full h-full object-cover" />
14
+ <div v-else class="w-full h-full flex items-center justify-center text-gray-600 text-xs">{{ item.vod_name }}</div>
15
+ </NuxtLink>
16
+ <div class="flex-1 min-w-0">
17
+ <NuxtLink :to="`/vod/${item.vod_id}`" class="text-white font-medium hover:text-emerald-400 transition">{{ item.vod_name }}</NuxtLink>
18
+ <p class="text-sm text-gray-400 mt-1">{{ item.episode || '未知集数' }}</p>
19
+ <p v-if="item.duration > 0" class="text-xs text-gray-500 mt-1">
20
+ 播放进度: {{ formatTime(item.progress) }} / {{ formatTime(item.duration) }}
21
+ </p>
22
+ </div>
23
+ <button
24
+ class="flex-shrink-0 self-center text-gray-600 hover:text-red-400 transition"
25
+ @click="deleteItem(item.id)"
26
+ >
27
+ <svg xmlns="http://www.w3.org/2000/svg" class="w-5 h-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" /></svg>
28
+ </button>
29
+ </div>
30
+ </div>
31
+ <div v-else class="text-center text-gray-500 py-12">暂无播放记录</div>
32
+ </template>
33
+ </div>
34
+ </template>
35
+
36
+ <script setup lang="ts">
37
+ definePageMeta({ middleware: "auth" })
38
+
39
+ import type { PaginatedData } from '~/types/api'
40
+
41
+ const { get, del } = useApi()
42
+ const list = ref<any[]>([])
43
+ const loading = ref(true)
44
+
45
+ async function fetchHistory() {
46
+ loading.value = true
47
+ try {
48
+ const data = await get<PaginatedData<any>>('/user/history', { page: 1, page_size: 50 })
49
+ list.value = data?.list ?? []
50
+ } catch {} finally {
51
+ loading.value = false
52
+ }
53
+ }
54
+
55
+ async function deleteItem(id: number) {
56
+ try {
57
+ await del(`/user/history/${id}`)
58
+ list.value = list.value.filter(item => item.id !== id)
59
+ } catch {}
60
+ }
61
+
62
+ function formatTime(seconds: number): string {
63
+ const m = Math.floor(seconds / 60)
64
+ const s = seconds % 60
65
+ return `${m}:${s.toString().padStart(2, '0')}`
66
+ }
67
+
68
+ onMounted(() => fetchHistory())
69
+ useHead({ title: '播放历史 - BinV' })
70
+ </script>
pages/index.vue CHANGED
@@ -1,16 +1,39 @@
1
  <template>
2
- <div class="container mx-auto px-4 py-8">
3
- <h1 class="text-3xl font-bold mb-6">推荐影片</h1>
4
- <div class="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-5 xl:grid-cols-6 gap-4">
5
- <div v-for="i in 12" :key="i" class="bg-gray-800 rounded-lg overflow-hidden hover:scale-105 transition-transform">
6
- <div class="aspect-[2/3] bg-gray-700 flex items-center justify-center text-gray-500 text-sm">
7
- Poster {{ i }}
8
- </div>
9
- <div class="p-2">
10
- <p class="text-sm truncate">影片名称 {{ i }}</p>
11
- <p class="text-xs text-gray-500">备注</p>
12
- </div>
 
 
 
 
13
  </div>
14
- </div>
15
  </div>
16
- </template>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  <template>
2
+ <div class="max-w-7xl mx-auto px-4 py-6">
3
+ <section v-if="recommended.length" class="mb-10">
4
+ <h2 class="text-xl font-bold mb-4 flex items-center gap-2">
5
+ <span class="text-emerald-400">&#x1F525;</span> 推荐
6
+ </h2>
7
+ <VodGrid :list="recommended" />
8
+ </section>
9
+
10
+ <section v-if="latest.length" class="mb-10">
11
+ <h2 class="text-xl font-bold mb-4 flex items-center gap-2">
12
+ <span class="text-blue-400">&#x1F195;</span> 最新更新
13
+ </h2>
14
+ <VodGrid :list="latest" />
15
+ <div v-if="latest.length >= 24" class="mt-6 text-center">
16
+ <NuxtLink to="/category/1" class="text-emerald-400 hover:underline text-sm">查看更多 &rarr;</NuxtLink>
17
  </div>
18
+ </section>
19
  </div>
20
+ </template>
21
+
22
+ <script setup lang="ts">
23
+ import type { VodUserItem } from '~/types/vod'
24
+ import type { PaginatedData } from '~/types/api'
25
+
26
+ const { get } = useApi()
27
+
28
+ const { data: recData } = await useAsyncData('recommended', () =>
29
+ get<PaginatedData<VodUserItem>>('/user/vod/recommended', { page: 1, page_size: 12 })
30
+ )
31
+ const { data: latData } = await useAsyncData('latest', () =>
32
+ get<PaginatedData<VodUserItem>>('/user/vod/latest', { hours: 72, page: 1, page_size: 24 })
33
+ )
34
+
35
+ const recommended = computed(() => recData.value?.list ?? [])
36
+ const latest = computed(() => latData.value?.list ?? [])
37
+
38
+ useHead({ title: 'BinV - 影视资源聚合' })
39
+ </script>
pages/login.vue CHANGED
@@ -1 +1,72 @@
1
- <template><div class="container mx-auto p-4 max-w-md"><h1 class="text-2xl font-bold mb-4">登录</h1><div class="space-y-4"><input type="text" placeholder="用户名" class="w-full p-2 rounded bg-gray-800 border border-gray-700" /><input type="password" placeholder="密码" class="w-full p-2 rounded bg-gray-800 border border-gray-700" /><button class="w-full p-2 rounded bg-emerald-600 hover:bg-emerald-500">登录</button></div></div></template>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <template>
2
+ <div class="max-w-md mx-auto px-4 py-16">
3
+ <div class="bg-gray-900 rounded-lg p-8">
4
+ <h1 class="text-2xl font-bold text-center mb-6">登录</h1>
5
+ <div class="space-y-4">
6
+ <div>
7
+ <label class="block text-sm text-gray-400 mb-1">用户名</label>
8
+ <input
9
+ v-model="form.username"
10
+ type="text"
11
+ placeholder="请输入用户名"
12
+ class="w-full px-3 py-2.5 rounded-lg bg-gray-800 border border-gray-700 text-white placeholder-gray-500 focus:outline-none focus:border-emerald-500"
13
+ />
14
+ </div>
15
+ <div>
16
+ <label class="block text-sm text-gray-400 mb-1">密码</label>
17
+ <input
18
+ v-model="form.password"
19
+ type="password"
20
+ placeholder="请输入密码"
21
+ class="w-full px-3 py-2.5 rounded-lg bg-gray-800 border border-gray-700 text-white placeholder-gray-500 focus:outline-none focus:border-emerald-500"
22
+ @keyup.enter="handleLogin"
23
+ />
24
+ </div>
25
+ <p v-if="errorMsg" class="text-red-400 text-sm">{{ errorMsg }}</p>
26
+ <button
27
+ :disabled="loading"
28
+ class="w-full py-2.5 rounded-lg bg-emerald-600 hover:bg-emerald-500 disabled:opacity-50 disabled:cursor-not-allowed text-white font-medium transition"
29
+ @click="handleLogin"
30
+ >
31
+ {{ loading ? '登录中...' : '登录' }}
32
+ </button>
33
+ </div>
34
+ <p class="mt-4 text-center text-sm text-gray-500">
35
+ 还没有账号?
36
+ <NuxtLink to="/register" class="text-emerald-400 hover:underline">立即注册</NuxtLink>
37
+ </p>
38
+ </div>
39
+ </div>
40
+ </template>
41
+
42
+ <script setup lang="ts">
43
+ const userStore = useUserStore()
44
+ const { post } = useApi()
45
+ const route = useRoute()
46
+
47
+ const form = reactive({ username: '', password: '' })
48
+ const loading = ref(false)
49
+ const errorMsg = ref('')
50
+
51
+ async function handleLogin() {
52
+ if (!form.username || !form.password) {
53
+ errorMsg.value = '请填写用户名和密码'
54
+ return
55
+ }
56
+ loading.value = true
57
+ errorMsg.value = ''
58
+ try {
59
+ const data = await post<any>('/user/auth/login', form)
60
+ userStore.token = data.accessToken
61
+ await userStore.fetchProfile()
62
+ const redirect = (route.query.redirect as string) || '/'
63
+ navigateTo(redirect)
64
+ } catch (e: any) {
65
+ errorMsg.value = e?.statusMessage || e?.message || '登录失败'
66
+ } finally {
67
+ loading.value = false
68
+ }
69
+ }
70
+
71
+ useHead({ title: '登录 - BinV' })
72
+ </script>
pages/register.vue CHANGED
@@ -1 +1,91 @@
1
- <template><div class="container mx-auto p-4 max-w-md"><h1 class="text-2xl font-bold mb-4">注册</h1><div class="space-y-4"><input type="text" placeholder="用户名" class="w-full p-2 rounded bg-gray-800 border border-gray-700" /><input type="email" placeholder="邮箱" class="w-full p-2 rounded bg-gray-800 border border-gray-700" /><input type="password" placeholder="密码" class="w-full p-2 rounded bg-gray-800 border border-gray-700" /><button class="w-full p-2 rounded bg-emerald-600 hover:bg-emerald-500">注册</button></div></div></template>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <template>
2
+ <div class="max-w-md mx-auto px-4 py-16">
3
+ <div class="bg-gray-900 rounded-lg p-8">
4
+ <h1 class="text-2xl font-bold text-center mb-6">注册</h1>
5
+ <div class="space-y-4">
6
+ <div>
7
+ <label class="block text-sm text-gray-400 mb-1">用户名</label>
8
+ <input
9
+ v-model="form.username"
10
+ type="text"
11
+ placeholder="3-30位字符"
12
+ class="w-full px-3 py-2.5 rounded-lg bg-gray-800 border border-gray-700 text-white placeholder-gray-500 focus:outline-none focus:border-emerald-500"
13
+ />
14
+ </div>
15
+ <div>
16
+ <label class="block text-sm text-gray-400 mb-1">邮箱</label>
17
+ <input
18
+ v-model="form.email"
19
+ type="email"
20
+ placeholder="可选"
21
+ class="w-full px-3 py-2.5 rounded-lg bg-gray-800 border border-gray-700 text-white placeholder-gray-500 focus:outline-none focus:border-emerald-500"
22
+ />
23
+ </div>
24
+ <div>
25
+ <label class="block text-sm text-gray-400 mb-1">昵称</label>
26
+ <input
27
+ v-model="form.nickname"
28
+ type="text"
29
+ placeholder="可选,默认同用户名"
30
+ class="w-full px-3 py-2.5 rounded-lg bg-gray-800 border border-gray-700 text-white placeholder-gray-500 focus:outline-none focus:border-emerald-500"
31
+ />
32
+ </div>
33
+ <div>
34
+ <label class="block text-sm text-gray-400 mb-1">密码</label>
35
+ <input
36
+ v-model="form.password"
37
+ type="password"
38
+ placeholder="6-50位字符"
39
+ class="w-full px-3 py-2.5 rounded-lg bg-gray-800 border border-gray-700 text-white placeholder-gray-500 focus:outline-none focus:border-emerald-500"
40
+ />
41
+ </div>
42
+ <p v-if="errorMsg" class="text-red-400 text-sm">{{ errorMsg }}</p>
43
+ <button
44
+ :disabled="loading"
45
+ class="w-full py-2.5 rounded-lg bg-emerald-600 hover:bg-emerald-500 disabled:opacity-50 disabled:cursor-not-allowed text-white font-medium transition"
46
+ @click="handleRegister"
47
+ >
48
+ {{ loading ? '注册中...' : '注册' }}
49
+ </button>
50
+ </div>
51
+ <p class="mt-4 text-center text-sm text-gray-500">
52
+ 已有账号?
53
+ <NuxtLink to="/login" class="text-emerald-400 hover:underline">去登录</NuxtLink>
54
+ </p>
55
+ </div>
56
+ </div>
57
+ </template>
58
+
59
+ <script setup lang="ts">
60
+ const userStore = useUserStore()
61
+ const { post } = useApi()
62
+
63
+ const form = reactive({ username: '', email: '', nickname: '', password: '' })
64
+ const loading = ref(false)
65
+ const errorMsg = ref('')
66
+
67
+ async function handleRegister() {
68
+ if (!form.username || !form.password) {
69
+ errorMsg.value = '请填写用户名和密码'
70
+ return
71
+ }
72
+ if (form.password.length < 6) {
73
+ errorMsg.value = '密码至少6位'
74
+ return
75
+ }
76
+ loading.value = true
77
+ errorMsg.value = ''
78
+ try {
79
+ const data = await post<any>('/user/auth/register', form)
80
+ userStore.token = data.accessToken
81
+ await userStore.fetchProfile()
82
+ navigateTo('/')
83
+ } catch (e: any) {
84
+ errorMsg.value = e?.statusMessage || e?.message || '注册失败'
85
+ } finally {
86
+ loading.value = false
87
+ }
88
+ }
89
+
90
+ useHead({ title: '注册 - BinV' })
91
+ </script>
pages/search.vue CHANGED
@@ -1 +1,69 @@
1
- <template><div class="container mx-auto p-4"><h1 class="text-2xl font-bold">搜索</h1></div></template>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <template>
2
+ <div class="max-w-7xl mx-auto px-4 py-6">
3
+ <div class="mb-8">
4
+ <div class="relative max-w-xl mx-auto">
5
+ <input
6
+ v-model="keyword"
7
+ type="text"
8
+ placeholder="搜索影片..."
9
+ class="w-full px-4 py-3 rounded-lg bg-gray-800 border border-gray-700 text-white placeholder-gray-500 focus:outline-none focus:border-emerald-500"
10
+ @keyup.enter="doSearch"
11
+ />
12
+ <button class="absolute right-2 top-1/2 -translate-y-1/2 px-4 py-1.5 bg-emerald-600 hover:bg-emerald-500 rounded text-sm" @click="doSearch">搜索</button>
13
+ </div>
14
+ </div>
15
+
16
+ <div v-if="searched">
17
+ <h2 class="text-lg mb-4 text-gray-300">搜索结果 <span class="text-gray-500 text-sm">共 {{ total }} 条</span></h2>
18
+ <VodGrid v-if="list.length" :list="list" />
19
+ <div v-else class="text-center text-gray-500 py-12">未找到相关影片</div>
20
+ <div v-if="total > pageSize" class="flex justify-center mt-8">
21
+ <NPagination v-model:page="page" :page-count="Math.ceil(total / pageSize)" />
22
+ </div>
23
+ </div>
24
+ </div>
25
+ </template>
26
+
27
+ <script setup lang="ts">
28
+ import type { VodUserItem } from '~/types/vod'
29
+ import type { PaginatedData } from '~/types/api'
30
+
31
+ const route = useRoute()
32
+ const { get } = useApi()
33
+
34
+ const keyword = ref((route.query.q as string) ?? '')
35
+ const page = ref(1)
36
+ const pageSize = 24
37
+ const searched = ref(!!keyword.value)
38
+ const list = ref<VodUserItem[]>([])
39
+ const total = ref(0)
40
+
41
+ async function doSearch() {
42
+ if (!keyword.value.trim()) return
43
+ searched.value = true
44
+ page.value = 1
45
+ navigateTo({ path: '/search', query: { q: keyword.value } })
46
+ await fetchResults()
47
+ }
48
+
49
+ async function fetchResults() {
50
+ try {
51
+ const data = await get<PaginatedData<VodUserItem>>('/user/vod/search', {
52
+ keyword: keyword.value,
53
+ page: page.value,
54
+ page_size: pageSize,
55
+ })
56
+ list.value = data?.list ?? []
57
+ total.value = data?.total ?? 0
58
+ } catch {
59
+ list.value = []
60
+ total.value = 0
61
+ }
62
+ }
63
+
64
+ watch(page, fetchResults)
65
+
66
+ if (keyword.value) fetchResults()
67
+
68
+ useHead({ title: '搜索 - BinV' })
69
+ </script>
pages/vod/[id].vue CHANGED
@@ -1 +1,198 @@
1
- <template><div class="container mx-auto p-4"><h1 class="text-2xl font-bold">影片详情</h1><p>影片ID: {{ $route.params.id }}</p></div></template>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <template>
2
+ <div class="max-w-7xl mx-auto px-4 py-6">
3
+ <div v-if="pending" class="text-center text-gray-500 py-20">加载中...</div>
4
+ <div v-else-if="!vod" class="text-center text-gray-500 py-20">影片不存在</div>
5
+ <template v-else>
6
+ <div class="lg:flex gap-8">
7
+ <div class="lg:w-2/3">
8
+ <VodPlayer
9
+ v-if="currentEpisodeUrl"
10
+ :url="currentEpisodeUrl"
11
+ :type="currentPlayType"
12
+ :poster="vod.cover ?? undefined"
13
+ :parse-url="currentParseUrl"
14
+ @time-update="onTimeUpdate"
15
+ />
16
+ <div v-else class="aspect-video bg-gray-800 rounded-lg flex items-center justify-center text-gray-500">
17
+ 选择集数开始播放
18
+ </div>
19
+
20
+ <div v-if="vod.sources?.length" class="mt-4">
21
+ <div class="flex gap-2 mb-3 flex-wrap">
22
+ <button
23
+ v-for="src in vod.sources"
24
+ :key="src.source_id"
25
+ :class="[
26
+ 'px-3 py-1.5 rounded text-sm transition',
27
+ activeSourceId === src.source_id
28
+ ? 'bg-emerald-600 text-white'
29
+ : 'bg-gray-800 text-gray-400 hover:text-white hover:bg-gray-700'
30
+ ]"
31
+ @click="activeSourceId = src.source_id"
32
+ >
33
+ {{ src.play_from_label }}
34
+ </button>
35
+ </div>
36
+
37
+ <div v-if="activeSource" class="flex flex-wrap gap-2">
38
+ <button
39
+ v-for="(ep, ei) in activeSource.episodes"
40
+ :key="ei"
41
+ :class="[
42
+ 'px-3 py-1.5 rounded text-sm transition min-w-[3rem]',
43
+ currentEpisodeIndex === ei && activeSourceId === activeSource.source_id
44
+ ? 'bg-emerald-600 text-white'
45
+ : 'bg-gray-800 text-gray-400 hover:text-white hover:bg-gray-700'
46
+ ]"
47
+ @click="selectEpisode(ei)"
48
+ >
49
+ {{ ep.name }}
50
+ </button>
51
+ </div>
52
+ </div>
53
+ </div>
54
+
55
+ <div class="lg:w-1/3 mt-6 lg:mt-0">
56
+ <div class="bg-gray-900 rounded-lg p-5">
57
+ <h1 class="text-xl font-bold mb-3">{{ vod.name }}</h1>
58
+ <p v-if="vod.sub_name" class="text-sm text-gray-400 mb-2">{{ vod.sub_name }}</p>
59
+
60
+ <div class="flex items-center gap-3 mb-4 text-sm">
61
+ <span v-if="vod.score" class="text-amber-400 font-bold">{{ vod.score }}分</span>
62
+ <span v-if="vod.year" class="text-gray-400">{{ vod.year }}</span>
63
+ <span v-if="vod.area" class="text-gray-400">{{ vod.area }}</span>
64
+ <span v-if="vod.is_end" class="text-emerald-400 text-xs">已完结</span>
65
+ <span v-else class="text-orange-400 text-xs">连载中</span>
66
+ </div>
67
+
68
+ <div class="space-y-2 text-sm text-gray-400">
69
+ <p v-if="vod.director"><span class="text-gray-500">导演:</span> {{ vod.director }}</p>
70
+ <p v-if="vod.actor"><span class="text-gray-500">演员:</span> {{ vod.actor }}</p>
71
+ <p v-if="vod.lang"><span class="text-gray-500">语言:</span> {{ vod.lang }}</p>
72
+ <p v-if="vod.duration"><span class="text-gray-500">时长:</span> {{ vod.duration }}</p>
73
+ <p v-if="vod.remarks"><span class="text-gray-500">备注:</span> {{ vod.remarks }}</p>
74
+ </div>
75
+
76
+ <div class="flex gap-2 mt-5">
77
+ <button
78
+ :class="[
79
+ 'px-4 py-2 rounded text-sm transition',
80
+ isFavorited
81
+ ? 'bg-pink-600 text-white'
82
+ : 'bg-gray-700 text-gray-300 hover:bg-gray-600'
83
+ ]"
84
+ @click="toggleFavorite"
85
+ >
86
+ {{ isFavorited ? '已收藏' : '收藏' }}
87
+ </button>
88
+ </div>
89
+
90
+ <div v-if="vod.blurb" class="mt-5 pt-4 border-t border-gray-800">
91
+ <h3 class="text-sm text-gray-500 mb-2">简介</h3>
92
+ <p class="text-sm text-gray-400 leading-relaxed">{{ vod.blurb }}</p>
93
+ </div>
94
+ </div>
95
+ </div>
96
+ </div>
97
+ </template>
98
+ </div>
99
+ </template>
100
+
101
+ <script setup lang="ts">
102
+ import type { VodUserDetail, VodPlaySource } from '~/types/vod'
103
+
104
+ const route = useRoute()
105
+ const userStore = useUserStore()
106
+ const { get, post, del } = useApi()
107
+
108
+ const vodId = computed(() => Number(route.params.id))
109
+ const activeSourceId = ref<number | null>(null)
110
+ const currentEpisodeIndex = ref(-1)
111
+ const isFavorited = ref(false)
112
+
113
+ const { data: vod, pending } = await useAsyncData(
114
+ () => `vod-${vodId.value}`,
115
+ () => get<VodUserDetail>(`/user/vod/${vodId.value}`)
116
+ )
117
+
118
+ const activeSource = computed<VodPlaySource | null>(() => {
119
+ if (!vod.value?.sources?.length) return null
120
+ if (activeSourceId.value !== null) {
121
+ return vod.value.sources.find(s => s.source_id === activeSourceId.value) || vod.value.sources[0]
122
+ }
123
+ return vod.value.sources[0]
124
+ })
125
+
126
+ const currentEpisodeUrl = computed<string>(() => {
127
+ if (!activeSource.value || currentEpisodeIndex.value < 0) return ""
128
+ return activeSource.value.episodes[currentEpisodeIndex.value]?.url || ""
129
+ })
130
+
131
+ const currentPlayType = computed<"m3u8" | "iframe">(() => {
132
+ if (!activeSource.value) return "m3u8"
133
+ const url = currentEpisodeUrl.value.toLowerCase()
134
+ if (url.includes(".m3u8")) return "m3u8"
135
+ if (activeSource.value.parse_url) return "iframe"
136
+ return "m3u8"
137
+ })
138
+
139
+ const currentParseUrl = computed<string | null>(() => {
140
+ return activeSource.value?.parse_url || null
141
+ })
142
+
143
+ watch(
144
+ () => vod.value,
145
+ (v) => {
146
+ if (v?.sources?.length) {
147
+ activeSourceId.value = v.sources[0].source_id
148
+ }
149
+ },
150
+ { immediate: true }
151
+ )
152
+
153
+ function selectEpisode(index: number) {
154
+ currentEpisodeIndex.value = index
155
+ }
156
+
157
+ function onTimeUpdate(payload: { currentTime: number; duration: number }) {
158
+ if (!userStore.isLoggedIn || currentEpisodeIndex.value < 0 || !activeSource.value) return
159
+ const ep = activeSource.value.episodes[currentEpisodeIndex.value]
160
+ if (!ep) return
161
+ post("/user/history", {
162
+ vod_id: vodId.value,
163
+ source_id: activeSource.value.source_id,
164
+ episode: ep.name,
165
+ play_url: ep.url,
166
+ progress: Math.floor(payload.currentTime),
167
+ duration: Math.floor(payload.duration),
168
+ }).catch(() => {})
169
+ }
170
+
171
+ async function checkFavorite() {
172
+ if (!userStore.isLoggedIn) return
173
+ try {
174
+ const data = await get<any[]>("/user/favorite", { page: 1, page_size: 1000 })
175
+ isFavorited.value = Array.isArray(data) ? data.some((f: any) => f.vod_id === vodId.value) : false
176
+ } catch {}
177
+ }
178
+
179
+ async function toggleFavorite() {
180
+ if (!userStore.isLoggedIn) {
181
+ navigateTo("/login")
182
+ return
183
+ }
184
+ try {
185
+ if (isFavorited.value) {
186
+ await del(`/user/favorite/${vodId.value}`)
187
+ isFavorited.value = false
188
+ } else {
189
+ await post("/user/favorite", { vod_id: vodId.value })
190
+ isFavorited.value = true
191
+ }
192
+ } catch {}
193
+ }
194
+
195
+ onMounted(() => checkFavorite())
196
+
197
+ useHead({ title: vod.value ? `${vod.value.name} - BinV` : "影片详情 - BinV" })
198
+ </script>
stores/user.ts CHANGED
@@ -1,12 +1,28 @@
1
  export const useUserStore = defineStore("user", () => {
2
- const token = useCookie<string | null>("binv_token", { maxAge: 60 * 60 * 24 * 7 });
3
- const userInfo = ref<any>(null);
4
- const isLoggedIn = computed(() => !!token.value);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  function logout() {
7
- token.value = null;
8
- userInfo.value = null;
9
  }
10
 
11
- return { token, userInfo, isLoggedIn, logout };
12
- });
 
1
  export const useUserStore = defineStore("user", () => {
2
+ const token = useCookie<string | null>("binv_token", { maxAge: 60 * 60 * 24 * 7 })
3
+ const userInfo = ref<{
4
+ id: number
5
+ username: string | null
6
+ nickname: string | null
7
+ avatar: string | null
8
+ email: string | null
9
+ } | null>(null)
10
+ const isLoggedIn = computed(() => !!token.value)
11
+
12
+ async function fetchProfile() {
13
+ if (!token.value) return
14
+ try {
15
+ const { get } = useApi()
16
+ userInfo.value = await get<any>("/user/auth/profile")
17
+ } catch {
18
+ userInfo.value = null
19
+ }
20
+ }
21
 
22
  function logout() {
23
+ token.value = null
24
+ userInfo.value = null
25
  }
26
 
27
+ return { token, userInfo, isLoggedIn, fetchProfile, logout }
28
+ })
tsconfig.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "extends": "./.nuxt/tsconfig.json"
3
+ }
types/vod.ts CHANGED
@@ -3,7 +3,7 @@ export interface VodUserItem {
3
  name: string;
4
  cover: string | null;
5
  category_id: number;
6
- category_name: string;
7
  score: number | null;
8
  year: string | null;
9
  area: string | null;
@@ -14,6 +14,11 @@ export interface VodUserItem {
14
  }
15
 
16
  export interface VodUserDetail extends VodUserItem {
 
 
 
 
 
17
  blurb: string | null;
18
  content: string | null;
19
  sources: VodPlaySource[];
@@ -31,4 +36,4 @@ export interface EpisodeItem {
31
  name: string;
32
  url: string;
33
  parse_url: string | null;
34
- }
 
3
  name: string;
4
  cover: string | null;
5
  category_id: number;
6
+ category_name: string | null;
7
  score: number | null;
8
  year: string | null;
9
  area: string | null;
 
14
  }
15
 
16
  export interface VodUserDetail extends VodUserItem {
17
+ sub_name: string | null;
18
+ actor: string | null;
19
+ director: string | null;
20
+ lang: string | null;
21
+ duration: string | null;
22
  blurb: string | null;
23
  content: string | null;
24
  sources: VodPlaySource[];
 
36
  name: string;
37
  url: string;
38
  parse_url: string | null;
39
+ }