可信代码库-AI大模型对话历史分页及搜索功能对接
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
></d-search>
|
||||
<div class="mt-3 px-20">
|
||||
<d-table
|
||||
v-if="currentDhlsData.length>0"
|
||||
class="jyh-table"
|
||||
:data="currentDhlsData"
|
||||
row-key="id"
|
||||
@@ -32,6 +33,7 @@
|
||||
</template>
|
||||
</d-column>
|
||||
</d-table>
|
||||
<NoData v-else :small="false"></NoData>
|
||||
</div>
|
||||
<div class="mt-20 mb-20 flex justify-end">
|
||||
<d-pagination
|
||||
@@ -56,6 +58,7 @@
|
||||
></d-search>
|
||||
<div class="mt-3 px-20">
|
||||
<d-table
|
||||
v-if="currentCollectionData.length>0"
|
||||
class="jyh-table"
|
||||
:data="currentCollectionData"
|
||||
row-key="id"
|
||||
@@ -76,6 +79,7 @@
|
||||
</template>
|
||||
</d-column>
|
||||
</d-table>
|
||||
<NoData v-else :small="false"></NoData>
|
||||
</div>
|
||||
<div class="mt-20 mb-20 flex justify-end">
|
||||
<d-pagination
|
||||
@@ -111,6 +115,7 @@
|
||||
import { ref, computed, watch } from 'vue';
|
||||
import axios from 'axios';
|
||||
import { Message } from 'vue-devui/message';
|
||||
import NoData from '@/components/NoData/NoData.vue';
|
||||
|
||||
// 接收父组件传递的用户名
|
||||
const props = defineProps(['username']);
|
||||
@@ -154,9 +159,14 @@ const getQuestionHistory = async () => {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const { data } = await axios.get(
|
||||
`${import.meta.env.VITE_AI_API_HOST}/api/conversationList?userId=${props.username}&list_type=history`
|
||||
);
|
||||
const {data} = await axios.post(VITE_AI_API_HOST + '/api/conversationList', {
|
||||
"userId": props.username,
|
||||
"list_type": "history",
|
||||
"is_manage": true,
|
||||
"page": currentPage.value,
|
||||
"size": pageSize.value,
|
||||
"search": searchText.value
|
||||
});
|
||||
if (data.conversationList) {
|
||||
dhlsList.value = data.conversationList
|
||||
}
|
||||
@@ -172,9 +182,14 @@ const getQuestionCollection = async () => {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const { data } = await axios.get(
|
||||
`${import.meta.env.VITE_AI_API_HOST}/api/conversationList?userId=${props.username}&list_type=collection`
|
||||
);
|
||||
const {data} = await axios.post(VITE_AI_API_HOST + '/api/conversationList', {
|
||||
"userId": props.username,
|
||||
"list_type": "collection",
|
||||
"is_manage": true,
|
||||
"page": currentPage.value,
|
||||
"size": pageSize.value,
|
||||
"search": searchText.value
|
||||
});
|
||||
if (data.conversationList) {
|
||||
collectionList.value = data.conversationList
|
||||
}
|
||||
@@ -186,27 +201,65 @@ const getQuestionCollection = async () => {
|
||||
// 打开模态框时加载数据
|
||||
const openModal = async () => {
|
||||
visible.value = true;
|
||||
await getQuestionHistory();
|
||||
await getQuestionCollection();
|
||||
await fetchData(); // 调用接口
|
||||
currentPage.value = 1; // 重置页码
|
||||
};
|
||||
|
||||
// 搜索处理
|
||||
const handleSearch = () => {
|
||||
// 搜索时触发数据加载
|
||||
const handleSearch = async () => {
|
||||
currentPage.value = 1; // 搜索后重置到第一页
|
||||
await fetchData(); // 调用接口
|
||||
};
|
||||
|
||||
// 分页大小变化
|
||||
const handlePageSizeChange = (size) => {
|
||||
// 分页大小变化时触发数据加载
|
||||
const handlePageSizeChange = async (size) => {
|
||||
pageSize.value = size;
|
||||
currentPage.value = 1;
|
||||
currentPage.value = 1; // 切换页大小后重置到第一页
|
||||
await fetchData(); // 调用接口
|
||||
};
|
||||
|
||||
// 页码变化
|
||||
const handlePageChange = (page) => {
|
||||
// 页码变化时触发数据加载
|
||||
const handlePageChange = async (page) => {
|
||||
currentPage.value = page;
|
||||
await fetchData(); // 调用接口
|
||||
};
|
||||
|
||||
// 统一数据获取方法
|
||||
const fetchData = async () => {
|
||||
if (!props.username) {
|
||||
Message.error('请先登录');
|
||||
return;
|
||||
}
|
||||
|
||||
// 构建公共参数
|
||||
const commonParams = {
|
||||
userId: props.username,
|
||||
is_manage: true,
|
||||
page: currentPage.value,
|
||||
size: pageSize.value,
|
||||
search: searchText.value,
|
||||
};
|
||||
|
||||
// 获取对话历史
|
||||
const historyData = await axios.post(
|
||||
`${import.meta.env.VITE_AI_API_HOST}/api/conversationList`,
|
||||
{ ...commonParams, list_type: 'history' }
|
||||
);
|
||||
if (historyData.data.conversationList) {
|
||||
dhlsList.value = historyData.data.conversationList;
|
||||
}
|
||||
|
||||
// 获取收藏对话
|
||||
const collectionData = await axios.post(
|
||||
`${import.meta.env.VITE_AI_API_HOST}/api/conversationList`,
|
||||
{ ...commonParams, list_type: 'collection' }
|
||||
);
|
||||
if (collectionData.data.conversationList) {
|
||||
collectionList.value = collectionData.data.conversationList;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// 选中的行ID
|
||||
const selectedRowKeys = ref([]);
|
||||
// 复选框选中状态变化
|
||||
@@ -235,8 +288,7 @@ const handleDelete = async (conversationIds, tabType) => {
|
||||
);
|
||||
if (res.data.code === 20000) {
|
||||
Message.success(res.data.message || '删除成功');
|
||||
getQuestionHistory()
|
||||
getQuestionCollection()
|
||||
await fetchData(); // 删除后重新加载数据
|
||||
selectedRowKeys.value = []; // 清空选中项
|
||||
} else {
|
||||
Message.error(res.data.message || '删除失败');
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<Card class="ViewHistoryAside">
|
||||
<d-tabs class="jyh-tabs-4" type="wrapped" v-model="selectTab">
|
||||
<d-tab id="dhls" title="对话历史">
|
||||
<d-search icon-position="left" style="width: 100%" placeholder="请输入搜索软件名称" v-model="searchText" @change="handleSearch"></d-search>
|
||||
<d-search icon-position="left" style="width: 100%" placeholder="请输入搜索软件名称" v-model="searchText" @change="loadData"></d-search>
|
||||
<!-- 可滚动内容区域 -->
|
||||
<div class="scrollable-content">
|
||||
<d-collapse class="jyh-collapse" v-model="collapseValue">
|
||||
@@ -101,11 +101,12 @@
|
||||
style="width: 60px"
|
||||
size="sm"
|
||||
class="jyh-select"
|
||||
@value-change="handleHistoryLimitChange"
|
||||
>
|
||||
<d-option value="10">10</d-option>
|
||||
<d-option value="20">20</d-option>
|
||||
<d-option value="30">30</d-option>
|
||||
<d-option value="0">0</d-option>
|
||||
<d-option value="0">不限</d-option>
|
||||
</d-select>
|
||||
</div>
|
||||
<div class="control-right">
|
||||
@@ -120,7 +121,7 @@
|
||||
</div>
|
||||
</d-tab>
|
||||
<d-tab id="scdh" title="收藏对话">
|
||||
<d-search icon-position="left" style="width: 100%" placeholder="请输入搜索软件名称" v-model="searchText" @change="handleSearch"></d-search>
|
||||
<d-search icon-position="left" style="width: 100%" placeholder="请输入搜索软件名称" v-model="searchText" @change="loadData"></d-search>
|
||||
<!-- 可滚动内容区域 -->
|
||||
<div class="scrollable-content">
|
||||
<d-collapse class="jyh-collapse" v-model="collapseValue">
|
||||
@@ -222,15 +223,15 @@
|
||||
<d-option value="0">0</d-option>
|
||||
</d-select>
|
||||
</div>
|
||||
<!-- <div class="control-right">-->
|
||||
<!-- <d-button class="jyh-button2" variant="solid" @click="openBatchManageModal">-->
|
||||
<!-- <template #icon>-->
|
||||
<!-- <d-icon name="icon-property-setting"></d-icon>-->
|
||||
<!-- </template>-->
|
||||
<!-- 批量管理-->
|
||||
<!-- </d-button>-->
|
||||
<!-- <BatchManageModal ref="BatchManageModalRef"/>-->
|
||||
<!-- </div>-->
|
||||
<div class="control-right">
|
||||
<d-button class="jyh-button2" variant="solid" @click="openBatchManageModal">
|
||||
<template #icon>
|
||||
<d-icon name="icon-property-setting"></d-icon>
|
||||
</template>
|
||||
批量管理
|
||||
</d-button>
|
||||
<BatchManageModal ref="BatchManageModalRef"/>
|
||||
</div>
|
||||
</div>
|
||||
</d-tab>
|
||||
</d-tabs>
|
||||
@@ -260,6 +261,20 @@ const BatchManageModalRef = ref(null);
|
||||
|
||||
const { formatTime } = useTimeFormat();
|
||||
|
||||
// 监听historyLimit变化,更新page.size并重置页码
|
||||
const handleHistoryLimitChange = (val) => {
|
||||
debugger
|
||||
page.value.size = Number(val) || Infinity; // 0转换为Infinity表示不限
|
||||
page.value.pageNum = 1; // 重置为第一页
|
||||
loadData(); // 重新加载数据
|
||||
};
|
||||
|
||||
|
||||
// 统一数据加载方法
|
||||
const loadData = async () => {
|
||||
await getQuestionHistory();
|
||||
await getQuestionCollection();
|
||||
};
|
||||
|
||||
const handleSelect = (item) => {
|
||||
// 触发父组件事件,传递选中的 convId
|
||||
@@ -377,11 +392,23 @@ const cardList = ref([
|
||||
]);
|
||||
const dhlsList = ref([]);
|
||||
const collectionList = ref([]);
|
||||
const page = ref({
|
||||
pageNum: 1,
|
||||
size: 10
|
||||
});
|
||||
|
||||
const VITE_AI_API_HOST = import.meta.env.VITE_AI_API_HOST;
|
||||
const getQuestionHistory = async () => {
|
||||
if(props.username) {
|
||||
const {data} = await axios.get(VITE_AI_API_HOST + '/api/conversationList?userId='+props.username + '&list_type=history');
|
||||
const {data} = await axios.post(VITE_AI_API_HOST + '/api/conversationList', {
|
||||
"userId": props.username,
|
||||
"list_type": "history",
|
||||
"is_manage": true,
|
||||
"page": page.value.pageNum,
|
||||
"size": page.value.size,
|
||||
"search": searchText.value
|
||||
});
|
||||
|
||||
if(data.conversationList) {
|
||||
dhlsList.value = data.conversationList
|
||||
} else {
|
||||
@@ -393,7 +420,14 @@ const getQuestionHistory = async () => {
|
||||
};
|
||||
const getQuestionCollection = async () => {
|
||||
if(props.username) {
|
||||
const {data} = await axios.get(VITE_AI_API_HOST + '/api/conversationList?userId='+props.username + '&list_type=collection');
|
||||
const {data} = await axios.post(VITE_AI_API_HOST + '/api/conversationList', {
|
||||
"userId": props.username,
|
||||
"list_type": "collection",
|
||||
"is_manage": true,
|
||||
"page": page.value.pageNum,
|
||||
"size": page.value.size,
|
||||
"search": searchText.value
|
||||
});
|
||||
if(data.conversationList) {
|
||||
collectionList.value = data.conversationList
|
||||
} else {
|
||||
@@ -421,8 +455,7 @@ const handleDelete = async (conversationIds, tabType) => {
|
||||
);
|
||||
if (res.data.code === 20000) {
|
||||
Message.success(res.data.message || '删除成功');
|
||||
getQuestionHistory()
|
||||
getQuestionCollection()
|
||||
loadData()
|
||||
} else {
|
||||
Message.error(res.data.message || '删除失败');
|
||||
}
|
||||
@@ -434,8 +467,7 @@ const handleDelete = async (conversationIds, tabType) => {
|
||||
|
||||
|
||||
onMounted(() => {
|
||||
getQuestionHistory()
|
||||
getQuestionCollection()
|
||||
loadData()
|
||||
});
|
||||
|
||||
defineExpose({
|
||||
|
||||
Reference in New Issue
Block a user