|
@@ -14,7 +14,8 @@
|
|
|
getHistoryChatList
|
|
|
} from '@/api/ai'
|
|
|
import {
|
|
|
- Top
|
|
|
+ Top,
|
|
|
+ Plus
|
|
|
} from '@element-plus/icons-vue'
|
|
|
import {
|
|
|
useUserStore
|
|
@@ -37,6 +38,7 @@
|
|
|
// 当前AI流式响应内容
|
|
|
const currentAIResponse = ref('');
|
|
|
const paramId = ref(useRoute().params.id);
|
|
|
+ const paramType = ref(useRoute().params.type);
|
|
|
const conversationId = ref('');
|
|
|
const chatBody = ref(null);
|
|
|
const previewUrl = ref('');
|
|
@@ -51,7 +53,7 @@
|
|
|
})
|
|
|
let timerId = null;
|
|
|
const init = async () => {
|
|
|
- if (useRoute().params.type === 'chat') {
|
|
|
+ if (paramType.type === 'chat') {
|
|
|
conversationId.value = paramId.value;
|
|
|
initChatList();
|
|
|
return;
|
|
@@ -92,6 +94,7 @@
|
|
|
const initChatList = async () => {
|
|
|
let flowData = await getHistoryChatList(conversationId.value);
|
|
|
if (flowData.state) {
|
|
|
+ versionIndex.value = 1;
|
|
|
chatHistory.value = flowData.data.data.map(node => {
|
|
|
node['AIoutputs'] = renderMarkdown(node.answer);
|
|
|
return node
|
|
@@ -104,17 +107,13 @@
|
|
|
prompt.value = value;
|
|
|
sendMessage();
|
|
|
}
|
|
|
- const sendMessage = async () => {
|
|
|
- if (!prompt.value.trim() || loading.value) {
|
|
|
- ElMessage({
|
|
|
- type: 'warning',
|
|
|
- message: '输入不能为空!'
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
+ const sendMessage = () => {
|
|
|
+ if (!prompt.value.trim() || loading.value) return;
|
|
|
+ AIMessage(prompt.value)
|
|
|
+ }
|
|
|
+ const AIMessage = async (userMessage) => {
|
|
|
try {
|
|
|
// 1. 添加用户消息到历史记录
|
|
|
- const userMessage = prompt.value
|
|
|
chatHistory.value.push({
|
|
|
isUser: true,
|
|
|
query: userMessage,
|
|
@@ -132,7 +131,11 @@
|
|
|
},
|
|
|
body: JSON.stringify({
|
|
|
query: userMessage,
|
|
|
- conversationId: conversationId.value
|
|
|
+ conversationId: conversationId.value,
|
|
|
+ inputs: {
|
|
|
+ websiteURL: "",
|
|
|
+ fileURL: ""
|
|
|
+ }
|
|
|
})
|
|
|
});
|
|
|
const reader = response.body.getReader();
|
|
@@ -149,10 +152,8 @@
|
|
|
stream: true
|
|
|
});
|
|
|
loading.value = false;
|
|
|
- result += resultString;
|
|
|
- result = result.replaceAll('data:', '');
|
|
|
+ result += resultString.replaceAll('data:', '');
|
|
|
chatHistory.value[chatHistory.value.length - 1].AIoutputs = renderMarkdown(result);
|
|
|
- initChatList();
|
|
|
scrollToBottom();
|
|
|
}
|
|
|
} catch (error) {
|
|
@@ -174,7 +175,7 @@
|
|
|
* 使用 marked 解析 Markdown
|
|
|
* @param markdown 解析的文本
|
|
|
*/
|
|
|
- let versionIndex = 1;
|
|
|
+ const versionIndex = ref(1);
|
|
|
const renderMarkdown = markdown => {
|
|
|
const renderer = new marked.Renderer();
|
|
|
renderer.code = ({
|
|
@@ -191,10 +192,10 @@
|
|
|
renderer.link = (href) => {
|
|
|
let divBox = document.createElement('div');
|
|
|
let div = document.createElement('div');
|
|
|
- div.innerHTML = `version-${versionIndex}`
|
|
|
+ div.innerHTML = `version-${versionIndex.value}`
|
|
|
div.id = href.href;
|
|
|
div.className = 'version-href'
|
|
|
- versionIndex++;
|
|
|
+ versionIndex.value++;
|
|
|
divBox.appendChild(div);
|
|
|
previewUrl.value = href.href;
|
|
|
return divBox.innerHTML;
|
|
@@ -209,7 +210,12 @@
|
|
|
let href = target.id;
|
|
|
emits('updateURL', href);
|
|
|
}
|
|
|
-
|
|
|
+ }
|
|
|
+ const selectVisible = ref(false);
|
|
|
+ const functionList = ref(['登录功能']);
|
|
|
+ const selectFunction = data => {
|
|
|
+ AIMessage('新增' + data);
|
|
|
+ selectVisible.value = false;
|
|
|
}
|
|
|
// 组件卸载时清除定时器(重要!)
|
|
|
onUnmounted(() => {
|
|
@@ -254,12 +260,26 @@
|
|
|
:autosize="{ minRows: 2, maxRows: 6 }">
|
|
|
</el-input>
|
|
|
<div class="input-button">
|
|
|
+ <el-button style="margin-left: 10px;" size="default" :icon="Plus" circle
|
|
|
+ @click="selectVisible = true">
|
|
|
+ </el-button>
|
|
|
<el-button circle type="primary" @click="sendMessage" :disabled="!prompt.trim() || loading"
|
|
|
:icon="Top">
|
|
|
</el-button>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
+ <el-dialog v-model="selectVisible" title="新增功能" width="800px" class="ai-dialog select-dialog">
|
|
|
+ <div class="select-item">
|
|
|
+ <el-row :gutter="15">
|
|
|
+ <el-col :span="6" v-for="(item,index) in functionList" :key="index">
|
|
|
+ <el-button style="width: 100%;" @click="selectFunction(item)">
|
|
|
+ {{item}}
|
|
|
+ </el-button>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
</div>
|
|
|
</template>
|
|
|
|