init: initial commit

This commit is contained in:
Blizzard
2026-02-28 17:35:31 +08:00
commit da7ac70eeb
44 changed files with 13146 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
VITE_API_BASE_URL=http://localhost:8889/api
+24
View File
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
+73
View File
@@ -0,0 +1,73 @@
# React + TypeScript + Vite
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
## React Compiler
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
## Expanding the ESLint configuration
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
```js
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
// Other configs...
// Remove tseslint.configs.recommended and replace with this
tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
tseslint.configs.stylisticTypeChecked,
// Other configs...
],
languageOptions: {
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
// other options...
},
},
])
```
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
```js
// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
// Other configs...
// Enable lint rules for React
reactX.configs['recommended-typescript'],
// Enable lint rules for React DOM
reactDom.configs.recommended,
],
languageOptions: {
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
// other options...
},
},
])
```
+23
View File
@@ -0,0 +1,23 @@
{
"$schema": "https://ui.shadcn.com/schema.json",
"style": "new-york",
"rsc": false,
"tsx": true,
"tailwind": {
"config": "",
"css": "src/index.css",
"baseColor": "neutral",
"cssVariables": true,
"prefix": ""
},
"iconLibrary": "lucide",
"rtl": false,
"aliases": {
"components": "@/components",
"utils": "@/lib/utils",
"ui": "@/components/ui",
"lib": "@/lib",
"hooks": "@/hooks"
},
"registries": {}
}
+23
View File
@@ -0,0 +1,23 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
import { defineConfig, globalIgnores } from 'eslint/config'
export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
js.configs.recommended,
tseslint.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
},
])
+13
View File
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>morning-radio-frontend</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
+9703
View File
File diff suppressed because it is too large Load Diff
+47
View File
@@ -0,0 +1,47 @@
{
"name": "morning-radio-frontend",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@hookform/resolvers": "^5.2.2",
"@tailwindcss/vite": "^4.2.1",
"axios": "^1.13.6",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"lucide-react": "^0.575.0",
"next-themes": "^0.4.6",
"radix-ui": "^1.4.3",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"react-hook-form": "^7.71.2",
"react-router-dom": "^7.13.1",
"sonner": "^2.0.7",
"tailwind-merge": "^3.5.0",
"zod": "^4.3.6",
"zustand": "^5.0.11"
},
"devDependencies": {
"@eslint/js": "^9.39.1",
"@types/node": "^24.11.0",
"@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.1",
"eslint": "^9.39.1",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.24",
"globals": "^16.5.0",
"shadcn": "^3.8.5",
"tailwindcss": "^4.2.1",
"tw-animate-css": "^1.4.0",
"typescript": "~5.9.3",
"typescript-eslint": "^8.48.0",
"vite": "^7.3.1"
}
}
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

+42
View File
@@ -0,0 +1,42 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}
@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}
.card {
padding: 2em;
}
.read-the-docs {
color: #888;
}
+14
View File
@@ -0,0 +1,14 @@
import { RouterProvider } from 'react-router-dom';
import router from './router';
import { Toaster } from './components/ui/sonner';
function App() {
return (
<>
<RouterProvider router={router} />
<Toaster position="top-center" richColors />
</>
);
}
export default App;
+13
View File
@@ -0,0 +1,13 @@
import request from '../utils/request';
export const loginApi = (data: any) => {
return request.post('/auth/login', data);
};
export const getCaptchaApi = () => {
return request.get('/auth/captcha');
};
export const logoutApi = () => {
return request.get('/auth/logout');
};
+13
View File
@@ -0,0 +1,13 @@
import request from '../utils/request';
export const uploadFileApi = (formData: FormData) => {
return request.post('/oss/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data',
},
});
};
export const getFileListApi = (data: any) => request.post('/oss/getFileList', data);
export const deleteFileApi = (data: { id: number }) => request.post('/oss/delete', data);
export const getFileDetailApi = (id: number) => request.get('/oss/getFile', { params: { id } });
+23
View File
@@ -0,0 +1,23 @@
import request from '../utils/request';
// --- Category API ---
export const getCategoryPageApi = (data: any) => request.post('/radio/category/page', data);
export const getCategoryListApi = (data: any = {}) => request.post('/radio/category/list', data);
export const getCategoryDetailApi = (id: number) => request.get('/radio/category/detail', { params: { id } });
export const saveCategoryApi = (data: any) => request.post('/radio/category/save', data);
export const updateCategoryApi = (data: any) => request.post('/radio/category/update', data);
export const deleteCategoryApi = (data: { id: number }) => request.post('/radio/category/delete', data);
// --- Channel API ---
export const getChannelListApi = (data: any = {}) => request.post('/radio/channel/list', data);
export const getChannelDetailApi = (id: number) => request.get('/radio/channel/detail', { params: { id } });
export const saveChannelApi = (data: any) => request.post('/radio/channel/save', data);
export const updateChannelApi = (data: any) => request.post('/radio/channel/update', data);
export const deleteChannelApi = (data: { id: number }) => request.post('/radio/channel/delete', data);
// --- Program API ---
export const getProgramListApi = (data: any = {}) => request.post('/radio/program/list', data);
export const getProgramDetailApi = (id: number) => request.get('/radio/program/detail', { params: { id } });
export const saveProgramApi = (data: any) => request.post('/radio/program/save', data);
export const updateProgramApi = (data: any) => request.post('/radio/program/update', data);
export const deleteProgramApi = (data: { id: number }) => request.post('/radio/program/delete', data);
+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>

After

Width:  |  Height:  |  Size: 4.0 KiB

+107
View File
@@ -0,0 +1,107 @@
import * as React from "react"
import { Avatar as AvatarPrimitive } from "radix-ui"
import { cn } from "@/lib/utils"
function Avatar({
className,
size = "default",
...props
}: React.ComponentProps<typeof AvatarPrimitive.Root> & {
size?: "default" | "sm" | "lg"
}) {
return (
<AvatarPrimitive.Root
data-slot="avatar"
data-size={size}
className={cn(
"group/avatar relative flex size-8 shrink-0 overflow-hidden rounded-full select-none data-[size=lg]:size-10 data-[size=sm]:size-6",
className
)}
{...props}
/>
)
}
function AvatarImage({
className,
...props
}: React.ComponentProps<typeof AvatarPrimitive.Image>) {
return (
<AvatarPrimitive.Image
data-slot="avatar-image"
className={cn("aspect-square size-full", className)}
{...props}
/>
)
}
function AvatarFallback({
className,
...props
}: React.ComponentProps<typeof AvatarPrimitive.Fallback>) {
return (
<AvatarPrimitive.Fallback
data-slot="avatar-fallback"
className={cn(
"bg-muted text-muted-foreground flex size-full items-center justify-center rounded-full text-sm group-data-[size=sm]/avatar:text-xs",
className
)}
{...props}
/>
)
}
function AvatarBadge({ className, ...props }: React.ComponentProps<"span">) {
return (
<span
data-slot="avatar-badge"
className={cn(
"bg-primary text-primary-foreground ring-background absolute right-0 bottom-0 z-10 inline-flex items-center justify-center rounded-full ring-2 select-none",
"group-data-[size=sm]/avatar:size-2 group-data-[size=sm]/avatar:[&>svg]:hidden",
"group-data-[size=default]/avatar:size-2.5 group-data-[size=default]/avatar:[&>svg]:size-2",
"group-data-[size=lg]/avatar:size-3 group-data-[size=lg]/avatar:[&>svg]:size-2",
className
)}
{...props}
/>
)
}
function AvatarGroup({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="avatar-group"
className={cn(
"*:data-[slot=avatar]:ring-background group/avatar-group flex -space-x-2 *:data-[slot=avatar]:ring-2",
className
)}
{...props}
/>
)
}
function AvatarGroupCount({
className,
...props
}: React.ComponentProps<"div">) {
return (
<div
data-slot="avatar-group-count"
className={cn(
"bg-muted text-muted-foreground ring-background relative flex size-8 shrink-0 items-center justify-center rounded-full text-sm ring-2 group-has-data-[size=lg]/avatar-group:size-10 group-has-data-[size=sm]/avatar-group:size-6 [&>svg]:size-4 group-has-data-[size=lg]/avatar-group:[&>svg]:size-5 group-has-data-[size=sm]/avatar-group:[&>svg]:size-3",
className
)}
{...props}
/>
)
}
export {
Avatar,
AvatarImage,
AvatarFallback,
AvatarBadge,
AvatarGroup,
AvatarGroupCount,
}
+64
View File
@@ -0,0 +1,64 @@
import * as React from "react"
import { cva, type VariantProps } from "class-variance-authority"
import { Slot } from "radix-ui"
import { cn } from "@/lib/utils"
const buttonVariants = cva(
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground hover:bg-primary/90",
destructive:
"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
outline:
"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
secondary:
"bg-secondary text-secondary-foreground hover:bg-secondary/80",
ghost:
"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
link: "text-primary underline-offset-4 hover:underline",
},
size: {
default: "h-9 px-4 py-2 has-[>svg]:px-3",
xs: "h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
icon: "size-9",
"icon-xs": "size-6 rounded-md [&_svg:not([class*='size-'])]:size-3",
"icon-sm": "size-8",
"icon-lg": "size-10",
},
},
defaultVariants: {
variant: "default",
size: "default",
},
}
)
function Button({
className,
variant = "default",
size = "default",
asChild = false,
...props
}: React.ComponentProps<"button"> &
VariantProps<typeof buttonVariants> & {
asChild?: boolean
}) {
const Comp = asChild ? Slot.Root : "button"
return (
<Comp
data-slot="button"
data-variant={variant}
data-size={size}
className={cn(buttonVariants({ variant, size, className }))}
{...props}
/>
)
}
export { Button, buttonVariants }
+92
View File
@@ -0,0 +1,92 @@
import * as React from "react"
import { cn } from "@/lib/utils"
function Card({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card"
className={cn(
"bg-card text-card-foreground flex flex-col gap-6 rounded-xl border py-6 shadow-sm",
className
)}
{...props}
/>
)
}
function CardHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-header"
className={cn(
"@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-2 px-6 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6",
className
)}
{...props}
/>
)
}
function CardTitle({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-title"
className={cn("leading-none font-semibold", className)}
{...props}
/>
)
}
function CardDescription({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-description"
className={cn("text-muted-foreground text-sm", className)}
{...props}
/>
)
}
function CardAction({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-action"
className={cn(
"col-start-2 row-span-2 row-start-1 self-start justify-self-end",
className
)}
{...props}
/>
)
}
function CardContent({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-content"
className={cn("px-6", className)}
{...props}
/>
)
}
function CardFooter({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="card-footer"
className={cn("flex items-center px-6 [.border-t]:pt-6", className)}
{...props}
/>
)
}
export {
Card,
CardHeader,
CardFooter,
CardTitle,
CardAction,
CardDescription,
CardContent,
}
+156
View File
@@ -0,0 +1,156 @@
import * as React from "react"
import { XIcon } from "lucide-react"
import { Dialog as DialogPrimitive } from "radix-ui"
import { cn } from "@/lib/utils"
import { Button } from "@/components/ui/button"
function Dialog({
...props
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
return <DialogPrimitive.Root data-slot="dialog" {...props} />
}
function DialogTrigger({
...props
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
}
function DialogPortal({
...props
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
}
function DialogClose({
...props
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
}
function DialogOverlay({
className,
...props
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
return (
<DialogPrimitive.Overlay
data-slot="dialog-overlay"
className={cn(
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
className
)}
{...props}
/>
)
}
function DialogContent({
className,
children,
showCloseButton = true,
...props
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
showCloseButton?: boolean
}) {
return (
<DialogPortal data-slot="dialog-portal">
<DialogOverlay />
<DialogPrimitive.Content
data-slot="dialog-content"
className={cn(
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg",
className
)}
{...props}
>
{children}
{showCloseButton && (
<DialogPrimitive.Close
data-slot="dialog-close"
className="ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
>
<XIcon />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
)}
</DialogPrimitive.Content>
</DialogPortal>
)
}
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
return (
<div
data-slot="dialog-header"
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
{...props}
/>
)
}
function DialogFooter({
className,
showCloseButton = false,
children,
...props
}: React.ComponentProps<"div"> & {
showCloseButton?: boolean
}) {
return (
<div
data-slot="dialog-footer"
className={cn(
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
className
)}
{...props}
>
{children}
{showCloseButton && (
<DialogPrimitive.Close asChild>
<Button variant="outline">Close</Button>
</DialogPrimitive.Close>
)}
</div>
)
}
function DialogTitle({
className,
...props
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
return (
<DialogPrimitive.Title
data-slot="dialog-title"
className={cn("text-lg leading-none font-semibold", className)}
{...props}
/>
)
}
function DialogDescription({
className,
...props
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
return (
<DialogPrimitive.Description
data-slot="dialog-description"
className={cn("text-muted-foreground text-sm", className)}
{...props}
/>
)
}
export {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogOverlay,
DialogPortal,
DialogTitle,
DialogTrigger,
}
+257
View File
@@ -0,0 +1,257 @@
"use client"
import * as React from "react"
import { CheckIcon, ChevronRightIcon, CircleIcon } from "lucide-react"
import { DropdownMenu as DropdownMenuPrimitive } from "radix-ui"
import { cn } from "@/lib/utils"
function DropdownMenu({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Root>) {
return <DropdownMenuPrimitive.Root data-slot="dropdown-menu" {...props} />
}
function DropdownMenuPortal({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Portal>) {
return (
<DropdownMenuPrimitive.Portal data-slot="dropdown-menu-portal" {...props} />
)
}
function DropdownMenuTrigger({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Trigger>) {
return (
<DropdownMenuPrimitive.Trigger
data-slot="dropdown-menu-trigger"
{...props}
/>
)
}
function DropdownMenuContent({
className,
sideOffset = 4,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Content>) {
return (
<DropdownMenuPrimitive.Portal>
<DropdownMenuPrimitive.Content
data-slot="dropdown-menu-content"
sideOffset={sideOffset}
className={cn(
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
className
)}
{...props}
/>
</DropdownMenuPrimitive.Portal>
)
}
function DropdownMenuGroup({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Group>) {
return (
<DropdownMenuPrimitive.Group data-slot="dropdown-menu-group" {...props} />
)
}
function DropdownMenuItem({
className,
inset,
variant = "default",
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Item> & {
inset?: boolean
variant?: "default" | "destructive"
}) {
return (
<DropdownMenuPrimitive.Item
data-slot="dropdown-menu-item"
data-inset={inset}
data-variant={variant}
className={cn(
"focus:bg-accent focus:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
/>
)
}
function DropdownMenuCheckboxItem({
className,
children,
checked,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.CheckboxItem>) {
return (
<DropdownMenuPrimitive.CheckboxItem
data-slot="dropdown-menu-checkbox-item"
className={cn(
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
checked={checked}
{...props}
>
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
<DropdownMenuPrimitive.ItemIndicator>
<CheckIcon className="size-4" />
</DropdownMenuPrimitive.ItemIndicator>
</span>
{children}
</DropdownMenuPrimitive.CheckboxItem>
)
}
function DropdownMenuRadioGroup({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioGroup>) {
return (
<DropdownMenuPrimitive.RadioGroup
data-slot="dropdown-menu-radio-group"
{...props}
/>
)
}
function DropdownMenuRadioItem({
className,
children,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.RadioItem>) {
return (
<DropdownMenuPrimitive.RadioItem
data-slot="dropdown-menu-radio-item"
className={cn(
"focus:bg-accent focus:text-accent-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
>
<span className="pointer-events-none absolute left-2 flex size-3.5 items-center justify-center">
<DropdownMenuPrimitive.ItemIndicator>
<CircleIcon className="size-2 fill-current" />
</DropdownMenuPrimitive.ItemIndicator>
</span>
{children}
</DropdownMenuPrimitive.RadioItem>
)
}
function DropdownMenuLabel({
className,
inset,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Label> & {
inset?: boolean
}) {
return (
<DropdownMenuPrimitive.Label
data-slot="dropdown-menu-label"
data-inset={inset}
className={cn(
"px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",
className
)}
{...props}
/>
)
}
function DropdownMenuSeparator({
className,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Separator>) {
return (
<DropdownMenuPrimitive.Separator
data-slot="dropdown-menu-separator"
className={cn("bg-border -mx-1 my-1 h-px", className)}
{...props}
/>
)
}
function DropdownMenuShortcut({
className,
...props
}: React.ComponentProps<"span">) {
return (
<span
data-slot="dropdown-menu-shortcut"
className={cn(
"text-muted-foreground ml-auto text-xs tracking-widest",
className
)}
{...props}
/>
)
}
function DropdownMenuSub({
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.Sub>) {
return <DropdownMenuPrimitive.Sub data-slot="dropdown-menu-sub" {...props} />
}
function DropdownMenuSubTrigger({
className,
inset,
children,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubTrigger> & {
inset?: boolean
}) {
return (
<DropdownMenuPrimitive.SubTrigger
data-slot="dropdown-menu-sub-trigger"
data-inset={inset}
className={cn(
"focus:bg-accent focus:text-accent-foreground data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[inset]:pl-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
>
{children}
<ChevronRightIcon className="ml-auto size-4" />
</DropdownMenuPrimitive.SubTrigger>
)
}
function DropdownMenuSubContent({
className,
...props
}: React.ComponentProps<typeof DropdownMenuPrimitive.SubContent>) {
return (
<DropdownMenuPrimitive.SubContent
data-slot="dropdown-menu-sub-content"
className={cn(
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border p-1 shadow-lg",
className
)}
{...props}
/>
)
}
export {
DropdownMenu,
DropdownMenuPortal,
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuLabel,
DropdownMenuItem,
DropdownMenuCheckboxItem,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuSeparator,
DropdownMenuShortcut,
DropdownMenuSub,
DropdownMenuSubTrigger,
DropdownMenuSubContent,
}
+165
View File
@@ -0,0 +1,165 @@
import * as React from "react"
import type { Label as LabelPrimitive } from "radix-ui"
import { Slot } from "radix-ui"
import {
Controller,
FormProvider,
useFormContext,
useFormState,
type ControllerProps,
type FieldPath,
type FieldValues,
} from "react-hook-form"
import { cn } from "@/lib/utils"
import { Label } from "@/components/ui/label"
const Form = FormProvider
type FormFieldContextValue<
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
> = {
name: TName
}
const FormFieldContext = React.createContext<FormFieldContextValue>(
{} as FormFieldContextValue
)
const FormField = <
TFieldValues extends FieldValues = FieldValues,
TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,
>({
...props
}: ControllerProps<TFieldValues, TName>) => {
return (
<FormFieldContext.Provider value={{ name: props.name }}>
<Controller {...props} />
</FormFieldContext.Provider>
)
}
const useFormField = () => {
const fieldContext = React.useContext(FormFieldContext)
const itemContext = React.useContext(FormItemContext)
const { getFieldState } = useFormContext()
const formState = useFormState({ name: fieldContext.name })
const fieldState = getFieldState(fieldContext.name, formState)
if (!fieldContext) {
throw new Error("useFormField should be used within <FormField>")
}
const { id } = itemContext
return {
id,
name: fieldContext.name,
formItemId: `${id}-form-item`,
formDescriptionId: `${id}-form-item-description`,
formMessageId: `${id}-form-item-message`,
...fieldState,
}
}
type FormItemContextValue = {
id: string
}
const FormItemContext = React.createContext<FormItemContextValue>(
{} as FormItemContextValue
)
function FormItem({ className, ...props }: React.ComponentProps<"div">) {
const id = React.useId()
return (
<FormItemContext.Provider value={{ id }}>
<div
data-slot="form-item"
className={cn("grid gap-2", className)}
{...props}
/>
</FormItemContext.Provider>
)
}
function FormLabel({
className,
...props
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
const { error, formItemId } = useFormField()
return (
<Label
data-slot="form-label"
data-error={!!error}
className={cn("data-[error=true]:text-destructive", className)}
htmlFor={formItemId}
{...props}
/>
)
}
function FormControl({ ...props }: React.ComponentProps<typeof Slot.Root>) {
const { error, formItemId, formDescriptionId, formMessageId } = useFormField()
return (
<Slot.Root
data-slot="form-control"
id={formItemId}
aria-describedby={
!error
? `${formDescriptionId}`
: `${formDescriptionId} ${formMessageId}`
}
aria-invalid={!!error}
{...props}
/>
)
}
function FormDescription({ className, ...props }: React.ComponentProps<"p">) {
const { formDescriptionId } = useFormField()
return (
<p
data-slot="form-description"
id={formDescriptionId}
className={cn("text-muted-foreground text-sm", className)}
{...props}
/>
)
}
function FormMessage({ className, ...props }: React.ComponentProps<"p">) {
const { error, formMessageId } = useFormField()
const body = error ? String(error?.message ?? "") : props.children
if (!body) {
return null
}
return (
<p
data-slot="form-message"
id={formMessageId}
className={cn("text-destructive text-sm", className)}
{...props}
>
{body}
</p>
)
}
export {
useFormField,
Form,
FormItem,
FormLabel,
FormControl,
FormDescription,
FormMessage,
FormField,
}
+21
View File
@@ -0,0 +1,21 @@
import * as React from "react"
import { cn } from "@/lib/utils"
function Input({ className, type, ...props }: React.ComponentProps<"input">) {
return (
<input
type={type}
data-slot="input"
className={cn(
"file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground dark:bg-input/30 border-input h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",
"focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]",
"aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
className
)}
{...props}
/>
)
}
export { Input }
+24
View File
@@ -0,0 +1,24 @@
"use client"
import * as React from "react"
import { Label as LabelPrimitive } from "radix-ui"
import { cn } from "@/lib/utils"
function Label({
className,
...props
}: React.ComponentProps<typeof LabelPrimitive.Root>) {
return (
<LabelPrimitive.Root
data-slot="label"
className={cn(
"flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",
className
)}
{...props}
/>
)
}
export { Label }
+188
View File
@@ -0,0 +1,188 @@
import * as React from "react"
import { CheckIcon, ChevronDownIcon, ChevronUpIcon } from "lucide-react"
import { Select as SelectPrimitive } from "radix-ui"
import { cn } from "@/lib/utils"
function Select({
...props
}: React.ComponentProps<typeof SelectPrimitive.Root>) {
return <SelectPrimitive.Root data-slot="select" {...props} />
}
function SelectGroup({
...props
}: React.ComponentProps<typeof SelectPrimitive.Group>) {
return <SelectPrimitive.Group data-slot="select-group" {...props} />
}
function SelectValue({
...props
}: React.ComponentProps<typeof SelectPrimitive.Value>) {
return <SelectPrimitive.Value data-slot="select-value" {...props} />
}
function SelectTrigger({
className,
size = "default",
children,
...props
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
size?: "sm" | "default"
}) {
return (
<SelectPrimitive.Trigger
data-slot="select-trigger"
data-size={size}
className={cn(
"border-input data-[placeholder]:text-muted-foreground [&_svg:not([class*='text-'])]:text-muted-foreground focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive dark:bg-input/30 dark:hover:bg-input/50 flex w-fit items-center justify-between gap-2 rounded-md border bg-transparent px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50 data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
className
)}
{...props}
>
{children}
<SelectPrimitive.Icon asChild>
<ChevronDownIcon className="size-4 opacity-50" />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
)
}
function SelectContent({
className,
children,
position = "item-aligned",
align = "center",
...props
}: React.ComponentProps<typeof SelectPrimitive.Content>) {
return (
<SelectPrimitive.Portal>
<SelectPrimitive.Content
data-slot="select-content"
className={cn(
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border shadow-md",
position === "popper" &&
"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",
className
)}
position={position}
align={align}
{...props}
>
<SelectScrollUpButton />
<SelectPrimitive.Viewport
className={cn(
"p-1",
position === "popper" &&
"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"
)}
>
{children}
</SelectPrimitive.Viewport>
<SelectScrollDownButton />
</SelectPrimitive.Content>
</SelectPrimitive.Portal>
)
}
function SelectLabel({
className,
...props
}: React.ComponentProps<typeof SelectPrimitive.Label>) {
return (
<SelectPrimitive.Label
data-slot="select-label"
className={cn("text-muted-foreground px-2 py-1.5 text-xs", className)}
{...props}
/>
)
}
function SelectItem({
className,
children,
...props
}: React.ComponentProps<typeof SelectPrimitive.Item>) {
return (
<SelectPrimitive.Item
data-slot="select-item"
className={cn(
"focus:bg-accent focus:text-accent-foreground [&_svg:not([class*='text-'])]:text-muted-foreground relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
className
)}
{...props}
>
<span
data-slot="select-item-indicator"
className="absolute right-2 flex size-3.5 items-center justify-center"
>
<SelectPrimitive.ItemIndicator>
<CheckIcon className="size-4" />
</SelectPrimitive.ItemIndicator>
</span>
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
</SelectPrimitive.Item>
)
}
function SelectSeparator({
className,
...props
}: React.ComponentProps<typeof SelectPrimitive.Separator>) {
return (
<SelectPrimitive.Separator
data-slot="select-separator"
className={cn("bg-border pointer-events-none -mx-1 my-1 h-px", className)}
{...props}
/>
)
}
function SelectScrollUpButton({
className,
...props
}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
return (
<SelectPrimitive.ScrollUpButton
data-slot="select-scroll-up-button"
className={cn(
"flex cursor-default items-center justify-center py-1",
className
)}
{...props}
>
<ChevronUpIcon className="size-4" />
</SelectPrimitive.ScrollUpButton>
)
}
function SelectScrollDownButton({
className,
...props
}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
return (
<SelectPrimitive.ScrollDownButton
data-slot="select-scroll-down-button"
className={cn(
"flex cursor-default items-center justify-center py-1",
className
)}
{...props}
>
<ChevronDownIcon className="size-4" />
</SelectPrimitive.ScrollDownButton>
)
}
export {
Select,
SelectContent,
SelectGroup,
SelectItem,
SelectLabel,
SelectScrollDownButton,
SelectScrollUpButton,
SelectSeparator,
SelectTrigger,
SelectValue,
}
+26
View File
@@ -0,0 +1,26 @@
import * as React from "react"
import { Separator as SeparatorPrimitive } from "radix-ui"
import { cn } from "@/lib/utils"
function Separator({
className,
orientation = "horizontal",
decorative = true,
...props
}: React.ComponentProps<typeof SeparatorPrimitive.Root>) {
return (
<SeparatorPrimitive.Root
data-slot="separator"
decorative={decorative}
orientation={orientation}
className={cn(
"bg-border shrink-0 data-[orientation=horizontal]:h-px data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-px",
className
)}
{...props}
/>
)
}
export { Separator }
+40
View File
@@ -0,0 +1,40 @@
"use client"
import {
CircleCheckIcon,
InfoIcon,
Loader2Icon,
OctagonXIcon,
TriangleAlertIcon,
} from "lucide-react"
import { useTheme } from "next-themes"
import { Toaster as Sonner, type ToasterProps } from "sonner"
const Toaster = ({ ...props }: ToasterProps) => {
const { theme = "system" } = useTheme()
return (
<Sonner
theme={theme as ToasterProps["theme"]}
className="toaster group"
icons={{
success: <CircleCheckIcon className="size-4" />,
info: <InfoIcon className="size-4" />,
warning: <TriangleAlertIcon className="size-4" />,
error: <OctagonXIcon className="size-4" />,
loading: <Loader2Icon className="size-4 animate-spin" />,
}}
style={
{
"--normal-bg": "var(--popover)",
"--normal-text": "var(--popover-foreground)",
"--normal-border": "var(--border)",
"--border-radius": "var(--radius)",
} as React.CSSProperties
}
{...props}
/>
)
}
export { Toaster }
+116
View File
@@ -0,0 +1,116 @@
"use client"
import * as React from "react"
import { cn } from "@/lib/utils"
function Table({ className, ...props }: React.ComponentProps<"table">) {
return (
<div
data-slot="table-container"
className="relative w-full overflow-x-auto"
>
<table
data-slot="table"
className={cn("w-full caption-bottom text-sm", className)}
{...props}
/>
</div>
)
}
function TableHeader({ className, ...props }: React.ComponentProps<"thead">) {
return (
<thead
data-slot="table-header"
className={cn("[&_tr]:border-b", className)}
{...props}
/>
)
}
function TableBody({ className, ...props }: React.ComponentProps<"tbody">) {
return (
<tbody
data-slot="table-body"
className={cn("[&_tr:last-child]:border-0", className)}
{...props}
/>
)
}
function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">) {
return (
<tfoot
data-slot="table-footer"
className={cn(
"bg-muted/50 border-t font-medium [&>tr]:last:border-b-0",
className
)}
{...props}
/>
)
}
function TableRow({ className, ...props }: React.ComponentProps<"tr">) {
return (
<tr
data-slot="table-row"
className={cn(
"hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors",
className
)}
{...props}
/>
)
}
function TableHead({ className, ...props }: React.ComponentProps<"th">) {
return (
<th
data-slot="table-head"
className={cn(
"text-foreground h-10 px-2 text-left align-middle font-medium whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
className
)}
{...props}
/>
)
}
function TableCell({ className, ...props }: React.ComponentProps<"td">) {
return (
<td
data-slot="table-cell"
className={cn(
"p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",
className
)}
{...props}
/>
)
}
function TableCaption({
className,
...props
}: React.ComponentProps<"caption">) {
return (
<caption
data-slot="table-caption"
className={cn("text-muted-foreground mt-4 text-sm", className)}
{...props}
/>
)
}
export {
Table,
TableHeader,
TableBody,
TableFooter,
TableHead,
TableRow,
TableCell,
TableCaption,
}
+124
View File
@@ -0,0 +1,124 @@
@import "tailwindcss";
@import "tw-animate-css";
@import "shadcn/tailwind.css";
@custom-variant dark (&:is(.dark *));
@theme inline {
--radius-sm: calc(var(--radius) - 4px);
--radius-md: calc(var(--radius) - 2px);
--radius-lg: var(--radius);
--radius-xl: calc(var(--radius) + 4px);
--radius-2xl: calc(var(--radius) + 8px);
--radius-3xl: calc(var(--radius) + 12px);
--radius-4xl: calc(var(--radius) + 16px);
--color-background: var(--background);
--color-foreground: var(--foreground);
--color-card: var(--card);
--color-card-foreground: var(--card-foreground);
--color-popover: var(--popover);
--color-popover-foreground: var(--popover-foreground);
--color-primary: var(--primary);
--color-primary-foreground: var(--primary-foreground);
--color-secondary: var(--secondary);
--color-secondary-foreground: var(--secondary-foreground);
--color-muted: var(--muted);
--color-muted-foreground: var(--muted-foreground);
--color-accent: var(--accent);
--color-accent-foreground: var(--accent-foreground);
--color-destructive: var(--destructive);
--color-border: var(--border);
--color-input: var(--input);
--color-ring: var(--ring);
--color-chart-1: var(--chart-1);
--color-chart-2: var(--chart-2);
--color-chart-3: var(--chart-3);
--color-chart-4: var(--chart-4);
--color-chart-5: var(--chart-5);
--color-sidebar: var(--sidebar);
--color-sidebar-foreground: var(--sidebar-foreground);
--color-sidebar-primary: var(--sidebar-primary);
--color-sidebar-primary-foreground: var(--sidebar-primary-foreground);
--color-sidebar-accent: var(--sidebar-accent);
--color-sidebar-accent-foreground: var(--sidebar-accent-foreground);
--color-sidebar-border: var(--sidebar-border);
--color-sidebar-ring: var(--sidebar-ring);
}
:root {
--radius: 0.625rem;
--background: oklch(1 0 0);
--foreground: oklch(0.145 0 0);
--card: oklch(1 0 0);
--card-foreground: oklch(0.145 0 0);
--popover: oklch(1 0 0);
--popover-foreground: oklch(0.145 0 0);
--primary: oklch(0.205 0 0);
--primary-foreground: oklch(0.985 0 0);
--secondary: oklch(0.97 0 0);
--secondary-foreground: oklch(0.205 0 0);
--muted: oklch(0.97 0 0);
--muted-foreground: oklch(0.556 0 0);
--accent: oklch(0.97 0 0);
--accent-foreground: oklch(0.205 0 0);
--destructive: oklch(0.577 0.245 27.325);
--border: oklch(0.922 0 0);
--input: oklch(0.922 0 0);
--ring: oklch(0.708 0 0);
--chart-1: oklch(0.646 0.222 41.116);
--chart-2: oklch(0.6 0.118 184.704);
--chart-3: oklch(0.398 0.07 227.392);
--chart-4: oklch(0.828 0.189 84.429);
--chart-5: oklch(0.769 0.188 70.08);
--sidebar: oklch(0.985 0 0);
--sidebar-foreground: oklch(0.145 0 0);
--sidebar-primary: oklch(0.205 0 0);
--sidebar-primary-foreground: oklch(0.985 0 0);
--sidebar-accent: oklch(0.97 0 0);
--sidebar-accent-foreground: oklch(0.205 0 0);
--sidebar-border: oklch(0.922 0 0);
--sidebar-ring: oklch(0.708 0 0);
}
.dark {
--background: oklch(0.145 0 0);
--foreground: oklch(0.985 0 0);
--card: oklch(0.205 0 0);
--card-foreground: oklch(0.985 0 0);
--popover: oklch(0.205 0 0);
--popover-foreground: oklch(0.985 0 0);
--primary: oklch(0.922 0 0);
--primary-foreground: oklch(0.205 0 0);
--secondary: oklch(0.269 0 0);
--secondary-foreground: oklch(0.985 0 0);
--muted: oklch(0.269 0 0);
--muted-foreground: oklch(0.708 0 0);
--accent: oklch(0.269 0 0);
--accent-foreground: oklch(0.985 0 0);
--destructive: oklch(0.704 0.191 22.216);
--border: oklch(1 0 0 / 10%);
--input: oklch(1 0 0 / 15%);
--ring: oklch(0.556 0 0);
--chart-1: oklch(0.488 0.243 264.376);
--chart-2: oklch(0.696 0.17 162.48);
--chart-3: oklch(0.769 0.188 70.08);
--chart-4: oklch(0.627 0.265 303.9);
--chart-5: oklch(0.645 0.246 16.439);
--sidebar: oklch(0.205 0 0);
--sidebar-foreground: oklch(0.985 0 0);
--sidebar-primary: oklch(0.488 0.243 264.376);
--sidebar-primary-foreground: oklch(0.985 0 0);
--sidebar-accent: oklch(0.269 0 0);
--sidebar-accent-foreground: oklch(0.985 0 0);
--sidebar-border: oklch(1 0 0 / 10%);
--sidebar-ring: oklch(0.556 0 0);
}
@layer base {
* {
@apply border-border outline-ring/50;
}
body {
@apply bg-background text-foreground;
}
}
+151
View File
@@ -0,0 +1,151 @@
import { Outlet, Navigate, useNavigate, Link, useLocation } from 'react-router-dom';
import { useAuthStore } from '../store/authStore';
import { logoutApi } from '../api/auth';
import {
Radio,
LayoutDashboard,
ListMusic,
Mic2,
Disc3,
FolderOpen,
LogOut,
User as UserIcon,
ChevronDown
} from 'lucide-react';
import { Button } from '../components/ui/button';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "../components/ui/dropdown-menu"
import { Avatar, AvatarFallback, AvatarImage } from "../components/ui/avatar"
export default function AdminLayout() {
const token = useAuthStore((state) => state.token);
const userInfo = useAuthStore((state) => state.userInfo);
const logout = useAuthStore((state) => state.logout);
const navigate = useNavigate();
const location = useLocation();
if (!token) {
return <Navigate to="/login" replace />;
}
const handleLogout = async () => {
try {
await logoutApi();
} catch (e) {
console.warn('登出失败');
}
logout();
navigate('/login');
};
const navItems = [
{ name: '工作台', path: '/', icon: LayoutDashboard },
{ name: '频道分类', path: '/radio/category', icon: ListMusic },
{ name: '频道管理', path: '/radio/channel', icon: Mic2 },
{ name: '节目管理', path: '/radio/program', icon: Disc3 },
{ name: '文件管理', path: '/system/oss', icon: FolderOpen },
];
return (
<div className="flex h-screen bg-slate-50 dark:bg-slate-950 overflow-hidden">
{/* Sidebar */}
<aside className="fixed inset-y-0 left-0 z-50 w-64 bg-slate-900 text-slate-100 hidden md:flex flex-col shadow-xl">
<div className="flex items-center h-16 px-6 border-b border-slate-800 shrink-0">
<div className="w-8 h-8 rounded-lg bg-primary flex items-center justify-center mr-3 shadow-lg shadow-primary/20">
<Radio className="w-5 h-5 text-white" />
</div>
<span className="font-bold text-lg tracking-wide uppercase"></span>
</div>
<div className="flex-1 px-4 py-6 space-y-2 overflow-y-auto custom-scrollbar">
{navItems.map((item) => {
const isActive = location.pathname === item.path || (item.path !== '/' && location.pathname.startsWith(item.path));
return (
<Link key={item.path} to={item.path}>
<Button
variant="ghost"
className={`w-full justify-start h-11 px-4 rounded-xl transition-all duration-200 group ${isActive
? 'bg-primary text-primary-foreground shadow-lg shadow-primary/10'
: 'text-slate-400 hover:text-slate-100 hover:bg-slate-800'
}`}
>
<item.icon className={`w-5 h-5 mr-3 shrink-0 ${isActive ? 'text-white' : 'group-hover:text-primary'}`} />
<span className="font-medium">{item.name}</span>
</Button>
</Link>
)
})}
</div>
<div className="p-4 border-t border-slate-800 shrink-0">
<div className="bg-slate-800/50 rounded-2xl p-3 flex items-center space-x-3">
<Avatar className="h-10 w-10 ring-2 ring-slate-700">
<AvatarImage src={userInfo?.avatar || ''} />
<AvatarFallback className="bg-slate-700 text-slate-100">
<UserIcon className="w-5 h-5" />
</AvatarFallback>
</Avatar>
<div className="flex-1 min-w-0">
<p className="text-sm font-semibold truncate">{userInfo?.nickName || '管理员'}</p>
<p className="text-xs text-slate-500 truncate">{userInfo?.account || 'admin'}</p>
</div>
</div>
</div>
</aside>
{/* Main Area */}
<div className="flex-1 md:ml-64 flex flex-col h-full overflow-hidden relative">
{/* Navbar */}
<header className="h-16 flex items-center justify-between px-8 bg-white dark:bg-slate-900 border-b shrink-0 z-40">
<div className="flex items-center space-x-4">
<div className="md:hidden">
<Radio className="w-6 h-6 text-primary" />
</div>
<h2 className="text-sm font-medium text-slate-500 uppercase tracking-widest hidden sm:block"></h2>
</div>
<div className="flex items-center space-x-4">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="ghost" className="h-10 px-3 rounded-xl hover:bg-slate-100 dark:hover:bg-slate-800 flex items-center space-x-2">
<div className="text-right hidden sm:block">
<p className="text-sm font-medium leading-none">{userInfo?.nickName || '管理员'}</p>
</div>
<ChevronDown className="w-4 h-4 text-slate-400" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent className="w-56 mt-2 rounded-xl p-1" align="end" forceMount>
<DropdownMenuLabel className="font-normal px-2 py-3">
<div className="flex flex-col space-y-1">
<p className="text-sm font-bold text-slate-900 dark:text-slate-100">{userInfo?.nickName || '管理员'}</p>
<p className="text-xs text-slate-500">{userInfo?.account || 'admin'}</p>
</div>
</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={handleLogout}
className="cursor-pointer text-rose-500 focus:bg-rose-50 focus:text-rose-600 rounded-lg p-2 font-medium"
>
<LogOut className="mr-3 h-4 w-4" />
<span>退</span>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</header>
{/* Page Content */}
<main className="flex-1 overflow-y-auto p-4 md:p-10 bg-slate-50/50 dark:bg-slate-950/50 scroll-smooth">
<div className="max-w-7xl mx-auto h-full">
<Outlet />
</div>
</main>
</div>
</div>
);
}
+6
View File
@@ -0,0 +1,6 @@
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
+7
View File
@@ -0,0 +1,7 @@
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'
createRoot(document.getElementById('root')!).render(
<App />
)
+105
View File
@@ -0,0 +1,105 @@
import {
Radio,
ListMusic,
Mic2,
Disc3,
TrendingUp,
Users,
Activity,
ArrowUpRight,
ArrowDownRight
} from 'lucide-react';
import { Card, CardContent, CardHeader, CardTitle } from '../../components/ui/card';
export default function Dashboard() {
const stats = [
{ name: '总分类数', value: '12', icon: ListMusic, change: '+2', trend: 'up' },
{ name: '活跃频道', value: '45', icon: Mic2, change: '+5', trend: 'up' },
{ name: '节目总数', value: '3,284', icon: Disc3, change: '+124', trend: 'up' },
{ name: '订阅用户', value: '12.4K', icon: Users, change: '-24', trend: 'down' },
];
return (
<div className="space-y-8 animate-in fade-in duration-500">
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
<div>
<h1 className="text-3xl font-extrabold tracking-tight text-slate-900 dark:text-slate-100"></h1>
<p className="text-slate-500 mt-1"></p>
</div>
<div className="flex items-center space-x-2 bg-white dark:bg-slate-900 border px-4 py-2 rounded-2xl shadow-sm self-start">
<Activity className="w-4 h-4 text-emerald-500 animate-pulse" />
<span className="text-sm font-medium text-slate-600 dark:text-slate-400 uppercase tracking-widest">线</span>
</div>
</div>
<div className="grid gap-6 md:grid-cols-2 lg:grid-cols-4">
{stats.map((stat) => (
<Card key={stat.name} className="border-none shadow-sm hover:shadow-md transition-shadow group rounded-3xl overflow-hidden bg-white dark:bg-slate-900">
<CardHeader className="flex flex-row items-center justify-between space-y-0 pb-2">
<CardTitle className="text-sm font-semibold text-slate-500 uppercase tracking-wider">{stat.name}</CardTitle>
<div className={`p-2 rounded-xl group-hover:scale-110 transition-transform ${stat.trend === 'up' ? 'bg-emerald-50 text-emerald-600' : 'bg-rose-50 text-rose-600'
}`}>
<stat.icon className="h-5 w-5" />
</div>
</CardHeader>
<CardContent>
<div className="text-3xl font-bold tracking-tight text-slate-900 dark:text-white mt-1">{stat.value}</div>
<p className="text-xs text-slate-500 mt-2 flex items-center">
<span className={`flex items-center font-medium mr-1 ${stat.trend === 'up' ? 'text-emerald-500' : 'text-rose-500'
}`}>
{stat.trend === 'up' ? <ArrowUpRight className="w-3 h-3 mr-0.5" /> : <ArrowDownRight className="w-3 h-3 mr-0.5" />}
{stat.change}
</span>
</p>
</CardContent>
</Card>
))}
</div>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
<Card className="lg:col-span-2 border-none shadow-sm rounded-3xl bg-white dark:bg-slate-900">
<CardHeader className="pb-0">
<CardTitle className="text-lg font-bold flex items-center">
<TrendingUp className="w-5 h-5 mr-2 text-primary" />
</CardTitle>
</CardHeader>
<CardContent className="h-[300px] flex items-center justify-center text-slate-400 bg-slate-50/50 dark:bg-slate-950/20 m-6 rounded-2xl border-2 border-dashed">
(Growth data visualization)
</CardContent>
</Card>
<Card className="border-none shadow-sm rounded-3xl bg-white dark:bg-slate-900">
<CardHeader className="pb-0">
<CardTitle className="text-lg font-bold flex items-center">
<Radio className="w-5 h-5 mr-2 text-primary" />
</CardTitle>
</CardHeader>
<CardContent className="pt-6">
<div className="space-y-4">
{[1, 2, 3, 4, 5].map(i => (
<div key={i} className="flex items-center justify-between p-3 rounded-2xl hover:bg-slate-50 dark:hover:bg-slate-800 transition-colors cursor-pointer group">
<div className="flex items-center space-x-3">
<div className="w-10 h-10 rounded-xl bg-slate-100 dark:bg-slate-800 flex items-center justify-center font-bold text-slate-500 group-hover:bg-primary group-hover:text-white transition-colors">
#{i}
</div>
<div>
<p className="text-sm font-bold text-slate-900 dark:text-slate-100"> #{i}</p>
<p className="text-xs text-slate-400"></p>
</div>
</div>
<div className="text-right">
<p className="text-sm font-bold text-slate-900 dark:text-slate-100">{(1000 / i).toFixed(0)}</p>
<p className="text-[10px] text-slate-400 uppercase tracking-tighter"></p>
</div>
</div>
))}
</div>
</CardContent>
</Card>
</div>
</div>
);
}
+164
View File
@@ -0,0 +1,164 @@
import { useState, useEffect, useRef } from 'react';
import { useNavigate } from 'react-router-dom';
import { useAuthStore } from '../../store/authStore';
import { loginApi, getCaptchaApi } from '../../api/auth';
import { toast } from 'sonner';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '../../components/ui/card';
import { Button } from '../../components/ui/button';
import { Input } from '../../components/ui/input';
import { Label } from '../../components/ui/label';
import { Radio } from 'lucide-react';
export default function Login() {
const navigate = useNavigate();
const setToken = useAuthStore((state) => state.setToken);
const setUserInfo = useAuthStore((state) => state.setUserInfo);
const [account, setAccount] = useState('');
const [password, setPassword] = useState('');
const [captcha, setCaptcha] = useState('');
const [captchaId, setCaptchaId] = useState('');
const [captchaImage, setCaptchaImage] = useState('');
const [loading, setLoading] = useState(false);
// Guard to ensure we only fetch on mount once
const mounted = useRef(false);
const fetchCaptcha = async () => {
try {
const res: any = await getCaptchaApi();
const b64 = res.captcha;
if (b64 && !b64.startsWith('data:')) {
setCaptchaImage(`data:image/png;base64,${b64}`);
} else {
setCaptchaImage(b64);
}
setCaptchaId(res.captchaId);
} catch (error) {
console.error('获取验证码失败', error);
}
};
useEffect(() => {
if (!mounted.current) {
fetchCaptcha();
mounted.current = true;
}
}, []);
const handleLogin = async (e: React.FormEvent) => {
e.preventDefault();
if (!account || !password) {
toast.error('请输入账号和密码');
return;
}
if (!captcha) {
toast.error('请输入验证码');
return;
}
try {
setLoading(true);
const res: any = await loginApi({
account,
password,
captcha,
captchaId
});
toast.success('登录成功');
setToken(res.token);
setUserInfo(res.user);
navigate('/');
} catch (error: any) {
fetchCaptcha();
setCaptcha('');
} finally {
setLoading(false);
}
};
return (
<div className="min-h-screen flex items-center justify-center bg-slate-50 dark:bg-slate-950 p-4">
<Card className="w-full max-w-sm border-none shadow-2xl rounded-3xl overflow-hidden bg-white dark:bg-slate-900">
<CardHeader className="space-y-2 flex flex-col items-center pt-10 pb-6 bg-slate-50/50">
<div className="w-16 h-16 bg-primary text-primary-foreground rounded-2xl flex items-center justify-center mb-2 shadow-xl shadow-primary/20 rotate-3 transform hover:rotate-0 transition-transform">
<Radio className="w-8 h-8" />
</div>
<div className="text-center">
<CardTitle className="text-3xl font-extrabold tracking-tight text-slate-900 dark:text-white"></CardTitle>
<CardDescription className="text-slate-500 font-medium">
portal
</CardDescription>
</div>
</CardHeader>
<CardContent className="p-8">
<form onSubmit={handleLogin} className="space-y-6">
<div className="space-y-2">
<Label htmlFor="account"></Label>
<Input
id="account"
placeholder="请输入管理员账号"
className="h-12 rounded-xl bg-slate-50 border-none focus:ring-2 focus:ring-primary"
value={account}
onChange={(e) => setAccount(e.target.value)}
disabled={loading}
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="password"></Label>
<Input
id="password"
type="password"
placeholder="请输入密码"
className="h-12 rounded-xl bg-slate-50 border-none focus:ring-2 focus:ring-primary"
value={password}
onChange={(e) => setPassword(e.target.value)}
disabled={loading}
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="captcha"></Label>
<div className="flex gap-3">
<Input
id="captcha"
placeholder="验证码"
autoComplete="off"
className="h-12 rounded-xl bg-slate-50 border-none focus:ring-2 focus:ring-primary flex-1"
value={captcha}
onChange={(e) => setCaptcha(e.target.value)}
disabled={loading}
required
/>
{captchaImage ? (
<div
className="h-12 w-32 border rounded-xl overflow-hidden bg-white shrink-0 cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => fetchCaptcha()}
>
<img
src={captchaImage}
alt="captcha"
className="w-full h-full object-contain p-1"
title="点击刷新"
/>
</div>
) : (
<div className="h-12 w-32 border rounded-xl bg-slate-100 animate-pulse shrink-0" />
)}
</div>
</div>
<Button
className="w-full h-12 text-base font-bold rounded-2xl shadow-lg shadow-primary/20 mt-4 active:scale-[0.98] transition-all"
type="submit"
disabled={loading}
>
{loading ? '验证中...' : '立即登录'}
</Button>
</form>
</CardContent>
</Card>
</div>
);
}
+235
View File
@@ -0,0 +1,235 @@
import { useState, useEffect } from 'react';
import {
getCategoryPageApi,
saveCategoryApi,
updateCategoryApi,
deleteCategoryApi
} from '../../../api/radio';
import { Button } from '../../../components/ui/button';
import { Input } from '../../../components/ui/input';
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '../../../components/ui/table';
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '../../../components/ui/dialog';
import { Label } from '../../../components/ui/label';
import { Plus, Edit, Trash2 } from 'lucide-react';
import { toast } from 'sonner';
export default function Category() {
const [data, setData] = useState([]);
const [total, setTotal] = useState(0);
const [loading, setLoading] = useState(false);
// Pagination & Search
const [page, setPage] = useState(1);
const [pageSize] = useState(10);
const [searchName, setSearchName] = useState('');
// Dialog State
const [open, setOpen] = useState(false);
const [isEdit, setIsEdit] = useState(false);
const [formData, setFormData] = useState({
ID: undefined,
name: '',
description: '',
sort: 0,
status: 1
});
const fetchData = async () => {
if (loading) return;
setLoading(true);
try {
const res: any = await getCategoryPageApi({
current: page,
pageSize: pageSize,
keyword: searchName,
name: searchName,
status: 0
});
setData(res.list || []);
setTotal(res.total || 0);
} catch (e) {
console.error(e);
} finally {
setLoading(false);
}
};
// Only trigger fetch on page/pageSize change
useEffect(() => {
fetchData();
}, [page, pageSize]);
// Handle Search specifically to avoid double fetch
const handleSearch = () => {
if (page === 1) {
fetchData();
} else {
setPage(1); // Setting page to 1 will trigger the useEffect above
}
};
const handleOpenAdd = () => {
setIsEdit(false);
setFormData({ ID: undefined, name: '', description: '', sort: 0, status: 1 });
setOpen(true);
};
const handleOpenEdit = (record: any) => {
setIsEdit(true);
setFormData({
ID: record.ID,
name: record.name,
description: record.description,
sort: record.sort,
status: record.status
});
setOpen(true);
};
const handleDelete = async (id: number) => {
if (!confirm('确定要删除这个分类吗?')) return;
try {
await deleteCategoryApi({ id });
toast.success('删除成功');
fetchData();
} catch (e) {
console.error(e);
}
};
const handleSubmit = async () => {
if (!formData.name) {
toast.error('请填写分类名称');
return;
}
try {
if (isEdit) {
await updateCategoryApi(formData);
toast.success('更新成功');
} else {
await saveCategoryApi(formData);
toast.success('创建成功');
}
setOpen(false);
fetchData();
} catch (e) {
console.error(e);
}
};
return (
<div className="space-y-4 flex flex-col h-full bg-background rounded-lg border p-6">
<div className="flex justify-between items-center">
<div>
<h1 className="text-2xl font-bold tracking-tight"></h1>
<p className="text-muted-foreground"></p>
</div>
</div>
{/* Toolbar */}
<div className="flex justify-between items-center space-x-2">
<div className="flex space-x-2 w-full max-w-sm">
<Input
placeholder="根据名称搜索..."
value={searchName}
onChange={(e) => setSearchName(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && handleSearch()}
/>
<Button variant="secondary" onClick={handleSearch}></Button>
</div>
<Button onClick={handleOpenAdd}>
<Plus className="w-4 h-4 mr-2" />
</Button>
</div>
{/* Data Table */}
<div className="border rounded-md mt-4 flex-1 overflow-auto">
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-[80px]">ID</TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{loading && data.length === 0 ? (
<TableRow>
<TableCell colSpan={6} className="text-center h-32">...</TableCell>
</TableRow>
) : data.length === 0 ? (
<TableRow>
<TableCell colSpan={6} className="text-center h-32 text-muted-foreground"></TableCell>
</TableRow>
) : (
data.map((item: any) => (
<TableRow key={item.ID} className={loading ? 'opacity-50' : ''}>
<TableCell>{item.ID}</TableCell>
<TableCell className="font-medium">{item.name}</TableCell>
<TableCell>{item.description}</TableCell>
<TableCell>{item.sort}</TableCell>
<TableCell>{item.status === 1 ? '开启' : '禁用'}</TableCell>
<TableCell className="text-right">
<Button variant="ghost" size="icon" onClick={() => handleOpenEdit(item)}>
<Edit className="w-4 h-4 text-blue-500" />
</Button>
<Button variant="ghost" size="icon" onClick={() => handleDelete(item.ID)}>
<Trash2 className="w-4 h-4 text-red-500" />
</Button>
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</div>
<div className="flex bg-muted p-2 mt-2 rounded items-center justify-between text-sm text-muted-foreground">
<span>: {total} </span>
<span>: {pageSize} </span>
</div>
{/* Form Dialog */}
<Dialog open={open} onOpenChange={setOpen}>
<DialogContent>
<DialogHeader>
<DialogTitle>{isEdit ? '编辑分类' : '新增分类'}</DialogTitle>
</DialogHeader>
<div className="space-y-4 py-4">
<div className="space-y-2">
<Label></Label>
<Input
value={formData.name}
onChange={e => setFormData({ ...formData, name: e.target.value })}
placeholder="输入分类名称"
/>
</div>
<div className="space-y-2">
<Label></Label>
<Input
value={formData.description}
onChange={e => setFormData({ ...formData, description: e.target.value })}
placeholder="分类描述"
/>
</div>
<div className="space-y-2">
<Label></Label>
<Input
type="number"
value={formData.sort}
onChange={e => setFormData({ ...formData, sort: parseInt(e.target.value) || 0 })}
/>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => setOpen(false)}></Button>
<Button onClick={handleSubmit}></Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
);
}
+325
View File
@@ -0,0 +1,325 @@
import { useState, useEffect } from 'react';
import {
getChannelListApi,
saveChannelApi,
updateChannelApi,
deleteChannelApi,
getCategoryListApi
} from '../../../api/radio';
import { Button } from '../../../components/ui/button';
import { Input } from '../../../components/ui/input';
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '../../../components/ui/table';
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '../../../components/ui/dialog';
import { Label } from '../../../components/ui/label';
import { Plus, Edit, Trash2 } from 'lucide-react';
import { toast } from 'sonner';
export default function Channel() {
const [data, setData] = useState([]);
const [total, setTotal] = useState(0);
const [loading, setLoading] = useState(false);
const [categories, setCategories] = useState([]);
// Pagination & Search
const [page, setPage] = useState(1);
const [pageSize] = useState(10);
const [searchName, setSearchName] = useState('');
// Dialog State
const [open, setOpen] = useState(false);
const [isEdit, setIsEdit] = useState(false);
const [formData, setFormData] = useState({
ID: undefined,
categoryId: '',
name: '',
description: '',
price: 0,
coverId: '',
tags: '',
isVipOnly: 0,
sort: 0,
status: 1
});
const fetchCategories = async () => {
try {
const res: any = await getCategoryListApi();
setCategories(res.list || res || []);
} catch (e) {
console.error(e);
}
}
const fetchData = async () => {
if (loading) return;
setLoading(true);
try {
const res: any = await getChannelListApi({
current: page,
pageSize: pageSize,
keyword: searchName,
name: searchName
});
setData(res.list || []);
setTotal(res.total || 0);
} catch (e) {
console.error(e);
} finally {
setLoading(false);
}
};
// Table data fetch only on pagination change
useEffect(() => {
fetchData();
}, [page, pageSize]);
// Lazy load categories only when dialog opens
useEffect(() => {
if (open) {
fetchCategories();
}
}, [open]);
const handleSearch = () => {
if (page === 1) {
fetchData();
} else {
setPage(1);
}
};
const handleOpenAdd = () => {
setIsEdit(false);
setFormData({
ID: undefined, categoryId: '', name: '', description: '',
price: 0, coverId: '', tags: '', isVipOnly: 0, sort: 0, status: 1
});
setOpen(true);
};
const handleOpenEdit = (record: any) => {
setIsEdit(true);
setFormData({
ID: record.ID,
categoryId: record.categoryId,
name: record.name,
description: record.description,
price: record.price,
coverId: record.coverId,
tags: record.tags,
isVipOnly: record.isVipOnly,
sort: record.sort,
status: record.status
});
setOpen(true);
};
const handleDelete = async (id: number) => {
if (!confirm('确定要删除这个频道吗?')) return;
try {
await deleteChannelApi({ id });
toast.success('删除成功');
fetchData();
} catch (e) {
console.error(e);
}
};
const handleSubmit = async () => {
if (!formData.name) {
toast.error('请填写频道名称');
return;
}
try {
if (isEdit) {
await updateChannelApi(formData);
toast.success('更新成功');
} else {
await saveChannelApi(formData);
toast.success('创建成功');
}
setOpen(false);
fetchData();
} catch (e) {
console.error(e);
}
};
return (
<div className="space-y-4 flex flex-col h-full bg-background rounded-lg border p-6">
<div className="flex justify-between items-center">
<div>
<h1 className="text-2xl font-bold tracking-tight"></h1>
<p className="text-muted-foreground"></p>
</div>
</div>
{/* Toolbar */}
<div className="flex justify-between items-center space-x-2">
<div className="flex space-x-2 w-full max-sm">
<Input
placeholder="根据名称搜索..."
value={searchName}
onChange={(e) => setSearchName(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && handleSearch()}
/>
<Button variant="secondary" onClick={handleSearch}></Button>
</div>
<Button onClick={handleOpenAdd}>
<Plus className="w-4 h-4 mr-2" />
</Button>
</div>
{/* Data Table */}
<div className="border rounded-md mt-4 flex-1 overflow-auto">
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-[80px]">ID</TableHead>
<TableHead>ID</TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead>()</TableHead>
<TableHead>VIP</TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{loading && data.length === 0 ? (
<TableRow>
<TableCell colSpan={9} className="text-center h-32">...</TableCell>
</TableRow>
) : data.length === 0 ? (
<TableRow>
<TableCell colSpan={9} className="text-center h-32 text-muted-foreground"></TableCell>
</TableRow>
) : (
data.map((item: any) => (
<TableRow key={item.ID} className={loading ? 'opacity-50' : ''}>
<TableCell>{item.ID}</TableCell>
<TableCell>{item.categoryId}</TableCell>
<TableCell className="font-medium">{item.name}</TableCell>
<TableCell>{item.description}</TableCell>
<TableCell>{item.tags}</TableCell>
<TableCell>{item.price}</TableCell>
<TableCell>{item.isVipOnly === 1 ? '是' : '否'}</TableCell>
<TableCell>{item.status === 1 ? '启用' : '禁用'}</TableCell>
<TableCell className="text-right">
<Button variant="ghost" size="icon" onClick={() => handleOpenEdit(item)}>
<Edit className="w-4 h-4 text-blue-500" />
</Button>
<Button variant="ghost" size="icon" onClick={() => handleDelete(item.ID)}>
<Trash2 className="w-4 h-4 text-red-500" />
</Button>
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</div>
<div className="flex bg-muted p-2 mt-2 rounded items-center justify-between text-sm text-muted-foreground">
<span>: {total} </span>
<span>: {pageSize} </span>
</div>
{/* Form Dialog */}
<Dialog open={open} onOpenChange={setOpen}>
<DialogContent className="max-w-md">
<DialogHeader>
<DialogTitle>{isEdit ? '编辑频道' : '新增频道'}</DialogTitle>
</DialogHeader>
<div className="space-y-4 py-4 max-h-[60vh] overflow-y-auto px-1">
<div className="space-y-2">
<Label></Label>
<Input
value={formData.name}
onChange={e => setFormData({ ...formData, name: e.target.value })}
placeholder="输入频道名称"
/>
</div>
<div className="space-y-2">
<Label></Label>
<select
className="flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm"
value={formData.categoryId}
onChange={e => setFormData({ ...formData, categoryId: e.target.value })}
>
<option value="" disabled></option>
{categories.map((c: any) => (
<option key={c.ID} value={c.ID}>{c.name}</option>
))}
</select>
</div>
<div className="space-y-2">
<Label></Label>
<Input
value={formData.description}
onChange={e => setFormData({ ...formData, description: e.target.value })}
placeholder="频道描述"
/>
</div>
<div className="space-y-2">
<Label> ()</Label>
<Input
value={formData.tags}
onChange={e => setFormData({ ...formData, tags: e.target.value })}
placeholder="例:音乐,新闻"
/>
</div>
<div className="flex space-x-4">
<div className="space-y-2 flex-1">
<Label> ()</Label>
<Input
type="number"
value={formData.price}
onChange={e => setFormData({ ...formData, price: parseInt(e.target.value) || 0 })}
/>
</div>
<div className="space-y-2 flex-1">
<Label></Label>
<Input
type="number"
value={formData.sort}
onChange={e => setFormData({ ...formData, sort: parseInt(e.target.value) || 0 })}
/>
</div>
</div>
<div className="flex space-x-4">
<div className="space-y-2 flex-1">
<Label>VIP</Label>
<select
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm"
value={formData.isVipOnly}
onChange={e => setFormData({ ...formData, isVipOnly: parseInt(e.target.value) })}
>
<option value={0}></option>
<option value={1}></option>
</select>
</div>
<div className="space-y-2 flex-1">
<Label></Label>
<select
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm"
value={formData.status}
onChange={e => setFormData({ ...formData, status: parseInt(e.target.value) })}
>
<option value={1}></option>
<option value={0}></option>
</select>
</div>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => setOpen(false)}></Button>
<Button onClick={handleSubmit}></Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
);
}
+318
View File
@@ -0,0 +1,318 @@
import { useState, useEffect } from 'react';
import {
getProgramListApi,
saveProgramApi,
updateProgramApi,
deleteProgramApi,
getChannelListApi
} from '../../../api/radio';
import { Button } from '../../../components/ui/button';
import { Input } from '../../../components/ui/input';
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '../../../components/ui/table';
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '../../../components/ui/dialog';
import { Label } from '../../../components/ui/label';
import { Plus, Edit, Trash2 } from 'lucide-react';
import { toast } from 'sonner';
export default function Program() {
const [data, setData] = useState([]);
const [total, setTotal] = useState(0);
const [loading, setLoading] = useState(false);
const [channels, setChannels] = useState([]);
// Pagination & Search
const [page, setPage] = useState(1);
const [pageSize, setPageSize] = useState(10);
const [searchTitle, setSearchTitle] = useState('');
// Dialog State
const [open, setOpen] = useState(false);
const [isEdit, setIsEdit] = useState(false);
const [formData, setFormData] = useState({
ID: undefined,
channelId: '',
title: '',
description: '',
content: '',
duration: 0,
coverId: '',
audioId: '',
tags: '',
status: 1
});
const fetchChannels = async () => {
try {
const res: any = await getChannelListApi();
setChannels(res.list || res || []);
} catch (e) {
console.error(e);
}
}
const fetchData = async () => {
if (loading) return;
setLoading(true);
try {
const res: any = await getProgramListApi({
current: page,
pageSize: pageSize,
keyword: searchTitle,
title: searchTitle
});
setData(res.list || []);
setTotal(res.total || 0);
} catch (e) {
console.error(e);
} finally {
setLoading(false);
}
};
// Table data fetch only on pagination change
useEffect(() => {
fetchData();
}, [page, pageSize]);
// Lazy load channels only when dialog opens
useEffect(() => {
if (open) {
fetchChannels();
}
}, [open]);
const handleSearch = () => {
if (page === 1) {
fetchData();
} else {
setPage(1);
}
};
const handleOpenAdd = () => {
setIsEdit(false);
setFormData({
ID: undefined, channelId: '', title: '', description: '', content: '',
duration: 0, coverId: '', audioId: '', tags: '', status: 1
});
setOpen(true);
};
const handleOpenEdit = (record: any) => {
setIsEdit(true);
setFormData({
ID: record.ID,
channelId: record.channelId,
title: record.title,
description: record.description,
content: record.content,
duration: record.duration,
coverId: record.coverId,
audioId: record.audioId,
tags: record.tags,
status: record.status
});
setOpen(true);
};
const handleDelete = async (id: number) => {
if (!confirm('确定要删除这个节目吗?')) return;
try {
await deleteProgramApi({ id });
toast.success('删除成功');
fetchData();
} catch (e) {
console.error(e);
}
};
const handleSubmit = async () => {
if (!formData.title) {
toast.error('请填写节目标题');
return;
}
if (!formData.channelId) {
toast.error('请选择所属频道');
return;
}
try {
if (isEdit) {
await updateProgramApi(formData);
toast.success('更新成功');
} else {
await saveProgramApi(formData);
toast.success('创建成功');
}
setOpen(false);
fetchData();
} catch (e) {
console.error(e);
}
};
return (
<div className="space-y-4 flex flex-col h-full bg-background rounded-lg border p-6">
<div className="flex justify-between items-center">
<div>
<h1 className="text-2xl font-bold tracking-tight"></h1>
<p className="text-muted-foreground">广</p>
</div>
</div>
{/* Toolbar */}
<div className="flex justify-between items-center space-x-2">
<div className="flex space-x-2 w-full max-w-sm">
<Input
placeholder="根据标题搜索..."
value={searchTitle}
onChange={(e) => setSearchTitle(e.target.value)}
onKeyDown={(e) => e.key === 'Enter' && handleSearch()}
/>
<Button variant="secondary" onClick={handleSearch}></Button>
</div>
<Button onClick={handleOpenAdd}>
<Plus className="w-4 h-4 mr-2" />
</Button>
</div>
{/* Data Table */}
<div className="border rounded-md mt-4 flex-1 overflow-auto">
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-[80px]">ID</TableHead>
<TableHead></TableHead>
<TableHead>ID</TableHead>
<TableHead>()</TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{loading && data.length === 0 ? (
<TableRow>
<TableCell colSpan={9} className="text-center h-32">...</TableCell>
</TableRow>
) : data.length === 0 ? (
<TableRow>
<TableCell colSpan={9} className="text-center h-32 text-muted-foreground"></TableCell>
</TableRow>
) : (
data.map((item: any) => (
<TableRow key={item.ID} className={loading ? 'opacity-50' : ''}>
<TableCell>{item.ID}</TableCell>
<TableCell className="font-medium">{item.title}</TableCell>
<TableCell>{item.channelId}</TableCell>
<TableCell>{item.duration}</TableCell>
<TableCell>{item.tags}</TableCell>
<TableCell>{item.playCount}</TableCell>
<TableCell>{item.likeCount}</TableCell>
<TableCell>{item.status === 1 ? '已发布' : '已下架'}</TableCell>
<TableCell className="text-right">
<Button variant="ghost" size="icon" onClick={() => handleOpenEdit(item)}>
<Edit className="w-4 h-4 text-blue-500" />
</Button>
<Button variant="ghost" size="icon" onClick={() => handleDelete(item.ID)}>
<Trash2 className="w-4 h-4 text-red-500" />
</Button>
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</div>
<div className="flex bg-muted p-2 mt-2 rounded items-center justify-between text-sm text-muted-foreground">
<span>: {total} </span>
<span>: {pageSize} </span>
</div>
{/* Form Dialog */}
<Dialog open={open} onOpenChange={setOpen}>
<DialogContent className="max-w-xl">
<DialogHeader>
<DialogTitle>{isEdit ? '编辑节目' : '新增节目'}</DialogTitle>
</DialogHeader>
<div className="space-y-4 py-4 max-h-[60vh] overflow-y-auto px-1">
<div className="space-y-2">
<Label></Label>
<Input
value={formData.title}
onChange={e => setFormData({ ...formData, title: e.target.value })}
placeholder="输入节目标题"
/>
</div>
<div className="space-y-2">
<Label></Label>
<select
className="flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm"
value={formData.channelId}
onChange={e => setFormData({ ...formData, channelId: e.target.value })}
>
<option value="" disabled></option>
{channels.map((c: any) => (
<option key={c.ID} value={c.ID}>{c.name}</option>
))}
</select>
</div>
<div className="space-y-2">
<Label></Label>
<Input
value={formData.description}
onChange={e => setFormData({ ...formData, description: e.target.value })}
placeholder="节目描述"
/>
</div>
<div className="space-y-2">
<Label></Label>
<textarea
className="flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm"
value={formData.content}
onChange={e => setFormData({ ...formData, content: e.target.value })}
placeholder="节目具体详情内容"
/>
</div>
<div className="flex space-x-4">
<div className="space-y-2 flex-1">
<Label> ()</Label>
<Input
type="number"
value={formData.duration}
onChange={e => setFormData({ ...formData, duration: parseInt(e.target.value) || 0 })}
/>
</div>
<div className="space-y-2 flex-1">
<Label> ()</Label>
<Input
value={formData.tags}
onChange={e => setFormData({ ...formData, tags: e.target.value })}
placeholder="例:搞笑,音乐"
/>
</div>
</div>
<div className="space-y-2">
<Label></Label>
<select
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm"
value={formData.status}
onChange={e => setFormData({ ...formData, status: parseInt(e.target.value) })}
>
<option value={1}></option>
<option value={0}></option>
</select>
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => setOpen(false)}></Button>
<Button onClick={handleSubmit}></Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
);
}
+213
View File
@@ -0,0 +1,213 @@
import { useState, useEffect } from 'react';
import {
getFileListApi,
deleteFileApi,
uploadFileApi
} from '../../../api/oss';
import { Button } from '../../../components/ui/button';
import { Input } from '../../../components/ui/input';
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '../../../components/ui/table';
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '../../../components/ui/dialog';
import { Label } from '../../../components/ui/label';
import { Plus, Trash2, Copy, FileIcon } from 'lucide-react';
import { toast } from 'sonner';
export default function Oss() {
const [data, setData] = useState([]);
const [total, setTotal] = useState(0);
const [loading, setLoading] = useState(false);
// Pagination
const [page, setPage] = useState(1);
const [pageSize, setPageSize] = useState(10);
const [keyword, setKeyword] = useState('');
// Upload Dialog State
const [open, setOpen] = useState(false);
const [file, setFile] = useState<File | null>(null);
const [uploading, setUploading] = useState(false);
const fetchData = async () => {
setLoading(true);
try {
const res: any = await getFileListApi({
current: page,
pageSize: pageSize,
keyword
});
setData(res.list || []);
setTotal(res.total || 0);
} catch (e) {
console.error(e);
} finally {
setLoading(false);
}
};
useEffect(() => {
fetchData();
}, [page, pageSize]);
const handleDelete = async (id: number) => {
if (!confirm('确定要删除这个文件吗?')) return;
try {
await deleteFileApi({ id });
toast.success('删除成功');
fetchData();
} catch (e) {
console.error(e);
}
};
const handleCopyUrl = (url: string) => {
navigator.clipboard.writeText(url);
toast.success('链接已复制到剪贴板');
};
const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
if (e.target.files && e.target.files.length > 0) {
setFile(e.target.files[0]);
}
};
const handleUpload = async () => {
if (!file) {
toast.error('请选择一个文件');
return;
}
const formData = new FormData();
formData.append('file', file);
try {
setUploading(true);
await uploadFileApi(formData);
toast.success('上传成功');
setOpen(false);
setFile(null);
fetchData();
} catch (e) {
console.error(e);
} finally {
setUploading(false);
const fileInput: any = document.getElementById('file-upload');
if (fileInput) fileInput.value = '';
}
};
return (
<div className="space-y-4 flex flex-col h-full bg-background rounded-lg border p-6">
<div className="flex justify-between items-center">
<div>
<h1 className="text-2xl font-bold tracking-tight"> (OSS)</h1>
<p className="text-muted-foreground"></p>
</div>
</div>
{/* Toolbar */}
<div className="flex justify-between items-center space-x-2">
<div className="flex space-x-2 w-full max-w-sm">
<Input
placeholder="关键字搜索..."
value={keyword}
onChange={(e) => setKeyword(e.target.value)}
/>
<Button variant="secondary" onClick={() => { setPage(1); fetchData(); }}></Button>
</div>
<Button onClick={() => setOpen(true)}>
<Plus className="w-4 h-4 mr-2" />
</Button>
</div>
{/* Data Table */}
<div className="border rounded-md mt-4 flex-1 overflow-auto">
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-[80px]">ID</TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead></TableHead>
<TableHead className="text-right"></TableHead>
</TableRow>
</TableHeader>
<TableBody>
{loading ? (
<TableRow>
<TableCell colSpan={6} className="text-center h-32">...</TableCell>
</TableRow>
) : data.length === 0 ? (
<TableRow>
<TableCell colSpan={6} className="text-center h-32 text-muted-foreground"></TableCell>
</TableRow>
) : (
data.map((item: any) => (
<TableRow key={item.ID}>
<TableCell>{item.ID}</TableCell>
<TableCell>
{['jpg', 'png', 'jpeg', 'gif', 'webp'].includes(item.suffix?.toLowerCase()) ? (
<img src={item.url} alt="preview" className="w-8 h-8 object-cover rounded shadow-sm" />
) : (
<div className="w-8 h-8 flex items-center justify-center bg-muted rounded">
<FileIcon className="w-4 h-4 text-muted-foreground" />
</div>
)}
</TableCell>
<TableCell className="font-medium max-w-[200px] truncate" title={item.name}>
{item.name}
</TableCell>
<TableCell>{item.suffix}</TableCell>
<TableCell className="max-w-[250px] truncate text-muted-foreground" title={item.url}>
{item.url}
</TableCell>
<TableCell className="text-right space-x-2">
<Button variant="ghost" size="icon" onClick={() => handleCopyUrl(item.url)} title="复制链接">
<Copy className="w-4 h-4 text-blue-500" />
</Button>
<Button variant="ghost" size="icon" onClick={() => handleDelete(item.ID)} title="删除文件">
<Trash2 className="w-4 h-4 text-red-500" />
</Button>
</TableCell>
</TableRow>
))
)}
</TableBody>
</Table>
</div>
<div className="flex bg-muted p-2 mt-2 rounded items-center justify-between text-sm text-muted-foreground">
<span>: {total} </span>
<span>: {pageSize} </span>
</div>
{/* Upload Dialog */}
<Dialog open={open} onOpenChange={setOpen}>
<DialogContent className="max-w-md">
<DialogHeader>
<DialogTitle></DialogTitle>
</DialogHeader>
<div className="space-y-4 py-4">
<div className="space-y-2">
<Label></Label>
<Input
id="file-upload"
type="file"
onChange={handleFileChange}
/>
{file && (
<p className="text-sm text-muted-foreground mt-2">
: {file.name} ({(file.size / 1024).toFixed(2)} KB)
</p>
)}
</div>
</div>
<DialogFooter>
<Button variant="outline" onClick={() => setOpen(false)} disabled={uploading}></Button>
<Button onClick={handleUpload} disabled={uploading || !file}>
{uploading ? '上传中...' : '提交上传'}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
);
}
+47
View File
@@ -0,0 +1,47 @@
import { createBrowserRouter, Navigate } from 'react-router-dom';
import AdminLayout from '../layouts/AdminLayout';
import Login from '../pages/Login';
import Dashboard from '../pages/Dashboard';
import Category from '../pages/Radio/Category';
import Channel from '../pages/Radio/Channel';
import Program from '../pages/Radio/Program';
import Oss from '../pages/System/Oss';
const router = createBrowserRouter([
{
path: '/login',
element: <Login />,
},
{
path: '/',
element: <AdminLayout />,
children: [
{
index: true,
element: <Dashboard />,
},
{
path: 'radio/category',
element: <Category />,
},
{
path: 'radio/channel',
element: <Channel />,
},
{
path: 'radio/program',
element: <Program />,
},
{
path: 'system/oss',
element: <Oss />,
},
],
},
{
path: '*',
element: <Navigate to="/" replace />,
},
]);
export default router;
+25
View File
@@ -0,0 +1,25 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
interface AuthState {
token: string | null;
userInfo: any | null;
setToken: (token: string) => void;
setUserInfo: (info: any) => void;
logout: () => void;
}
export const useAuthStore = create<AuthState>()(
persist(
(set) => ({
token: null,
userInfo: null,
setToken: (token) => set({ token }),
setUserInfo: (info) => set({ userInfo: info }),
logout: () => set({ token: null, userInfo: null }),
}),
{
name: 'auth-storage',
}
)
);
+47
View File
@@ -0,0 +1,47 @@
import axios, { type InternalAxiosRequestConfig, type AxiosResponse } from 'axios';
import { toast } from 'sonner';
import { useAuthStore } from '../store/authStore';
const request = axios.create({
baseURL: '/api',
timeout: 30000,
});
request.interceptors.request.use(
(config: InternalAxiosRequestConfig) => {
const token = useAuthStore.getState().token;
if (token && config.headers) {
config.headers['Authorization'] = `Bearer ${token}`;
}
return config;
},
(error) => {
return Promise.reject(error);
}
);
request.interceptors.response.use(
(response: AxiosResponse) => {
const res = response.data;
// Assuming a standard response structure: { code: 0, data: ..., msg: ... }
if (res.code !== 200) {
toast.error(res.msg || 'Error');
if (res.code === 401 || res.code === 7) {
useAuthStore.getState().logout();
}
return Promise.reject(new Error(res.msg || 'Error'));
}
return res.data;
},
(error) => {
if (error.response?.status === 401) {
useAuthStore.getState().logout();
toast.error('Session expired. Please login again.');
} else {
toast.error(error.message || 'Network Error');
}
return Promise.reject(error);
}
);
export default request;
+41
View File
@@ -0,0 +1,41 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2022",
"useDefineForClassFields": true,
"lib": [
"ES2022",
"DOM",
"DOM.Iterable"
],
"module": "ESNext",
"types": [
"vite/client"
],
"skipLibCheck": true,
/* Path Aliases */
"baseUrl": ".",
"paths": {
"@/*": [
"./src/*"
]
},
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": [
"src"
]
}
+19
View File
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": [
"./src/*"
]
}
},
"files": [],
"references": [
{
"path": "./tsconfig.app.json"
},
{
"path": "./tsconfig.node.json"
}
]
}
+26
View File
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2023",
"lib": ["ES2023"],
"module": "ESNext",
"types": ["node"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["vite.config.ts"]
}
+23
View File
@@ -0,0 +1,23 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tailwindcss from '@tailwindcss/vite'
import path from "path"
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), tailwindcss()],
server: {
proxy: {
'/api': {
target: 'http://localhost:8889',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
},
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),
},
},
})