|
|
@ -100,6 +100,12 @@ const currentRecordList = ref([]) |
|
|
|
const sessionId = ref(Cookies.get("chatSessionId")) // 当前历史记录Id 默认为'new' |
|
|
|
const mouseId = ref('') |
|
|
|
|
|
|
|
const paginationConfig = reactive({ |
|
|
|
current_page: 1, |
|
|
|
page_size: 20, |
|
|
|
total: 0 |
|
|
|
}) |
|
|
|
|
|
|
|
function mouseenter(row) { |
|
|
|
mouseId.value = row.sessionId |
|
|
|
} |
|
|
@ -124,7 +130,6 @@ function showChatHistory(){ |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function newChat() { |
|
|
|
currentRecordList.value = [] |
|
|
|
sessionId.value = uuidv4() |
|
|
@ -133,16 +138,31 @@ function newChat() { |
|
|
|
} |
|
|
|
|
|
|
|
function handleScroll(event) { |
|
|
|
if (event.scrollTop === 0 && currentRecordList.value.length>0) { |
|
|
|
if ( |
|
|
|
event.scrollTop === 0 && |
|
|
|
paginationConfig.total > currentRecordList.value.length |
|
|
|
) { |
|
|
|
const history_height = event.dialogScrollbar.offsetHeight |
|
|
|
event.scrollDiv.setScrollTop(event.dialogScrollbar.offsetHeight - history_height) |
|
|
|
paginationConfig.current_page += 1 |
|
|
|
getChatRecord({sessionId: sessionId.value, pageNum: paginationConfig.current_page, pageSize: paginationConfig.page_size}).then(() => { |
|
|
|
event.scrollDiv.setScrollTop(event.dialogScrollbar.offsetHeight - history_height) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function clickListHandle(item){ |
|
|
|
getChatList(item.sessionId).then(res=>{ |
|
|
|
currentRecordList.value = [] |
|
|
|
let array = res.data |
|
|
|
paginationConfig.current_page = 1 |
|
|
|
currentRecordList.value = [] |
|
|
|
sessionId.value = item.sessionId |
|
|
|
Cookies.set("chatSessionId",sessionId.value) |
|
|
|
getChatRecord({sessionId: item.sessionId, pageNum: paginationConfig.current_page, pageSize: paginationConfig.page_size}) |
|
|
|
show.value = false |
|
|
|
} |
|
|
|
|
|
|
|
function getChatRecord(data){ |
|
|
|
return getChatList(data).then(res=>{ |
|
|
|
let array = res.data.rows |
|
|
|
paginationConfig.total = res.data.total |
|
|
|
for (let i = 0; i < array.length; i++) { |
|
|
|
if (array[i].type === 'answer'){ |
|
|
|
array[i].content = JSON.parse(array[i].content) |
|
|
@ -150,12 +170,16 @@ function clickListHandle(item){ |
|
|
|
if (array[i].type === 'question'){ |
|
|
|
array[i].file = JSON.parse(array[i].file) |
|
|
|
} |
|
|
|
currentRecordList.value.push(array[i]) |
|
|
|
AiChatRef.value.setScrollBottom() |
|
|
|
} |
|
|
|
show.value = false |
|
|
|
sessionId.value = item.sessionId |
|
|
|
Cookies.set("chatSessionId",sessionId.value) |
|
|
|
currentRecordList.value = [...array, ...currentRecordList.value].sort((a, b) => |
|
|
|
a.time.localeCompare(b.time) |
|
|
|
) |
|
|
|
if (paginationConfig.current_page === 1) { |
|
|
|
nextTick(() => { |
|
|
|
// 将滚动条滚动到最下面 |
|
|
|
AiChatRef.value.setScrollBottom() |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
|
} |
|
|
|
watch(() => props.chatDataList, value => currentRecordList.value = JSON.parse(JSON.stringify(value))) |
|
|
@ -163,22 +187,7 @@ onMounted( |
|
|
|
()=>{ |
|
|
|
if (Cookies.get("chatSessionId")){ |
|
|
|
//调用子页面的赋值方法,给子页面赋值 |
|
|
|
getChatList(Cookies.get("chatSessionId")).then(res=>{ |
|
|
|
let array = res.data |
|
|
|
if (array && array.length >0){ |
|
|
|
for (let i = 0; i < array.length; i++) { |
|
|
|
if (array[i].type === 'answer'){ |
|
|
|
array[i].content = JSON.parse(array[i].content) |
|
|
|
} |
|
|
|
if (array[i].type === 'question'){ |
|
|
|
array[i].file = JSON.parse(array[i].file) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
currentRecordList.value = array |
|
|
|
}).then(()=>{ |
|
|
|
AiChatRef.value.setScrollBottom() |
|
|
|
}) |
|
|
|
getChatRecord({sessionId: Cookies.get("chatSessionId"), pageNum: paginationConfig.current_page, pageSize: paginationConfig.page_size}) |
|
|
|
}else { |
|
|
|
Cookies.set("chatSessionId",uuidv4()) |
|
|
|
} |
|
|
|