refactor(widget): 简化前端配置并重构核心逻辑

移除前端配置中的 postSlug 和 avatarPrefix 参数,改为从后端接口获取
重构 CWDComments 核心类,自动推导 postSlug 等参数并异步加载服务端配置
更新文档和示例页面以反映配置变更
This commit is contained in:
anghunk
2026-01-20 10:39:48 +08:00
parent 1c0c4b5657
commit 0485b1320c
11 changed files with 149 additions and 86 deletions

View File

@@ -129,10 +129,6 @@
<label>API 地址</label>
<input type="text" id="apiBaseUrl" value="http://localhost:8788" />
</div>
<div class="config-item">
<label>文章标识符</label>
<input type="text" id="postSlug" value="demo-post" />
</div>
<div class="config-item">
<label>主题</label>
<select id="theme">
@@ -140,10 +136,6 @@
<option value="dark">深色</option>
</select>
</div>
<div class="config-item">
<label>头像源前缀</label>
<input type="text" id="avatarPrefix" value="https://gravatar.com/avatar" />
</div>
<div class="config-actions">
<button class="btn btn-primary" onclick="initWidget()">保存</button>
<button class="btn btn-secondary" onclick="toggleTheme()">切换主题</button>
@@ -155,7 +147,7 @@
<div class="demo-post">
<h2>这是一篇示例文章</h2>
<p>
这是一个演示 CWD Comments Widget 的示例页面。你可以在上方的配置面板中修改 API 地址和文章标识符
这是一个演示 CWD Comments Widget 的示例页面。你可以在上方的配置面板中修改 API 地址和主题
然后点击"应用配置"按钮重新加载评论组件。
</p>
</div>
@@ -169,4 +161,4 @@
<script type="module" src="/src/dev.js"></script>
</body>
</html>
</html>