diff --git a/src/App.vue b/src/App.vue index d82e9cd..401e078 100644 --- a/src/App.vue +++ b/src/App.vue @@ -5,15 +5,13 @@ import { useProjects } from "./composables/useProjects" const { projects, fetchProjects } = useProjects() -const getApiBase = () => { +function getApiBase() { if (window.location.hostname !== "localhost") { - return "/api" + return `${window.location.protocol}//${window.location.host}/api` } return "http://localhost:3000/api" } -const API_BASE = getApiBase() - onMounted(() => { fetchProjects() }) @@ -23,7 +21,7 @@ onMounted(() => {
diff --git a/src/components/ProjectManager.vue b/src/components/ProjectManager.vue index 45de134..f641c3b 100644 --- a/src/components/ProjectManager.vue +++ b/src/components/ProjectManager.vue @@ -24,11 +24,27 @@ const fileInput = ref() const handleFileSelect = () => { const file = fileInput.value?.files?.[0] - if (file && file.name.endsWith(".html")) { - uploadProject(file) - } else { + if (!file) return + + // 文件类型验证 + if (!file.name.endsWith(".html")) { showMessage("请选择HTML文件", "error") + return } + + // 文件大小验证 (5MB) + const maxSize = 5 * 1024 * 1024 + if (file.size > maxSize) { + showMessage("文件大小不能超过5MB", "error") + return + } + + if (file.size === 0) { + showMessage("文件不能为空", "error") + return + } + + uploadProject(file) } const uploadProject = async (file: File) => { @@ -36,6 +52,11 @@ const uploadProject = async (file: File) => { showMessage("请输入项目名称", "error") return } + + if (projectName.value.length > 50) { + showMessage("项目名称不能超过50个字符", "error") + return + } isUploading.value = true @@ -129,7 +150,10 @@ const deleteProject = async (projectSlug: string, projectName: string) => { id="projectName" placeholder="请输入项目名称" class="form-input" + maxlength="50" + :disabled="isUploading" /> + 最多50个字符
@@ -139,6 +163,7 @@ const deleteProject = async (projectSlug: string, projectName: string) => { accept=".html" @change="handleFileSelect" style="display: none" + :disabled="isUploading" />