From 5ae7e85eb7172e5798fad4dac8683ea98f124f21 Mon Sep 17 00:00:00 2001 From: feie9454 Date: Fri, 19 Sep 2025 22:59:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=84=E8=AE=BA=E4=B8=8E=E8=AF=84=E5=88=86?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/client.ts | 49 ++++++++ src/views/ModelDetail.vue | 239 ++++++++++++++++++++++++++++++++++---- 2 files changed, 265 insertions(+), 23 deletions(-) diff --git a/src/api/client.ts b/src/api/client.ts index c67bb56..c899780 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -18,6 +18,8 @@ export type ModelSummary = { authorName?: string createdAt?: string updatedAt?: string + avgRating?: number | null + ratingCount?: number } export type ModelDetail = ModelSummary & { @@ -25,6 +27,15 @@ export type ModelDetail = ModelSummary & { desc: string } +export type CommentItem = { + id: string + content: string + authorId: string + authorName?: string + createdAt: string + updatedAt?: string +} + export type ListModelsQuery = { q?: string authorId?: string @@ -135,6 +146,44 @@ export const api = { previewUrl(id: string) { return `${API_BASE}/models/${encodeURIComponent(id)}/preview` }, + + // Ratings + async setRating(id: string, value: number, basicToken?: string) { + const res = await fetch(`${API_BASE}/models/${encodeURIComponent(id)}/rating`, { + method: 'POST', + headers: { 'content-type': 'application/json', ...buildAuthHeader(basicToken) }, + body: JSON.stringify({ value }) + }) + return handle<{ id: string; value: number }>(res) + }, + async getMyRating(id: string, basicToken?: string) { + const res = await fetch(`${API_BASE}/models/${encodeURIComponent(id)}/my-rating`, { + headers: { ...buildAuthHeader(basicToken) } + }) + return handle<{ myRating: number | null }>(res) + }, + + // Comments + async listComments(id: string, page = 1, pageSize = 20) { + const usp = new URLSearchParams({ page: String(page), pageSize: String(pageSize) }) + const res = await fetch(`${API_BASE}/models/${encodeURIComponent(id)}/comments?${usp}`) + return handle<{ items: CommentItem[]; total: number; page: number; pageSize: number }>(res) + }, + async addComment(id: string, content: string, basicToken?: string) { + const res = await fetch(`${API_BASE}/models/${encodeURIComponent(id)}/comments`, { + method: 'POST', + headers: { 'content-type': 'application/json', ...buildAuthHeader(basicToken) }, + body: JSON.stringify({ content }) + }) + return handle<{ id: string }>(res) + }, + async deleteComment(id: string, commentId: string, basicToken?: string) { + const res = await fetch(`${API_BASE}/models/${encodeURIComponent(id)}/comments/${encodeURIComponent(commentId)}`, { + method: 'DELETE', + headers: { ...buildAuthHeader(basicToken) } + }) + return handle(res) + }, } export type BasicCredential = { username: string; password: string } diff --git a/src/views/ModelDetail.vue b/src/views/ModelDetail.vue index 19c5d6d..a9d9d08 100644 --- a/src/views/ModelDetail.vue +++ b/src/views/ModelDetail.vue @@ -1,10 +1,10 @@