mirror of
https://github.com/certd/certd.git
synced 2026-04-30 09:17:24 +08:00
chore: 优化插件的翻页查询
This commit is contained in:
@@ -4,39 +4,33 @@ export type UserContext = IContext;
|
|||||||
export type PipelineContext = IContext;
|
export type PipelineContext = IContext;
|
||||||
|
|
||||||
export type PageSearch = {
|
export type PageSearch = {
|
||||||
offset?: number;
|
pageNo?: number;
|
||||||
limit?: number;
|
pageSize?: number;
|
||||||
searchKey?: string;
|
searchKey?: string;
|
||||||
// sortBy?: string;
|
// sortBy?: string;
|
||||||
// sortOrder?: "asc" | "desc";
|
// sortOrder?: "asc" | "desc";
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PageRes = {
|
export type PageRes = {
|
||||||
offset?: number;
|
pageNo?: number;
|
||||||
limit?: number;
|
pageSize?: number;
|
||||||
total?: string;
|
total?: string;
|
||||||
list: any[];
|
list: any[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Pager {
|
export class Pager {
|
||||||
offset: number;
|
pageNo: number;
|
||||||
limit: number;
|
pageSize: number;
|
||||||
constructor(req: PageSearch) {
|
constructor(req: PageSearch) {
|
||||||
this.offset = req.offset ?? 0;
|
this.pageNo = req.pageNo ?? 1;
|
||||||
this.limit = req.limit || 50;
|
this.pageSize = req.pageSize || 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
getPageNo() {
|
getOffset() {
|
||||||
const size = this.limit;
|
return (this.pageNo - 1) * (this.pageSize ?? 50);
|
||||||
const offset = this.offset;
|
|
||||||
let page = Math.floor(offset / size);
|
|
||||||
if (offset % size === 0) {
|
|
||||||
page++;
|
|
||||||
}
|
|
||||||
return page;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setPageNo(pageNo: number) {
|
setOffset(offset: number) {
|
||||||
this.offset = (pageNo - 1) * (this.limit ?? 50);
|
this.pageNo = Math.ceil(offset / (this.pageSize ?? 50)) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
<v-nodes :vnodes="menu" />
|
<v-nodes :vnodes="menu" />
|
||||||
|
|
||||||
<div v-if="pager === true" class="pager text-center p-5">
|
<div v-if="pager === true" class="pager text-center p-5">
|
||||||
<a-pagination v-model:current="pagerRef.current" simple :total="pagerRef.total" :page-size="pagerRef.limit" />
|
<a-pagination v-model:current="pagerRef.pageNo" simple :total="pagerRef.total" :page-size="pagerRef.pageSize" @change="onPageChange" />
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</a-select>
|
</a-select>
|
||||||
@@ -119,9 +119,8 @@ const getOptions = async () => {
|
|||||||
message.value = "";
|
message.value = "";
|
||||||
hasError.value = false;
|
hasError.value = false;
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
optionsRef.value = [];
|
const pageNo = pagerRef.value.pageNo;
|
||||||
|
const pageSize = pagerRef.value.pageSize;
|
||||||
const offset = (pagerRef.value.current - 1) * (pagerRef.value.limit ?? 100);
|
|
||||||
try {
|
try {
|
||||||
const res = await doRequest(
|
const res = await doRequest(
|
||||||
{
|
{
|
||||||
@@ -131,8 +130,8 @@ const getOptions = async () => {
|
|||||||
input,
|
input,
|
||||||
data: {
|
data: {
|
||||||
searchKey: props.search ? searchKeyRef.value : "",
|
searchKey: props.search ? searchKeyRef.value : "",
|
||||||
offset: offset,
|
pageNo,
|
||||||
limit: pagerRef.value.limit,
|
pageSize,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -150,17 +149,15 @@ const getOptions = async () => {
|
|||||||
optionsRef.value = list;
|
optionsRef.value = list;
|
||||||
pagerRef.value.total = list.length;
|
pagerRef.value.total = list.length;
|
||||||
if (props.pager) {
|
if (props.pager) {
|
||||||
if (res.offset != null) {
|
if (res.pageNo != null) {
|
||||||
pagerRef.value.offset = res.offset ?? 0;
|
pagerRef.value.pageNo = res.pageNo ?? 1;
|
||||||
}
|
}
|
||||||
if (res.limit != null) {
|
if (res.pageSize != null) {
|
||||||
pagerRef.value.limit = res.limit ?? 100;
|
pagerRef.value.pageSize = res.pageSize ?? 100;
|
||||||
}
|
}
|
||||||
if (res.total != null) {
|
if (res.total != null) {
|
||||||
pagerRef.value.total = res.total ?? list.length;
|
pagerRef.value.total = res.total ?? list.length;
|
||||||
}
|
}
|
||||||
const { offset, limit } = pagerRef.value;
|
|
||||||
pagerRef.value.current = offset % limit === 0 ? offset / limit + 1 : offset / limit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@@ -184,7 +181,7 @@ async function refreshOptions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function doSearch() {
|
async function doSearch() {
|
||||||
pagerRef.value.current = 1;
|
pagerRef.value.pageNo = 1;
|
||||||
await refreshOptions();
|
await refreshOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -222,6 +219,10 @@ watch(
|
|||||||
immediate: true,
|
immediate: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
async function onPageChange(current: any) {
|
||||||
|
await refreshOptions();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less"></style>
|
<style lang="less"></style>
|
||||||
|
|||||||
@@ -183,8 +183,8 @@ export class AliyunDeployCertToWaf extends AbstractTaskPlugin {
|
|||||||
const params:any = {
|
const params:any = {
|
||||||
RegionId: this.regionId,
|
RegionId: this.regionId,
|
||||||
InstanceId: instanceId,
|
InstanceId: instanceId,
|
||||||
PageSize: pager.limit,
|
PageSize: pager.pageSize,
|
||||||
PageNumber: pager.getPageNo(),
|
PageNumber: pager.pageNo,
|
||||||
};
|
};
|
||||||
if (data.searchKey){
|
if (data.searchKey){
|
||||||
params.Domain = data.searchKey
|
params.Domain = data.searchKey
|
||||||
@@ -206,11 +206,13 @@ export class AliyunDeployCertToWaf extends AbstractTaskPlugin {
|
|||||||
});
|
});
|
||||||
const list= this.ctx.utils.options.buildGroupOptions(options, this.certDomains);
|
const list= this.ctx.utils.options.buildGroupOptions(options, this.certDomains);
|
||||||
|
|
||||||
|
// const list = [{value:"1",label:"1"},{value:"2",label:"2"}]
|
||||||
|
// const total = 120
|
||||||
return {
|
return {
|
||||||
list,
|
list,
|
||||||
total: total,
|
total: total,
|
||||||
offset: pager.offset,
|
pageNo: pager.pageNo,
|
||||||
limit: pager.limit
|
pageSize: pager.pageSize
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AbstractTaskPlugin, IsTaskPlugin, PageSearch, pluginGroups, RunStrategy, TaskInput } from "@certd/pipeline";
|
import { AbstractTaskPlugin, IsTaskPlugin, Pager, PageSearch, pluginGroups, RunStrategy, TaskInput } from "@certd/pipeline";
|
||||||
import { CertApplyPluginNames, CertInfo } from "@certd/plugin-cert";
|
import { CertApplyPluginNames, CertInfo } from "@certd/plugin-cert";
|
||||||
import { createCertDomainGetterInputDefine, createRemoteSelectInputDefine } from "@certd/plugin-lib";
|
import { createCertDomainGetterInputDefine, createRemoteSelectInputDefine } from "@certd/plugin-lib";
|
||||||
import { FarcdnAccess } from "../access.js";
|
import { FarcdnAccess } from "../access.js";
|
||||||
@@ -81,9 +81,10 @@ export class FarcdnRefreshCert extends AbstractTaskPlugin {
|
|||||||
async onGetCertList(data:PageSearch = {}) {
|
async onGetCertList(data:PageSearch = {}) {
|
||||||
const access = await this.getAccess<FarcdnAccess>(this.accessId);
|
const access = await this.getAccess<FarcdnAccess>(this.accessId);
|
||||||
|
|
||||||
|
const pager = new Pager(data);
|
||||||
const res = await access.getSSLCertList({
|
const res = await access.getSSLCertList({
|
||||||
offset: data.offset?? 0,
|
offset: pager.getOffset(),
|
||||||
size: data.limit?? 100,
|
size: pager.pageSize,
|
||||||
});
|
});
|
||||||
const list = res.list
|
const list = res.list
|
||||||
if (!list || list.length === 0) {
|
if (!list || list.length === 0) {
|
||||||
@@ -100,8 +101,8 @@ export class FarcdnRefreshCert extends AbstractTaskPlugin {
|
|||||||
return {
|
return {
|
||||||
list:this.ctx.utils.options.buildGroupOptions(options, this.certDomains),
|
list:this.ctx.utils.options.buildGroupOptions(options, this.certDomains),
|
||||||
total:res.total,
|
total:res.total,
|
||||||
offset: res.offset,
|
pageNo: pager.pageNo,
|
||||||
limit:res.size
|
pageSize: pager.pageSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,20 +75,16 @@ export class RainyunAccess extends BaseAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async getCertList(req:{offset?:number,limit?:number,query?:string}){
|
async getCertList(req:{pageNo?:number,pageSize?:number,query?:string}){
|
||||||
const size = req.limit ?? 20;
|
const pageNo = req.pageNo ?? 1;
|
||||||
const offset = req.offset ?? 0;
|
const pageSize = req.pageSize ?? 20;
|
||||||
let page = Math.floor(offset / size);
|
|
||||||
if(offset % size === 0 ){
|
|
||||||
page++
|
|
||||||
}
|
|
||||||
const options ={
|
const options ={
|
||||||
columnFilters: {
|
columnFilters: {
|
||||||
Domain: req.query??""
|
Domain: req.query??""
|
||||||
},
|
},
|
||||||
sort:[],
|
sort:[],
|
||||||
page: page,
|
page: pageNo,
|
||||||
perPage: size,
|
perPage: pageSize,
|
||||||
|
|
||||||
}
|
}
|
||||||
const res = await this.doRequest({
|
const res = await this.doRequest({
|
||||||
@@ -99,8 +95,8 @@ export class RainyunAccess extends BaseAccess {
|
|||||||
return {
|
return {
|
||||||
total: res.TotalRecords,
|
total: res.TotalRecords,
|
||||||
list: res.Records || [],
|
list: res.Records || [],
|
||||||
limit: size,
|
pageNo: pageNo,
|
||||||
offset: offset
|
pageSize: pageSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,11 +81,11 @@ export class RainyunRefreshCert extends AbstractTaskPlugin {
|
|||||||
async onGetCertList(req: PageSearch = {}) {
|
async onGetCertList(req: PageSearch = {}) {
|
||||||
const access = await this.getAccess<RainyunAccess>(this.accessId);
|
const access = await this.getAccess<RainyunAccess>(this.accessId);
|
||||||
|
|
||||||
const offset = req.offset ?? 0;
|
const pageNo = req.pageNo ?? 1;
|
||||||
const limit = req.limit ?? 100;
|
const pageSize = req.pageSize ?? 100;
|
||||||
const res = await access.getCertList({
|
const res = await access.getCertList({
|
||||||
offset,
|
pageNo,
|
||||||
limit
|
pageSize
|
||||||
});
|
});
|
||||||
const total = res.total;
|
const total = res.total;
|
||||||
const list = res.list;
|
const list = res.list;
|
||||||
@@ -103,8 +103,8 @@ export class RainyunRefreshCert extends AbstractTaskPlugin {
|
|||||||
return {
|
return {
|
||||||
list: this.ctx.utils.options.buildGroupOptions(options, this.certDomains),
|
list: this.ctx.utils.options.buildGroupOptions(options, this.certDomains),
|
||||||
total: total,
|
total: total,
|
||||||
offset: offset,
|
pageNo: pageNo,
|
||||||
limit: limit
|
pageSize: pageSize
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user