4.29技术中心合并前更改

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
qwq
2026-04-29 18:53:24 +08:00
co-authored by Copilot
parent 7687b4e7b8
commit ec35590493
25 changed files with 792 additions and 329 deletions
@@ -61,6 +61,8 @@
import { ref, onMounted } from 'vue';
import axios from 'axios';
const API = import.meta.env.VITE_API_BASE_URL;
const isLoggedIn = ref(false);
const username = ref('');
const password = ref('');
@@ -82,7 +84,7 @@ onMounted(() => {
const handleLogin = async () => {
try {
const res = await axios.post('http://localhost:3000/api/admin/login', {
const res = await axios.post(`${API}/api/admin/login`, {
username: username.value,
password: password.value
});
@@ -102,7 +104,7 @@ const logout = () => {
const fetchDocs = async () => {
try {
const res = await axios.get('http://localhost:3000/api/documents');
const res = await axios.get(`${API}/api/documents`);
documents.value = res.data;
} catch (e) {
console.error("Failed to load documents");
@@ -122,7 +124,7 @@ const handleUpload = async () => {
try {
const token = localStorage.getItem('admin_token');
await axios.post('http://localhost:3000/api/admin/upload', formData, {
await axios.post(`${API}/api/admin/upload`, formData, {
headers: {
'Content-Type': 'multipart/form-data',
'Authorization': `Bearer ${token}`
@@ -145,7 +147,7 @@ const deleteDoc = async (id) => {
if(!confirm("确定要执行此操作吗?")) return;
try {
const token = localStorage.getItem('admin_token');
await axios.delete(`http://localhost:3000/api/admin/documents/${id}`, {
await axios.delete(`${API}/api/admin/documents/${id}`, {
headers: { 'Authorization': `Bearer ${token}` }
});
fetchDocs();
+2 -1
View File
@@ -31,10 +31,11 @@ import axios from 'axios';
const documents = ref([]);
const loading = ref(true);
const router = useRouter();
const API = import.meta.env.VITE_API_BASE_URL;
onMounted(async () => {
try {
const res = await axios.get('http://localhost:3000/api/documents');
const res = await axios.get(`${API}/api/documents`);
documents.value = res.data;
} catch (error) {
console.error("Error fetching docs", error);
@@ -27,12 +27,18 @@ const router = useRouter();
const document = ref(null);
const loading = ref(true);
const error = ref('');
const API = import.meta.env.VITE_API_BASE_URL;
onMounted(async () => {
try {
const id = route.params.id;
const res = await axios.get(`http://localhost:3000/api/documents/${id}`);
document.value = res.data;
const res = await axios.get(`${API}/api/documents/${id}`);
// 将相对路径拼接为完整 URL,解决开发模式下跨端口访问问题
const data = res.data;
if (data.url && data.url.startsWith('/')) {
data.url = `${API}${data.url}`;
}
document.value = data;
} catch (err) {
error.value = "文档未找到或无法访问。";
} finally {