Merge branch 'main' of http://18.167.251.121:10003/aidlab/FiDA_Front
This commit is contained in:
@@ -29,7 +29,7 @@ export const createProject = (data: CreateProjectParamsType): Promise<any> => {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目信息
|
||||
* 获取项目信息和会话历史
|
||||
* @param data 获取项目信息参数
|
||||
* @param data.id 项目id
|
||||
* @returns 获取项目信息
|
||||
|
||||
@@ -1,2 +1,9 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
export const uploadImage = (data: FormData) => {
|
||||
return request({
|
||||
url: '/api/file/upload',
|
||||
method: 'POST',
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ export const versionTree = (data) => {
|
||||
* @param data 获取节点缩略信息的参数
|
||||
* @param data.projectId 项目id
|
||||
* @param data.id 节点id
|
||||
* @returns 获取节点缩略信息
|
||||
* @returns 回溯该节点之前的会话列表
|
||||
*/
|
||||
export const getNodeAncestors = (data) => {
|
||||
return request({
|
||||
|
||||
@@ -14,7 +14,7 @@ export const useAgentStore = defineStore('agent', () => {
|
||||
type: string
|
||||
area: string
|
||||
style: string
|
||||
} | null>(null)
|
||||
} | null>(null)
|
||||
|
||||
// 保存项目初始数据
|
||||
const setInitialProjectData = (data: {
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
import Input from '../../components/Input.vue'
|
||||
import { fetchAgentReply } from '@/api/agent'
|
||||
import type { AgentParamsType } from '@/api/agent'
|
||||
import { useUserInfoStore, useProjectStore } from '@/stores'
|
||||
import { useUserInfoStore, useProjectStore, } from '@/stores'
|
||||
import { useAgentStore } from '@/stores/agent'
|
||||
|
||||
const userStore = useUserInfoStore()
|
||||
@@ -67,8 +67,6 @@
|
||||
watch(
|
||||
sketchList,
|
||||
(newVal) => {
|
||||
console.log('添加图片链接--------')
|
||||
|
||||
emits('update:sketchList', newVal)
|
||||
},
|
||||
{ deep: true }
|
||||
@@ -120,7 +118,7 @@
|
||||
},
|
||||
skipUserMessage = false
|
||||
) => {
|
||||
console.log('Message sent:', message)
|
||||
// console.log('Message sent:', message)
|
||||
isPaused.value = false
|
||||
isGenerating.value = true
|
||||
params.message = message.text
|
||||
@@ -213,7 +211,7 @@
|
||||
while (flag) {
|
||||
const { done, value } = await reader.read()
|
||||
if (done) {
|
||||
console.log('传输结束 end---', contentBody)
|
||||
// console.log('传输结束 end---', contentBody)
|
||||
aiMessage.streaming = false
|
||||
aiMessage.loading = false
|
||||
isGenerating.value = false
|
||||
@@ -254,6 +252,7 @@
|
||||
// console.log('dataLInes', dataLines)
|
||||
if (isNodeIdEvent) {
|
||||
params.versionID = dataLines[0]
|
||||
projectStore.setProject({nodeId:dataLines[0]})
|
||||
}
|
||||
|
||||
if (dataLines.length === 0) continue
|
||||
@@ -361,8 +360,47 @@
|
||||
)
|
||||
}
|
||||
|
||||
const setChatInfo = (data) => {
|
||||
// messageList.value = list
|
||||
const { ancestors, current } = data
|
||||
const imgList = []
|
||||
const ancestorsList = []
|
||||
if (ancestors) {
|
||||
ancestors.forEach((item) => {
|
||||
const list = item.dialogue.map((el, index) => {
|
||||
if (el.image_url) {
|
||||
imgList.push(el.image_url)
|
||||
}
|
||||
return {
|
||||
...el,
|
||||
text: el.content,
|
||||
isUser: el.role === 'user',
|
||||
id: index + 1
|
||||
}
|
||||
})
|
||||
ancestorsList.push(...list)
|
||||
})
|
||||
}
|
||||
const currentList = current.dialogue.map((item, index) => {
|
||||
if (item.image_url) {
|
||||
imgList.push(item.image_url)
|
||||
}
|
||||
return {
|
||||
...item,
|
||||
text: item.content,
|
||||
isUser: item.role === 'user',
|
||||
id: index + 1 + ancestorsList.length
|
||||
}
|
||||
})
|
||||
messageList.value = [...ancestorsList, ...currentList]
|
||||
params.versionID = current.id
|
||||
sketchList.value = imgList
|
||||
// console.log('messagelist:', messageList.value)
|
||||
// debugger
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
inputRef
|
||||
setChatInfo
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -221,5 +221,8 @@
|
||||
ul {
|
||||
list-style-position: inside;
|
||||
}
|
||||
code {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -29,7 +29,7 @@ const projectStore = useProjectStore()
|
||||
let oldProjectId:any = ''
|
||||
watch(()=>props.versionTreeData?.drawer, (newVal, oldVal) => {
|
||||
console.log(newVal,oldProjectId,projectStore.state.id)
|
||||
if(newVal && oldProjectId !== projectStore.state.id && projectStore.state.id){
|
||||
if(newVal || (oldProjectId !== projectStore.state.id && projectStore.state.id)){
|
||||
getVersionTree()
|
||||
oldProjectId = JSON.parse(JSON.stringify(projectStore.state.id))
|
||||
}
|
||||
@@ -41,6 +41,7 @@ const getVersionTree = ()=>{
|
||||
}).then(res => {
|
||||
if(!res)return
|
||||
setVersionsList([res])
|
||||
treeKey.value++
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,6 @@ const initialize = ()=>{
|
||||
|
||||
const setSelectItem = (item)=>{
|
||||
if(!item.versionId)return
|
||||
console.log(item)
|
||||
projectStore.setProject({nodeId: item.id})
|
||||
emit('update:selectItem', {...item})
|
||||
emit('selectNode')
|
||||
@@ -97,10 +96,6 @@ watch(()=>treeStateTime.value,(newVal,oldVal)=>{
|
||||
}
|
||||
})
|
||||
|
||||
watch(()=>props.selectItem,(newVal,oldVal)=>{
|
||||
// scrollToActive()
|
||||
},{immediate: true})
|
||||
|
||||
onMounted(()=>{
|
||||
initialize()
|
||||
})
|
||||
|
||||
@@ -125,7 +125,7 @@ defineExpose({push})
|
||||
</template> -->
|
||||
</VueFlow>
|
||||
<div class="btnBox">
|
||||
<div class="item" v-if="selectItem.url" @click="versionRestore">
|
||||
<div class="item" :class="{'active':!selectItem.url}" @click="versionRestore">
|
||||
<div class="icon">
|
||||
<SvgIcon name="versionRestore" size="12" />
|
||||
</div>
|
||||
@@ -225,6 +225,11 @@ defineExpose({push})
|
||||
margin-bottom: 2rem;
|
||||
background-color: #ffffff;
|
||||
cursor: pointer;
|
||||
pointer-events: none;
|
||||
&.active{
|
||||
background-color: #f5f5f5;
|
||||
pointer-events: auto;
|
||||
}
|
||||
&:hover{
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ const props = defineProps<{
|
||||
<!-- <div>{{ props.data.id }}</div> -->
|
||||
<div class="item">
|
||||
<!-- {{ props.data.url }} -->
|
||||
<img :src="props.data?.url" />
|
||||
<img v-if="props.data?.url" :src="props.data?.url" />
|
||||
<div class="mask"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
ref="VersionTreeIndexRef"
|
||||
v-model:versionTreeData="versionTreeData"
|
||||
@restore="handleRestore"
|
||||
@selectNode="handleSelectNode"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -24,13 +25,14 @@
|
||||
import VersionTreeIndex from './components/versionTree/index.vue'
|
||||
import { useProjectStore } from '@/stores'
|
||||
import { getProjectInfo } from '@/api/agent'
|
||||
import { clearNodeChat, getNodeAncestors } from '@/api/versitonTree'
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
const route = useRoute()
|
||||
const projectStore = useProjectStore()
|
||||
|
||||
const agentTitle = ref('Retro Sofa Sketch')
|
||||
const previewType = ref<'sketch' | 'report'>('sketch')
|
||||
const route = useRoute()
|
||||
|
||||
const VersionTreeIndexRef = ref()
|
||||
const agentRef = ref()
|
||||
const sketchList = ref([])
|
||||
@@ -45,39 +47,48 @@
|
||||
})
|
||||
|
||||
const handleRestore = () => {
|
||||
console.log('-----------', agentRef.value.inputRef.addReportTag)
|
||||
// agentRef.value?.inputRef?.addReportTag('Restore')
|
||||
clearNodeChat({ projectId: projectStore.state.id, id: projectStore.state.nodeId }).then(
|
||||
(res) => {}
|
||||
)
|
||||
}
|
||||
const handleSelectNode = () => {
|
||||
console.log('handleSelectNode')
|
||||
getNodeAncestors({ projectId: projectStore.state.id, id: projectStore.state.nodeId }).then(
|
||||
(res) => {
|
||||
console.log('res', res)
|
||||
agentRef.value.setChatInfo(res)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
agentRef.value?.inputRef?.addReportTag('Restore')
|
||||
const handleGetProjectInfoAndHistory = () => {
|
||||
getProjectInfo({ id: route.params.id }).then((res) => {
|
||||
if(res?.conversation)agentRef.value.setChatInfo(res.conversation)
|
||||
let data = res?.project || res
|
||||
if(data?.latestNodeId)data.nodeId = data.latestNodeId
|
||||
projectStore.setProject({
|
||||
...data,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const proJectId = computed(() => route.params.id)
|
||||
const projectStore = useProjectStore()
|
||||
|
||||
watch(
|
||||
() => proJectId.value,
|
||||
(newVal, oldVal) => {
|
||||
projectStore.clearProject()
|
||||
if (newVal) {
|
||||
projectStore.clearProject()
|
||||
projectStore.setId(newVal)
|
||||
|
||||
}
|
||||
}
|
||||
)
|
||||
watch(
|
||||
() => projectStore.state.id,
|
||||
(newVal, oldVal) => {
|
||||
if (newVal) {
|
||||
getProjectInfo({ id: newVal }).then((res) => {
|
||||
projectStore.setProject(res.project)
|
||||
})
|
||||
handleGetProjectInfoAndHistory()
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
onMounted(() => {
|
||||
if (projectStore.state.id) {
|
||||
getProjectInfo({ id: projectStore.state.id }).then((res) => {
|
||||
projectStore.setProject(res.project)
|
||||
})
|
||||
projectStore.clearProject()
|
||||
if (proJectId.value) {
|
||||
handleGetProjectInfoAndHistory()
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -188,6 +188,7 @@
|
||||
import restoreCloseIcon from '@/assets/images/tag-close.png'
|
||||
import { createProject } from '@/api/agent'
|
||||
import { getStyleImage } from './style'
|
||||
import { uploadImage } from '@/api/upload'
|
||||
// import Tag from './Tag.vue'
|
||||
|
||||
const router = useRouter()
|
||||
@@ -221,18 +222,26 @@
|
||||
// 处理文件选择
|
||||
const handleFileChange = (event: Event) => {
|
||||
const input = event.target as HTMLInputElement
|
||||
|
||||
if (input.files) {
|
||||
Array.from(input.files).forEach((file) => {
|
||||
// 只处理图片文件
|
||||
if (file.type.startsWith('image/')) {
|
||||
const reader = new FileReader()
|
||||
reader.onload = (e) => {
|
||||
uploadedImages.value.push({
|
||||
url: e.target?.result as string,
|
||||
name: file.name
|
||||
})
|
||||
}
|
||||
reader.readAsDataURL(file)
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
uploadImage(formData).then((res) => {
|
||||
console.log(res)
|
||||
|
||||
const reader = new FileReader()
|
||||
reader.onload = (e) => {
|
||||
uploadedImages.value.push({
|
||||
url: e.target?.result as string,
|
||||
name: file.name,
|
||||
path: res
|
||||
})
|
||||
}
|
||||
reader.readAsDataURL(file)
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -293,7 +302,6 @@
|
||||
imgClose.src = closeIcon as unknown as string
|
||||
}
|
||||
|
||||
|
||||
textSpan.innerText = tagText
|
||||
|
||||
imgClose.addEventListener('click', (ev) => {
|
||||
@@ -467,19 +475,15 @@
|
||||
}
|
||||
|
||||
const handleSendAgent = async () => {
|
||||
console.log('发送信息--------')
|
||||
|
||||
if (props.generating) {
|
||||
emits('pause')
|
||||
return
|
||||
}
|
||||
if (!inputValue.value.trim()) return
|
||||
console.log('222222')
|
||||
const imageUrlList = uploadedImages.value.map((item) => item.path)
|
||||
|
||||
const payload = { text: inputValue.value.trim(), images: uploadedImages.value }
|
||||
console.log('准备发送 send 事件', payload)
|
||||
const payload = { text: inputValue.value.trim(), images: imageUrlList }
|
||||
emits('send', payload)
|
||||
console.log('send 事件已发送')
|
||||
|
||||
// 发送后清空输入框
|
||||
if (editorRef.value) {
|
||||
@@ -573,7 +577,7 @@
|
||||
})
|
||||
|
||||
// console.log('Create project with:', params)
|
||||
router.push('/home/agent', { query: params })
|
||||
router.push(`/home/agent/${projectres}`, { query: params })
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
@@ -1056,15 +1060,14 @@
|
||||
height: 1rem;
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
&.restore{
|
||||
&.restore {
|
||||
width: 0.5rem;
|
||||
height: 0.5rem;
|
||||
}
|
||||
}
|
||||
.restore-icon{
|
||||
.restore-icon {
|
||||
width: 1.2rem;
|
||||
height: 1.2rem;
|
||||
}
|
||||
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user