新增后台接口
Change-Id: Ibd8183079a77aad05b2c81658c2d6fe9b648e042
diff --git a/front/src/UserProfile.js b/front/src/UserProfile.js
index cf38e7f..f6ef9f4 100644
--- a/front/src/UserProfile.js
+++ b/front/src/UserProfile.js
@@ -17,7 +17,7 @@
avatar_url: "",
username: "示例用户",
email: "user@example.com",
- invite_left: "",
+ invitetimes: "",
school: "",
account_status: "",
gender: "",
@@ -61,12 +61,17 @@
// 获取用户信息
useEffect(() => {
const fetchUserInfo = async () => {
- const userid = "550e8400-e29b-41d4-a716-446655440000";
+ // 假设userid存储在localStorage或其他地方
+ // const userid = localStorage.getItem("userid");
+ // const userid = "550e8400-e29b-41d4-a716-446655440000"; // 示例userid
+ const match = document.cookie.match('(^|;)\\s*userId=([^;]+)');
+ const userid = match ? match[2] : null;
if (!userid) return;
try {
const res = await fetch(`${API_BASE_URL}/api/user-profile?userid=${userid}`);
if (res.ok) {
const data = await res.json();
+ console.log("获取用户信息:", data);
setUserInfo(data);
setTempUserInfo(data);
}
@@ -80,7 +85,10 @@
// 获取上传种子
useEffect(() => {
const fetchUserSeeds = async () => {
- const userid = "550e8400-e29b-41d4-a716-446655440000";
+ // const userid = localStorage.getItem("userid");
+ // const userid = "550e8400-e29b-41d4-a716-446655440000"; // 示例userid
+ const match = document.cookie.match('(^|;)\\s*userId=([^;]+)');
+ const userid = match ? match[2] : null;
if (!userid) return;
try {
const res = await fetch(`${API_BASE_URL}/api/user-seeds?userid=${userid}`);
@@ -125,13 +133,17 @@
};
const handleSave = async () => {
- if (tempUserInfo.gender === "男性") {
+ if (tempUserInfo.gender === "男"){
tempUserInfo.gender = "m";
- } else if (tempUserInfo.gender === "女性") {
+ }else if (tempUserInfo.gender === "女"){
tempUserInfo.gender = "f";
}
setUserInfo({ ...tempUserInfo });
- const userid = "550e8400-e29b-41d4-a716-446655440000";
+ // 获取userid
+ // const userid = localStorage.getItem("userid");
+ // const userid = "550e8400-e29b-41d4-a716-446655440000"; // 示例userid
+ const match = document.cookie.match('(^|;)\\s*userId=([^;]+)');
+ const userid = match ? match[2] : null;
try {
const res = await fetch(`${API_BASE_URL}/api/change-profile`, {
method: 'POST',
@@ -152,9 +164,9 @@
};
const handleAvatarClick = () => {
- const pictureUrl = prompt("请输入头像的URL:");
- if (pictureUrl) {
- setTempUserInfo({ ...tempUserInfo, avatar_url: pictureUrl });
+ const avatarUrl = prompt("请输入头像的URL:");
+ if (avatarUrl) {
+ setTempUserInfo({ ...tempUserInfo, avatar_url: avatarUrl });
}
};
@@ -484,7 +496,7 @@
}}
onClick={e => {
if (e.target.classList.contains('delete-btn')) return;
- navigate(`/torrent/${seed.seedid}`);
+ navigate(`/torrent/${seed.seed_id}`);
}}
onMouseOver={e => e.currentTarget.style.background = '#f3f6ff'}
onMouseOut={e => e.currentTarget.style.background = ''}
@@ -498,9 +510,24 @@
color="error"
size="small"
sx={{ marginLeft: 2, borderRadius: 1, minWidth: 60 }}
- onClick={e => {
+ onClick={async e => {
e.stopPropagation();
- handleDeleteSeed(seed.seedid);
+ // const userid = localStorage.getItem("userid");
+ const userid = "550e8400-e29b-41d4-a716-446655440000"; // 示例userid
+ try {
+ const res = await fetch(`${API_BASE_URL}/api/delete-seed`, {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ seed_id: seed.seed_id, userid }),
+ });
+ if (res.ok) {
+ setUserSeeds(userSeeds.filter((s, i) => (s.seed_id || i) !== (seed.seed_id || idx)));
+ } else {
+ alert('删除失败,请重试');
+ }
+ } catch (err) {
+ alert('删除失败,请检查网络');
+ }
}}
>删除</Button>
</li>