Skip to content

Commit 592d032

Browse files
committed
refactor(web): 视图静态化,移除 Thymeleaf 依赖
- chat.html 移至 static/index.html,去掉 xmlns:th 与所有 th:text 占位 - 前端启动时 fetch /chat/meta 回填 title / 欢迎语 / 版本号 - WebController.chat() 替换为 GET /chat/meta(JSON)+ GET / 302 重定向到 /index.html - 移除 solon-view-thymeleaf 依赖
1 parent 4b359cb commit 592d032

3 files changed

Lines changed: 35 additions & 24 deletions

File tree

soloncode-cli/pom.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@
4343
<artifactId>solon-server-smarthttp</artifactId>
4444
</dependency>
4545

46-
<dependency>
47-
<groupId>org.noear</groupId>
48-
<artifactId>solon-view-thymeleaf</artifactId>
49-
</dependency>
50-
5146
<dependency>
5247
<groupId>org.noear</groupId>
5348
<artifactId>solon-web-staticfiles</artifactId>
@@ -132,4 +127,4 @@
132127
</plugin>
133128
</plugins>
134129
</build>
135-
</project>
130+
</project>

soloncode-cli/src/main/java/org/noear/solon/codecli/portal/WebController.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
import org.noear.solon.codecli.provider.ModelProviderFactory;
4444
import org.noear.solon.codecli.command.builtin.LoopScheduler;
4545
import org.noear.solon.core.handle.Context;
46-
import org.noear.solon.core.handle.ModelAndView;
4746
import org.noear.solon.core.handle.Result;
4847
import org.noear.solon.core.handle.UploadedFile;
4948
import org.noear.solon.core.util.Assert;
@@ -186,21 +185,26 @@ public SseEmitter chatEvents(String sessionId) throws Throwable {
186185
}
187186

188187
/**
189-
* 对话主界面
190-
*
191-
* @return
192-
* @author oisin
193-
* @date 2026年3月14日
188+
* 入口:重定向到静态首页 index.html。
194189
*/
195190
@Get
196191
@Mapping("/")
197-
public ModelAndView chat() {
198-
ModelAndView mv = new ModelAndView("chat.html");
199-
mv.put("appTitle", Solon.cfg().appTitle());
200-
mv.put("appVersion", AgentFlags.getVersion());
201-
mv.put("workspace", engine.getProps().getWorkspace());
202-
mv.put("workname", getLastSegment(engine.getProps().getWorkspace()));
203-
return mv;
192+
public void index(Context ctx) throws Throwable {
193+
ctx.redirect("/index.html");
194+
}
195+
196+
/**
197+
* 页面元信息:由静态首页(/index.html)启动时 fetch 一次,用于回填标题与侧栏。
198+
*/
199+
@Get
200+
@Mapping("/chat/meta")
201+
public Result<Map> meta() {
202+
Map<String, Object> data = new LinkedHashMap<>();
203+
data.put("appTitle", Solon.cfg().appTitle());
204+
data.put("appVersion", AgentFlags.getVersion());
205+
data.put("workspace", engine.getProps().getWorkspace());
206+
data.put("workname", getLastSegment(engine.getProps().getWorkspace()));
207+
return Result.succeed(data);
204208
}
205209

206210
private static String getLastSegment(String pathStr) {

soloncode-cli/src/main/resources/templates/chat.html renamed to soloncode-cli/src/main/resources/static/index.html

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<!DOCTYPE html>
2-
<html xmlns:th="http://www.thymeleaf.org" lang="zh-CN">
2+
<html lang="zh-CN">
33
<head>
44
<meta charset="UTF-8"/>
55
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
6-
<title th:text="${workname} + ' - ' + ${workspace}">Solon Code Web</title>
6+
<title>Solon Code Web</title>
77
<link rel="stylesheet" href="/layui/css/layui.css"/>
88
<link rel="stylesheet" href="/css/theme.css"/>
99
<style>
@@ -338,7 +338,7 @@
338338
<div class="sidebar-list" id="historyList"></div>
339339
<div class="sidebar-footer">
340340
<i class="layui-icon layui-icon-about" style="font-size:15px;color:var(--text-secondary)"></i>
341-
<span style="font-size:12px;color:var(--text-secondary)" th:text="${appVersion}">AI</span>
341+
<span id="appVersionLabel" style="font-size:12px;color:var(--text-secondary)">AI</span>
342342
</div>
343343
</div>
344344
<button class="sidebar-toggle-btn" id="sidebarToggleBtn" title="收起侧边栏"></button>
@@ -357,7 +357,7 @@
357357
<div class="blob blob-outer"></div>
358358
<div class="blob-core"></div>
359359
</div>
360-
<div class="welcome-title" th:text="'你好,我是 ' + ${appTitle} + ' Web !'">你好,我是 SolonCode Web !</div>
360+
<div class="welcome-title" id="welcomeTitle">你好,我是 SolonCode Web !</div>
361361
<div class="welcome-sub">有什么我可以帮你的吗?</div>
362362
<div class="welcome-input-box">
363363
<div class="attachments-wrap" id="welcomeAttachmentsWrap"></div>
@@ -454,8 +454,20 @@
454454
<script src="/layui/layui.js"></script>
455455
<script src="/js/marked.min.js"></script>
456456

457-
<script th:inline="javascript">
457+
<script>
458458
var SSE_ENDPOINT = "/chat/input";
459+
// 启动时拉取页面元信息(appTitle / appVersion / workspace / workname),回填标题/侧栏
460+
fetch('/chat/meta').then(function (r) { return r.json(); }).then(function (res) {
461+
var meta = (res && res.data) ? res.data : res;
462+
if (!meta) return;
463+
if (meta.workname || meta.workspace) {
464+
document.title = (meta.workname || '') + ' - ' + (meta.workspace || '');
465+
}
466+
var verEl = document.getElementById('appVersionLabel');
467+
if (verEl && meta.appVersion) verEl.textContent = meta.appVersion;
468+
var titleEl = document.getElementById('welcomeTitle');
469+
if (titleEl && meta.appTitle) titleEl.textContent = '你好,我是 ' + meta.appTitle + ' Web !';
470+
}).catch(function () { /* ignore */ });
459471
</script>
460472

461473
<script>

0 commit comments

Comments
 (0)