refactor: 记住排序优化

This commit is contained in:
chenjianxing 2021-09-06 10:54:54 +08:00 committed by jianxing
parent 9ac645a4df
commit 353bb0eafa
12 changed files with 71 additions and 202 deletions

View File

@ -14,11 +14,11 @@
:total="total" :total="total"
:fields.sync="fields" :fields.sync="fields"
:field-key=tableHeaderKey :field-key=tableHeaderKey
:remember-order="true"
operator-width="200" operator-width="200"
@refresh="search(projectId)" @refresh="search(projectId)"
@callBackSelectAll="callBackSelectAll" @callBackSelectAll="callBackSelectAll"
@callBackSelect="callBackSelect" @callBackSelect="callBackSelect"
@saveSortField="saveSortField"
ref="scenarioTable"> ref="scenarioTable">
<ms-table-column <ms-table-column
prop="deleteTime" prop="deleteTime"
@ -489,10 +489,7 @@ export default {
if(this.trashEnable){ if(this.trashEnable){
this.condition.orders = [{"name":"delete_time","type":"desc"}]; this.condition.orders = [{"name":"delete_time","type":"desc"}];
}else { }else {
let orderArr = this.getSortField(); this.condition.orders = getLastTableSortField(this.tableHeaderKey);
if (orderArr) {
this.condition.orders = orderArr;
}
} }
this.search(); this.search();
@ -1022,21 +1019,6 @@ export default {
} }
}); });
}, },
saveSortField(key, orders) {
saveLastTableSortField(key, JSON.stringify(orders));
},
getSortField() {
let orderJsonStr = getLastTableSortField(this.tableHeaderKey);
let returnObj = null;
if (orderJsonStr) {
try {
returnObj = JSON.parse(orderJsonStr);
} catch (e) {
return null;
}
}
return returnObj;
},
stop(row) { stop(row) {
let url = "/api/automation/stop/" + this.reportId; let url = "/api/automation/stop/" + this.reportId;
this.$get(url, () => { this.$get(url, () => {

View File

@ -19,7 +19,7 @@
:screenHeight="screenHeight" :screenHeight="screenHeight"
:fields.sync="fields" :fields.sync="fields"
:field-key="tableHeaderKey" :field-key="tableHeaderKey"
@saveSortField="saveSortField" :remember-order="true"
operator-width="190px" operator-width="190px"
@refresh="initTable" @refresh="initTable"
ref="caseTable" ref="caseTable"
@ -213,7 +213,7 @@ import {
_filter, _filter,
_sort, _sort,
getCustomTableHeader, getCustomTableHeader,
getCustomTableWidth, saveLastTableSortField, getLastTableSortField getCustomTableWidth, getLastTableSortField
} from "@/common/js/tableUtils"; } from "@/common/js/tableUtils";
import {API_CASE_LIST} from "@/common/js/constants"; import {API_CASE_LIST} from "@/common/js/constants";
import HeaderLabelOperate from "@/business/components/common/head/HeaderLabelOperate"; import HeaderLabelOperate from "@/business/components/common/head/HeaderLabelOperate";
@ -374,10 +374,7 @@ export default {
planId: String planId: String
}, },
created: function () { created: function () {
let orderArr = this.getSortField(); this.condition.orders = getLastTableSortField(this.tableHeaderKey);
if (orderArr) {
this.condition.orders = orderArr;
}
if (this.trashEnable) { if (this.trashEnable) {
this.operators = this.trashOperators; this.operators = this.trashOperators;
@ -914,21 +911,6 @@ export default {
column.width = finalWidth; column.width = finalWidth;
column.realWidth = finalWidth; column.realWidth = finalWidth;
}, },
saveSortField(key, orders) {
saveLastTableSortField(key, JSON.stringify(orders));
},
getSortField() {
let orderJsonStr = getLastTableSortField(this.tableHeaderKey);
let returnObj = null;
if (orderJsonStr) {
try {
returnObj = JSON.parse(orderJsonStr);
} catch (e) {
return null;
}
}
return returnObj;
},
stop(id) { stop(id) {
for (let item of this.tableData) { for (let item of this.tableData) {
if (id && id === item.id) { if (id && id === item.id) {

View File

@ -9,15 +9,15 @@
<ms-table <ms-table
:data="tableData" :select-node-ids="selectNodeIds" :condition="condition" :page-size="pageSize" :data="tableData" :select-node-ids="selectNodeIds" :condition="condition" :page-size="pageSize"
:total="total" enableSelection :total="total" enableSelection
:batch-operators="trashEnable ? trashButtons : buttons" :screen-height="screenHeight" :batch-operators="trashEnable ? trashButtons : buttons" :screen-height="screenHeight"
:operators="tableOperatorButtons" operator-width="200px" :operators="tableOperatorButtons" operator-width="200px"
@refresh="initTable" :remember-order="true"
:fields.sync="fields" @refresh="initTable"
:table-is-loading="this.result.loading" :fields.sync="fields"
:field-key="tableHeaderKey" :table-is-loading="this.result.loading"
@saveSortField="saveSortField" :field-key="tableHeaderKey"
ref="table"> ref="table">
<ms-table-column <ms-table-column
prop="deleteTime" prop="deleteTime"
sortable sortable
@ -429,10 +429,8 @@ export default {
this.tableOperatorButtons = this.tableUsualOperatorButtons; this.tableOperatorButtons = this.tableUsualOperatorButtons;
this.condition.filters = {status: ["Prepare", "Underway", "Completed"]}; this.condition.filters = {status: ["Prepare", "Underway", "Completed"]};
} }
let orderArr = this.getSortField(); this.condition.orders = getLastTableSortField(this.tableHeaderKey);
if (orderArr) {
this.condition.orders = orderArr;
}
this.initTable(); this.initTable();
this.getMaintainerOptions(); this.getMaintainerOptions();
}, },
@ -824,21 +822,6 @@ export default {
return false; return false;
} }
}, },
saveSortField(key, orders) {
saveLastTableSortField(key, JSON.stringify(orders));
},
getSortField() {
let orderJsonStr = getLastTableSortField(this.tableHeaderKey);
let returnObj = null;
if (orderJsonStr) {
try {
returnObj = JSON.parse(orderJsonStr);
} catch (e) {
return null;
}
}
return returnObj;
}
}, },
}; };
</script> </script>

View File

@ -9,6 +9,7 @@
@select="handleSelect" @select="handleSelect"
@header-dragend="headerDragend" @header-dragend="headerDragend"
@cell-mouse-enter="showPopover" @cell-mouse-enter="showPopover"
:default-sort="defaultSort"
class="test-content adjust-table ms-table" class="test-content adjust-table ms-table"
:class="{'ms-select-all-fixed': showSelectAll}" :class="{'ms-select-all-fixed': showSelectAll}"
:height="screenHeight" :height="screenHeight"
@ -75,14 +76,13 @@
import { import {
_filter, _filter,
_handleSelect, _handleSelect,
_handleSelectAll, _sort, getLabel, _handleSelectAll, _sort,
getSelectDataCounts, getSelectDataCounts,
setUnSelectIds, setUnSelectIds,
toggleAllSelection, toggleAllSelection,
checkTableRowIsSelect, getCustomTableHeader, saveCustomTableWidth, checkTableRowIsSelect, getCustomTableHeader, saveCustomTableWidth, saveLastTableSortField,
} from "@/common/js/tableUtils"; } from "@/common/js/tableUtils";
import MsTableHeaderSelectPopover from "@/business/components/common/components/table/MsTableHeaderSelectPopover"; import MsTableHeaderSelectPopover from "@/business/components/common/components/table/MsTableHeaderSelectPopover";
import {TEST_CASE_LIST} from "@/common/js/constants";
import MsTablePagination from "@/business/components/common/pagination/TablePagination"; import MsTablePagination from "@/business/components/common/pagination/TablePagination";
import ShowMoreBtn from "@/business/components/track/case/components/ShowMoreBtn"; import ShowMoreBtn from "@/business/components/track/case/components/ShowMoreBtn";
import MsTableColumn from "@/business/components/common/components/table/MsTableColumn"; import MsTableColumn from "@/business/components/common/components/table/MsTableColumn";
@ -116,7 +116,8 @@ export default {
selectRows: new Set(), selectRows: new Set(),
selectIds: [], selectIds: [],
tableActive: true, tableActive: true,
hasBatchTipShow: false hasBatchTipShow: false,
defaultSort: {}
}; };
}, },
props: { props: {
@ -198,14 +199,19 @@ export default {
fieldKey: String, fieldKey: String,
customFields: Array, customFields: Array,
highlightCurrentRow: Boolean, highlightCurrentRow: Boolean,
//
rememberOrder: Boolean
}, },
mounted() { mounted() {
getLabel(this, TEST_CASE_LIST); this.setDefaultOrders();
}, },
watch: { watch: {
selectNodeIds() { selectNodeIds() {
this.selectDataCounts = 0; this.selectDataCounts = 0;
}, },
'condition.orders'() {
}
}, },
methods: { methods: {
// , , // , ,
@ -238,6 +244,20 @@ export default {
let columnTop = column.getBoundingClientRect().top; let columnTop = column.getBoundingClientRect().top;
return columnTop - tableTop > 30; return columnTop - tableTop > 30;
}, },
setDefaultOrders() {
let orders = this.condition.orders;
if (orders) {
orders.forEach(item => {
this.defaultSort = {};
this.defaultSort.prop = item.name;
if (item.type === 'asc') {
this.defaultSort.order = 'ascending';
} else {
this.defaultSort.order = 'descending';
}
});
}
},
handleSelectAll(selection) { handleSelectAll(selection) {
_handleSelectAll(this, selection, this.data, this.selectRows, this.condition); _handleSelectAll(this, selection, this.data, this.selectRows, this.condition);
setUnSelectIds(this.data, this.condition, this.selectRows); setUnSelectIds(this.data, this.condition, this.selectRows);
@ -303,7 +323,9 @@ export default {
this.condition.orders = []; this.condition.orders = [];
} }
_sort(column, this.condition); _sort(column, this.condition);
this.$emit("saveSortField", this.fieldKey,this.condition.orders); if (this.rememberOrder) {
saveLastTableSortField(this.fieldKey, JSON.stringify(this.condition.orders));
}
this.handleRefresh(); this.handleRefresh();
}, },
handleBatchEdit() { handleBatchEdit() {

View File

@ -249,10 +249,8 @@ export default {
} else { } else {
this.condition.testId = null; this.condition.testId = null;
} }
let orderArr = this.getSortField(); this.condition.orders = getLastTableSortField(this.tableHeaderKey);
if(orderArr){
this.condition.orders = orderArr;
}
if (!getCurrentProjectID()) { if (!getCurrentProjectID()) {
return; return;
} }
@ -351,18 +349,6 @@ export default {
saveSortField(key,orders){ saveSortField(key,orders){
saveLastTableSortField(key,JSON.stringify(orders)); saveLastTableSortField(key,JSON.stringify(orders));
}, },
getSortField(){
let orderJsonStr = getLastTableSortField(this.tableHeaderKey);
let returnObj = null;
if(orderJsonStr){
try {
returnObj = JSON.parse(orderJsonStr);
}catch (e){
return null;
}
}
return returnObj;
},
handleSelectAll(selection) { handleSelectAll(selection) {
if (selection.length > 0) { if (selection.length > 0) {
this.tableData.forEach(item => { this.tableData.forEach(item => {

View File

@ -179,10 +179,8 @@ export default {
}); });
}, },
initTableData() { initTableData() {
let orderArr = this.getSortField(); this.condition.orders = getLastTableSortField(this.tableHeaderKey);
if(orderArr){
this.condition.orders = orderArr;
}
this.condition.projectId = getCurrentProjectID(); this.condition.projectId = getCurrentProjectID();
this.condition.workspaceId = getCurrentWorkspaceId(); this.condition.workspaceId = getCurrentWorkspaceId();
this.result = this.$post(this.buildPagePath('/performance/list'), this.condition, response => { this.result = this.$post(this.buildPagePath('/performance/list'), this.condition, response => {
@ -243,7 +241,7 @@ export default {
this.condition.orders = []; this.condition.orders = [];
} }
_sort(column, this.condition); _sort(column, this.condition);
this.saveSortField(this.tableHeaderKey,this.condition.orders); saveLastTableSortField(this.tableHeaderKey, JSON.stringify(this.condition.orders));
this.initTableData(); this.initTableData();
}, },
filter(filters) { filter(filters) {
@ -266,21 +264,6 @@ export default {
return; return;
} }
this.$router.push('/performance/test/create'); this.$router.push('/performance/test/create');
},
saveSortField(key,orders){
saveLastTableSortField(key,JSON.stringify(orders));
},
getSortField(){
let orderJsonStr = getLastTableSortField(this.tableHeaderKey);
let returnObj = null;
if(orderJsonStr){
try {
returnObj = JSON.parse(orderJsonStr);
}catch (e){
return null;
}
}
return returnObj;
} }
} }
}; };

View File

@ -14,12 +14,12 @@
:operators="operators" :operators="operators"
:screen-height="screenHeight" :screen-height="screenHeight"
:batch-operators="batchButtons" :batch-operators="batchButtons"
:remember-order="true"
@handlePageChange="initTableData" @handlePageChange="initTableData"
@handleRowClick="handleEdit" @handleRowClick="handleEdit"
:fields.sync="fields" :fields.sync="fields"
:field-key="tableHeaderKey" :field-key="tableHeaderKey"
@refresh="initTableData" @refresh="initTableData"
@saveSortField="saveSortField"
:custom-fields="testCaseTemplate.customFields" :custom-fields="testCaseTemplate.customFields"
ref="table"> ref="table">
@ -199,7 +199,7 @@ import {
getCustomTableWidth, getLastTableSortField, getCustomTableWidth, getLastTableSortField,
getPageInfo, getPageInfo,
getTableHeaderWithCustomFields, getTableHeaderWithCustomFields,
initCondition, saveLastTableSortField, initCondition,
} from "@/common/js/tableUtils"; } from "@/common/js/tableUtils";
import HeaderLabelOperate from "@/business/components/common/head/HeaderLabelOperate"; import HeaderLabelOperate from "@/business/components/common/head/HeaderLabelOperate";
import PlanStatusTableItem from "@/business/components/track/common/tableItems/plan/PlanStatusTableItem"; import PlanStatusTableItem from "@/business/components/track/common/tableItems/plan/PlanStatusTableItem";
@ -378,10 +378,8 @@ export default {
}else { }else {
this.condition.filters = {reviewStatus: ["Prepare", "Pass", "UnPass"]}; this.condition.filters = {reviewStatus: ["Prepare", "Pass", "UnPass"]};
} }
let orderArr = this.getSortField(); this.condition.orders = getLastTableSortField(this.tableHeaderKey);
if(orderArr){
this.condition.orders = orderArr;
}
this.initTableData(); this.initTableData();
let redirectParam = this.$route.query.dataSelectRange; let redirectParam = this.$route.query.dataSelectRange;
this.checkRedirectEditPage(redirectParam); this.checkRedirectEditPage(redirectParam);
@ -791,21 +789,6 @@ export default {
this.$refs.testBatchMove.close(); this.$refs.testBatchMove.close();
this.refresh(); this.refresh();
}); });
},
saveSortField(key,orders){
saveLastTableSortField(key,JSON.stringify(orders));
},
getSortField(){
let orderJsonStr = getLastTableSortField(this.tableHeaderKey);
let returnObj = null;
if(orderJsonStr){
try {
returnObj = JSON.parse(orderJsonStr);
}catch (e){
return null;
}
}
return returnObj;
} }
} }
}; };

View File

@ -25,10 +25,10 @@
:operators="operators" :operators="operators"
:show-select-all="false" :show-select-all="false"
:screen-height="screenHeight" :screen-height="screenHeight"
:remember-order="true"
@handlePageChange="getIssues" @handlePageChange="getIssues"
:fields.sync="fields" :fields.sync="fields"
:field-key="tableHeaderKey" :field-key="tableHeaderKey"
@saveSortField="saveSortField"
@refresh="getIssues" @refresh="getIssues"
:custom-fields="issueTemplate.customFields" :custom-fields="issueTemplate.customFields"
ref="table" ref="table"
@ -290,10 +290,8 @@ export default {
}, },
getIssues() { getIssues() {
this.page.condition.projectId = this.projectId; this.page.condition.projectId = this.projectId;
let orderArr = this.getSortField(); this.page.condition.orders = getLastTableSortField(this.tableHeaderKey);
if(orderArr){
this.page.condition.orders = orderArr;
}
this.page.result = getIssues(this.page); this.page.result = getIssues(this.page);
}, },
handleEdit(data) { handleEdit(data) {
@ -321,25 +319,10 @@ export default {
} }
return true; return true;
}, },
saveSortField(key,orders){
saveLastTableSortField(key,JSON.stringify(orders));
},
syncIssues() { syncIssues() {
this.page.result = syncIssues(() => { this.page.result = syncIssues(() => {
this.getIssues(); this.getIssues();
}); });
},
getSortField(){
let orderJsonStr = getLastTableSortField(this.tableHeaderKey);
let returnObj = null;
if(orderJsonStr){
try {
returnObj = JSON.parse(orderJsonStr);
}catch (e){
return null;
}
}
return returnObj;
} }
} }
}; };

View File

@ -326,10 +326,8 @@ export default {
this.projectId = getCurrentProjectID(); this.projectId = getCurrentProjectID();
} }
this.hasEditPermission = hasPermission('PROJECT_TRACK_PLAN:READ+EDIT'); this.hasEditPermission = hasPermission('PROJECT_TRACK_PLAN:READ+EDIT');
let orderArr = this.getSortField(); this.condition.orders = getLastTableSortField(this.tableHeaderKey);
if(orderArr){
this.condition.orders = orderArr;
}
this.initTableData(); this.initTableData();
}, },
methods: { methods: {
@ -454,18 +452,6 @@ export default {
saveSortField(key,orders){ saveSortField(key,orders){
saveLastTableSortField(key,JSON.stringify(orders)); saveLastTableSortField(key,JSON.stringify(orders));
}, },
getSortField(){
let orderJsonStr = getLastTableSortField(this.tableHeaderKey);
let returnObj = null;
if(orderJsonStr){
try {
returnObj = JSON.parse(orderJsonStr);
}catch (e){
return null;
}
}
return returnObj;
},
handleCommand(cmd, row) { handleCommand(cmd, row) {
switch (cmd) { switch (cmd) {
case "delete": case "delete":

View File

@ -156,10 +156,8 @@ export default {
methods: { methods: {
initTableData() { initTableData() {
initCondition(this.condition, this.condition.selectAll); initCondition(this.condition, this.condition.selectAll);
let orderArr = this.getSortField(); this.condition.orders = getLastTableSortField(this.tableHeaderKey);
if(orderArr){
this.condition.orders = orderArr;
}
this.selectRows = new Set(); this.selectRows = new Set();
if (this.planId) { if (this.planId) {
this.condition.planId = this.planId; this.condition.planId = this.planId;
@ -272,18 +270,6 @@ export default {
saveSortField(key,orders){ saveSortField(key,orders){
saveLastTableSortField(key,JSON.stringify(orders)); saveLastTableSortField(key,JSON.stringify(orders));
}, },
getSortField(){
let orderJsonStr = getLastTableSortField(this.tableHeaderKey);
let returnObj = null;
if(orderJsonStr){
try {
returnObj = JSON.parse(orderJsonStr);
}catch (e){
return null;
}
}
return returnObj;
}
} }
} }
</script> </script>

View File

@ -178,10 +178,8 @@ export default {
}, },
created() { created() {
this.isTestManagerOrTestUser = true; this.isTestManagerOrTestUser = true;
let orderArr = this.getSortField(); this.condition.orders = getLastTableSortField(this.tableHeaderKey);
if(orderArr){
this.condition.orders = orderArr;
}
this.initTableData(); this.initTableData();
}, },
computed: { computed: {
@ -271,18 +269,6 @@ export default {
saveSortField(key,orders){ saveSortField(key,orders){
saveLastTableSortField(key,JSON.stringify(orders)); saveLastTableSortField(key,JSON.stringify(orders));
}, },
getSortField(){
let orderJsonStr = getLastTableSortField(this.tableHeaderKey);
let returnObj = null;
if(orderJsonStr){
try {
returnObj = JSON.parse(orderJsonStr);
}catch (e){
return null;
}
}
return returnObj;
}
} }
}; };
</script> </script>

View File

@ -385,8 +385,15 @@ export function saveLastTableSortField(key, field) {
} }
export function getLastTableSortField(key) { export function getLastTableSortField(key) {
let fieldStr = localStorage.getItem(key+"_SORT"); let orderJsonStr = localStorage.getItem(key+"_SORT");
return fieldStr; if(orderJsonStr){
try {
return JSON.parse(orderJsonStr);
}catch (e){
return [];
}
}
return [];
} }