UnisKB/ui/src/views/log/component/ChatRecordDrawer.vue

130 lines
2.7 KiB
Vue
Raw Normal View History

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-11 02:35:26 +00:00
<InfiniteScroll
:size="recordList.length"
:total="paginationConfig.total"
:page_size="paginationConfig.page_size"
v-model:current_page="paginationConfig.current_page"
@load="getChatRecord"
:loading="loading"
>
2023-12-08 10:10:47 +00:00
<AiChat :data="application" :record="recordList" log></AiChat>
2023-12-11 02:35:26 +00:00
</InfiniteScroll>
2023-12-07 11:28:38 +00:00
</div>
2023-12-07 07:22:07 +00:00
<template #footer>
<div>
2023-12-11 02:35:26 +00:00
<el-button @click="pre" :disabled="pre_disable || loading">上一条</el-button>
<el-button @click="next" :disabled="next_disable || loading">下一条</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
*/
2023-12-11 02:35:26 +00:00
chartId?: string
2023-12-08 10:10:47 +00:00
/**
* 下一条
*/
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-11 02:35:26 +00:00
defineEmits(['update:chartId'])
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,
2023-12-11 02:35:26 +00:00
page_size: 10,
2023-12-07 07:22:07 +00:00
total: 0
})
2023-12-07 11:28:38 +00:00
function closeHandel() {
recordList.value = []
paginationConfig.total = 0
paginationConfig.current_page = 1
}
function getChatRecord() {
2023-12-11 02:35:26 +00:00
if (props.chartId && visible.value) {
logApi.getChatRecordLog(id as string, props.chartId, 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(
2023-12-11 02:35:26 +00:00
() => props.chartId,
2023-12-08 10:10:47 +00:00
() => {
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
}
2023-12-11 02:35:26 +00:00
.el-divider__text {
background: var(--app-layout-bg-color);
}
2023-12-07 07:22:07 +00:00
}
</style>