UnisKB/ui/src/views/log/index.vue

355 lines
9.9 KiB
Vue
Raw Normal View History

2023-11-15 09:42:31 +00:00
<template>
2023-12-05 03:36:11 +00:00
<LayoutContainer header="对话日志">
<div class="p-24">
<div class="mb-16">
2024-02-23 08:48:15 +00:00
<el-select v-model="history_day" class="mr-12 w-240" @change="changeHandle">
2023-12-05 03:36:11 +00:00
<el-option
v-for="item in dayOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
2023-12-06 09:30:46 +00:00
<el-input
v-model="search"
@change="getList"
placeholder="搜索"
prefix-icon="Search"
class="w-240"
clearable
2023-12-06 09:30:46 +00:00
/>
<el-button class="float-right" @click="exportLog"></el-button>
2023-12-05 03:36:11 +00:00
</div>
<app-table
2023-12-06 09:30:46 +00:00
:data="tableData"
2023-12-05 03:36:11 +00:00
:pagination-config="paginationConfig"
@sizeChange="handleSizeChange"
2023-12-06 09:30:46 +00:00
@changePage="getList"
@row-click="rowClickHandle"
2023-12-05 06:27:50 +00:00
v-loading="loading"
2023-12-08 04:42:40 +00:00
:row-class-name="setRowClass"
2023-12-27 07:31:20 +00:00
class="log-table"
2023-12-05 03:36:11 +00:00
>
2023-12-06 09:30:46 +00:00
<el-table-column prop="abstract" label="摘要" show-overflow-tooltip />
2023-12-05 03:36:11 +00:00
<el-table-column prop="chat_record_count" label="对话提问数" align="right" />
2024-01-29 06:46:40 +00:00
<el-table-column prop="star_num" align="right">
2024-01-29 09:13:59 +00:00
<template #header>
2024-03-04 06:16:25 +00:00
<div>
2024-01-29 06:46:40 +00:00
<span>用户反馈</span>
2024-03-04 06:21:39 +00:00
<el-popover :width="190" trigger="click" :visible="popoverVisible">
2024-01-29 06:46:40 +00:00
<template #reference>
<el-button
2024-03-04 06:16:25 +00:00
style="margin-top: -2px"
2024-01-29 07:44:33 +00:00
:type="filter.min_star || filter.min_trample ? 'primary' : ''"
2024-01-29 06:46:40 +00:00
link
@click="popoverVisible = !popoverVisible"
>
<el-icon><Filter /></el-icon>
</el-button>
</template>
<div class="filter">
<div class="form-item mb-16">
<div @click.stop>
赞同 >=
<el-input-number
v-model="filter.min_star"
:min="0"
:step="1"
controls-position="right"
2024-03-04 06:21:39 +00:00
style="width: 100px"
2024-01-29 06:46:40 +00:00
size="small"
2024-03-04 06:19:52 +00:00
step-strictly
2024-01-29 06:46:40 +00:00
/>
</div>
</div>
<div class="form-item mb-16">
<div @click.stop>
反对 >=
<el-input-number
v-model="filter.min_trample"
:min="0"
:step="1"
controls-position="right"
2024-03-04 06:21:39 +00:00
style="width: 100px"
2024-01-29 06:46:40 +00:00
size="small"
2024-03-04 06:19:52 +00:00
step-strictly
2024-01-29 06:46:40 +00:00
/>
</div>
</div>
</div>
<div class="text-right">
<el-button size="small" @click="filterChange('clear')"></el-button>
<el-button type="primary" @click="filterChange" size="small">确认</el-button>
</div>
</el-popover>
</div>
</template>
2023-12-05 03:36:11 +00:00
<template #default="{ row }">
2024-01-29 06:46:40 +00:00
<span class="mr-8" v-if="!row.trample_num && !row.star_num"> - </span>
<span class="mr-8" v-else>
2023-12-07 03:08:05 +00:00
<span v-if="row.star_num">
<AppIcon iconName="app-like-color"></AppIcon>
{{ row.star_num }}
</span>
2024-02-23 08:48:15 +00:00
<span v-if="row.trample_num" class="ml-8">
2023-12-07 03:08:05 +00:00
<AppIcon iconName="app-oppose-color"></AppIcon>
{{ row.trample_num }}
</span>
</span>
2023-12-05 03:36:11 +00:00
</template>
</el-table-column>
<el-table-column prop="mark_sum" label="改进标注" align="right" />
<el-table-column label="时间" width="180">
<template #default="{ row }">
{{ datetimeFormat(row.create_time) }}
</template>
</el-table-column>
2024-03-14 07:37:25 +00:00
<!-- <el-table-column label="操作" width="70" align="left">
2023-12-05 03:36:11 +00:00
<template #default="{ row }">
<el-tooltip effect="dark" content="删除" placement="top">
2023-12-07 03:08:05 +00:00
<el-button type="primary" text @click.stop="deleteLog(row)">
2023-12-05 03:36:11 +00:00
<el-icon><Delete /></el-icon>
</el-button>
</el-tooltip>
</template>
2024-03-14 07:37:25 +00:00
</el-table-column> -->
2023-12-05 03:36:11 +00:00
</app-table>
</div>
2023-12-08 10:10:47 +00:00
<ChatRecordDrawer
:next="nextChatRecord"
:pre="preChatRecord"
ref="ChatRecordRef"
2023-12-11 02:35:26 +00:00
v-model:chartId="currentChatId"
2024-01-22 02:43:51 +00:00
v-model:currentAbstract="currentAbstract"
2023-12-08 10:10:47 +00:00
:application="detail"
:pre_disable="pre_disable"
:next_disable="next_disable"
2024-01-25 07:08:25 +00:00
@refresh="refresh"
2023-12-08 10:10:47 +00:00
/>
2023-12-05 03:36:11 +00:00
</LayoutContainer>
2023-11-15 09:42:31 +00:00
</template>
<script setup lang="ts">
2023-12-08 04:42:40 +00:00
import { ref, onMounted, reactive, watch, computed } from 'vue'
2023-12-07 07:22:07 +00:00
import { useRoute } from 'vue-router'
2024-01-29 06:46:40 +00:00
import { cloneDeep } from 'lodash'
2023-12-07 07:22:07 +00:00
import ChatRecordDrawer from './component/ChatRecordDrawer.vue'
2023-12-08 10:10:47 +00:00
import { MsgSuccess, MsgConfirm, MsgError } from '@/utils/message'
2023-12-06 09:30:46 +00:00
import logApi from '@/api/log'
2023-12-05 03:36:11 +00:00
import { datetimeFormat } from '@/utils/time'
2023-12-07 11:28:38 +00:00
import useStore from '@/stores'
2023-12-08 10:10:47 +00:00
import type { Dict } from '@/api/type/common'
2023-12-07 11:28:38 +00:00
const { application } = useStore()
2023-12-05 03:36:11 +00:00
const route = useRoute()
const {
params: { id }
} = route
const dayOptions = [
{
value: 7,
label: '过去7天'
},
{
value: 30,
label: '过去30天'
},
{
value: 90,
label: '过去90天'
},
{
2023-12-05 08:30:22 +00:00
value: 183,
2023-12-05 03:36:11 +00:00
label: '过去半年'
}
]
2023-12-07 07:22:07 +00:00
2023-12-11 02:35:26 +00:00
const ChatRecordRef = ref()
const loading = ref(false)
const paginationConfig = reactive({
current_page: 1,
page_size: 20,
total: 0
})
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 search = ref('')
const detail = ref<any>(null)
const currentChatId = ref<string>('')
2024-01-22 02:43:51 +00:00
const currentAbstract = ref<string>('')
2024-01-29 06:46:40 +00:00
const popoverVisible = ref(false)
const defaultFilter = {
min_star: 0,
min_trample: 0,
comparer: 'and'
}
const filter = ref<any>({
min_star: 0,
min_trample: 0,
comparer: 'and'
})
function filterChange(val: string) {
if (val === 'clear') {
filter.value = cloneDeep(defaultFilter)
}
getList()
popoverVisible.value = false
}
2023-12-11 02:35:26 +00:00
2023-12-08 10:10:47 +00:00
/**
* 下一页
*/
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
) {
return
}
paginationConfig.current_page = paginationConfig.current_page + 1
getList().then(() => {
index = 0
currentChatId.value = tableData.value[index].id
2024-01-22 02:43:51 +00:00
currentAbstract.value = tableData.value[index].abstract
2023-12-08 10:10:47 +00:00
})
} else {
currentChatId.value = tableData.value[index].id
2024-01-22 02:43:51 +00:00
currentAbstract.value = tableData.value[index].abstract
2023-12-08 10:10:47 +00:00
}
}
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) {
return
}
paginationConfig.current_page = paginationConfig.current_page - 1
getList().then((ok) => {
index = paginationConfig.page_size - 1
currentChatId.value = tableData.value[index].id
2024-01-22 02:43:51 +00:00
currentAbstract.value = tableData.value[index].abstract
2023-12-08 10:10:47 +00:00
})
} else {
currentChatId.value = tableData.value[index].id
2024-01-22 02:43:51 +00:00
currentAbstract.value = tableData.value[index].abstract
2023-12-08 10:10:47 +00:00
}
}
function rowClickHandle(row: any, column?: any) {
if (column && column.type === 'selection') {
return
}
2023-12-08 04:42:40 +00:00
currentChatId.value = row.id
2024-01-22 02:43:51 +00:00
currentAbstract.value = row.abstract
2023-12-08 10:10:47 +00:00
ChatRecordRef.value.open()
2023-12-06 09:30:46 +00:00
}
2023-12-05 06:27:50 +00:00
2023-12-08 04:42:40 +00:00
const setRowClass = ({ row }: any) => {
2024-04-15 10:46:03 +00:00
return currentChatId.value === row?.id ? 'highlight' : ''
2023-12-08 04:42:40 +00:00
}
2023-12-07 03:08:05 +00:00
function deleteLog(row: any) {
MsgConfirm(`是否删除对话:${row.abstract} ?`, `删除后无法恢复,请谨慎操作。`, {
confirmButtonText: '删除',
confirmButtonClass: 'danger'
})
.then(() => {
loading.value = true
logApi.delChatLog(id as string, row.id, loading).then(() => {
MsgSuccess('删除成功')
getList()
})
})
.catch(() => {})
}
2023-12-05 06:27:50 +00:00
function handleSizeChange() {
2023-12-06 09:30:46 +00:00
paginationConfig.current_page = 1
getList()
2023-12-05 03:36:11 +00:00
}
2023-12-05 06:27:50 +00:00
function changeHandle(val: number) {
history_day.value = val
2023-12-06 09:30:46 +00:00
paginationConfig.current_page = 1
2023-12-05 06:27:50 +00:00
getList()
2023-12-05 03:36:11 +00:00
}
function getList() {
2023-12-07 03:08:05 +00:00
let obj: any = {
2024-01-29 06:46:40 +00:00
history_day: history_day.value,
...filter.value
2023-12-06 09:30:46 +00:00
}
if (search.value) {
2024-01-23 08:49:53 +00:00
obj = { ...obj, abstract: search.value }
2023-12-06 09:30:46 +00:00
}
2023-12-08 10:10:47 +00:00
return logApi.getChatLog(id as string, paginationConfig, obj, loading).then((res) => {
2023-12-06 09:30:46 +00:00
tableData.value = res.data.records
2023-12-08 04:42:40 +00:00
if (currentChatId.value) {
currentChatId.value = tableData.value[0]?.id
}
2023-12-06 09:30:46 +00:00
paginationConfig.total = res.data.total
2023-12-05 03:36:11 +00:00
})
}
2023-12-07 11:28:38 +00:00
function getDetail() {
application.asyncGetApplicationDetail(id as string, loading).then((res: any) => {
detail.value = res.data
})
}
const exportLog = () => {
if (detail.value) {
let obj: any = {
history_day: history_day.value,
...filter.value
}
if (search.value) {
obj = { ...obj, abstract: search.value }
}
logApi.exportChatLog(detail.value.id, detail.value.name, obj, loading)
}
}
2024-01-25 07:08:25 +00:00
function refresh() {
getList()
}
2023-12-05 03:36:11 +00:00
onMounted(() => {
getList()
2023-12-07 11:28:38 +00:00
getDetail()
2023-12-05 03:36:11 +00:00
})
2023-11-15 09:42:31 +00:00
</script>
2023-12-27 07:31:20 +00:00
<style lang="scss" scoped>
.log-table tr {
cursor: pointer;
}
</style>