Files
cwd/docs/.vitepress/components/footerDoc.vue
anghunk ac87af705f fix(api): 移除评论导出接口的站点筛选功能
移除评论导出接口的站点筛选功能,现在导出所有站点的评论数据。同时更新相关文档,移除站点隔离相关的API说明,并修复文档组件的内存泄漏问题。导入接口现在支持自动识别和转换第三方评论系统数据格式,并修复站点ID字段的导入问题。

- 移除 `/admin/comments/export` 接口的 `siteId` 查询参数
- 更新数据导入文档,说明第三方评论系统自动转换功能
- 修复文档组件页面切换时的配置更新和内存泄漏
- 修复评论和统计数据的导入逻辑,确保站点ID字段正确保存
- 更新数据库表结构,为统计相关表添加站点ID字段和联合唯一约束
2026-02-09 16:52:48 +08:00

74 lines
1.6 KiB
Vue

<template>
<div id="comments" ref="commentsRoot"></div>
</template>
<script setup>
import { onMounted, onBeforeUnmount, ref, watch } from "vue";
import { useData } from "vitepress";
const commentsRoot = ref(null);
const commentsInstance = ref(null);
const { isDark, page } = useData();
const getTheme = () => (isDark.value ? "dark" : "light");
onMounted(async () => {
if (!commentsRoot.value || typeof window === "undefined") return;
const apiBaseUrl = "https://cwd-api.zishu.me";
if (!apiBaseUrl) return;
if (!window.CWDComments) {
await new Promise((resolve, reject) => {
const script = document.createElement("script");
script.src = "https://cwd.js.org/cwd.js";
script.async = true;
script.onload = () => resolve();
script.onerror = (e) => reject(e);
document.head.appendChild(script);
}).catch(() => {});
}
if (!window.CWDComments) return;
const comments = new window.CWDComments({
el: commentsRoot.value,
apiBaseUrl,
siteId: 'cwd-doc',
theme: getTheme(),
});
commentsInstance.value = comments;
comments.mount();
watch(
isDark,
(value) => {
if (!commentsInstance.value) return;
commentsInstance.value.updateConfig({
theme: value ? "dark" : "light",
});
},
{ immediate: false }
);
watch(
() => page.value.relativePath,
() => {
if (!commentsInstance.value) return;
commentsInstance.value.updateConfig({});
},
{ immediate: false }
);
});
onBeforeUnmount(() => {
if (commentsInstance.value) {
commentsInstance.value.unmount();
commentsInstance.value = null;
}
});
</script>