feat: 对话日志详情翻页
This commit is contained in:
parent
44a88f647b
commit
58955a63bf
@ -7,7 +7,7 @@
|
|||||||
class="chat-record-drawer"
|
class="chat-record-drawer"
|
||||||
>
|
>
|
||||||
<template #header>
|
<template #header>
|
||||||
<h4>{{ data?.name }}</h4>
|
<h4>{{ application?.name }}</h4>
|
||||||
</template>
|
</template>
|
||||||
<div
|
<div
|
||||||
v-loading="paginationConfig.current_page === 1 && loading"
|
v-loading="paginationConfig.current_page === 1 && loading"
|
||||||
@ -15,7 +15,7 @@
|
|||||||
style="padding: 24px 0"
|
style="padding: 24px 0"
|
||||||
>
|
>
|
||||||
<div v-infinite-scroll="loadDataset" :infinite-scroll-disabled="disabledScroll">
|
<div v-infinite-scroll="loadDataset" :infinite-scroll-disabled="disabledScroll">
|
||||||
<AiChat :data="data" :record="recordList" log></AiChat>
|
<AiChat :data="application" :record="recordList" log></AiChat>
|
||||||
</div>
|
</div>
|
||||||
<div style="padding: 16px 10px">
|
<div style="padding: 16px 10px">
|
||||||
<el-divider class="custom-divider" v-if="recordList.length > 0 && loading">
|
<el-divider class="custom-divider" v-if="recordList.length > 0 && loading">
|
||||||
@ -28,27 +28,50 @@
|
|||||||
</div>
|
</div>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<div>
|
<div>
|
||||||
<el-button>上一条</el-button>
|
<el-button @click="pre" :disabled="pre_disable != undefined ? pre_disable : false"
|
||||||
<el-button>下一条</el-button>
|
>上一条</el-button
|
||||||
|
>
|
||||||
|
<el-button @click="next" :disabled="next_disable != undefined ? next_disable : false"
|
||||||
|
>下一条</el-button
|
||||||
|
>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</el-drawer>
|
</el-drawer>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, reactive, computed } from 'vue'
|
import { ref, reactive, computed, watch } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import logApi from '@/api/log'
|
import logApi from '@/api/log'
|
||||||
import { type chatType } from '@/api/type/application'
|
import { type chatType } from '@/api/type/application'
|
||||||
|
import { type ApplicationFormType } from '@/api/type/application'
|
||||||
|
const props = withDefaults(
|
||||||
|
defineProps<{
|
||||||
|
/**
|
||||||
|
* 应用信息
|
||||||
|
*/
|
||||||
|
application?: ApplicationFormType
|
||||||
|
/**
|
||||||
|
* 对话 记录id
|
||||||
|
*/
|
||||||
|
id?: string
|
||||||
|
/**
|
||||||
|
* 下一条
|
||||||
|
*/
|
||||||
|
next: () => void
|
||||||
|
/**
|
||||||
|
* 上一条
|
||||||
|
*/
|
||||||
|
pre: () => void
|
||||||
|
|
||||||
const props = defineProps({
|
pre_disable: boolean
|
||||||
data: {
|
|
||||||
type: Object,
|
|
||||||
default: () => {}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
const emit = defineEmits(['changeId', 'close'])
|
next_disable: boolean
|
||||||
|
}>(),
|
||||||
|
{}
|
||||||
|
)
|
||||||
|
|
||||||
|
defineEmits(['update:id'])
|
||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const {
|
const {
|
||||||
@ -57,7 +80,6 @@ const {
|
|||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const visible = ref(false)
|
const visible = ref(false)
|
||||||
const recordList = ref<chatType[]>([])
|
const recordList = ref<chatType[]>([])
|
||||||
const currentChatId = ref('')
|
|
||||||
|
|
||||||
const paginationConfig = reactive({
|
const paginationConfig = reactive({
|
||||||
current_page: 1,
|
current_page: 1,
|
||||||
@ -78,10 +100,8 @@ const disabledScroll = computed(
|
|||||||
|
|
||||||
function closeHandel() {
|
function closeHandel() {
|
||||||
recordList.value = []
|
recordList.value = []
|
||||||
currentChatId.value = ''
|
|
||||||
paginationConfig.total = 0
|
paginationConfig.total = 0
|
||||||
paginationConfig.current_page = 1
|
paginationConfig.current_page = 1
|
||||||
emit('close')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadDataset() {
|
function loadDataset() {
|
||||||
@ -92,25 +112,25 @@ function loadDataset() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getChatRecord() {
|
function getChatRecord() {
|
||||||
logApi
|
if (props.id && visible.value) {
|
||||||
.getChatRecordLog(id as string, currentChatId.value, paginationConfig, loading)
|
logApi.getChatRecordLog(id as string, props.id, paginationConfig, loading).then((res) => {
|
||||||
.then((res) => {
|
|
||||||
paginationConfig.total = res.data.total
|
paginationConfig.total = res.data.total
|
||||||
recordList.value = [...recordList.value, ...res.data.records]
|
recordList.value = [...recordList.value, ...res.data.records]
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// function nextRecord(id: string) {
|
watch(
|
||||||
// currentChatId.value = id
|
() => props.id,
|
||||||
// emit('changeId', id)
|
() => {
|
||||||
// recordList.value = []
|
recordList.value = []
|
||||||
// paginationConfig.total = 0
|
paginationConfig.total = 0
|
||||||
// paginationConfig.current_page = 1
|
paginationConfig.current_page = 1
|
||||||
// getChatRecord()
|
getChatRecord()
|
||||||
// }
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const open = (id: string) => {
|
const open = () => {
|
||||||
currentChatId.value = id
|
|
||||||
getChatRecord()
|
getChatRecord()
|
||||||
visible.value = true
|
visible.value = true
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,17 +63,26 @@
|
|||||||
</el-table-column>
|
</el-table-column>
|
||||||
</app-table>
|
</app-table>
|
||||||
</div>
|
</div>
|
||||||
<ChatRecordDrawer ref="ChatRecordRef" :data="detail" />
|
<ChatRecordDrawer
|
||||||
|
:next="nextChatRecord"
|
||||||
|
:pre="preChatRecord"
|
||||||
|
ref="ChatRecordRef"
|
||||||
|
v-model:id="currentChatId"
|
||||||
|
:application="detail"
|
||||||
|
:pre_disable="pre_disable"
|
||||||
|
:next_disable="next_disable"
|
||||||
|
/>
|
||||||
</LayoutContainer>
|
</LayoutContainer>
|
||||||
</template>
|
</template>
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, onMounted, reactive, watch, computed } from 'vue'
|
import { ref, onMounted, reactive, watch, computed } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute } from 'vue-router'
|
||||||
import ChatRecordDrawer from './component/ChatRecordDrawer.vue'
|
import ChatRecordDrawer from './component/ChatRecordDrawer.vue'
|
||||||
import { MsgSuccess, MsgConfirm } from '@/utils/message'
|
import { MsgSuccess, MsgConfirm, MsgError } from '@/utils/message'
|
||||||
import logApi from '@/api/log'
|
import logApi from '@/api/log'
|
||||||
import { datetimeFormat } from '@/utils/time'
|
import { datetimeFormat } from '@/utils/time'
|
||||||
import useStore from '@/stores'
|
import useStore from '@/stores'
|
||||||
|
import type { Dict } from '@/api/type/common'
|
||||||
const { application } = useStore()
|
const { application } = useStore()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const {
|
const {
|
||||||
@ -99,6 +108,62 @@ const dayOptions = [
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 下一页
|
||||||
|
*/
|
||||||
|
const nextChatRecord = () => {
|
||||||
|
let index = tableIndexMap.value[currentChatId.value] + 1
|
||||||
|
if (index >= tableData.value.length) {
|
||||||
|
if (
|
||||||
|
index + (paginationConfig.current_page - 1) * paginationConfig.page_size >=
|
||||||
|
paginationConfig.total - 1
|
||||||
|
) {
|
||||||
|
MsgError('没有更多了')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
paginationConfig.current_page = paginationConfig.current_page + 1
|
||||||
|
getList().then(() => {
|
||||||
|
index = 0
|
||||||
|
currentChatId.value = tableData.value[index].id
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
currentChatId.value = tableData.value[index].id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const pre_disable = computed(() => {
|
||||||
|
let index = tableIndexMap.value[currentChatId.value] - 1
|
||||||
|
return index < 0 && paginationConfig.current_page <= 1
|
||||||
|
})
|
||||||
|
|
||||||
|
const next_disable = computed(() => {
|
||||||
|
let index = tableIndexMap.value[currentChatId.value] + 1
|
||||||
|
return (
|
||||||
|
index >= tableData.value.length &&
|
||||||
|
index + (paginationConfig.current_page - 1) * paginationConfig.page_size >=
|
||||||
|
paginationConfig.total - 1
|
||||||
|
)
|
||||||
|
})
|
||||||
|
/**
|
||||||
|
* 上一页
|
||||||
|
*/
|
||||||
|
const preChatRecord = () => {
|
||||||
|
let index = tableIndexMap.value[currentChatId.value] - 1
|
||||||
|
|
||||||
|
if (index < 0) {
|
||||||
|
if (paginationConfig.current_page <= 1) {
|
||||||
|
MsgError('到头了')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
paginationConfig.current_page = paginationConfig.current_page - 1
|
||||||
|
getList().then((ok) => {
|
||||||
|
index = paginationConfig.page_size - 1
|
||||||
|
currentChatId.value = tableData.value[index].id
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
currentChatId.value = tableData.value[index].id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const ChatRecordRef = ref()
|
const ChatRecordRef = ref()
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const paginationConfig = reactive({
|
const paginationConfig = reactive({
|
||||||
@ -107,36 +172,18 @@ const paginationConfig = reactive({
|
|||||||
total: 0
|
total: 0
|
||||||
})
|
})
|
||||||
const tableData = ref<any[]>([])
|
const tableData = ref<any[]>([])
|
||||||
|
const tableIndexMap = computed<Dict<number>>(() => {
|
||||||
|
return tableData.value
|
||||||
|
.map((row, index) => ({
|
||||||
|
[row.id]: index
|
||||||
|
}))
|
||||||
|
.reduce((pre, next) => ({ ...pre, ...next }), {})
|
||||||
|
})
|
||||||
const history_day = ref(7)
|
const history_day = ref(7)
|
||||||
const search = ref('')
|
const search = ref('')
|
||||||
const detail = ref<any>(null)
|
const detail = ref<any>(null)
|
||||||
|
|
||||||
const currentChatId = ref('')
|
const currentChatId = ref<string>('')
|
||||||
|
|
||||||
// watch(
|
|
||||||
// () => currentChatId.value,
|
|
||||||
// (val) => {
|
|
||||||
// const index = tableData.value.findIndex((item: any) => item.id === val)
|
|
||||||
// if (isFirst(index)) {
|
|
||||||
// prevChatId.value = ''
|
|
||||||
// } else {
|
|
||||||
// prevChatId.value = tableData.value[index - 1]?.id
|
|
||||||
// }
|
|
||||||
// console.log(isLast(index))
|
|
||||||
// if (isLast(index)) {
|
|
||||||
// nextChatId.value = ''
|
|
||||||
// } else {
|
|
||||||
// if (tableData.value[index + 1]) {
|
|
||||||
// nextChatId.value = tableData.value[index + 1]?.id
|
|
||||||
// // } else {
|
|
||||||
// // paginationConfig.current_page += 1
|
|
||||||
// // getList()
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// },
|
|
||||||
// { immediate: true }
|
|
||||||
// )
|
|
||||||
|
|
||||||
function isFirst(index: number) {
|
function isFirst(index: number) {
|
||||||
if (index === 0 && paginationConfig.current_page === 1) {
|
if (index === 0 && paginationConfig.current_page === 1) {
|
||||||
@ -160,7 +207,7 @@ function isLast(index: number) {
|
|||||||
|
|
||||||
function rowClickHandle(row: any) {
|
function rowClickHandle(row: any) {
|
||||||
currentChatId.value = row.id
|
currentChatId.value = row.id
|
||||||
ChatRecordRef.value.open(row.id)
|
ChatRecordRef.value.open()
|
||||||
}
|
}
|
||||||
|
|
||||||
const setRowClass = ({ row }: any) => {
|
const setRowClass = ({ row }: any) => {
|
||||||
@ -200,7 +247,7 @@ function getList() {
|
|||||||
if (search.value) {
|
if (search.value) {
|
||||||
obj = { ...obj, search: search.value }
|
obj = { ...obj, search: search.value }
|
||||||
}
|
}
|
||||||
logApi.getChatLog(id as string, paginationConfig, obj, loading).then((res) => {
|
return logApi.getChatLog(id as string, paginationConfig, obj, loading).then((res) => {
|
||||||
tableData.value = res.data.records
|
tableData.value = res.data.records
|
||||||
if (currentChatId.value) {
|
if (currentChatId.value) {
|
||||||
currentChatId.value = tableData.value[0]?.id
|
currentChatId.value = tableData.value[0]?.id
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user