diff --git a/cwd-comments-admin/index.html b/cwd-comments-admin/index.html index 092c0b2..07829fa 100644 --- a/cwd-comments-admin/index.html +++ b/cwd-comments-admin/index.html @@ -1,13 +1,15 @@ - - - - CWD 评论系统后台 - - -
- - - + + + + CWD 评论系统后台 + + + +
+ + + + \ No newline at end of file diff --git a/cwd-comments-admin/src/api/admin.ts b/cwd-comments-admin/src/api/admin.ts index fa85f49..06bc777 100644 --- a/cwd-comments-admin/src/api/admin.ts +++ b/cwd-comments-admin/src/api/admin.ts @@ -11,6 +11,7 @@ export type CommentItem = { pubDate: string; author: string; email: string; + avatar: string; postSlug: string; url: string | null; ipAddress: string | null; @@ -32,6 +33,12 @@ export type AdminEmailResponse = { email: string | null; }; +export type CommentSettingsResponse = { + adminEmail: string | null; + adminBadge: string | null; + avatarPrefix: string | null; +}; + export async function loginAdmin(name: string, password: string): Promise { const res = await post('/admin/login', { name, password }); const key = res.data.key; @@ -63,3 +70,14 @@ export function saveAdminEmail(email: string): Promise<{ message: string }> { return put<{ message: string }>('/admin/settings/email', { email }); } +export function fetchCommentSettings(): Promise { + return get('/admin/settings/comments'); +} + +export function saveCommentSettings(data: { + adminEmail?: string; + adminBadge?: string; + avatarPrefix?: string; +}): Promise<{ message: string }> { + return put<{ message: string }>('/admin/settings/comments', data); +} diff --git a/cwd-comments-admin/src/views/CommentsView.vue b/cwd-comments-admin/src/views/CommentsView.vue index a9e404c..3e809e0 100644 --- a/cwd-comments-admin/src/views/CommentsView.vue +++ b/cwd-comments-admin/src/views/CommentsView.vue @@ -27,9 +27,19 @@
-
{{ item.author }}
-
{{ item.email }}
- {{ formatDate(item.pubDate) }} +
+ +
+
{{ item.author }}
+
{{ item.email }}
+ {{ formatDate(item.pubDate) }} +
+
{{ item.contentText }}
@@ -291,8 +301,6 @@ onMounted(() => { .table-cell-author { width: 180px; - flex-direction: column; - align-items: flex-start !important; flex-shrink: 0; } @@ -369,6 +377,24 @@ onMounted(() => { color: #57606a; } +.cell-author-wrapper { + display: flex; + align-items: flex-start; + gap: 8px; +} + +.cell-author-main { + display: flex; + flex-direction: column; +} + +.cell-avatar { + width: 32px; + height: 32px; + border-radius: 50%; + flex-shrink: 0; +} + .cell-status { padding: 3px 8px; border-radius: 999px; diff --git a/cwd-comments-admin/src/views/SettingsView.vue b/cwd-comments-admin/src/views/SettingsView.vue index d2ad0cb..d214695 100644 --- a/cwd-comments-admin/src/views/SettingsView.vue +++ b/cwd-comments-admin/src/views/SettingsView.vue @@ -19,8 +19,30 @@ {{ message }}
- +
+
+ +
+

评论显示配置

+
+ + +
+
+ + +
+
+ + +
+
+
@@ -31,10 +53,19 @@ - + + \ No newline at end of file diff --git a/widget/src/dev.js b/widget/src/dev.js index e3b32c9..bc7f76c 100644 --- a/widget/src/dev.js +++ b/widget/src/dev.js @@ -9,10 +9,10 @@ const STORAGE_KEY = 'cwd-dev-config'; // 默认配置 const DEFAULT_CONFIG = { + el: '#comments', apiBaseUrl: 'http://localhost:8788', - postSlug: "https://zishu.me/message", + postSlug: window.location.pathname, theme: 'light', - avatarPrefix: 'https://gravatar.com/avatar', }; let widgetInstance = null; @@ -69,10 +69,28 @@ function getConfigFromInputs() { return { apiBaseUrl, postSlug, theme, avatarPrefix }; } +async function loadServerCommentConfig(apiBaseUrl) { + try { + const res = await fetch(`${apiBaseUrl}/api/config/comments`); + if (!res.ok) { + return {}; + } + const data = await res.json(); + return { + adminEmail: data.adminEmail || '', + adminBadge: data.adminBadge || '', + avatarPrefix: data.avatarPrefix || '', + }; + } catch (e) { + console.warn('[CWDComments] 加载服务端评论配置失败:', e); + return {}; + } +} + /** * 初始化 widget */ -function initWidget() { +async function initWidget() { const config = getConfigFromInputs(); // 保存到本地存储 @@ -92,15 +110,17 @@ function initWidget() { // 创建新实例 try { + const serverConfig = await loadServerCommentConfig(config.apiBaseUrl); + widgetInstance = new CWDComments({ el: '#comments', apiBaseUrl: config.apiBaseUrl, postSlug: config.postSlug, theme: config.theme, - avatarPrefix: config.avatarPrefix, + avatarPrefix: serverConfig.avatarPrefix || config.avatarPrefix, pageSize: 20, - adminEmail: 'anghunk@gmail.com', // 博主邮箱,留空不进行匹配 - adminBadge: '博主', // 自定义标识,默认为"博主" + ...(serverConfig.adminEmail ? { adminEmail: serverConfig.adminEmail } : {}), + ...(serverConfig.adminBadge ? { adminBadge: serverConfig.adminBadge } : {}), }); widgetInstance.mount(); console.log('[CWDComments] Widget 初始化成功', config);