fix(项目设置): 项目设置环境通用配置分页过滤有误

--bug=1027538 --user=宋昌昌 [项目设置] github#25332项目设置-项目环境:创建环境-通用配置,应用场景筛选,实际只有2条数据,但统计量为12条、3页 https://www.tapd.cn/55049933/s/1389993
This commit is contained in:
song-cc-rock 2023-07-06 16:20:00 +08:00 committed by 刘瑞斌
parent 2aaf7c00fb
commit 6a572a0b8d
1 changed files with 52 additions and 42 deletions

View File

@ -44,7 +44,7 @@
<ms-table <ms-table
v-loading="loading" v-loading="loading"
row-key="id" row-key="id"
:data="variables" :data="pageData"
:screen-height="screenHeight" :screen-height="screenHeight"
:batch-operators="batchButtons" :batch-operators="batchButtons"
:remember-order="true" :remember-order="true"
@ -53,6 +53,7 @@
:total="total" :total="total"
enableSelection enableSelection
:condition="condition" :condition="condition"
@filter="filterScope"
@refresh="onChange" @refresh="onChange"
ref="variableTable"> ref="variableTable">
<ms-table-column prop="num" sortable label="ID" min-width="60" /> <ms-table-column prop="num" sortable label="ID" min-width="60" />
@ -61,7 +62,6 @@
sortable sortable
:label="$t('commons.scope')" :label="$t('commons.scope')"
:filters="scopeTypeFilters" :filters="scopeTypeFilters"
:filter-method="filterScope"
min-width="120"> min-width="120">
<template slot-scope="scope"> <template slot-scope="scope">
<el-select <el-select
@ -148,7 +148,7 @@
</ms-table-column> </ms-table-column>
</ms-table> </ms-table>
<ms-table-pagination <ms-table-pagination
:change="nextPage" :change="queryPage"
:current-page.sync="currentPage" :current-page.sync="currentPage"
:page-size.sync="pageSize" :page-size.sync="pageSize"
:total="total" /> :total="total" />
@ -227,7 +227,7 @@ export default {
{ value: 'JSON', label: this.$t('api_test.automation.json') }, { value: 'JSON', label: this.$t('api_test.automation.json') },
{ value: 'NUMBER', label: this.$t('api_test.automation.number') }, { value: 'NUMBER', label: this.$t('api_test.automation.number') },
], ],
variables: {}, pageData: [],
selectVariable: '', selectVariable: '',
editData: {}, editData: {},
allData: [], allData: [],
@ -239,17 +239,13 @@ export default {
condition: { condition: {
selectAll : false, selectAll : false,
unSelectIds: [], unSelectIds: [],
} },
}; };
}, },
watch: { watch: {
items: { items: {
handler(v) { handler(v) {
this.allData = v;
this.pageSize = 10;
this.total = this.allData.length;
this.sortParameters(); this.sortParameters();
this.nextPage();
}, },
immediate: true, immediate: true,
deep: true, deep: true,
@ -257,26 +253,22 @@ export default {
}, },
methods: { methods: {
remove: function (index) { remove: function (index) {
const dataIndex = this.variables.findIndex((d) => d.name === index.name); const dataIndex = this.pageData.findIndex((d) => d.name === index.name);
this.variables.splice(dataIndex, 1); this.pageData.splice(dataIndex, 1);
const allDataIndex = this.allData.findIndex((d) => d.name === index.name); const allDataIndex = this.allData.findIndex((d) => d.name === index.name);
this.allData.splice(allDataIndex, 1); this.allData.splice(allDataIndex, 1);
this.nextPage(); this.queryPage();
}, },
nextPage() { queryPage() {
// 0pageSize this.total = this.allData.length;
if (this.currentPage == 1) {
this.variables = this.allData.slice(0, this.pageSize);
this.variables.forEach((item) => {
item.showMore = false;
delete item.hashTree;
});
}
let start = (this.currentPage - 1) * this.pageSize; let start = (this.currentPage - 1) * this.pageSize;
let end = this.currentPage * this.pageSize; let end = this.currentPage * this.pageSize;
this.variables = this.allData.slice(start, end); this.pageData = this.allData.slice(start, end);
this.total = this.allData.length; this.pageData.forEach((item) => {
item.showMore = false;
delete item.hashTree;
});
}, },
change: function () { change: function () {
let isNeedCreate = true; let isNeedCreate = true;
@ -375,10 +367,10 @@ export default {
let ids = this.$refs.variableTable.selectRows; let ids = this.$refs.variableTable.selectRows;
ids.forEach((row) => { ids.forEach((row) => {
if (row.id) { if (row.id) {
const index = this.variables.findIndex((d) => d.id === row.id); const index = this.pageData.findIndex((d) => d.id === row.id);
const allIndex = this.allData.findIndex((d) => d.id === row.id); const allIndex = this.allData.findIndex((d) => d.id === row.id);
if (index !== this.variables.length - 1) { if (index !== this.pageData.length - 1) {
this.variables.splice(index, 1); this.pageData.splice(index, 1);
} }
if (allIndex !== this.allData.length - 1) { if (allIndex !== this.allData.length - 1) {
this.allData.splice(allIndex, 1); this.allData.splice(allIndex, 1);
@ -388,15 +380,15 @@ export default {
this.sortParameters(); this.sortParameters();
this.$refs.variableTable.cancelCurrentRow(); this.$refs.variableTable.cancelCurrentRow();
this.$refs.variableTable.clear(); this.$refs.variableTable.clear();
this.variables.forEach((item) => { this.pageData.forEach((item) => {
item.showMore = false; item.showMore = false;
}); });
}); });
}, },
filter(scope) { filter() {
let datas = []; let datas = [];
this.items.forEach((item) => { this.items.forEach((item) => {
if (this.selectVariable && this.selectVariable != '' && item.name) { if (this.selectVariable && this.selectVariable !== '' && item.name) {
if (item.name.toLowerCase().indexOf(this.selectVariable.toLowerCase()) === -1) { if (item.name.toLowerCase().indexOf(this.selectVariable.toLowerCase()) === -1) {
item.hidden = true; item.hidden = true;
} else { } else {
@ -410,20 +402,39 @@ export default {
} }
}); });
this.total = datas.length; this.total = datas.length;
// 0pageSize
if (this.currentPage == 1) {
this.variables = datas.slice(0, this.pageSize);
return;
}
let start = (this.currentPage - 1) * this.pageSize; let start = (this.currentPage - 1) * this.pageSize;
let end = this.currentPage * this.pageSize; let end = this.currentPage * this.pageSize;
this.variables = datas.slice(start, end); this.pageData = datas.slice(start, end);
}, },
filterScope(value, row) { filterScope() {
if (value == 'ui') { /**
return row.scope == 'ui'; * 全量数据过滤, 过滤后分页
*/
this.currentPage = 1;
this.allData = [];
let scopes = this.condition.filters.scope;
if (!scopes || scopes.length === 0) {
//
forEach(this.items, (item) => {
delete item.hidden;
if (!item.scope) {
this.$set(item, 'scope', 'api');
}
});
this.allData = this.items;
} else {
this.items.forEach((item) => {
if (scopes.indexOf(item.scope) === -1) {
item.hidden = true;
} else {
item.hidden = undefined;
}
if (!item.hidden) {
this.allData.push(item);
}
});
} }
return !row.scope || row.scope == 'api'; this.queryPage();
}, },
openSetting(data) { openSetting(data) {
this.$refs.apiVariableSetting.open(data); this.$refs.apiVariableSetting.open(data);
@ -474,7 +485,7 @@ export default {
}); });
if (isAdd) { if (isAdd) {
this.items.splice( this.items.splice(
this.variables.indexOf((i) => !i.name), this.pageData.indexOf((i) => !i.name),
0, 0,
keyValue keyValue
); );
@ -553,9 +564,8 @@ export default {
} }
}); });
this.allData = this.items; this.allData = this.items;
this.nextPage(); this.queryPage();
} }
this.total = this.allData.length;
}, },
}; };
</script> </script>