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

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; this.loading = false;
if (response.status === 'success' && response.data) { if (response.status === 'success' && response.data) {
// //
const records = (response.data.items || []).map(record => ({ this.dnsRecords = (response.data.items || []).map(record => ({
...record, ...record,
editing: false, editing: false,
isNew: false isNew: false
})); }));
//
this.dnsRecords = this.sortRecordsByType(records);
this.pagination = { this.pagination = {
pageno: response.data.pageno || 1, pageno: response.data.pageno || 1,
limit: response.data.limit || 20, limit: response.data.limit || 20,
@ -470,9 +467,8 @@ export default {
isNew: true isNew: true
}; };
// //
this.dnsRecords.push(newRecord); 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() { getVisiblePages() {
const current = this.pagination.pageno; const current = this.pagination.pageno;

View File

@ -875,7 +875,8 @@ def get_west_domain_dns_records(**data):
if not domain: if not domain:
return {"status": "error", "message": "缺少域名参数"} 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": if response.get("status") == "error":
return response return response
@ -886,16 +887,29 @@ def get_west_domain_dns_records(**data):
return {"status": "error", "message": "API查询失败"} return {"status": "error", "message": "API查询失败"}
data = response.get("data", {}) 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 { return {
"status": "success", "status": "success",
"data": { "data": {
"pageno": data.get("pageno", 1), "pageno": pageno,
"limit": data.get("limit", 20), "limit": limit,
"total": data.get("total", 0), "total": total,
"pagecount": data.get("pagecount", 0), "pagecount": pagecount,
"items": data.get("items", []) "items": current_page_items
} }
} }