Skip to content

Let's use AI to Earn!

素材库

daoyianb56561761339
diff --git a/src/api/account.ts b/src/api/account.ts
index 4335dc6b..d25219a8 100644
--- a/src/api/account.ts
+++ b/src/api/account.ts
@@ -1,5 +1,5 @@
// 创建或更新账户
-import sxRequest from "@/utils/request";
+import http from "@/utils/request";
import {
AccountGroupItem,
SocialAccount,
@@ -7,12 +7,12 @@ import {
} from "@/api/types/account.type";
export const createOrUpdateAccountApi = (data: Partial<SocialAccount>) => {
- return sxRequest.post<SocialAccount>("account/login", data);
+ return http.post<SocialAccount>("account/login", data);
};
// 更新账户
export const updateAccountApi = (data: Partial<SocialAccount>) => {
- return sxRequest.post<SocialAccount>("account/update", data);
+ return http.post<SocialAccount>("account/update", data);
};
// 更新账户状态
@@ -20,55 +20,55 @@ export const updateAccountStatusApi = (data: {
id: string;
status: number;
}) => {
- return sxRequest.post<SocialAccount>("account/status", data);
+ return http.post<SocialAccount>("account/status", data);
};
// 获取账户列表
export const getAccountListApi = () => {
- return sxRequest.get<SocialAccount[]>("account/list/all");
+ return http.get<SocialAccount[]>("account/list/all");
};
// 获取账户详情
export const getAccountDetailApi = (id: string) => {
- return sxRequest.get<SocialAccount>(`account/${id}`);
+ return http.get<SocialAccount>(`account/${id}`);
};
export const updateAccountStatisticsApi = (
data: UpdateAccountStatisticsParams,
) => {
- return sxRequest.post<SocialAccount>("account/statistics/update", data);
+ return http.post<SocialAccount>("account/statistics/update", data);
};
// 删除账户
export const deleteAccountApi = (id: string) => {
- return sxRequest.post<SocialAccount>(`account/delete/${id}`);
+ return http.post<SocialAccount>(`account/delete/${id}`);
};
// 删除多个账户
export const deleteAccountsApi = (ids: string[]) => {
- return sxRequest.post<SocialAccount>("account/deletes", {
+ return http.post<SocialAccount>("account/deletes", {
ids,
});
};
// 创建账户组
export const createAccountGroupApi = (data: Partial<AccountGroupItem>) => {
- return sxRequest.post("accountGroup/create", data);
+ return http.post("accountGroup/create", data);
};
// 更新账户组
export const updateAccountGroupApi = (data: Partial<AccountGroupItem>) => {
- return sxRequest.post("accountGroup/update", data);
+ return http.post("accountGroup/update", data);
};
// 删除账户组
export const deleteAccountGroupApi = (ids: string[]) => {
- return sxRequest.post("accountGroup/deletes", {
+ return http.post("accountGroup/deletes", {
ids,
});
};
// 获取所有账户组
export const getAccountGroupApi = () => {
- return sxRequest.get<AccountGroupItem[]>("accountGroup/getList");
+ return http.get<AccountGroupItem[]>("accountGroup/getList");
};
diff --git a/src/api/apiReq.ts b/src/api/apiReq.ts
index 0cf3dfe2..cf491a95 100644
--- a/src/api/apiReq.ts
+++ b/src/api/apiReq.ts
@@ -1,4 +1,4 @@
-import sxRequest from "@/utils/request";
+import http from "@/utils/request";
import { UserInfo } from "@/store/user";
export interface LoginResponse {
@@ -18,40 +18,40 @@ export interface RegistCheckParams {
// 获取用户信息
export const getUserInfoApi = () => {
- return sxRequest.get<UserInfo>("user/mine");
+ return http.get<UserInfo>("user/mine");
};
// 更新用户信息
export const updateUserInfoApi = (data: { name: string }) => {
- return sxRequest.put<UserInfo>("user/info/update", data);
+ return http.put<UserInfo>("user/info/update", data);
};
export const getMoneyStampApi = () => {
- return sxRequest.get<any>("cfg/money/stamp");
+ return http.get<any>("cfg/money/stamp");
};
export const fluxSchnellApi = (data: any) => {
- return sxRequest.post<any>("experience-ai/text2image/flux_schnell", data);
+ return http.post<any>("experience-ai/text2image/flux_schnell", data);
};
// 邮箱登录接口
export const loginWithMailApi = (data: { mail: string; password: string }) => {
- return sxRequest.post<LoginResponse>("login/mail", data);
+ return http.post<LoginResponse>("login/mail", data);
};
// 获取注册链接
export const getRegistUrlApi = (mail: string) => {
- return sxRequest.get<LoginResponse>(`login/mail/regist/url?mail=${mail}`);
+ return http.get<LoginResponse>(`login/mail/regist/url?mail=${mail}`);
};
// 检查注册状态 post!!
export const checkRegistStatusApi = (data: RegistCheckParams) => {
- return sxRequest.post<LoginResponse>(`login/mail/regist/back`, data);
+ return http.post<LoginResponse>(`login/mail/regist/back`, data);
};
// 发送重置密码邮件
export const sendResetPasswordMailApi = (data: { mail: string }) => {
- return sxRequest.post<LoginResponse>("login/repassword/mail", data);
+ return http.post<LoginResponse>("login/repassword/mail", data);
};
// 重置密码
@@ -60,7 +60,7 @@ export const resetPasswordApi = (data: {
mail: string;
password: string;
}) => {
- return sxRequest.post<LoginResponse>("login/repassword/mail/back", data);
+ return http.post<LoginResponse>("login/repassword/mail/back", data);
};
// Google 登录参数
@@ -71,5 +71,5 @@ export interface GoogleLoginParams {
// Google 登录
export const googleLoginApi = (data: GoogleLoginParams) => {
- return sxRequest.post<LoginResponse>("login/google", data);
+ return http.post<LoginResponse>("login/google", data);
};
diff --git a/src/api/bilibili.ts b/src/api/bilibili.ts
index 8c4db3f4..b2065c9e 100644
--- a/src/api/bilibili.ts
+++ b/src/api/bilibili.ts
@@ -1,5 +1,5 @@
// 创建或更新账户
-import sxRequest from "@/utils/request";
+import http from "@/utils/request";
import { request } from '@/utils/request';
/**
@@ -7,7 +7,7 @@ import { request } from '@/utils/request';
* @returns
*/
export const apiGetBilibiliLoginUrl = (type: "h5" | "pc") => {
- return sxRequest.get<{ code: number; data: { taskId: string; url: string } }>(
+ return http.get<{ code: number; data: { taskId: string; url: string } }>(
`plat/bilibili/auth/url/${type}`,
);
};
@@ -18,7 +18,7 @@ export const apiGetBilibiliLoginUrl = (type: "h5" | "pc") => {
* @returns
*/
export const apiCheckBilibiliAuth = (taskId: string) => {
- return sxRequest.post<{ code: number; data: any }>(
+ return http.post<{ code: number; data: any }>(
`plat/bilibili/auth/create-account/${taskId}`,
);
};
@@ -29,7 +29,7 @@ export const apiCheckBilibiliAuth = (taskId: string) => {
* @returns
*/
export const apiInitBilibiliVideo = (data: any) => {
- return sxRequest.post<{ code: number; data: any }>(
+ return http.post<{ code: number; data: any }>(
`plat/bilibili/video/init`,
data,
);
@@ -77,7 +77,7 @@ export const apiSubmitBilibiliArchive = (
source: string;
},
) => {
- return sxRequest.post<{ code: number; data: any }>(
+ return http.post<{ code: number; data: any }>(
`plat/bilibili/archive/add-by-utoken/${accountId}`,
data,
);
diff --git a/src/api/media.ts b/src/api/media.ts
new file mode 100644
index 00000000..2984c074
--- /dev/null
+++ b/src/api/media.ts
@@ -0,0 +1,54 @@
+import http from "@/utils/request";
+
+
+// 创建媒体资源组
+export const createMediaGroup = (data: {
+ title: string;
+ desc: string;
+ type: 'video' | 'img' | 'audio';
+}) => {
+ return http.post('/media/group', data);
+};
+
+// 删除媒体资源组
+export const deleteMediaGroup = (id: string) => {
+ return http.delete(`/media/group/${id}`);
+};
+
+// 获取媒体资源组列表
+export const getMediaGroupList = (pageNo: number, pageSize: number) => {
+ return http.get(`/media/group/list/${pageNo}/${pageSize}`);
+};
+
+// 更新媒体资源组信息
+export const updateMediaGroupInfo = (id: string, data: {
+ title?: string;
+ desc?: string;
+ type?: 'video' | 'img' | 'audio';
+}) => {
+ return http.post(`/media/group/info/${id}`, data);
+};
+
+
+// 创建媒体资源
+export const createMedia = (data:any) => {
+ return http.post('/media', data);
+};
+
+// 删除媒体资源
+export const deleteMedia = (id: string) => {
+ return http.delete(`/media/${id}`);
+};
+
+// 获取媒体资源列表
+export const getMediaList = (pageNo: number, pageSize: number) => {
+ return http.get(`/media/list/${pageNo}/${pageSize}`);
+};
+
+// 更新媒体资源信息
+export const updateMediaInfo = (id: string, data: {
+ title?: string;
+ desc?: string;
+}) => {
+ return http.put(`/media/info/${id}`, data);
+};
\ No newline at end of file
diff --git a/src/api/oss.ts b/src/api/oss.ts
new file mode 100644
index 00000000..6de206d0
--- /dev/null
+++ b/src/api/oss.ts
@@ -0,0 +1,24 @@
+import http from "@/utils/request";
+import { request } from '@/utils/request';
+
+
+// 上传文件到OSS
+export const uploadToOss = async (file: File) => {
+ try {
+
+ // 2. 上传文件到OSS
+ const formData = new FormData();
+ formData.append('file', file);
+
+ let res:any = await request({
+ url: '/oss/upload',
+ method: 'POST',
+ body: formData,
+ });
+ return res?.data.name;
+
+ } catch (error) {
+ console.error('上传文件失败:', error);
+ throw error;
+ }
+};
\ No newline at end of file
diff --git a/src/app/[lng]/material/album/[id]/album.module.scss b/src/app/[lng]/material/album/[id]/album.module.scss
new file mode 100644
index 00000000..e43a509c
--- /dev/null
+++ b/src/app/[lng]/material/album/[id]/album.module.scss
@@ -0,0 +1,254 @@
+.container {
+ padding: 24px;
+ width: 100%;
+ max-width: 1440px;
+ margin: 0 auto;
+ box-sizing: border-box;
+}
+
+.header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 32px;
+
+ h2 {
+ margin: 0;
+ font-size: 24px;
+ color: #333;
+ }
+}
+
+.uploadButton {
+ background-color: var(--theColor5);
+ color: white;
+ border: none;
+ padding: 8px 16px;
+ border-radius: 4px;
+ cursor: pointer;
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ transition: all 0.3s ease;
+
+ &:hover {
+ background-color: var(--theColor6);
+ }
+
+ &:active {
+ background-color: var(--theColor7);
+ }
+}
+
+.mediaGrid {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
+ gap: 24px;
+}
+
+.mediaCard {
+ background: white;
+ border-radius: 8px;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
+ overflow: hidden;
+ transition: transform 0.3s, box-shadow 0.3s;
+
+ &:hover {
+ transform: translateY(-4px);
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
+ }
+}
+
+.mediaWrapper {
+ position: relative;
+ padding-top: 75%;
+ background: #f5f5f5;
+ cursor: pointer;
+
+ img, video, audio {
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ }
+}
+
+.mediaActions {
+ position: absolute;
+ top: 8px;
+ right: 8px;
+ display: flex;
+ gap: 8px;
+ opacity: 0;
+ transition: opacity 0.3s;
+}
+
+.mediaWrapper:hover .mediaActions {
+ opacity: 1;
+}
+
+.actionButton {
+ background: rgba(255, 255, 255, 0.9);
+ border: none;
+ padding: 6px 12px;
+ border-radius: 4px;
+ cursor: pointer;
+ display: flex;
+ align-items: center;
+ gap: 4px;
+ font-size: 14px;
+ color: var(--theColor5);
+ transition: all 0.3s ease;
+
+ &:hover {
+ background: white;
+ color: var(--theColor6);
+ }
+
+ &:active {
+ color: var(--theColor7);
+ }
+
+ &.delete {
+ color: var(--error-color);
+
+ &:hover {
+ color: #ff7875;
+ }
+
+ &:active {
+ color: #d9363e;
+ }
+ }
+}
+
+.mediaInfo {
+ padding: 16px;
+
+ h3 {
+ margin: 0 0 8px 0;
+ font-size: 16px;
+ color: #333;
+ }
+
+ p {
+ margin: 0;
+ color: #666;
+ font-size: 14px;
+ }
+}
+
+.emptyState {
+ text-align: center;
+ padding: 48px 24px;
+ background: white;
+ border-radius: 8px;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
+
+ h3 {
+ margin: 0 0 16px 0;
+ color: #333;
+ }
+
+ p {
+ color: #666;
+ margin-bottom: 24px;
+ }
+}
+
+.modal {
+ position: fixed;
+ top: 0;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ background: rgba(0, 0, 0, 0.5);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ z-index: 1000;
+}
+
+.modalContent {
+ background: white;
+ padding: 24px;
+ border-radius: 8px;
+ max-width: 90%;
+ max-height: 90vh;
+ overflow: auto;
+}
+
+.modalHeader {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 24px;
+
+ h3 {
+ margin: 0;
+ font-size: 20px;
+ }
+
+ button {
+ background: none;
+ border: none;
+ font-size: 20px;
+ cursor: pointer;
+ color: #666;
+ }
+}
+
+.form {
+ display: flex;
+ flex-direction: column;
+ gap: 16px;
+}
+
+.formGroup {
+ display: flex;
+ flex-direction: column;
+ gap: 8px;
+
+ label {
+ font-weight: 500;
+ color: #333;
+ }
+
+ input, textarea {
+ padding: 8px 12px;
+ border: 1px solid #d9d9d9;
+ border-radius: 4px;
+ font-size: 14px;
+
+ &:focus {
+ outline: none;
+ border-color: #40a9ff;
+ }
+ }
+
+ textarea {
+ min-height: 100px;
+ resize: vertical;
+ }
+}
+
+.submitButton {
+ background: var(--theColor5);
+ color: white;
+ border: none;
+ padding: 8px 16px;
+ border-radius: 4px;
+ cursor: pointer;
+ align-self: flex-start;
+ transition: all 0.3s ease;
+
+ &:hover {
+ background: var(--theColor6);
+ }
+
+ &:active {
+ background: var(--theColor7);
+ }
+}
\ No newline at end of file
diff --git a/src/app/[lng]/material/album/[id]/albumDetailCore.tsx b/src/app/[lng]/material/album/[id]/albumDetailCore.tsx
index 7d87e630..31850b0b 100644
--- a/src/app/[lng]/material/album/[id]/albumDetailCore.tsx
+++ b/src/app/[lng]/material/album/[id]/albumDetailCore.tsx
@@ -4,7 +4,7 @@ import { useEffect, useState } from "react";
import { Card, Row, Col, Typography, Button, Upload, message } from "antd";
import { useRouter } from "next/navigation";
import { PlusOutlined, PlayCircleOutlined, PictureOutlined, SoundOutlined } from "@ant-design/icons";
-import styles from "./styles/albumDetail.module.scss";
+import styles from "./albumDetail.module.scss";
const { Title } = Typography;
@@ -12,7 +12,7 @@ interface Material {
id: string;
name: string;
url: string;
- type: 'video' | 'image' | 'audio';
+ type: 'video' | 'img' | 'audio';
createTime: string;
}
@@ -25,7 +25,7 @@ export const AlbumDetailCore = ({ albumId }: AlbumDetailCoreProps) => {
const [materials, setMaterials] = useState<Material[]>([]);
const [albumInfo, setAlbumInfo] = useState({
name: "视频素材",
- type: "video" as 'video' | 'image' | 'audio',
+ type: "video" as 'video' | 'img' | 'audio',
count: 0
});
@@ -54,7 +54,7 @@ export const AlbumDetailCore = ({ albumId }: AlbumDetailCoreProps) => {
switch (type) {
case 'video':
return <PlayCircleOutlined />;
- case 'image':
+ case 'img':
return <PictureOutlined />;
case 'audio':
return <SoundOutlined />;
@@ -69,11 +69,11 @@ export const AlbumDetailCore = ({ albumId }: AlbumDetailCoreProps) => {
<div className={styles.titleSection}>
<Title level={2}>{albumInfo.name}</Title>
<span className={styles.typeTag}>
- {albumInfo.type === 'video' ? '视频' : albumInfo.type === 'image' ? '图片' : '音频'}
+ {albumInfo.type === 'video' ? '视频' : albumInfo.type === 'img' ? '图片' : '音频'}
</span>
</div>
<Upload
- accept={albumInfo.type === 'video' ? 'video/*' : albumInfo.type === 'image' ? 'image/*' : 'audio/*'}
+ accept={albumInfo.type === 'video' ? 'video/*' : albumInfo.type === 'img' ? 'img/*' : 'audio/*'}
showUploadList={false}
beforeUpload={handleUpload}
>
diff --git a/src/app/[lng]/material/album/[id]/page.tsx b/src/app/[lng]/material/album/[id]/page.tsx
index b7168e18..bd522357 100644
--- a/src/app/[lng]/material/album/[id]/page.tsx
+++ b/src/app/[lng]/material/album/[id]/page.tsx
@@ -1,27 +1,223 @@
-import { useTranslation } from "@/app/i18n";
-import { PageParams } from "@/app/globals";
-import * as React from "react";
-import { getMetadata } from "@/utils/general";
-import { AlbumDetailCore } from "./albumDetailCore";
-
-export async function generateMetadata({ params }: PageParams) {
- const { lng } = await params;
- const { t } = await useTranslation(lng, "material");
- return await getMetadata(
- {
- title: "素材库详情",
- },
- lng,
- );
+"use client";
+
+import { useEffect, useState } from "react";
+import { useParams } from "next/navigation";
+import { message } from "antd";
+import styles from "./album.module.scss";
+import { createMedia, deleteMedia, getMediaList, updateMediaInfo } from "@/api/media";
+import { uploadToOss } from "@/api/oss";
+import { getOssUrl } from "@/utils/oss";
+
+interface Media {
+ id: string;
+ name: string;
+ url: string;
+ type: 'video' | 'img' | 'audio';
+ description?: string;
+ title: string;
+ desc: string;
}
-export default async function Page({ params }: PageParams) {
- const { lng } = await params;
- const { t } = await useTranslation(lng, "material");
+export default function AlbumPage() {
+ const params = useParams();
+ const albumId = params.id as string;
+
+ const [mediaList, setMediaList] = useState<Media[]>([]);
+ const [loading, setLoading] = useState(false);
+ const [currentPage, setCurrentPage] = useState(1);
+ const pageSize = 12;
+
+ const [editingMedia, setEditingMedia] = useState<Media | null>(null);
+ const [previewMedia, setPreviewMedia] = useState<Media | null>(null);
+
+ useEffect(() => {
+ fetchMediaList();
+ }, [currentPage, albumId]);
+
+ const fetchMediaList = async () => {
+ try {
+ setLoading(true);
+ const response:any = await getMediaList(currentPage, pageSize);
+ if (response?.data?.list) {
+ setMediaList(response.data.list);
+ } else {
+ setMediaList([]);
+ }
+ } catch (error) {
+ message.error('获取媒体资源列表失败');
+ setMediaList([]);
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ const handleUpload = async (event: React.ChangeEvent<HTMLInputElement>) => {
+ const file = event.target.files?.[0];
+ if (!file) return;
+
+ try {
+ const url = await uploadToOss(file);
+
+ await createMedia({
+ groupId: albumId,
+ type: file.type.startsWith('video/') ? 'video' : file.type.startsWith('image/') ? 'img' : 'audio',
+ url,
+ title: file.name,
+ desc: ''
+ });
+
+ message.success('上传成功');
+ fetchMediaList();
+ } catch (error) {
+ message.error('上传失败');
+ }
+ };
+
+ const handleDelete = async (mediaId: string) => {
+ if (!confirm('确定要删除吗?')) return;
+
+ try {
+ await deleteMedia(mediaId);
+ message.success('删除成功');
+ fetchMediaList();
+ } catch (error) {
+ message.error('删除失败');
+ }
+ };
+
+ const handleEditSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
+ event.preventDefault();
+ if (!editingMedia) return;
+
+ const formData = new FormData(event.currentTarget);
+ const values = {
+ title: formData.get('title') as string,
+ desc: formData.get('desc') as string
+ };
+
+ try {
+ await updateMediaInfo(editingMedia.id, values);
+ message.success('更新成功');
+ setEditingMedia(null);
+ fetchMediaList();
+ } catch (error) {
+ message.error('更新失败');
+ }
+ };
return (
- <>
- <AlbumDetailCore albumId={params.id} />
- </>
+ <div className={styles.container}>
+ <div className={styles.header}>
+ <h2>媒体资源</h2>
+ <label className={styles.uploadButton}>
+ <input
+ type="file"
+ accept="image/*,video/*,audio/*"
+ onChange={handleUpload}
+ style={{ display: 'none' }}
+ />
+ <span>上传资源</span>
+ </label>
+ </div>
+
+ <div className={styles.mediaGrid}>
+ {mediaList.length > 0 ? (
+ mediaList.map((media) => (
+ <div key={media.id} className={styles.mediaCard}>
+ <div className={styles.mediaWrapper} onClick={() => setPreviewMedia(media)}>
+ {media.type === 'video' ? (
+ <video src={getOssUrl(media.url)} />
+ ) : media.type === 'img' ? (
+ <img alt={media.title} src={getOssUrl(media.url)} />
+ ) : (
+ <audio src={getOssUrl(media.url)} />
+ )}
+ <div className={styles.mediaActions}>
+ <button
+ className={styles.actionButton}
+ onClick={(e) => {
+ e.stopPropagation();
+ setEditingMedia(media);
+ }}
+ >
+ 编辑
+ </button>
+ <button
+ className={`${styles.actionButton} ${styles.delete}`}
+ onClick={(e) => {
+ e.stopPropagation();
+ handleDelete(media.id);
+ }}
+ >
+ 删除
+ </button>
+ </div>
+ </div>
+ <div className={styles.mediaInfo}>
+ <h3>{media.title}</h3>
+ <p>{media.desc}</p>
+ </div>
+ </div>
+ ))
+ ) : (
+ <div className={styles.emptyState}>
+ <h3>暂无媒体资源</h3>
+ <p>点击上方按钮上传资源</p>
+ </div>
+ )}
+ </div>
+
+ {previewMedia && (
+ <div className={styles.modal} onClick={() => setPreviewMedia(null)}>
+ <div className={styles.modalContent} onClick={e => e.stopPropagation()}>
+ <div className={styles.modalHeader}>
+ <h3>{previewMedia.title}</h3>
+ <button onClick={() => setPreviewMedia(null)}>×</button>
+ </div>
+ {previewMedia.type === 'video' ? (
+ <video src={getOssUrl(previewMedia.url)} controls autoPlay />
+ ) : previewMedia.type === 'img' ? (
+ <img alt={previewMedia.title} src={getOssUrl(previewMedia.url)} />
+ ) : (
+ <audio src={getOssUrl(previewMedia.url)} controls autoPlay />
+ )}
+ </div>
+ </div>
+ )}
+
+ {editingMedia && (
+ <div className={styles.modal} onClick={() => setEditingMedia(null)}>
+ <div className={styles.modalContent} onClick={e => e.stopPropagation()}>
+ <div className={styles.modalHeader}>
+ <h3>编辑媒体信息</h3>
+ <button onClick={() => setEditingMedia(null)}>×</button>
+ </div>
+ <form className={styles.form} onSubmit={handleEditSubmit}>
+ <div className={styles.formGroup}>
+ <label htmlFor="title">标题</label>
+ <input
+ type="text"
+ id="title"
+ name="title"
+ defaultValue={editingMedia.title}
+ required
+ />
+ </div>
+ <div className={styles.formGroup}>
+ <label htmlFor="desc">描述</label>
+ <textarea
+ id="desc"
+ name="desc"
+ defaultValue={editingMedia.desc}
+ />
+ </div>
+ <button type="submit" className={styles.submitButton}>
+ 保存
+ </button>
+ </form>
+ </div>
+ </div>
+ )}
+ </div>
);
}
\ No newline at end of file
diff --git a/src/app/[lng]/material/album/[id]/styles/albumDetail.module.scss b/src/app/[lng]/material/album/[id]/styles/albumDetail.module.scss
deleted file mode 100644
index 5d9e9c9d..00000000
--- a/src/app/[lng]/material/album/[id]/styles/albumDetail.module.scss
+++ /dev/null
@@ -1,65 +0,0 @@
-.albumDetailContainer {
- padding: 24px;
- max-width: 1200px;
- margin: 0 auto;
-
- .header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 24px;
- }
-
- .titleSection {
- display: flex;
- align-items: center;
- gap: 16px;
- }
-
- .typeTag {
- background: #f0f0f0;
- padding: 4px 12px;
- border-radius: 16px;
- font-size: 14px;
- color: rgba(0, 0, 0, 0.65);
- }
-}
-
-.coverWrapper {
- position: relative;
- width: 100%;
- height: 200px;
- overflow: hidden;
-
- img {
- width: 100%;
- height: 100%;
- object-fit: cover;
- }
-}
-
-.videoIcon {
- position: absolute;
- left: 12px;
- bottom: 12px;
- background: rgba(0, 0, 0, 0.6);
- color: white;
- padding: 8px;
- border-radius: 50%;
- font-size: 24px;
- display: flex;
- align-items: center;
- justify-content: center;
-}
-
-.materialInfo {
- display: flex;
- justify-content: space-between;
- align-items: center;
- color: rgba(0, 0, 0, 0.45);
-}
-
-.typeIcon {
- font-size: 18px;
- color: rgba(0, 0, 0, 0.65);
-}
\ No newline at end of file
diff --git a/src/app/[lng]/material/materialPageCore.tsx b/src/app/[lng]/material/materialPageCore.tsx
index 89956273..774b6035 100644
--- a/src/app/[lng]/material/materialPageCore.tsx
+++ b/src/app/[lng]/material/materialPageCore.tsx
@@ -1,139 +1,275 @@
"use client";
import { useEffect, useState } from "react";
-import { Card, Row, Col, Typography, Button, Modal, Input, Select } from "antd";
+import { Card, Row, Col, Typography, Button, Modal, Input, Select, message, Popconfirm, Empty } from "antd";
import { useRouter } from "next/navigation";
-import { PlusOutlined, PlayCircleOutlined } from "@ant-design/icons";
+import { PlusOutlined, PlayCircleOutlined, DeleteOutlined, EditOutlined, FolderAddOutlined } from "@ant-design/icons";
import styles from "./styles/material.module.scss";
+import { createMediaGroup, deleteMediaGroup, getMediaGroupList, updateMediaGroupInfo } from "@/api/media";
const { Title } = Typography;
const { Option } = Select;
+const { TextArea } = Input;
-interface Album {
- id: string;
- name: string;
+interface MediaGroup {
+ _id: string;
+ title: string;
+ desc: string;
cover: string;
count: number;
- type: 'video' | 'image' | 'audio';
- isCustom?: boolean;
+ type: 'video' | 'img' | 'audio';
}
export const MaterialPageCore = () => {
const router = useRouter();
- const [albums, setAlbums] = useState<Album[]>([
- {
- id: "1",
- name: "视频素材",
- cover: "https://t9.baidu.com/it/u=4049930541,3060541868&fm=3031&app=3031&size=r3,4&q=100&n=0&g=11n&f=JPEG&fmt=auto&maxorilen2heic=2000000?s=5180DD1D4F1048C20269D5D303005030",
- count: 10,
- type: 'video'
- },
- {
- id: "2",
- name: "图片素材",
- cover: "https://t9.baidu.com/it/u=355272986,883798233&fm=3031&app=3031&size=r3,4&q=100&n=0&g=11n&f=JPEG&fmt=auto&maxorilen2heic=2000000?s=BDD04B977503EEF04CA566E90300702E",
- count: 20,
- type: 'image'
- },
- {
- id: "3",
- name: "音频素材",
- cover: "https://t9.baidu.com/it/u=3718371372,4045138797&fm=3031&app=3031&size=r3,4&q=100&n=0&g=11n&f=JPEG&fmt=auto&maxorilen2heic=2000000?s=BAA10F8E985263FD7899495E0300E0E6",
- count: 15,
- type: 'audio'
- }
- ]);
+ const [groups, setGroups] = useState<MediaGroup[]>([]);
+ const [loading, setLoading] = useState(false);
+ const [currentPage, setCurrentPage] = useState(1);
+ const [total, setTotal] = useState(0);
+ const pageSize = 12;
const [isModalVisible, setIsModalVisible] = useState(false);
- const [newAlbumName, setNewAlbumName] = useState("");
- const [newAlbumType, setNewAlbumType] = useState<'video' | 'image' | 'audio'>('video');
+ const [isEditModalVisible, setIsEditModalVisible] = useState(false);
+ const [newGroupTitle, setNewGroupTitle] = useState("");
+ const [newGroupDesc, setNewGroupDesc] = useState("");
+ const [newGroupType, setNewGroupType] = useState<'video' | 'img' | 'audio'>('video');
+ const [editingGroup, setEditingGroup] = useState<MediaGroup | null>(null);
+
+ useEffect(() => {
+ fetchGroups();
+ }, [currentPage]);
+
+ const fetchGroups = async () => {
+ try {
+ setLoading(true);
+ const response:any = await getMediaGroupList(currentPage, pageSize);
+ if (response?.data) {
+ setGroups(response.data.list);
+ setTotal(response.data.total);
+ }
+ } catch (error) {
+ message.error('获取媒体资源组列表失败');
+ } finally {
+ setLoading(false);
+ }
+ };
+
+ const handleGroupClick = (groupId: string) => {
+ router.push(`/material/album/${groupId}`);
+ };
+
+ const handleCreateGroup = async () => {
+ if (!newGroupTitle) return;
+
+ try {
+ await createMediaGroup({
+ title: newGroupTitle,
+ desc: newGroupDesc,
+ type: newGroupType
+ });
+ message.success('创建媒体资源组成功');
+ fetchGroups();
+ setIsModalVisible(false);
+ setNewGroupTitle("");
+ setNewGroupDesc("");
+ } catch (error) {
+ message.error('创建媒体资源组失败');
+ }
+ };
- const handleAlbumClick = (albumId: string) => {
- router.push(`/material/album/${albumId}`);
+ const handleDeleteGroup = async (groupId: string) => {
+ try {
+ await deleteMediaGroup(groupId);
+ message.success('删除媒体资源组成功');
+ fetchGroups();
+ } catch (error) {
+ message.error('删除媒体资源组失败');
+ }
};
- const handleCreateAlbum = () => {
- if (!newAlbumName) return;
+ const handleEditGroup = async () => {
+ if (!editingGroup || !newGroupTitle) return;
- const newAlbum: Album = {
- id: Date.now().toString(),
- name: newAlbumName,
- cover: "https://t9.baidu.com/it/u=4049930541,3060541868&fm=3031&app=3031&size=r3,4&q=100&n=0&g=11n&f=JPEG&fmt=auto&maxorilen2heic=2000000?s=5180DD1D4F1048C20269D5D303005030",
- count: 0,
- type: newAlbumType,
- isCustom: true
- };
-
- setAlbums([...albums, newAlbum]);
- setIsModalVisible(false);
- setNewAlbumName("");
+ try {
+ await updateMediaGroupInfo(editingGroup._id, {
+ title: newGroupTitle,
+ desc: newGroupDesc,
+ type: newGroupType
+ });
+ message.success('更新媒体资源组成功');
+ fetchGroups();
+ setIsEditModalVisible(false);
+ setEditingGroup(null);
+ setNewGroupTitle("");
+ setNewGroupDesc("");
+ } catch (error) {
+ message.error('更新媒体资源组失败');
+ }
+ };
+
+ const showEditModal = (group: MediaGroup) => {
+ setEditingGroup(group);
+ setNewGroupTitle(group.title);
+ setNewGroupDesc(group.desc);
+ setNewGroupType(group.type);
+ setIsEditModalVisible(true);
};
return (
<div className={styles.materialContainer}>
<div className={styles.header}>
- <Title level={2}>素材库</Title>
+ <Title level={2}>媒体资源组</Title>
<Button
type="primary"
icon={<PlusOutlined />}
onClick={() => setIsModalVisible(true)}
>
- 创建素材库
+ 创建媒体资源组
</Button>
</div>
- <Row gutter={[24, 24]}>
- {albums.map((album) => (
- <Col xs={24} sm={12} md={8} lg={6} key={album.id}>
- <Card
- hoverable
- cover={
- <div className={styles.coverWrapper}>
- <img alt={album.name} src={album.cover} />
- {album.type === 'video' && (
- <div className={styles.videoIcon}>
- <PlayCircleOutlined />
- </div>
- )}
- </div>
- }
- onClick={() => handleAlbumClick(album.id)}
- >
- <Card.Meta
- title={album.name}
- description={
- <div className={styles.albumInfo}>
- <span>{album.type === 'video' ? '视频' : album.type === 'image' ? '图片' : '音频'}</span>
- <span>共 {album.count} 个素材</span>
+ {groups.length > 0 ? (
+ <Row gutter={[24, 24]}>
+ {groups.map((group) => (
+ <Col xs={24} sm={12} md={8} lg={6} key={group._id}>
+ <Card
+ hoverable
+ loading={loading}
+ cover={
+ <div className={styles.coverWrapper}>
+ <img alt={group.title} src={group.cover} />
+ {group.type === 'video' && (
+ <div className={styles.videoIcon}>
+ <PlayCircleOutlined />
+ </div>
+ )}
</div>
}
- />
- </Card>
- </Col>
- ))}
- </Row>
+ actions={[
+ <EditOutlined key="edit" onClick={(e) => {
+ e.stopPropagation();
+ showEditModal(group);
+ }} />,
+ <Popconfirm
+ title="确定要删除这个媒体资源组吗?"
+ onConfirm={(e) => {
+ e?.stopPropagation();
+ handleDeleteGroup(group._id);
+ }}
+ onCancel={(e) => e?.stopPropagation()}
+ okText="确定"
+ cancelText="取消"
+ >
+ <DeleteOutlined key="delete" onClick={(e) => e.stopPropagation()} />
+ </Popconfirm>
+ ]}
+ onClick={() => handleGroupClick(group._id)}
+ >
+ <Card.Meta
+ title={group.title}
+ description={
+ <div className={styles.albumInfo}>
+ <div>{group.desc}</div>
+ <div>
+ <span>{group.type === 'video' ? '视频' : group.type === 'img' ? '图片' : ''}</span>
+ <span>共 {group.count} 个资源</span>
+ </div>
+ </div>
+ }
+ />
+ </Card>
+ </Col>
+ ))}
+ </Row>
+ ) : (
+ <div className={styles.emptyContainer}>
+ <Empty
+ image={Empty.PRESENTED_IMAGE_SIMPLE}
+ description={
+ <div className={styles.emptyDescription}>
+ <p>暂无媒体资源组</p>
+ <Button
+ type="primary"
+ icon={<FolderAddOutlined />}
+ onClick={() => setIsModalVisible(true)}
+ >
+ 创建媒体资源组
+ </Button>
+ </div>
+ }
+ />
+ </div>
+ )}
<Modal
- title="创建素材库"
+ title="创建媒体资源组"
open={isModalVisible}
- onOk={handleCreateAlbum}
- onCancel={() => setIsModalVisible(false)}
+ onOk={handleCreateGroup}
+ onCancel={() => {
+ setIsModalVisible(false);
+ setNewGroupTitle("");
+ setNewGroupDesc("");
+ }}
+ >
+ <div className={styles.createForm}>
+ <Input
+ placeholder="请输入媒体资源组标题"
+ value={newGroupTitle}
+ onChange={(e) => setNewGroupTitle(e.target.value)}
+ style={{ marginBottom: 16 }}
+ />
+ <TextArea
+ placeholder="请输入媒体资源组描述"
+ value={newGroupDesc}
+ onChange={(e) => setNewGroupDesc(e.target.value)}
+ rows={4}
+ style={{ marginBottom: 16 }}
+ />
+ <Select
+ value={newGroupType}
+ onChange={(value) => setNewGroupType(value)}
+ style={{ width: '100%' }}
+ >
+ <Option value="video">视频资源</Option>
+ <Option value="img">图片资源</Option>
+ <Option value="audio">音频资源</Option>
+ </Select>
+ </div>
+ </Modal>
+
+ <Modal
+ title="编辑媒体资源组"
+ open={isEditModalVisible}
+ onOk={handleEditGroup}
+ onCancel={() => {
+ setIsEditModalVisible(false);
+ setEditingGroup(null);
+ setNewGroupTitle("");
+ setNewGroupDesc("");
+ }}
>
<div className={styles.createForm}>
<Input
- placeholder="请输入素材库名称"
- value={newAlbumName}
- onChange={(e) => setNewAlbumName(e.target.value)}
+ placeholder="请输入媒体资源组标题"
+ value={newGroupTitle}
+ onChange={(e) => setNewGroupTitle(e.target.value)}
+ style={{ marginBottom: 16 }}
+ />
+ <TextArea
+ placeholder="请输入媒体资源组描述"
+ value={newGroupDesc}
+ onChange={(e) => setNewGroupDesc(e.target.value)}
+ rows={4}
style={{ marginBottom: 16 }}
/>
<Select
- value={newAlbumType}
- onChange={(value) => setNewAlbumType(value)}
+ value={newGroupType}
+ onChange={(value) => setNewGroupType(value)}
style={{ width: '100%' }}
>
- <Option value="video">视频素材</Option>
- <Option value="image">图片素材</Option>
- <Option value="audio">音频素材</Option>
+ <Option value="video">视频资源</Option>
+ <Option value="img">图片资源</Option>
+ <Option value="audio">音频资源</Option>
</Select>
</div>
</Modal>
diff --git a/src/app/[lng]/material/styles/material.module.scss b/src/app/[lng]/material/styles/material.module.scss
index 6cabc188..eb3c8235 100644
--- a/src/app/[lng]/material/styles/material.module.scss
+++ b/src/app/[lng]/material/styles/material.module.scss
@@ -1,41 +1,81 @@
.materialContainer {
padding: 24px;
- max-width: 1200px;
+ width: 100%;
+ max-width: 1440px;
margin: 0 auto;
+ box-sizing: border-box;
+}
- .header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 24px;
+.header {
+ display: flex;
+ justify-content: space-between;
+ align-items: center;
+ margin-bottom: 32px;
+
+ h2 {
+ margin: 0;
+ font-size: var(--fs-xl);
+ color: var(--text-primary);
}
+}
- :global {
- .ant-card {
- transition: all 0.3s;
-
- &:hover {
- transform: translateY(-5px);
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
- }
- }
+.createButton {
+ background-color: var(--theColor5);
+ color: white;
+ border: none;
+ padding: 8px 16px;
+ border-radius: 4px;
+ cursor: pointer;
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ transition: all 0.3s ease;
+ font-size: var(--fs-md);
+
+ &:hover {
+ background-color: var(--theColor6);
+ }
- .ant-card-cover {
- img {
- height: 200px;
- object-fit: cover;
- }
+ &:active {
+ background-color: var(--theColor7);
+ }
+}
+
+.mediaGrid {
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
+ gap: 24px;
+}
+
+.mediaCard {
+ background: white;
+ border-radius: 8px;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
+ overflow: hidden;
+ transition: transform 0.3s, box-shadow 0.3s;
+ cursor: pointer;
+ position: relative;
+
+ &:hover {
+ transform: translateY(-4px);
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
+
+ .cardActions {
+ opacity: 1;
}
}
}
.coverWrapper {
position: relative;
- width: 100%;
- height: 200px;
+ padding-top: 56.25%; // 16:9 比例
+ background: var(--grayColor1);
overflow: hidden;
img {
+ position: absolute;
+ top: 0;
+ left: 0;
width: 100%;
height: 100%;
object-fit: cover;
@@ -44,25 +84,227 @@
.videoIcon {
position: absolute;
- left: 12px;
- bottom: 12px;
- background: rgba(0, 0, 0, 0.6);
- color: white;
- padding: 8px;
+ top: 50%;
+ left: 50%;
+ transform: translate(-50%, -50%);
+ width: 48px;
+ height: 48px;
+ background: rgba(0, 0, 0, 0.5);
border-radius: 50%;
- font-size: 24px;
display: flex;
align-items: center;
justify-content: center;
+ color: white;
+ font-size: 24px;
+}
+
+.cardContent {
+ padding: 16px;
+}
+
+.cardTitle {
+ margin: 0 0 8px 0;
+ font-size: var(--fs-md);
+ color: var(--text-primary);
+ font-weight: 500;
}
.albumInfo {
+ color: var(--text-secondary);
+ font-size: var(--fs-sm);
+
+ > div:first-child {
+ margin-bottom: 8px;
+ }
+
+ > div:last-child {
+ display: flex;
+ justify-content: space-between;
+ color: var(--grayColor8);
+ }
+}
+
+.cardActions {
+ position: absolute;
+ top: 8px;
+ right: 8px;
+ display: flex;
+ gap: 8px;
+ opacity: 0;
+ transition: opacity 0.3s;
+ z-index: 1;
+
+ button {
+ background: rgba(255, 255, 255, 0.9);
+ border: none;
+ padding: 6px 12px;
+ border-radius: 4px;
+ cursor: pointer;
+ color: var(--grayColor8);
+ transition: all 0.3s;
+ font-size: var(--fs-sm);
+ backdrop-filter: blur(4px);
+
+ &:hover {
+ background: white;
+ color: var(--theColor5);
+ }
+
+ &.delete:hover {
+ color: var(--error-color);
+ }
+ }
+}
+
+.emptyContainer {
+ text-align: center;
+ padding: 48px 24px;
+ background: white;
+ border-radius: 8px;
+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
+
+ h3 {
+ margin: 0 0 16px 0;
+ color: var(--text-primary);
+ font-size: var(--fs-lg);
+ }
+
+ p {
+ color: var(--text-secondary);
+ margin-bottom: 24px;
+ font-size: var(--fs-md);
+ }
+}
+
+.modal {
+ position: fixed;
+ top: 0;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ background: rgba(0, 0, 0, 0.5);
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ z-index: 1000;
+}
+
+.modalContent {
+ background: white;
+ padding: 24px;
+ border-radius: 8px;
+ width: 100%;
+ max-width: 500px;
+ max-height: 90vh;
+ overflow: auto;
+}
+
+.modalHeader {
display: flex;
justify-content: space-between;
align-items: center;
- color: rgba(0, 0, 0, 0.45);
+ margin-bottom: 24px;
+
+ h3 {
+ margin: 0;
+ font-size: var(--fs-lg);
+ color: var(--text-primary);
+ }
+
+ button {
+ background: none;
+ border: none;
+ font-size: 24px;
+ cursor: pointer;
+ color: var(--grayColor8);
+ padding: 4px;
+ line-height: 1;
+
+ &:hover {
+ color: var(--text-primary);
+ }
+ }
+}
+
+.form {
+ display: flex;
+ flex-direction: column;
+ gap: 16px;
}
-.createForm {
- padding: 16px 0;
+.formGroup {
+ display: flex;
+ flex-direction: column;
+ gap: 8px;
+
+ label {
+ font-weight: 500;
+ color: var(--text-primary);
+ font-size: var(--fs-sm);
+ }
+
+ input, textarea, select {
+ padding: 8px 12px;
+ border: 1px solid var(--grayColor4);
+ border-radius: 4px;
+ font-size: var(--fs-md);
+ color: var(--text-primary);
+ background: white;
+
+ &:focus {
+ outline: none;
+ border-color: var(--theColor5);
+ }
+ }
+
+ textarea {
+ min-height: 100px;
+ resize: vertical;
+ }
+
+ select {
+ cursor: pointer;
+ }
+}
+
+.modalFooter {
+ display: flex;
+ justify-content: flex-end;
+ gap: 12px;
+ margin-top: 24px;
+ padding-top: 16px;
+ border-top: 1px solid var(--grayColor2);
+}
+
+.modalButton {
+ padding: 8px 16px;
+ border-radius: 4px;
+ cursor: pointer;
+ font-size: var(--fs-md);
+ transition: all 0.3s;
+
+ &.primary {
+ background: var(--theColor5);
+ color: white;
+ border: none;
+
+ &:hover {
+ background: var(--theColor6);
+ }
+
+ &:active {
+ background: var(--theColor7);
+ }
+ }
+
+ &.default {
+ background: white;
+ color: var(--text-primary);
+ border: 1px solid var(--grayColor4);
+
+ &:hover {
+ border-color: var(--theColor5);
+ color: var(--theColor5);
+ }
+ }
}
\ No newline at end of file
diff --git a/src/utils/oss.ts b/src/utils/oss.ts
new file mode 100644
index 00000000..b5c66974
--- /dev/null
+++ b/src/utils/oss.ts
@@ -0,0 +1,9 @@
+// 获取OSS域名
+const OSS_DOMAIN = 'https://ai-to-earn.oss-cn-beijing.aliyuncs.com';
+
+// 获取完整的OSS URL
+export const getOssUrl = (path: string) => {
+ if (!path) return '';
+ if (path.startsWith('http')) return path;
+ return `${OSS_DOMAIN}/${path}`;
+};
\ No newline at end of file