* add loading when waiting result.

This commit is contained in:
dingyongliang
2024-02-19 14:35:39 +08:00
parent dfd4714e68
commit c15a358560
8 changed files with 28 additions and 12 deletions
+2 -2
View File
@@ -154,7 +154,7 @@ class ai extends control
$messages = array();
if(!empty($_POST))
{
if($miniProgram->published === '0' && $this->post->test !== '1') return $this->send(array('result' => 'fail', 'reason' => 'unpublished'));
if($miniProgram->published === '0' && $this->post->test !== '1') return $this->send(array('result' => 'fail', 'message' => $this->lang->ai->miniPrograms->unpublishedTip, 'reason' => 'unpublished'));
$history = $this->post->history;
$message = $this->post->message;
@@ -169,7 +169,7 @@ class ai extends control
if($this->ai->isModelConfigured())
{
$response = $this->ai->converse($messages);
if(empty($response)) return $this->send(array('result' => 'fail', 'message' => $this->lang->ai->chatNoResponse, 'reason' => 'no response'));
if(empty($response)) return $this->send(array('result' => 'fail', 'message' => $this->lang->ai->miniPrograms->chatNoResponse , 'reason' => 'no response'));
if(!isset($this->post->test) || $this->post->test !== '1') $this->ai->saveMiniProgramMessage($id, 'res', is_array($response) ? current($response) : $response);
return $this->send(array('result' => 'success', 'message' => array('time' => date("Y/n/j G:i"), 'role' => 'assistant', 'content' => is_array($response) ? current($response) : $response)));
+9 -5
View File
@@ -677,7 +677,9 @@ $(function ()
const message = $('.prompt-preview-area .preview-container').text();
if(!message) return;
$('#generate-result').attr('disabled', 'disabled');
const trigger = new $.zui.ModalTrigger({backdrop: 'static'});
trigger.show();
$.post(
createLink('ai', 'miniProgramChat', `id=${appID}`),
{
@@ -686,7 +688,7 @@ $(function ()
},
).done(function(response)
{
$('#generate-result').removeAttr('disabled');
trigger.close();
response = JSON.parse(response);
const {message, result} = response;
if(result === 'success')
@@ -696,9 +698,11 @@ $(function ()
return;
}
const {reason} = response;
$('.preview-container').html(reason);
$('.prompt-result-area .preview-container').html(message);
}).fail(function()
{
trigger.close();
$('.prompt-result-area .preview-container').html('Network error');
});
});
});
-1
View File
@@ -138,7 +138,6 @@ function sendMessagesToAI(message)
$('.chat').addClass('hidden');
$('.chat-nomodel').removeClass('hidden');
$('form .footer .btn.primary').attr('disabled', 'disabled');
// $('.language-model .btn').attr('disabled', 'disabled');
return;
}
if(reason === 'unpublished')
+9 -4
View File
@@ -89,7 +89,9 @@ $(function()
const message = $('.prompt-preview-area .preview-container').text();
if(!message) return;
$('#generate-result').attr('disabled', 'disabled');
const trigger = new $.zui.ModalTrigger({backdrop: 'static'});
trigger.show();
$.post(
createLink('ai', 'miniProgramChat', `id=${appID}`),
{
@@ -98,7 +100,7 @@ $(function()
},
).done(function(response)
{
$('#generate-result').removeAttr('disabled');
trigger.close();
response = JSON.parse(response);
const {message, result} = response;
if(result === 'success')
@@ -108,8 +110,11 @@ $(function()
return;
}
const {reason} = response;
$('.preview-container').html(reason);
$('.prompt-result-area .preview-container').html(message);
}).fail(function()
{
trigger.close();
$('.prompt-result-area .preview-container').html('Network error');
});
})
});
+2
View File
@@ -439,6 +439,7 @@ $lang->ai->miniPrograms->latestPublishedDate = 'Latest Published Date';
$lang->ai->miniPrograms->deleteTip = 'Are you sure you want to delete this mini program? It can be restored from the backend recycle bin after deletion.';
$lang->ai->miniPrograms->disableTip = 'Disabling the mini program will prevent users from accessing it. Are you sure you want to disable it?';
$lang->ai->miniPrograms->publishTip = 'Are you sure you want to publish? After publishing, it will be displayed on the frontend mini program square.';
$lang->ai->miniPrograms->unpublishedTip = 'The mini program you are using is not published.';
$lang->ai->miniPrograms->placeholder = new stdClass();
$lang->ai->miniPrograms->placeholder->name = 'Please enter a small program name';
@@ -503,6 +504,7 @@ $lang->ai->miniPrograms->clearContext = 'The context content has been clea
$lang->ai->miniPrograms->newChatTip = 'Please click on the Generate button on the left side to start a new conversation.';
$lang->ai->miniPrograms->newVersionTip = 'The mini-program has been updated on %s. The above is the past record.';
$lang->ai->miniPrograms->disabledTip = 'The current mini program is disabled.';
$lang->ai->miniPrograms->chatNoResponse = 'Something went wrong.';
$lang->ai->models = new stdclass();
$lang->ai->models->title = 'Language Model Configuration';
+2
View File
@@ -439,6 +439,7 @@ $lang->ai->miniPrograms->latestPublishedDate = 'Latest Published Date';
$lang->ai->miniPrograms->deleteTip = 'Are you sure you want to delete this mini program? It can be restored from the backend recycle bin after deletion.';
$lang->ai->miniPrograms->disableTip = 'Disabling the mini program will prevent users from accessing it. Are you sure you want to disable it?';
$lang->ai->miniPrograms->publishTip = 'Are you sure you want to publish? After publishing, it will be displayed on the frontend mini program square.';
$lang->ai->miniPrograms->unpublishedTip = 'The mini program you are using is not published.';
$lang->ai->miniPrograms->placeholder = new stdClass();
$lang->ai->miniPrograms->placeholder->name = 'Please enter a small program name';
@@ -503,6 +504,7 @@ $lang->ai->miniPrograms->clearContext = 'The context content has been clea
$lang->ai->miniPrograms->newChatTip = 'Please click on the Generate button on the left side to start a new conversation.';
$lang->ai->miniPrograms->newVersionTip = 'The mini-program has been updated on %s. The above is the past record.';
$lang->ai->miniPrograms->disabledTip = 'The current mini program is disabled.';
$lang->ai->miniPrograms->chatNoResponse = 'Something went wrong.';
$lang->ai->models = new stdclass();
$lang->ai->models->title = 'Language Model Configuration';
+2
View File
@@ -439,6 +439,7 @@ $lang->ai->miniPrograms->latestPublishedDate = 'Latest Published Date';
$lang->ai->miniPrograms->deleteTip = 'Are you sure you want to delete this mini program? It can be restored from the backend recycle bin after deletion.';
$lang->ai->miniPrograms->disableTip = 'Disabling the mini program will prevent users from accessing it. Are you sure you want to disable it?';
$lang->ai->miniPrograms->publishTip = 'Are you sure you want to publish? After publishing, it will be displayed on the frontend mini program square.';
$lang->ai->miniPrograms->unpublishedTip = 'The mini program you are using is not published.';
$lang->ai->miniPrograms->placeholder = new stdClass();
$lang->ai->miniPrograms->placeholder->name = 'Please enter a small program name';
@@ -504,6 +505,7 @@ $lang->ai->miniPrograms->clearContext = 'The context content has been clea
$lang->ai->miniPrograms->newChatTip = 'Please click on the Generate button on the left side to start a new conversation.';
$lang->ai->miniPrograms->newVersionTip = 'The mini-program has been updated on %s. The above is the past record.';
$lang->ai->miniPrograms->disabledTip = 'The current mini program is disabled.';
$lang->ai->miniPrograms->chatNoResponse = 'Something went wrong.';
$lang->ai->models = new stdclass();
$lang->ai->models->title = 'Language Model Configuration';
+2
View File
@@ -439,6 +439,7 @@ $lang->ai->miniPrograms->latestPublishedDate = '最新发布时间';
$lang->ai->miniPrograms->deleteTip = '确定删除该小程序吗?删除后可以到后台回收站恢复';
$lang->ai->miniPrograms->disableTip = '禁用小程序用户将无法使用,是否确认禁用?';
$lang->ai->miniPrograms->publishTip = '您确定要发布吗?发布后将在客户端前台小程序广场显示';
$lang->ai->miniPrograms->unpublishedTip = '您使用的小程序没有发布';
$lang->ai->miniPrograms->placeholder = new stdClass();
$lang->ai->miniPrograms->placeholder->name = '请输入小程序名称';
@@ -504,6 +505,7 @@ $lang->ai->miniPrograms->clearContext = '上下文内容已清除';
$lang->ai->miniPrograms->newChatTip = '请点击左侧生成按钮,开启新对话';
$lang->ai->miniPrograms->newVersionTip = '小程序已于 %s 更新,以上为过往记录';
$lang->ai->miniPrograms->disabledTip = '当前小程序已被禁用。';
$lang->ai->miniPrograms->chatNoResponse = '会话发生了错误';
$lang->ai->models = new stdclass();
$lang->ai->models->title = '语言模型配置';