提交 501beebb authored 作者: 王鹏飞's avatar 王鹏飞

chore: update

上级 9feeb73f
......@@ -14,7 +14,7 @@ const currentMenu = computed(() => {
})
const currentSubmenu = computed(() => {
return currentMenu.value?.children ? findMenu(route.path, currentMenu.value.children) : null
return currentMenu.value?.children ? findMenu(route.fullPath, currentMenu.value.children) : null
})
function findMenu(path: string, menus: IMenuItem[]) {
......@@ -22,13 +22,13 @@ function findMenu(path: string, menus: IMenuItem[]) {
if (
item.children &&
item.children.find(item => {
const regExp = new RegExp(`^${item.path}`)
const regExp = new RegExp(`^${item.path.replaceAll('?', '\\?')}`)
return regExp.test(path)
})
) {
return item
}
const regExp = new RegExp(`^${item.path}`)
const regExp = new RegExp(`^${item.path.replaceAll('?', '\\?')}`)
return regExp.test(path)
})
}
......
......@@ -32,6 +32,9 @@ const { usages, messages, post, isLoading } = useChat({ experiment_id: route.que
onMounted(() => {
messages.value.push({ role: 'system', content: welcomeMessage.value })
if (form.value.content) {
messages.value.push({ role: 'bot', content: form.value.content })
}
})
// 设置为最后一条ai回复的内容
......@@ -57,6 +60,18 @@ async function handleSend(event) {
}
async function handleSendType(type, context) {
switch (type) {
case 2:
context = `请帮我创作一个,${context}`
break
case 3:
context = `请帮我润色一个,${context}`
break
case 4:
context = `请帮我扩写一个,${context}`
break
}
post({ type, context })
}
......@@ -69,6 +84,10 @@ function scrollToBottom() {
watch(messages.value, () => nextTick(() => scrollToBottom()))
const { copy } = useClipboard()
function parseHtml(content) {
return content.replaceAll('\n', '<br/>')
}
</script>
<template>
......@@ -80,10 +99,10 @@ const { copy } = useClipboard()
<IconAI v-else />
</div>
<div class="chat-message-main">
<div class="chat-message-content" v-html="item.content"></div>
<div class="chat-message-content" v-html="parseHtml(item.content)"></div>
<div class="chat-message-extra" v-if="item.role !== 'user'">
<el-button size="small" type="primary" @click="copy(item.content)">复制</el-button>
<el-button size="small" type="primary" @click="handleSendType(5, item.content)" v-if="item.role == 'bot'"
<el-button size="small" type="primary" @click="handleSendType(5, item.input || item.content)" v-if="item.role == 'bot'"
>刷新({{ usages.ai_refresh_count }}/{{ usages.ai_refresh_max_count }})</el-button
>
<el-button size="small" type="primary" @click="handleSendType(2, item.content)"
......
......@@ -56,10 +56,10 @@ export function useChat(options: any) {
chatId.value = message.chatId + ''
const conversationId = message.conversationId
const messageIndex = messages.value.findIndex(session => session.conversationId === conversationId)
let content = message.content || ''
if (message.content === '\n') content = '<br/>'
const content = message.content || ''
// if (message.content === '\n') content = '<br/>'
if (messageIndex === -1) {
messages.value.push({ conversationId, role: 'bot', content })
messages.value.push({ conversationId, role: 'bot', content, input: data.context })
} else {
messages.value[messageIndex].content = messages.value[messageIndex].content + content
}
......
......@@ -32,4 +32,5 @@ export interface Message {
complete?: boolean
finish?: boolean
type?: string
input?: string
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论