2023-12-07 07:22:07 +00:00
|
|
|
|
<template>
|
|
|
|
|
|
<el-drawer
|
|
|
|
|
|
v-model="visible"
|
|
|
|
|
|
size="50%"
|
|
|
|
|
|
append-to-body
|
|
|
|
|
|
@close="closeHandel"
|
|
|
|
|
|
class="chat-record-drawer"
|
|
|
|
|
|
>
|
|
|
|
|
|
<template #header>
|
2023-12-08 10:10:47 +00:00
|
|
|
|
<h4>{{ application?.name }}</h4>
|
2023-12-07 07:22:07 +00:00
|
|
|
|
</template>
|
2023-12-08 04:42:40 +00:00
|
|
|
|
<div
|
|
|
|
|
|
v-loading="paginationConfig.current_page === 1 && loading"
|
|
|
|
|
|
class="h-full"
|
|
|
|
|
|
style="padding: 24px 0"
|
|
|
|
|
|
>
|
2023-12-07 11:28:38 +00:00
|
|
|
|
<div v-infinite-scroll="loadDataset" :infinite-scroll-disabled="disabledScroll">
|
2023-12-08 10:10:47 +00:00
|
|
|
|
<AiChat :data="application" :record="recordList" log></AiChat>
|
2023-12-07 11:28:38 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
<div style="padding: 16px 10px">
|
|
|
|
|
|
<el-divider class="custom-divider" v-if="recordList.length > 0 && loading">
|
|
|
|
|
|
<el-text type="info"> 加载中...</el-text>
|
|
|
|
|
|
</el-divider>
|
|
|
|
|
|
<el-divider class="custom-divider" v-if="noMore">
|
|
|
|
|
|
<el-text type="info"> 到底啦!</el-text>
|
|
|
|
|
|
</el-divider>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2023-12-07 07:22:07 +00:00
|
|
|
|
<template #footer>
|
|
|
|
|
|
<div>
|
2023-12-08 10:10:47 +00:00
|
|
|
|
<el-button @click="pre" :disabled="pre_disable != undefined ? pre_disable : false"
|
|
|
|
|
|
>上一条</el-button
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-button @click="next" :disabled="next_disable != undefined ? next_disable : false"
|
|
|
|
|
|
>下一条</el-button
|
|
|
|
|
|
>
|
2023-12-07 07:22:07 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-drawer>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2023-12-08 10:10:47 +00:00
|
|
|
|
import { ref, reactive, computed, watch } from 'vue'
|
2023-12-07 07:22:07 +00:00
|
|
|
|
import { useRoute } from 'vue-router'
|
|
|
|
|
|
import logApi from '@/api/log'
|
2023-12-07 11:28:38 +00:00
|
|
|
|
import { type chatType } from '@/api/type/application'
|
2023-12-08 10:10:47 +00:00
|
|
|
|
import { type ApplicationFormType } from '@/api/type/application'
|
|
|
|
|
|
const props = withDefaults(
|
|
|
|
|
|
defineProps<{
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 应用信息
|
|
|
|
|
|
*/
|
|
|
|
|
|
application?: ApplicationFormType
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 对话 记录id
|
|
|
|
|
|
*/
|
|
|
|
|
|
id?: string
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 下一条
|
|
|
|
|
|
*/
|
|
|
|
|
|
next: () => void
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 上一条
|
|
|
|
|
|
*/
|
|
|
|
|
|
pre: () => void
|
2023-12-07 11:28:38 +00:00
|
|
|
|
|
2023-12-08 10:10:47 +00:00
|
|
|
|
pre_disable: boolean
|
|
|
|
|
|
|
|
|
|
|
|
next_disable: boolean
|
|
|
|
|
|
}>(),
|
|
|
|
|
|
{}
|
|
|
|
|
|
)
|
2023-12-07 11:28:38 +00:00
|
|
|
|
|
2023-12-08 10:10:47 +00:00
|
|
|
|
defineEmits(['update:id'])
|
2023-12-08 04:42:40 +00:00
|
|
|
|
|
2023-12-07 07:22:07 +00:00
|
|
|
|
const route = useRoute()
|
|
|
|
|
|
const {
|
|
|
|
|
|
params: { id }
|
|
|
|
|
|
} = route
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
const visible = ref(false)
|
2023-12-07 11:28:38 +00:00
|
|
|
|
const recordList = ref<chatType[]>([])
|
2023-12-07 07:22:07 +00:00
|
|
|
|
|
|
|
|
|
|
const paginationConfig = reactive({
|
|
|
|
|
|
current_page: 1,
|
|
|
|
|
|
page_size: 20,
|
|
|
|
|
|
total: 0
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2023-12-07 11:28:38 +00:00
|
|
|
|
const noMore = computed(
|
|
|
|
|
|
() =>
|
|
|
|
|
|
recordList.value.length > 0 &&
|
|
|
|
|
|
recordList.value.length === paginationConfig.total &&
|
|
|
|
|
|
paginationConfig.total > 20 &&
|
|
|
|
|
|
!loading.value
|
|
|
|
|
|
)
|
|
|
|
|
|
const disabledScroll = computed(
|
|
|
|
|
|
() => recordList.value.length > 0 && (loading.value || noMore.value)
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
function closeHandel() {
|
|
|
|
|
|
recordList.value = []
|
|
|
|
|
|
paginationConfig.total = 0
|
|
|
|
|
|
paginationConfig.current_page = 1
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function loadDataset() {
|
|
|
|
|
|
if (paginationConfig.total > paginationConfig.page_size) {
|
|
|
|
|
|
paginationConfig.current_page += 1
|
|
|
|
|
|
getChatRecord()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-12-07 07:22:07 +00:00
|
|
|
|
|
2023-12-07 11:28:38 +00:00
|
|
|
|
function getChatRecord() {
|
2023-12-08 10:10:47 +00:00
|
|
|
|
if (props.id && visible.value) {
|
|
|
|
|
|
logApi.getChatRecordLog(id as string, props.id, paginationConfig, loading).then((res) => {
|
2023-12-07 11:28:38 +00:00
|
|
|
|
paginationConfig.total = res.data.total
|
|
|
|
|
|
recordList.value = [...recordList.value, ...res.data.records]
|
|
|
|
|
|
})
|
2023-12-08 10:10:47 +00:00
|
|
|
|
}
|
2023-12-07 07:22:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-12-08 10:10:47 +00:00
|
|
|
|
watch(
|
|
|
|
|
|
() => props.id,
|
|
|
|
|
|
() => {
|
|
|
|
|
|
recordList.value = []
|
|
|
|
|
|
paginationConfig.total = 0
|
|
|
|
|
|
paginationConfig.current_page = 1
|
|
|
|
|
|
getChatRecord()
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
2023-12-08 04:42:40 +00:00
|
|
|
|
|
2023-12-08 10:10:47 +00:00
|
|
|
|
const open = () => {
|
2023-12-07 11:28:38 +00:00
|
|
|
|
getChatRecord()
|
2023-12-07 07:22:07 +00:00
|
|
|
|
visible.value = true
|
|
|
|
|
|
}
|
2023-12-08 04:42:40 +00:00
|
|
|
|
|
2023-12-07 07:22:07 +00:00
|
|
|
|
defineExpose({
|
|
|
|
|
|
open
|
|
|
|
|
|
})
|
|
|
|
|
|
</script>
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
|
.chat-record-drawer {
|
|
|
|
|
|
.el-drawer__body {
|
|
|
|
|
|
background: var(--app-layout-bg-color);
|
2023-12-08 04:42:40 +00:00
|
|
|
|
padding: 0;
|
2023-12-07 07:22:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|