refactor(easy-admin): improve AI optimization feature and enhance user experience

- Remove line-height style from AI optimization content div
- Add smooth scrolling to the end of the content when streaming output Move input validation to the beginning of the aiOptimization function
This commit is contained in:
wolfcode
2025-03-10 11:54:41 +08:00
parent 51f2cbc0f4
commit a7a3ddef8b
2 changed files with 5 additions and 3 deletions

View File

@@ -79,6 +79,9 @@ class Goods extends AdminController
#[NodeAnnotation(title: 'AI优化', auth: true)]
public function aiOptimization(Request $request): void
{
$message = $request->post('message');
if (empty($message)) $this->error('请输入内容');
// 演示环境下 默认返回的内容
if ($this->isDemo) {
$content = <<<EOF
@@ -104,8 +107,6 @@ EOF;
$this->success('success', compact('choices'));
}
$message = $request->post('message');
if (empty($message)) $this->error('请输入内容');
try {
$result = AiChatService::instance()
// 当使用推理模型时,可能存在超时的情况,所以需要设置超时时间为 0

View File

@@ -1773,7 +1773,7 @@ define(["jquery", "tableSelect", "miniTheme", "xmSelect"], function ($, tableSel
scrollbar: options?.scrollbar || false,
maxmin: options?.maxmin || true,
anim: options?.anim || 0,
content: `<div style="padding: 20px;line-height: 1rem;white-space: pre-wrap;" id="${id}"></div>`,
content: `<div style="padding: 20px;white-space: pre-wrap;" id="${id}"></div>`,
success: function (layero, index) {
let elem = document.getElementById(id)
if (options?.stream) {
@@ -1808,6 +1808,7 @@ define(["jquery", "tableSelect", "miniTheme", "xmSelect"], function ($, tableSel
aiStreamCurrentIndex = endIndex;
aiStreamTimeout = setTimeout(() => {
admin.ai.streamOutput(dom, htmlContent);
dom.scrollIntoView({behavior: "smooth", block: "end"});
}, 60);
}
}