From 3bc3fb7d025dd8f94b8b26a155f225cf2768040b Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Wed, 22 Oct 2025 17:26:10 +0800 Subject: [PATCH] refactor --- src/App.vue | 33 +- src/components/ProjectCard.vue | 323 +++++++++++++++++ src/components/ProjectList.vue | 233 ++++++++++++ src/components/ProjectManager.vue | 584 ------------------------------ src/components/ProjectUpload.vue | 247 +++++++++++++ src/composables/useMessage.ts | 7 +- src/composables/useProjects.ts | 34 +- src/services/api.ts | 5 +- src/style.css | 78 +--- src/types/index.ts | 7 - 10 files changed, 864 insertions(+), 687 deletions(-) create mode 100644 src/components/ProjectCard.vue create mode 100644 src/components/ProjectList.vue delete mode 100644 src/components/ProjectManager.vue create mode 100644 src/components/ProjectUpload.vue diff --git a/src/App.vue b/src/App.vue index 401e078..bae46ab 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,9 +1,10 @@ + + + + diff --git a/src/components/ProjectList.vue b/src/components/ProjectList.vue new file mode 100644 index 0000000..fb278cd --- /dev/null +++ b/src/components/ProjectList.vue @@ -0,0 +1,233 @@ + + + + + diff --git a/src/components/ProjectManager.vue b/src/components/ProjectManager.vue deleted file mode 100644 index f641c3b..0000000 --- a/src/components/ProjectManager.vue +++ /dev/null @@ -1,584 +0,0 @@ - - - - - diff --git a/src/components/ProjectUpload.vue b/src/components/ProjectUpload.vue new file mode 100644 index 0000000..957ee8f --- /dev/null +++ b/src/components/ProjectUpload.vue @@ -0,0 +1,247 @@ + + + + + diff --git a/src/composables/useMessage.ts b/src/composables/useMessage.ts index 67eccc2..0b17d6d 100644 --- a/src/composables/useMessage.ts +++ b/src/composables/useMessage.ts @@ -15,14 +15,9 @@ export function useMessage() { } } - const clearMessage = () => { - message.value = '' - } - return { message, messageType, - showMessage, - clearMessage + showMessage } } diff --git a/src/composables/useProjects.ts b/src/composables/useProjects.ts index 66c1bf9..3e4045a 100644 --- a/src/composables/useProjects.ts +++ b/src/composables/useProjects.ts @@ -1,35 +1,49 @@ -import { ref } from 'vue' -import { api } from '../services/api' -import type { Project } from '../types' +import { ref } from "vue" +import { api } from "../services/api" +import type { Project } from "../types" export function useProjects() { const projects = ref([]) const loading = ref(false) const error = ref(null) + const searchQuery = ref("") - const fetchProjects = async () => { + const fetchProjects = async (search?: string) => { loading.value = true error.value = null - + try { - projects.value = await api.getProjects() + projects.value = await api.getProjects(search) } catch (err) { - error.value = err instanceof Error ? err.message : '获取项目列表失败' - console.error('获取项目列表失败:', err) + error.value = err instanceof Error ? err.message : "获取项目列表失败" + console.error("获取项目列表失败:", err) } finally { loading.value = false } } + const searchProjects = async (query: string) => { + searchQuery.value = query + await fetchProjects(query) + } + + const clearSearch = async () => { + searchQuery.value = "" + await fetchProjects() + } + const refreshProjects = () => { - return fetchProjects() + return fetchProjects(searchQuery.value) } return { projects, loading, error, + searchQuery, fetchProjects, - refreshProjects + searchProjects, + clearSearch, + refreshProjects, } } diff --git a/src/services/api.ts b/src/services/api.ts index 59a5009..022987f 100644 --- a/src/services/api.ts +++ b/src/services/api.ts @@ -31,7 +31,10 @@ async function request(url: string, options: RequestInit = {}): Promise { // API方法 export const api = { // 获取项目列表 - getProjects: (): Promise => request("/projects"), + getProjects: (searchQuery?: string): Promise => { + const url = searchQuery ? `/projects?search=${encodeURIComponent(searchQuery)}` : "/projects" + return request(url) + }, // 上传项目 uploadProject: (formData: FormData): Promise => { diff --git a/src/style.css b/src/style.css index f691315..dd0fa7a 100644 --- a/src/style.css +++ b/src/style.css @@ -1,79 +1,15 @@ -:root { - font-family: system-ui, Avenir, Helvetica, Arial, sans-serif; - line-height: 1.5; - font-weight: 400; - - color-scheme: light dark; - color: rgba(255, 255, 255, 0.87); - background-color: #242424; - - font-synthesis: none; - text-rendering: optimizeLegibility; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; -} - -a { - font-weight: 500; - color: #646cff; - text-decoration: inherit; -} -a:hover { - color: #535bf2; +/* 全局样式重置 */ +* { + box-sizing: border-box; } body { margin: 0; - display: flex; - place-items: center; - min-width: 320px; - min-height: 100vh; -} - -h1 { - font-size: 3.2em; - line-height: 1.1; -} - -button { - border-radius: 8px; - border: 1px solid transparent; - padding: 0.6em 1.2em; - font-size: 1em; - font-weight: 500; - font-family: inherit; - background-color: #1a1a1a; - cursor: pointer; - transition: border-color 0.25s; -} -button:hover { - border-color: #646cff; -} -button:focus, -button:focus-visible { - outline: 4px auto -webkit-focus-ring-color; -} - -.card { - padding: 2em; + font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; + background-color: #f5f5f5; + color: #333; } #app { - max-width: 1280px; - margin: 0 auto; - padding: 2rem; - text-align: center; -} - -@media (prefers-color-scheme: light) { - :root { - color: #213547; - background-color: #ffffff; - } - a:hover { - color: #747bff; - } - button { - background-color: #f9f9f9; - } + min-height: 100vh; } diff --git a/src/types/index.ts b/src/types/index.ts index 7688509..c33e82e 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -8,13 +8,6 @@ export interface Project { uploadedAt: string } -// API响应类型 -export interface ApiResponse { - data?: T - error?: string - message?: string -} - // 上传响应类型 export interface UploadResponse { id: number