|
@@ -233,6 +233,7 @@
|
|
|
type="checkbox"
|
|
|
id="webSearchToggle"
|
|
|
v-model="enableWebSearch"
|
|
|
+ @change="handleWebSearchToggle"
|
|
|
:disabled="attachedFiles.length > 0"
|
|
|
class="toggle-input"
|
|
|
/>
|
|
@@ -256,7 +257,7 @@
|
|
|
type="checkbox"
|
|
|
id="knowledgeSearchToggle"
|
|
|
v-model="enableKnowledgeSearch"
|
|
|
- @change="handleKnowledgeToggle(enableKnowledgeSearch)"
|
|
|
+ @change="handleKnowledgeToggle"
|
|
|
class="toggle-input"
|
|
|
/>
|
|
|
<label
|
|
@@ -507,15 +508,14 @@
|
|
|
id="searchToggle"
|
|
|
v-model="enableWebSearch"
|
|
|
class="toggle-input"
|
|
|
- @change="handleSearchToggle"
|
|
|
/>
|
|
|
<label for="searchToggle" class="toggle-label">
|
|
|
{{ enableWebSearch ? '搜索已开启' : '搜索已关闭' }}
|
|
|
</label>
|
|
|
</div>
|
|
|
</div>
|
|
|
+ <!-- v-if="enableWebSearch" -->
|
|
|
<SearchResults
|
|
|
- v-if="enableWebSearch"
|
|
|
:searchResults="searchResults"
|
|
|
:loading="isSearchLoading"
|
|
|
:total="searchTotal"
|
|
@@ -541,8 +541,8 @@
|
|
|
<div class="search-header">
|
|
|
<span>知识库搜索结果</span>
|
|
|
</div>
|
|
|
+ <!-- v-if="enableKnowledgeSearch" -->
|
|
|
<KnowledgeResults
|
|
|
- v-if="enableKnowledgeSearch"
|
|
|
:searchResults="knowledgeResults"
|
|
|
:loading="isKnowledgeLoading"
|
|
|
:total="knowledgeTotal"
|
|
@@ -665,7 +665,7 @@ const isMenuCollapsed = ref(false);
|
|
|
// 添加移动端检测
|
|
|
const isMobile = ref(false);
|
|
|
|
|
|
-// Add these with other reactive variables near the top of the script setup section
|
|
|
+//知识库搜索
|
|
|
const enableKnowledgeSearch = ref(false);
|
|
|
const knowledgeResults = ref([]);
|
|
|
const knowledgeTotal = ref(0);
|
|
@@ -938,10 +938,11 @@ const handleFileUpload = async (event) => {
|
|
|
isUploading.value = false;
|
|
|
event.target.value = ""; // 清空input以允许重复上传相同文件
|
|
|
|
|
|
- // 如果有文件上传成功,确保右侧面板展开
|
|
|
+ // 修改文件上传后的处理逻辑
|
|
|
if (attachedFiles.value.length > 0) {
|
|
|
- expandRightMenu();
|
|
|
+ // 仅切换到预览标签页,不自动展开右侧菜单
|
|
|
activeTab.value = 'preview';
|
|
|
+ /* expandRightMenu(); */
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1008,13 +1009,31 @@ const sendMessage = async () => {
|
|
|
)
|
|
|
return;
|
|
|
|
|
|
- // 如果启用了网络搜索,更新搜索查询
|
|
|
+ // 保存当前输入内容
|
|
|
+ const currentMessage = inputContent.value.trim();
|
|
|
+
|
|
|
+ // 立即清空输入框
|
|
|
+ inputContent.value = '';
|
|
|
+
|
|
|
+ // 根据开启的搜索类型执行相应的搜索
|
|
|
if (enableWebSearch.value) {
|
|
|
- currentSearchQuery.value = inputContent.value;
|
|
|
+ currentSearchQuery.value = currentMessage;
|
|
|
+ // 执行互联网搜索
|
|
|
+ sendMessageS(currentMessage).catch((error) => {
|
|
|
+ console.error("Web search failed:", error);
|
|
|
+ });
|
|
|
+ } else if (enableKnowledgeSearch.value) {
|
|
|
+ currentSearchQuery.value = currentMessage;
|
|
|
+ // 执行知识库搜索
|
|
|
+ handleKnowledgeSearch({
|
|
|
+ query: currentMessage,
|
|
|
+ page: 1,
|
|
|
+ pageSize: 20
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
// 构建消息内容,包含文件信息
|
|
|
- let messageContent = inputContent.value.trim();
|
|
|
+ let messageContent = currentMessage;
|
|
|
|
|
|
// 收集文件URLs
|
|
|
const imageUrls = [];
|
|
@@ -1048,19 +1067,6 @@ const sendMessage = async () => {
|
|
|
messages.value.push(userMessage);
|
|
|
scrollToBottom();
|
|
|
|
|
|
- // 异步执行搜索,但不等待结果
|
|
|
-
|
|
|
- sendMessageS(messageContent).catch((error) => {
|
|
|
- console.error("Web search failed:", error);
|
|
|
- });
|
|
|
-
|
|
|
- // 保存当前输入内容并清空输入框和附件
|
|
|
- const currentInput = inputContent.value;
|
|
|
- showAttachments.value = false;
|
|
|
- inputContent.value = "";
|
|
|
- const currentFiles = [...attachedFiles.value];
|
|
|
- attachedFiles.value = [];
|
|
|
-
|
|
|
// 添加临时AI消息
|
|
|
const tempAiMessage = {
|
|
|
id: Date.now() + 1,
|
|
@@ -1079,7 +1085,7 @@ const sendMessage = async () => {
|
|
|
: `${import.meta.env.VITE_BASE_AI_API}/api/chat/online/multimodal`;
|
|
|
|
|
|
const response = await axios.post(apiEndpoint, {
|
|
|
- message: currentInput,
|
|
|
+ message: currentMessage,
|
|
|
chat_config_id: "2",
|
|
|
user_id: "13365429324",
|
|
|
session_id: session_id.value,
|
|
@@ -1266,10 +1272,11 @@ const handleFileDrop = async (event) => {
|
|
|
} finally {
|
|
|
isUploading.value = false;
|
|
|
|
|
|
- // 上传完成后,自动展开右侧面板并切换到文档预览
|
|
|
+ // 修改文件上传后的处理逻辑
|
|
|
if (attachedFiles.value.length > 0) {
|
|
|
- expandRightMenu();
|
|
|
+ // 仅切换到预览标签页,不自动展开右侧菜单
|
|
|
activeTab.value = 'preview';
|
|
|
+ /* expandRightMenu(); */
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1412,9 +1419,15 @@ const currentSearchQuery = ref('');
|
|
|
|
|
|
// 添加输入变化处理方法
|
|
|
const handleInputChange = () => {
|
|
|
- if ((enableWebSearch.value || enableKnowledgeSearch.value) && inputContent.value.trim()) {
|
|
|
+ if (inputContent.value.trim()) {
|
|
|
currentSearchQuery.value = inputContent.value;
|
|
|
- if (enableKnowledgeSearch.value) {
|
|
|
+
|
|
|
+ // 根据当前选中的搜索类型执行相应的搜索
|
|
|
+ if (enableWebSearch.value) {
|
|
|
+ sendMessageS(inputContent.value).catch((error) => {
|
|
|
+ console.error("Web search failed:", error);
|
|
|
+ });
|
|
|
+ } else if (enableKnowledgeSearch.value) {
|
|
|
handleKnowledgeSearch({
|
|
|
query: inputContent.value,
|
|
|
page: 1,
|
|
@@ -1426,6 +1439,7 @@ const handleInputChange = () => {
|
|
|
|
|
|
// 添加处理搜索开关的方法
|
|
|
const handleSearchToggle = (value) => {
|
|
|
+ console.log(enableWebSearch);
|
|
|
enableWebSearch.value = value;
|
|
|
if (value) {
|
|
|
// 开启搜索时,确保右侧面板展开
|
|
@@ -1479,21 +1493,24 @@ const updateCollapsedState = () => {
|
|
|
|
|
|
// 添加计算属性
|
|
|
const isRightMenuVisible = computed(() => {
|
|
|
- return (!isRightMenuCollapsed.value && (
|
|
|
+ // 移除搜索开关对菜单显示的影响
|
|
|
+ return !isRightMenuCollapsed.value;
|
|
|
+ /* return (!isRightMenuCollapsed.value && (
|
|
|
(enableWebSearch.value && activeTab.value === 'search') ||
|
|
|
(enableKnowledgeSearch.value && activeTab.value === 'knowledge') ||
|
|
|
(activeTab.value === 'preview' && attachedFiles.value.length > 0)
|
|
|
- ));
|
|
|
+ )); */
|
|
|
});
|
|
|
|
|
|
// 修改知识库搜索开关处理方法
|
|
|
- const handleKnowledgeToggle = (value) => {
|
|
|
- enableKnowledgeSearch.value = value;
|
|
|
- if (value) {
|
|
|
- // 开启知识库搜索时,确保右侧面板展开
|
|
|
- expandRightMenu();
|
|
|
+ const handleKnowledgeToggle = (event) => {
|
|
|
+ if (event.target.checked) {
|
|
|
+ // 开启知识库搜索时关闭互联网搜索
|
|
|
+ enableWebSearch.value = false;
|
|
|
+ // 切换到知识库标签页
|
|
|
activeTab.value = 'knowledge';
|
|
|
- // 如果输入框有内容,立即执行搜索
|
|
|
+
|
|
|
+ // 如果有输入内容,执行知识库搜索
|
|
|
if (inputContent.value.trim()) {
|
|
|
handleKnowledgeSearch({
|
|
|
query: inputContent.value,
|
|
@@ -1504,24 +1521,26 @@ const updateCollapsedState = () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- // 添加知识库搜索方法
|
|
|
+ // 修改知识库搜索方法
|
|
|
const handleKnowledgeSearch = async (params) => {
|
|
|
if (!params.query.trim() || !enableKnowledgeSearch.value) return;
|
|
|
|
|
|
isKnowledgeLoading.value = true;
|
|
|
try {
|
|
|
const response = await axios.post(
|
|
|
- `${import.meta.env.VITE_BASE_AI_API}/api/knowledge-search/`,
|
|
|
+ `${import.meta.env.VITE_BASE_AI_F_API}/chataids/mysql_fuzzy_search/`,
|
|
|
{
|
|
|
- query: params.query,
|
|
|
- page: params.page,
|
|
|
- page_size: params.pageSize,
|
|
|
+ collection_names: ["25"], // 固定使用 "25" 作为 collection name
|
|
|
+ keywords: params.query, // 使用查询关键词
|
|
|
+ documents: [], // 保持空数组
|
|
|
+ document_ids: [], // 保持空数组
|
|
|
+ limit: 5 // 固定返回5条结果
|
|
|
}
|
|
|
);
|
|
|
-
|
|
|
- if (response.data && response.data.code === 200) {
|
|
|
- knowledgeResults.value = response.data.data.results || [];
|
|
|
- knowledgeTotal.value = response.data.data.total || 0;
|
|
|
+ console.log(response);
|
|
|
+ if (response.data && response.data.status === 200) {
|
|
|
+ knowledgeResults.value = response.data.data.data.results || [];
|
|
|
+ knowledgeTotal.value = response.data.data.data.total || 0;
|
|
|
}
|
|
|
} catch (error) {
|
|
|
console.error('Knowledge search failed:', error);
|
|
@@ -1531,6 +1550,24 @@ const updateCollapsedState = () => {
|
|
|
isKnowledgeLoading.value = false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 修改处理互联网搜索开关的方法
|
|
|
+ const handleWebSearchToggle = (event) => {
|
|
|
+ if (event.target.checked) {
|
|
|
+ // 开启互联网搜索时关闭知识库搜索
|
|
|
+ enableKnowledgeSearch.value = false;
|
|
|
+ // 切换到搜索标签页
|
|
|
+ activeTab.value = 'search';
|
|
|
+
|
|
|
+ // 如果有输入内容,执行互联网搜索
|
|
|
+ if (inputContent.value.trim()) {
|
|
|
+ currentSearchQuery.value = inputContent.value;
|
|
|
+ sendMessageS(inputContent.value).catch((error) => {
|
|
|
+ console.error("Web search failed:", error);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
</script>
|
|
|
|
|
|
<style scoped>
|