Commit ·
d003a1c
1
Parent(s): 2b5389d
chore: complete Nuxt 3 project setup with Naive UI, Tailwind, ArtPlayer
Browse files- .env.example +1 -1
- .gitignore +2 -0
- app.vue +4 -2
- assets/css/main.css +3 -0
- composables/useApi.ts +37 -0
- layouts/default.vue +19 -0
- middleware/auth.ts +6 -0
- nuxt.config.ts +12 -6
- package.json +13 -1
- pages/category/[id].vue +1 -0
- pages/favorite.vue +1 -0
- pages/history.vue +1 -0
- pages/index.vue +15 -2
- pages/login.vue +1 -0
- pages/register.vue +1 -0
- pages/search.vue +1 -0
- pages/vod/[id].vue +1 -0
- pnpm-lock.yaml +0 -0
- server/api/[...].ts +8 -0
- stores/user.ts +12 -0
- types/api.ts +12 -0
- types/category.ts +5 -0
- types/vod.ts +34 -0
.env.example
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
# Web
|
| 2 |
NUXT_PUBLIC_API_BASE=/api
|
| 3 |
-
NUXT_API_BASE_URL=http://localhost:9999
|
|
|
|
| 1 |
# Web
|
| 2 |
NUXT_PUBLIC_API_BASE=/api
|
| 3 |
+
NUXT_API_BASE_URL=http://localhost:9999
|
.gitignore
CHANGED
|
@@ -3,3 +3,5 @@ node_modules
|
|
| 3 |
.output
|
| 4 |
.env
|
| 5 |
.DS_Store
|
|
|
|
|
|
|
|
|
| 3 |
.output
|
| 4 |
.env
|
| 5 |
.DS_Store
|
| 6 |
+
*.log
|
| 7 |
+
dist
|
app.vue
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
<template>
|
| 2 |
<div>
|
| 3 |
-
<
|
|
|
|
|
|
|
| 4 |
</div>
|
| 5 |
-
</template>
|
|
|
|
| 1 |
<template>
|
| 2 |
<div>
|
| 3 |
+
<NuxtLayout>
|
| 4 |
+
<NuxtPage />
|
| 5 |
+
</NuxtLayout>
|
| 6 |
</div>
|
| 7 |
+
</template>
|
assets/css/main.css
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
@tailwind base;
|
| 2 |
+
@tailwind components;
|
| 3 |
+
@tailwind utilities;
|
composables/useApi.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
}
|
layouts/default.vue
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<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 |
+
<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 |
+
© {{ new Date().getFullYear() }} BinV
|
| 17 |
+
</footer>
|
| 18 |
+
</div>
|
| 19 |
+
</template>
|
middleware/auth.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export default defineNuxtRouteMiddleware((to) => {
|
| 2 |
+
const userStore = useUserStore();
|
| 3 |
+
if (!userStore.isLoggedIn) {
|
| 4 |
+
return navigateTo(`/login?redirect=${to.fullPath}`);
|
| 5 |
+
}
|
| 6 |
+
});
|
nuxt.config.ts
CHANGED
|
@@ -1,15 +1,21 @@
|
|
| 1 |
export default defineNuxtConfig({
|
| 2 |
devtools: { enabled: true },
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
runtimeConfig: {
|
| 5 |
apiBaseUrl: process.env.NUXT_API_BASE_URL || "http://localhost:9999",
|
| 6 |
public: {
|
| 7 |
-
apiBase: process.env.NUXT_PUBLIC_API_BASE || "/api"
|
| 8 |
-
|
|
|
|
| 9 |
},
|
| 10 |
routeRules: {
|
| 11 |
"/": { isr: 60 },
|
| 12 |
"/category/**": { isr: 60 },
|
| 13 |
-
"/vod/**": { isr: 300 }
|
| 14 |
-
}
|
| 15 |
-
})
|
|
|
|
| 1 |
export default defineNuxtConfig({
|
| 2 |
devtools: { enabled: true },
|
| 3 |
+
modules: [
|
| 4 |
+
"@pinia/nuxt",
|
| 5 |
+
"nuxtjs-naive-ui",
|
| 6 |
+
"@nuxtjs/tailwindcss",
|
| 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",
|
| 14 |
+
},
|
| 15 |
},
|
| 16 |
routeRules: {
|
| 17 |
"/": { isr: 60 },
|
| 18 |
"/category/**": { isr: 60 },
|
| 19 |
+
"/vod/**": { isr: 300 },
|
| 20 |
+
},
|
| 21 |
+
});
|
package.json
CHANGED
|
@@ -8,8 +8,20 @@
|
|
| 8 |
"preview": "nuxt preview"
|
| 9 |
},
|
| 10 |
"dependencies": {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
"nuxt": "^3.16.0",
|
|
|
|
|
|
|
| 12 |
"vue": "^3.5.13",
|
| 13 |
"vue-router": "^4.5.0"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
}
|
| 15 |
-
}
|
|
|
|
| 8 |
"preview": "nuxt preview"
|
| 9 |
},
|
| 10 |
"dependencies": {
|
| 11 |
+
"@iconify/vue": "^4.3.0",
|
| 12 |
+
"@pinia/nuxt": "^0.9.0",
|
| 13 |
+
"artplayer": "^5.4.0",
|
| 14 |
+
"hls.js": "^1.6.0",
|
| 15 |
+
"naive-ui": "^2.40.0",
|
| 16 |
"nuxt": "^3.16.0",
|
| 17 |
+
"nuxtjs-naive-ui": "^1.0.2",
|
| 18 |
+
"pinia": "^2.3.1",
|
| 19 |
"vue": "^3.5.13",
|
| 20 |
"vue-router": "^4.5.0"
|
| 21 |
+
},
|
| 22 |
+
"devDependencies": {
|
| 23 |
+
"@nuxtjs/tailwindcss": "^6.14.0",
|
| 24 |
+
"tailwindcss": "^3.4.0",
|
| 25 |
+
"typescript": "^5.6.0"
|
| 26 |
}
|
| 27 |
+
}
|
pages/category/[id].vue
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
<template><div class="container mx-auto p-4"><h1 class="text-2xl font-bold">分类列表</h1><p>分类ID: {{ $route.params.id }}</p></div></template>
|
pages/favorite.vue
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
<script setup>definePageMeta({ middleware: "auth" })</script><template><div class="container mx-auto p-4"><h1 class="text-2xl font-bold">我的收藏</h1></div></template>
|
pages/history.vue
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
<script setup>definePageMeta({ middleware: "auth" })</script><template><div class="container mx-auto p-4"><h1 class="text-2xl font-bold">播放历史</h1></div></template>
|
pages/index.vue
CHANGED
|
@@ -1,3 +1,16 @@
|
|
| 1 |
<template>
|
| 2 |
-
<div
|
| 3 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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>
|
pages/login.vue
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 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>
|
pages/register.vue
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 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>
|
pages/search.vue
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
<template><div class="container mx-auto p-4"><h1 class="text-2xl font-bold">搜索</h1></div></template>
|
pages/vod/[id].vue
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
<template><div class="container mx-auto p-4"><h1 class="text-2xl font-bold">影片详情</h1><p>影片ID: {{ $route.params.id }}</p></div></template>
|
pnpm-lock.yaml
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
server/api/[...].ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import type { H3Event } from "h3";
|
| 2 |
+
|
| 3 |
+
export default defineEventHandler(async (event: H3Event) => {
|
| 4 |
+
const config = useRuntimeConfig();
|
| 5 |
+
const targetPath = event.path.replace(/^\/api/, "");
|
| 6 |
+
const target = `${config.apiBaseUrl}${targetPath}`;
|
| 7 |
+
return proxyRequest(event, target);
|
| 8 |
+
});
|
stores/user.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
});
|
types/api.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export interface PaginatedData<T> {
|
| 2 |
+
list: T[];
|
| 3 |
+
total: number;
|
| 4 |
+
page: number;
|
| 5 |
+
page_size: number;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
export interface ApiResponse<T = any> {
|
| 9 |
+
code: number;
|
| 10 |
+
msg: string;
|
| 11 |
+
data: T;
|
| 12 |
+
}
|
types/category.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export interface CategoryUserNode {
|
| 2 |
+
id: number;
|
| 3 |
+
name: string;
|
| 4 |
+
children: CategoryUserNode[] | null;
|
| 5 |
+
}
|
types/vod.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
export interface VodUserItem {
|
| 2 |
+
id: number;
|
| 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;
|
| 10 |
+
is_end: boolean;
|
| 11 |
+
remarks: string | null;
|
| 12 |
+
source_count: number;
|
| 13 |
+
updated_at: string;
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
export interface VodUserDetail extends VodUserItem {
|
| 17 |
+
blurb: string | null;
|
| 18 |
+
content: string | null;
|
| 19 |
+
sources: VodPlaySource[];
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
export interface VodPlaySource {
|
| 23 |
+
source_id: number;
|
| 24 |
+
source_name: string;
|
| 25 |
+
play_from: string;
|
| 26 |
+
play_from_label: string;
|
| 27 |
+
episodes: EpisodeItem[];
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
export interface EpisodeItem {
|
| 31 |
+
name: string;
|
| 32 |
+
url: string;
|
| 33 |
+
parse_url: string | null;
|
| 34 |
+
}
|