feat(机架管理): 添加后端筛选功能并优化前端交互
- 后端路由添加对房间ID、状态和关键字的筛选支持 - 前端移除本地筛选逻辑,改为使用后端筛选参数 - 添加筛选条件变化时自动重置分页并重新加载数据
This commit is contained in:
+23
-4
@@ -17,11 +17,30 @@ router.get('/', async (req, res) => {
|
||||
const pageSize = parseInt(req.query.pageSize) || 10;
|
||||
const offset = (page - 1) * pageSize;
|
||||
|
||||
// 获取总记录数
|
||||
const total = await Rack.count();
|
||||
|
||||
// 筛选参数
|
||||
const { roomId, status, keyword } = req.query;
|
||||
|
||||
// 构建查询条件
|
||||
const where = {};
|
||||
if (roomId && roomId !== 'all') {
|
||||
where.roomId = roomId;
|
||||
}
|
||||
if (status && status !== 'all') {
|
||||
where.status = status;
|
||||
}
|
||||
if (keyword) {
|
||||
where[require('sequelize').Op.or] = [
|
||||
{ rackId: { [require('sequelize').Op.like]: `%${keyword}%` } },
|
||||
{ name: { [require('sequelize').Op.like]: `%${keyword}%` } }
|
||||
];
|
||||
}
|
||||
|
||||
// 获取总记录数(带筛选条件)
|
||||
const total = await Rack.count({ where });
|
||||
|
||||
// 获取分页数据
|
||||
const racks = await Rack.findAll({
|
||||
where,
|
||||
include: [
|
||||
{ model: Room },
|
||||
{ model: Device }
|
||||
@@ -29,7 +48,7 @@ router.get('/', async (req, res) => {
|
||||
limit: pageSize,
|
||||
offset: offset
|
||||
});
|
||||
|
||||
|
||||
// 返回带分页信息的响应
|
||||
res.json({
|
||||
racks,
|
||||
|
||||
Reference in New Issue
Block a user