chore(addon/aikefu): 调整会话列表列宽度及消息列表的分页处理
This commit is contained in:
@@ -159,8 +159,8 @@
|
||||
width: '100%',
|
||||
cols: [[
|
||||
{type: 'checkbox', fixed: 'left'},
|
||||
{field: 'conversation_id', title: '会话ID', width: 280, align: 'center'},
|
||||
{field: 'user_id', title: '用户ID', width: 200, align: 'center'},
|
||||
{field: 'conversation_id', title: '会话ID', width: 300, align: 'center'},
|
||||
{field: 'user_id', title: '用户ID', width: 120, align: 'center'},
|
||||
{field: 'name', title: '会话名称', width: 180, align: 'center'},
|
||||
{field: 'status', title: '状态', width: 100, align: 'center', templet: '#statusTpl' },
|
||||
{field: 'create_time', title: '创建时间', width: 180, align: 'center'},
|
||||
|
||||
@@ -158,7 +158,7 @@
|
||||
}
|
||||
|
||||
/* 分页样式 */
|
||||
.layui-fixbar {
|
||||
#msg_pagination {
|
||||
text-align: center;
|
||||
margin-top: 20px;
|
||||
}
|
||||
@@ -239,7 +239,7 @@
|
||||
</div>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div class="layui-fixbar" id="msg_pagination"></div>
|
||||
<div id="msg_pagination"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
@@ -313,9 +313,39 @@
|
||||
data: requestData,
|
||||
dataType: 'json',
|
||||
success: function(res) {
|
||||
// 调试:打印原始数据
|
||||
console.log('消息API返回原始数据:', res);
|
||||
|
||||
// 确保res存在
|
||||
if (!res) {
|
||||
layer.msg('服务器返回数据为空', {icon: 2});
|
||||
return;
|
||||
}
|
||||
|
||||
if (res.code === 0) {
|
||||
var list = res.data.messages;
|
||||
total = res.data.page_info.total;
|
||||
// 适配后端返回的格式
|
||||
// 检查data字段是否存在
|
||||
if (!res.data) {
|
||||
layer.msg('服务器返回数据格式错误:缺少data字段', {icon: 2});
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取消息列表,确保是数组
|
||||
var list = Array.isArray(res.data.messages) ? res.data.messages : [];
|
||||
|
||||
// 获取总记录数
|
||||
// 支持多种可能的返回格式
|
||||
var totalCount = 0;
|
||||
if (res.data.page_info && typeof res.data.page_info.total === 'number') {
|
||||
totalCount = res.data.page_info.total;
|
||||
} else if (typeof res.count === 'number') {
|
||||
totalCount = res.count;
|
||||
} else if (typeof res.data.total === 'number') {
|
||||
totalCount = res.data.total;
|
||||
}
|
||||
|
||||
// 更新总记录数
|
||||
total = totalCount;
|
||||
|
||||
var html = '';
|
||||
if (list.length > 0) {
|
||||
@@ -351,10 +381,11 @@
|
||||
// 渲染分页
|
||||
renderPagination();
|
||||
} else {
|
||||
layer.msg('加载失败:' + res.message, {icon: 2});
|
||||
layer.msg('加载失败:' + (res.message || '未知错误'), {icon: 2});
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
error: function(xhr, status, error) {
|
||||
console.error('消息API请求失败:', error);
|
||||
layer.msg('请求失败,请稍后重试', {icon: 2});
|
||||
}
|
||||
});
|
||||
@@ -367,6 +398,12 @@
|
||||
return;
|
||||
}
|
||||
|
||||
// 确保分页容器存在
|
||||
if ($('#msg_pagination').length === 0) {
|
||||
console.error('分页容器不存在');
|
||||
return;
|
||||
}
|
||||
|
||||
laypage.render({
|
||||
elem: 'msg_pagination',
|
||||
count: total,
|
||||
@@ -375,9 +412,20 @@
|
||||
layout: ['prev', 'page', 'next', 'count', 'skip'],
|
||||
jump: function(obj, first) {
|
||||
if (!first) {
|
||||
page = obj.curr;
|
||||
// 验证页码有效性
|
||||
var newPage = parseInt(obj.curr);
|
||||
if (isNaN(newPage) || newPage < 1) {
|
||||
console.error('无效的页码:', obj.curr);
|
||||
return;
|
||||
}
|
||||
|
||||
page = newPage;
|
||||
loadMessageList();
|
||||
}
|
||||
},
|
||||
done: function(obj, first) {
|
||||
// 分页渲染完成后的回调
|
||||
console.log('分页渲染完成,当前页:', obj.curr, '总记录数:', obj.count, '每页数量:', obj.limit);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user