mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
feat: 对话增加历史记录
This commit is contained in:
parent
b2a7283012
commit
823879add0
|
|
@ -337,13 +337,16 @@ class ChatRecordSerializer(serializers.Serializer):
|
|||
class Query(serializers.Serializer):
|
||||
application_id = serializers.UUIDField(required=True)
|
||||
chat_id = serializers.UUIDField(required=True)
|
||||
order_asc = serializers.BooleanField(required=False)
|
||||
|
||||
def list(self, with_valid=True):
|
||||
if with_valid:
|
||||
self.is_valid(raise_exception=True)
|
||||
QuerySet(ChatRecord).filter(chat_id=self.data.get('chat_id'))
|
||||
order_by = 'create_time' if self.data.get('order_asc') is None or self.data.get(
|
||||
'order_asc') else '-create_time'
|
||||
return [ChatRecordSerializerModel(chat_record).data for chat_record in
|
||||
QuerySet(ChatRecord).filter(chat_id=self.data.get('chat_id')).order_by("create_time")]
|
||||
QuerySet(ChatRecord).filter(chat_id=self.data.get('chat_id')).order_by(order_by)]
|
||||
|
||||
@staticmethod
|
||||
def reset_chat_record(chat_record):
|
||||
|
|
@ -372,8 +375,10 @@ class ChatRecordSerializer(serializers.Serializer):
|
|||
def page(self, current_page: int, page_size: int, with_valid=True):
|
||||
if with_valid:
|
||||
self.is_valid(raise_exception=True)
|
||||
order_by = 'create_time' if self.data.get('order_asc') is None or self.data.get(
|
||||
'order_asc') else '-create_time'
|
||||
page = page_search(current_page, page_size,
|
||||
QuerySet(ChatRecord).filter(chat_id=self.data.get('chat_id')).order_by("create_time"),
|
||||
QuerySet(ChatRecord).filter(chat_id=self.data.get('chat_id')).order_by(order_by),
|
||||
post_records_handler=lambda chat_record: self.reset_chat_record(chat_record))
|
||||
return page
|
||||
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@ class ChatView(APIView):
|
|||
def get(self, request: Request, application_id: str, chat_id: str):
|
||||
return result.success(ChatRecordSerializer.Query(
|
||||
data={'application_id': application_id,
|
||||
'chat_id': chat_id}).list())
|
||||
'chat_id': chat_id, 'order_asc': request.query_params.get('order_asc')}).list())
|
||||
|
||||
class Page(APIView):
|
||||
authentication_classes = [TokenAuth]
|
||||
|
|
@ -242,7 +242,8 @@ class ChatView(APIView):
|
|||
def get(self, request: Request, application_id: str, chat_id: str, current_page: int, page_size: int):
|
||||
return result.success(ChatRecordSerializer.Query(
|
||||
data={'application_id': application_id,
|
||||
'chat_id': chat_id}).page(current_page, page_size))
|
||||
'chat_id': chat_id, 'order_asc': request.query_params.get('order_asc')}).page(current_page,
|
||||
page_size))
|
||||
|
||||
class Vote(APIView):
|
||||
authentication_classes = [TokenAuth]
|
||||
|
|
|
|||
|
|
@ -64,11 +64,13 @@ const getChatRecordLog: (
|
|||
application_id: String,
|
||||
chart_id: String,
|
||||
page: pageRequest,
|
||||
loading?: Ref<boolean>
|
||||
) => Promise<Result<any>> = (application_id, chart_id, page, loading) => {
|
||||
loading?: Ref<boolean>,
|
||||
order_asc?: boolean
|
||||
) => Promise<Result<any>> = (application_id, chart_id, page, loading, order_asc) => {
|
||||
console.log(order_asc)
|
||||
return get(
|
||||
`${prefix}/${application_id}/chat/${chart_id}/chat_record/${page.current_page}/${page.page_size}`,
|
||||
undefined,
|
||||
{ order_asc: order_asc !== undefined ? order_asc : true },
|
||||
loading
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -564,7 +564,7 @@ const handleScrollTop = ($event: any) => {
|
|||
} else {
|
||||
scorll.value = false
|
||||
}
|
||||
emit('scroll', $event)
|
||||
emit('scroll', { ...$event, dialogScrollbar: dialogScrollbar.value, scrollDiv: scrollDiv.value })
|
||||
}
|
||||
|
||||
const handleScroll = () => {
|
||||
|
|
|
|||
|
|
@ -23,11 +23,12 @@ const useLogStore = defineStore({
|
|||
id: string,
|
||||
chatId: string,
|
||||
page: pageRequest,
|
||||
loading?: Ref<boolean>
|
||||
loading?: Ref<boolean>,
|
||||
order_asc?: boolean
|
||||
) {
|
||||
return new Promise((resolve, reject) => {
|
||||
logApi
|
||||
.getChatRecordLog(id, chatId, page, loading)
|
||||
.getChatRecordLog(id, chatId, page, loading, order_asc)
|
||||
.then((data) => {
|
||||
resolve(data)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -135,14 +135,22 @@ function getChatLog(id: string) {
|
|||
|
||||
function getChatRecord() {
|
||||
log
|
||||
.asyncChatRecordLog(applicationDetail.value.id, currentChatId.value, paginationConfig, loading)
|
||||
.asyncChatRecordLog(
|
||||
applicationDetail.value.id,
|
||||
currentChatId.value,
|
||||
paginationConfig,
|
||||
loading,
|
||||
false
|
||||
)
|
||||
.then((res: any) => {
|
||||
paginationConfig.total = res.data.total
|
||||
const list = res.data.records
|
||||
list.map((v: any) => {
|
||||
v['write_ed'] = true
|
||||
})
|
||||
currentRecordList.value = [...currentRecordList.value, ...list]
|
||||
currentRecordList.value = [...list, ...currentRecordList.value].sort((a, b) =>
|
||||
a.create_time.localeCompare(b.create_time)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ const chatLogeData = ref<any[]>([])
|
|||
|
||||
const paginationConfig = reactive({
|
||||
current_page: 1,
|
||||
page_size: 20,
|
||||
page_size: 3,
|
||||
total: 0
|
||||
})
|
||||
|
||||
|
|
@ -100,8 +100,11 @@ const currentChatName = ref('新建对话')
|
|||
|
||||
function handleScroll(event: any) {
|
||||
if (event.scrollTop === 0 && paginationConfig.total > currentRecordList.value.length) {
|
||||
const histry_height = event.dialogScrollbar.offsetHeight
|
||||
paginationConfig.current_page += 1
|
||||
getChatRecord()
|
||||
getChatRecord().then(() => {
|
||||
event.scrollDiv.setScrollTop(event.dialogScrollbar.offsetHeight - histry_height)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -152,15 +155,23 @@ function getChatLog(id: string) {
|
|||
}
|
||||
|
||||
function getChatRecord() {
|
||||
log
|
||||
.asyncChatRecordLog(applicationDetail.value.id, currentChatId.value, paginationConfig, loading)
|
||||
return log
|
||||
.asyncChatRecordLog(
|
||||
applicationDetail.value.id,
|
||||
currentChatId.value,
|
||||
paginationConfig,
|
||||
loading,
|
||||
false
|
||||
)
|
||||
.then((res: any) => {
|
||||
paginationConfig.total = res.data.total
|
||||
const list = res.data.records
|
||||
list.map((v: any) => {
|
||||
v['write_ed'] = true
|
||||
})
|
||||
currentRecordList.value = [...list, ...currentRecordList.value]
|
||||
currentRecordList.value = [...list, ...currentRecordList.value].sort((a, b) =>
|
||||
a.create_time.localeCompare(b.create_time)
|
||||
)
|
||||
if (paginationConfig.current_page === 1) {
|
||||
nextTick(() => {
|
||||
// 将滚动条滚动到最下面
|
||||
|
|
|
|||
Loading…
Reference in New Issue