域名解析记录列表实现后端通过记录类型排版并修复前端按类型排序

This commit is contained in:
jingrow 2025-08-04 21:14:33 +08:00
parent 88e8491720
commit c53f4bf421
2 changed files with 22 additions and 21 deletions

View File

@ -385,15 +385,12 @@ export default {
this.loading = false;
if (response.status === 'success' && response.data) {
//
const records = (response.data.items || []).map(record => ({
this.dnsRecords = (response.data.items || []).map(record => ({
...record,
editing: false,
isNew: false
}));
//
this.dnsRecords = this.sortRecordsByType(records);
this.pagination = {
pageno: response.data.pageno || 1,
limit: response.data.limit || 20,
@ -470,9 +467,8 @@ export default {
isNew: true
};
//
//
this.dnsRecords.push(newRecord);
this.dnsRecords = this.sortRecordsByType(this.dnsRecords);
},
//
@ -721,15 +717,6 @@ export default {
// DNS
sortRecordsByType(records) {
return records.sort((a, b) => {
const typeA = a.type || '';
const typeB = b.type || '';
return typeA.localeCompare(typeB);
});
},
//
getVisiblePages() {
const current = this.pagination.pageno;

View File

@ -875,7 +875,8 @@ def get_west_domain_dns_records(**data):
if not domain:
return {"status": "error", "message": "缺少域名参数"}
response = client.get_dns_records_paginated(domain, limit, pageno)
# 获取所有记录(不分页)
response = client.get_dns_records_paginated(domain, 1000, 1) # 获取足够多的记录
if response.get("status") == "error":
return response
@ -886,16 +887,29 @@ def get_west_domain_dns_records(**data):
return {"status": "error", "message": "API查询失败"}
data = response.get("data", {})
all_items = data.get("items", [])
# 对所有记录按类型排序
sorted_items = sorted(all_items, key=lambda x: x.get('type', ''))
# 计算分页
total = len(sorted_items)
pagecount = (total + limit - 1) // limit
start_index = (pageno - 1) * limit
end_index = start_index + limit
# 返回当前页的记录
current_page_items = sorted_items[start_index:end_index]
# 返回格式化的解析记录信息
return {
"status": "success",
"data": {
"pageno": data.get("pageno", 1),
"limit": data.get("limit", 20),
"total": data.get("total", 0),
"pagecount": data.get("pagecount", 0),
"items": data.get("items", [])
"pageno": pageno,
"limit": limit,
"total": total,
"pagecount": pagecount,
"items": current_page_items
}
}