feat: 添加多站点支持,引入site_id字段

- 在Comment表中添加site_id字段,用于区分不同站点的评论
- 更新前后端API以支持site_id参数传递
- 修改自动迁移脚本,添加site_id字段迁移逻辑
- 更新前端组件配置,支持设置siteId参数
This commit is contained in:
anghunk
2026-02-09 13:56:35 +08:00
parent 5948949400
commit 32603d281a
8 changed files with 86 additions and 27 deletions

View File

@@ -29,6 +29,9 @@ export class CWDComments {
*/
constructor(config) {
this.config = { ...config };
if (config.siteId) {
this.config.siteId = config.siteId;
}
if (typeof window !== 'undefined') {
this.config.postSlug = window.location.pathname;
}
@@ -571,6 +574,9 @@ export class CWDComments {
const prevConfig = { ...this.config };
Object.assign(this.config, newConfig);
if (newConfig.siteId !== undefined) {
this.config.siteId = newConfig.siteId;
}
if (typeof window !== 'undefined') {
this.config.postSlug = window.location.pathname;
}
@@ -589,7 +595,8 @@ export class CWDComments {
const shouldReload =
this.config.apiBaseUrl !== prevConfig.apiBaseUrl ||
this.config.pageSize !== prevConfig.pageSize ||
this.config.postSlug !== prevConfig.postSlug;
this.config.postSlug !== prevConfig.postSlug ||
this.config.siteId !== prevConfig.siteId;
if (shouldReload) {
const api = createApiClient(this.config);