修复域名所有者模板列表页分页功能

This commit is contained in:
jingrow 2025-08-06 18:38:45 +08:00
parent 0b355b12b3
commit bf0fce72cd
2 changed files with 157 additions and 39 deletions

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="space-y-4"> <div class="space-y-4">
<div class="mx-5 mt-5"> <div>
<div class="flex flex-col sm:flex-row gap-4 items-center"> <div class="flex flex-col sm:flex-row gap-4 items-center">
<div class="w-full sm:w-1/2"> <div class="w-full sm:w-1/2">
<div class="flex gap-2"> <div class="flex gap-2">
@ -34,7 +34,7 @@
</div> </div>
<!-- 列表内容 --> <!-- 列表内容 -->
<div class="rounded-lg border border-gray-200 bg-white mt-4"> <div class="rounded-lg border border-gray-200 bg-white my-4">
<!-- 表头 --> <!-- 表头 -->
<div class="grid grid-cols-12 gap-4 border-b border-gray-200 bg-gray-50 px-6 py-3 text-sm font-medium text-gray-700"> <div class="grid grid-cols-12 gap-4 border-b border-gray-200 bg-gray-50 px-6 py-3 text-sm font-medium text-gray-700">
<div class="col-span-4">所有者名称</div> <div class="col-span-4">所有者名称</div>
@ -112,28 +112,46 @@
</div> </div>
<!-- 分页 --> <!-- 分页 -->
<div v-if="pagination.total > pagination.limit" class="flex items-center justify-between mt-4"> <div v-if="pagination.total > pagination.limit" class="flex flex-col items-center space-y-4">
<div class="text-sm text-gray-700"> <div class="text-sm text-gray-700">
显示 {{ (pagination.pageno - 1) * pagination.limit + 1 }} 显示 {{ (pagination.pageno - 1) * pagination.limit + 1 }} -
{{ Math.min(pagination.pageno * pagination.limit, pagination.total) }} {{ Math.min(pagination.pageno * pagination.limit, pagination.total) }}
{{ pagination.total }} 条记录 {{ pagination.total }} 条记录
</div> </div>
<div class="flex gap-2"> <div class="flex items-center space-x-2">
<Button <Button
@click="previousPage" @click="previousPage"
:disabled="pagination.pageno <= 1" :disabled="pagination.pageno <= 1"
variant="outline" variant="outline"
size="sm" size="sm"
class="px-3"
> >
上一页
</Button> </Button>
<div class="flex items-center space-x-1">
<Button
v-for="page in getVisiblePages()"
:key="page"
@click="changePage(page)"
:class="[
'px-3 py-1 text-sm rounded',
page === pagination.pageno
? '!bg-[#1fc76f] text-white'
: 'bg-white text-gray-700 border border-gray-300 hover:bg-gray-50'
]"
:disabled="page === pagination.pageno"
>
{{ page }}
</Button>
</div>
<Button <Button
@click="nextPage" @click="nextPage"
:disabled="pagination.pageno >= pagination.pagecount" :disabled="pagination.pageno >= pagination.pagecount"
variant="outline" variant="outline"
size="sm" size="sm"
class="px-3"
> >
下一页
</Button> </Button>
</div> </div>
</div> </div>
@ -461,7 +479,7 @@ export default {
selectedStatus: '', selectedStatus: '',
pagination: { pagination: {
pageno: 1, pageno: 1,
limit: 20, limit: 10,
total: 0, total: 0,
pagecount: 0 pagecount: 0
}, },
@ -487,31 +505,20 @@ export default {
}, },
computed: { computed: {
filteredOwners() { filteredOwners() {
let filtered = [...this.owners]; //
return this.owners;
// }
if (this.searchQuery) { },
const query = this.searchQuery.toLowerCase(); watch: {
filtered = filtered.filter(owner => { //
const displayName = this.getDisplayName(owner).toLowerCase(); searchQuery() {
const title = (owner.title || '').toLowerCase(); this.pagination.pageno = 1; //
const email = (owner.c_em || '').toLowerCase(); this.fetchOwners();
return displayName.includes(query) || title.includes(query) || email.includes(query); },
}); //
} selectedStatus() {
this.pagination.pageno = 1; //
// this.fetchOwners();
if (this.selectedStatus) {
filtered = filtered.filter(owner => {
// r_status
// 0: , 1: , 2: , 3: , 4: , 5:
const rStatus = owner.r_status;
const isVerified = rStatus === '1'; // '1'
return String(isVerified ? '1' : '0') === this.selectedStatus;
});
}
return filtered;
} }
}, },
methods: { methods: {
@ -604,11 +611,21 @@ export default {
try { try {
const ownersRequest = createResource({ const ownersRequest = createResource({
url: 'jcloud.api.domain_west.get_domain_owners', url: 'jcloud.api.domain_west.get_domain_owners',
params: {
limit: this.pagination.limit,
pageno: this.pagination.pageno,
searchQuery: this.searchQuery,
selectedStatus: this.selectedStatus
},
onSuccess: (response) => { onSuccess: (response) => {
if (response.status === 'Success') { if (response.status === 'Success') {
this.owners = response.data || []; this.owners = response.data.items || [];
this.pagination.total = this.owners.length; this.pagination = {
this.pagination.pagecount = Math.ceil(this.pagination.total / this.pagination.limit); pageno: response.data.pageno || 1,
limit: response.data.limit || 20,
total: response.data.total || 0,
pagecount: response.data.pagecount || 0
};
} else { } else {
this.error = response.message || '获取域名所有者列表失败'; this.error = response.message || '获取域名所有者列表失败';
} }
@ -777,6 +794,7 @@ export default {
previousPage() { previousPage() {
if (this.pagination.pageno > 1) { if (this.pagination.pageno > 1) {
this.pagination.pageno--; this.pagination.pageno--;
this.fetchOwners();
} }
}, },
@ -784,12 +802,45 @@ export default {
nextPage() { nextPage() {
if (this.pagination.pageno < this.pagination.pagecount) { if (this.pagination.pageno < this.pagination.pagecount) {
this.pagination.pageno++; this.pagination.pageno++;
this.fetchOwners();
} }
}, },
// //
refresh() { refresh() {
this.fetchOwners(); this.fetchOwners();
},
//
getVisiblePages() {
const current = this.pagination.pageno;
const total = this.pagination.pagecount;
const pages = [];
// 5
if (total <= 5) {
for (let i = 1; i <= total; i++) {
pages.push(i);
}
} else {
//
const start = Math.max(1, current - 2);
const end = Math.min(total, current + 2);
for (let i = start; i <= end; i++) {
pages.push(i);
}
}
return pages;
},
//
changePage(page) {
if (page >= 1 && page <= this.pagination.pagecount) {
this.pagination.pageno = page;
this.fetchOwners();
}
} }
}, },
mounted() { mounted() {

View File

@ -1795,13 +1795,31 @@ def delete_domain(pagetype, name):
@jingrow.whitelist() @jingrow.whitelist()
def get_domain_owners(): def get_domain_owners(**data):
"""获取当前团队的域名所有者列表""" """获取当前团队的域名所有者列表(支持分页、搜索和过滤)"""
try: try:
team = get_current_team() team = get_current_team()
if not team: if not team:
return {"status": "Error", "message": "未找到当前团队"} return {"status": "Error", "message": "未找到当前团队"}
# 获取分页参数
limit = data.get('limit', 20)
pageno = data.get('pageno', 1)
search_query = data.get('searchQuery', '').strip()
selected_status = data.get('selectedStatus', '')
# 确保参数类型正确
try:
limit = int(limit)
pageno = int(pageno)
except (ValueError, TypeError):
limit = 20
pageno = 1
# 确保参数在合理范围内
limit = max(1, min(limit, 100)) # 限制每页最多100条
pageno = max(1, pageno)
# 获取当前团队的所有域名所有者 # 获取当前团队的所有域名所有者
domain_owners = jingrow.get_all( domain_owners = jingrow.get_all(
"Domain Owner", "Domain Owner",
@ -1811,9 +1829,58 @@ def get_domain_owners():
"c_idtype_gswl", "c_idnum_gswl", "c_sysid"] "c_idtype_gswl", "c_idnum_gswl", "c_sysid"]
) )
# 搜索过滤
if search_query:
search_query_lower = search_query.lower()
filtered_owners = []
for owner in domain_owners:
# 检查显示名称
display_name = ""
if owner.c_regtype == 'I':
if owner.fullname:
display_name = owner.fullname
else:
display_name = (owner.c_ln_m or '') + (owner.c_fn_m or '')
elif owner.c_regtype == 'E':
display_name = owner.c_org_m or owner.title or owner.name
else:
display_name = owner.title or owner.name
# 检查是否匹配搜索条件
if (search_query_lower in display_name.lower() or
search_query_lower in (owner.title or '').lower() or
search_query_lower in (owner.c_em or '').lower()):
filtered_owners.append(owner)
domain_owners = filtered_owners
# 状态过滤
if selected_status:
filtered_owners = []
for owner in domain_owners:
r_status = owner.r_status
is_verified = r_status == '1'
if str('1' if is_verified else '0') == selected_status:
filtered_owners.append(owner)
domain_owners = filtered_owners
# 计算分页信息
total = len(domain_owners)
pagecount = (total + limit - 1) // limit
start_index = (pageno - 1) * limit
end_index = start_index + limit
# 返回当前页的记录
current_page_items = domain_owners[start_index:end_index]
return { return {
"status": "Success", "status": "Success",
"data": domain_owners "data": {
"pageno": pageno,
"limit": limit,
"total": total,
"pagecount": pagecount,
"items": current_page_items
}
} }
except Exception as e: except Exception as e:
return {"status": "Error", "message": f"获取域名所有者列表失败: {str(e)}"} return {"status": "Error", "message": f"获取域名所有者列表失败: {str(e)}"}