Spaces:
Sleeping
Sleeping
trae-bot commited on
Commit ·
c6c1fa4
1
Parent(s): 8268e91
Update course access button to show resource link in a modal
Browse files
frontend/src/app/user/courses/page.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import { useEffect, useState } from "react";
|
|
| 4 |
import { useRouter } from "next/navigation";
|
| 5 |
import { api } from "@/lib/api";
|
| 6 |
import { useAuthStore } from "@/lib/store";
|
| 7 |
-
import { BookOpen,
|
| 8 |
import Link from "next/link";
|
| 9 |
|
| 10 |
export default function MyCourses() {
|
|
@@ -13,6 +13,7 @@ export default function MyCourses() {
|
|
| 13 |
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 14 |
const [courses, setCourses] = useState<any[]>([]);
|
| 15 |
const [loading, setLoading] = useState(true);
|
|
|
|
| 16 |
|
| 17 |
useEffect(() => {
|
| 18 |
if (!token) {
|
|
@@ -42,11 +43,20 @@ export default function MyCourses() {
|
|
| 42 |
try {
|
| 43 |
const res = await api.get(`/api/courses/${courseId}/access`);
|
| 44 |
if (res.success && res.data.hasAccess) {
|
| 45 |
-
|
| 46 |
}
|
| 47 |
} catch (err) {
|
| 48 |
console.error(err);
|
| 49 |
-
alert('获取学习
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
}
|
| 51 |
};
|
| 52 |
|
|
@@ -87,8 +97,8 @@ export default function MyCourses() {
|
|
| 87 |
onClick={() => handleAccess(course.id)}
|
| 88 |
className="flex-1 px-4 py-2 bg-blue-600 text-white rounded-lg text-sm font-medium hover:bg-blue-700 transition-colors flex items-center justify-center"
|
| 89 |
>
|
| 90 |
-
<
|
| 91 |
-
|
| 92 |
</button>
|
| 93 |
</div>
|
| 94 |
</div>
|
|
@@ -106,6 +116,60 @@ export default function MyCourses() {
|
|
| 106 |
</Link>
|
| 107 |
</div>
|
| 108 |
)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
</div>
|
| 110 |
);
|
| 111 |
}
|
|
|
|
| 4 |
import { useRouter } from "next/navigation";
|
| 5 |
import { api } from "@/lib/api";
|
| 6 |
import { useAuthStore } from "@/lib/store";
|
| 7 |
+
import { BookOpen, Link as LinkIcon, Clock, X, Copy } from "lucide-react";
|
| 8 |
import Link from "next/link";
|
| 9 |
|
| 10 |
export default function MyCourses() {
|
|
|
|
| 13 |
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
| 14 |
const [courses, setCourses] = useState<any[]>([]);
|
| 15 |
const [loading, setLoading] = useState(true);
|
| 16 |
+
const [selectedLink, setSelectedLink] = useState<string | null>(null);
|
| 17 |
|
| 18 |
useEffect(() => {
|
| 19 |
if (!token) {
|
|
|
|
| 43 |
try {
|
| 44 |
const res = await api.get(`/api/courses/${courseId}/access`);
|
| 45 |
if (res.success && res.data.hasAccess) {
|
| 46 |
+
setSelectedLink(res.data.driveLink);
|
| 47 |
}
|
| 48 |
} catch (err) {
|
| 49 |
console.error(err);
|
| 50 |
+
alert('获取学习资料失败');
|
| 51 |
+
}
|
| 52 |
+
};
|
| 53 |
+
|
| 54 |
+
const copyToClipboard = async (text: string) => {
|
| 55 |
+
try {
|
| 56 |
+
await navigator.clipboard.writeText(text);
|
| 57 |
+
alert('资料链接已复制到剪贴板');
|
| 58 |
+
} catch (err) {
|
| 59 |
+
console.error('Failed to copy!', err);
|
| 60 |
}
|
| 61 |
};
|
| 62 |
|
|
|
|
| 97 |
onClick={() => handleAccess(course.id)}
|
| 98 |
className="flex-1 px-4 py-2 bg-blue-600 text-white rounded-lg text-sm font-medium hover:bg-blue-700 transition-colors flex items-center justify-center"
|
| 99 |
>
|
| 100 |
+
<LinkIcon className="w-4 h-4 mr-1.5" />
|
| 101 |
+
获取资料
|
| 102 |
</button>
|
| 103 |
</div>
|
| 104 |
</div>
|
|
|
|
| 116 |
</Link>
|
| 117 |
</div>
|
| 118 |
)}
|
| 119 |
+
|
| 120 |
+
{/* 资料链接弹窗 */}
|
| 121 |
+
{selectedLink && (
|
| 122 |
+
<div className="fixed inset-0 bg-black/50 z-50 flex items-center justify-center p-4">
|
| 123 |
+
<div className="bg-white rounded-2xl max-w-lg w-full p-6 shadow-xl">
|
| 124 |
+
<div className="flex justify-between items-center mb-6">
|
| 125 |
+
<h3 className="text-xl font-bold text-gray-900">课程学习资料</h3>
|
| 126 |
+
<button
|
| 127 |
+
onClick={() => setSelectedLink(null)}
|
| 128 |
+
className="text-gray-400 hover:text-gray-600 transition-colors"
|
| 129 |
+
>
|
| 130 |
+
<X className="w-6 h-6" />
|
| 131 |
+
</button>
|
| 132 |
+
</div>
|
| 133 |
+
|
| 134 |
+
<div className="bg-blue-50 border border-blue-100 rounded-xl p-4 mb-6">
|
| 135 |
+
<p className="text-sm text-blue-800 mb-2">请复制以下链接在浏览器中打开,或直接点击访问:</p>
|
| 136 |
+
<div className="flex items-center gap-2">
|
| 137 |
+
<input
|
| 138 |
+
type="text"
|
| 139 |
+
readOnly
|
| 140 |
+
value={selectedLink}
|
| 141 |
+
className="flex-1 bg-white border border-blue-200 rounded-lg px-3 py-2 text-sm text-gray-700 outline-none"
|
| 142 |
+
/>
|
| 143 |
+
<button
|
| 144 |
+
onClick={() => copyToClipboard(selectedLink)}
|
| 145 |
+
className="p-2 bg-blue-100 text-blue-700 rounded-lg hover:bg-blue-200 transition-colors"
|
| 146 |
+
title="复制链接"
|
| 147 |
+
>
|
| 148 |
+
<Copy className="w-4 h-4" />
|
| 149 |
+
</button>
|
| 150 |
+
</div>
|
| 151 |
+
</div>
|
| 152 |
+
|
| 153 |
+
<div className="flex gap-3 justify-end">
|
| 154 |
+
<button
|
| 155 |
+
onClick={() => setSelectedLink(null)}
|
| 156 |
+
className="px-5 py-2.5 border border-gray-200 text-gray-700 rounded-xl font-medium hover:bg-gray-50 transition-colors"
|
| 157 |
+
>
|
| 158 |
+
关闭
|
| 159 |
+
</button>
|
| 160 |
+
<a
|
| 161 |
+
href={selectedLink}
|
| 162 |
+
target="_blank"
|
| 163 |
+
rel="noopener noreferrer"
|
| 164 |
+
className="px-5 py-2.5 bg-blue-600 text-white rounded-xl font-medium hover:bg-blue-700 transition-colors"
|
| 165 |
+
onClick={() => setSelectedLink(null)}
|
| 166 |
+
>
|
| 167 |
+
直接访问
|
| 168 |
+
</a>
|
| 169 |
+
</div>
|
| 170 |
+
</div>
|
| 171 |
+
</div>
|
| 172 |
+
)}
|
| 173 |
</div>
|
| 174 |
);
|
| 175 |
}
|