修复前端防火墙列表页排序问题

This commit is contained in:
jingrow 2025-08-09 21:48:03 +08:00
parent 538699d0f6
commit ba43a9954c
2 changed files with 15 additions and 11 deletions

View File

@ -69,9 +69,6 @@
@change="toggleSelectAll"
/>
</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
规则ID
</th>
<th class="px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
协议
</th>
@ -101,9 +98,6 @@
:disabled="rule.isNew"
/>
</td>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-900">
{{ rule.rule_id || '-' }}
</td>
<td class="px-4 py-4 whitespace-nowrap">
<!-- 协议编辑 -->
<div v-if="rule.editing" class="flex items-center space-x-2">
@ -143,7 +137,16 @@
</div>
</td>
<td class="px-4 py-4 whitespace-nowrap">
<div class="text-sm text-gray-900 max-w-xs truncate" :title="rule.source_cidr_ip">
<!-- 来源IP编辑 -->
<div v-if="rule.editing" class="flex items-center space-x-2">
<input
v-model="rule.source_cidr_ip"
type="text"
class="w-32 px-2 py-1 text-sm border border-gray-300 rounded focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
placeholder="来源IP"
/>
</div>
<div v-else class="text-sm text-gray-900 max-w-xs truncate" :title="rule.source_cidr_ip">
{{ rule.source_cidr_ip || '0.0.0.0/0' }}
</div>
</td>

View File

@ -1845,7 +1845,7 @@ def get_jingrow_firewall_rules(**data):
"""获取防火墙规则(从本地数据库获取,支持分页)"""
try:
instance_id = data.get('instance_id')
limit = data.get('limit', 20)
limit = data.get('limit', 10)
pageno = data.get('pageno', 1)
if not instance_id:
@ -1867,7 +1867,8 @@ def get_jingrow_firewall_rules(**data):
firewall_rules = jingrow.get_all(
"Firewall Rules",
{"parent": server_record.name},
["name", "rule_id", "rule_protocol", "port", "source_cidr_ip", "remark"]
["name", "rule_id", "rule_protocol", "port", "source_cidr_ip", "remark", "idx"],
order_by="idx desc"
)
# 转换为API格式的数据结构
@ -1882,8 +1883,8 @@ def get_jingrow_firewall_rules(**data):
}
all_items.append(item)
# 对所有记录按协议排序
sorted_items = sorted(all_items, key=lambda x: x.get('rule_protocol', ''))
# 数据已经按idx降序排列最新添加的在前面无需再次排序
sorted_items = all_items
# 计算分页
total = len(sorted_items)