Files
cwd/docs/.vitepress/components/footerDoc.vue
anghunk 32603d281a feat: 添加多站点支持,引入site_id字段
- 在Comment表中添加site_id字段,用于区分不同站点的评论
- 更新前后端API以支持site_id参数传递
- 修改自动迁移脚本,添加site_id字段迁移逻辑
- 更新前端组件配置,支持设置siteId参数
2026-02-09 13:56:35 +08:00

58 lines
1.3 KiB
Vue

<template>
<div id="comments" ref="commentsRoot"></div>
</template>
<script setup>
import { onMounted, ref, watch } from "vue";
import { useData } from "vitepress";
const commentsRoot = ref(null);
const commentsInstance = ref(null);
const { isDark } = 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 }
);
});
</script>