From 353bb0eafae1e2ffa4feef8f95dac20a9dc344ea Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Mon, 6 Sep 2021 10:54:54 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=AE=B0=E4=BD=8F=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../automation/scenario/ApiScenarioList.vue | 22 +---------- .../components/list/ApiCaseSimpleList.vue | 24 ++---------- .../definition/components/list/ApiList.vue | 39 ++++++------------- .../common/components/table/MsTable.vue | 34 +++++++++++++--- .../report/PerformanceTestReportList.vue | 18 +-------- .../performance/test/PerformanceTestList.vue | 23 ++--------- .../track/case/components/TestCaseList.vue | 25 ++---------- .../components/track/issue/IssueList.vue | 23 ++--------- .../track/plan/components/TestPlanList.vue | 18 +-------- .../report/components/TestPlanReportList.vue | 18 +-------- .../review/components/TestCaseReviewList.vue | 18 +-------- frontend/src/common/js/tableUtils.js | 11 +++++- 12 files changed, 71 insertions(+), 202 deletions(-) diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue index 6949abbdcf..7a4cf3409c 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue @@ -14,11 +14,11 @@ :total="total" :fields.sync="fields" :field-key=tableHeaderKey + :remember-order="true" operator-width="200" @refresh="search(projectId)" @callBackSelectAll="callBackSelectAll" @callBackSelect="callBackSelect" - @saveSortField="saveSortField" ref="scenarioTable"> { diff --git a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue index d77f0be4c1..0ef16bfbdb 100644 --- a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue +++ b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue @@ -19,7 +19,7 @@ :screenHeight="screenHeight" :fields.sync="fields" :field-key="tableHeaderKey" - @saveSortField="saveSortField" + :remember-order="true" operator-width="190px" @refresh="initTable" ref="caseTable" @@ -213,7 +213,7 @@ import { _filter, _sort, getCustomTableHeader, - getCustomTableWidth, saveLastTableSortField, getLastTableSortField + getCustomTableWidth, getLastTableSortField } from "@/common/js/tableUtils"; import {API_CASE_LIST} from "@/common/js/constants"; import HeaderLabelOperate from "@/business/components/common/head/HeaderLabelOperate"; @@ -374,10 +374,7 @@ export default { planId: String }, created: function () { - let orderArr = this.getSortField(); - if (orderArr) { - this.condition.orders = orderArr; - } + this.condition.orders = getLastTableSortField(this.tableHeaderKey); if (this.trashEnable) { this.operators = this.trashOperators; @@ -914,21 +911,6 @@ export default { column.width = 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) { for (let item of this.tableData) { if (id && id === item.id) { diff --git a/frontend/src/business/components/api/definition/components/list/ApiList.vue b/frontend/src/business/components/api/definition/components/list/ApiList.vue index c0df4b7eca..9cfbef563a 100644 --- a/frontend/src/business/components/api/definition/components/list/ApiList.vue +++ b/frontend/src/business/components/api/definition/components/list/ApiList.vue @@ -9,15 +9,15 @@ + :total="total" enableSelection + :batch-operators="trashEnable ? trashButtons : buttons" :screen-height="screenHeight" + :operators="tableOperatorButtons" operator-width="200px" + :remember-order="true" + @refresh="initTable" + :fields.sync="fields" + :table-is-loading="this.result.loading" + :field-key="tableHeaderKey" + ref="table"> diff --git a/frontend/src/business/components/common/components/table/MsTable.vue b/frontend/src/business/components/common/components/table/MsTable.vue index f80eaeb89a..47e6fcbbd7 100644 --- a/frontend/src/business/components/common/components/table/MsTable.vue +++ b/frontend/src/business/components/common/components/table/MsTable.vue @@ -9,6 +9,7 @@ @select="handleSelect" @header-dragend="headerDragend" @cell-mouse-enter="showPopover" + :default-sort="defaultSort" class="test-content adjust-table ms-table" :class="{'ms-select-all-fixed': showSelectAll}" :height="screenHeight" @@ -75,14 +76,13 @@ import { _filter, _handleSelect, - _handleSelectAll, _sort, getLabel, + _handleSelectAll, _sort, getSelectDataCounts, setUnSelectIds, toggleAllSelection, - checkTableRowIsSelect, getCustomTableHeader, saveCustomTableWidth, + checkTableRowIsSelect, getCustomTableHeader, saveCustomTableWidth, saveLastTableSortField, } from "@/common/js/tableUtils"; 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 ShowMoreBtn from "@/business/components/track/case/components/ShowMoreBtn"; import MsTableColumn from "@/business/components/common/components/table/MsTableColumn"; @@ -116,7 +116,8 @@ export default { selectRows: new Set(), selectIds: [], tableActive: true, - hasBatchTipShow: false + hasBatchTipShow: false, + defaultSort: {} }; }, props: { @@ -198,14 +199,19 @@ export default { fieldKey: String, customFields: Array, highlightCurrentRow: Boolean, + // 是否记住排序 + rememberOrder: Boolean }, mounted() { - getLabel(this, TEST_CASE_LIST); + this.setDefaultOrders(); }, watch: { selectNodeIds() { this.selectDataCounts = 0; }, + 'condition.orders'() { + + } }, methods: { // 批量操作提示, 第一次勾选提示, 之后不提示 @@ -238,6 +244,20 @@ export default { let columnTop = column.getBoundingClientRect().top; 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(this, selection, this.data, this.selectRows, this.condition); setUnSelectIds(this.data, this.condition, this.selectRows); @@ -303,7 +323,9 @@ export default { this.condition.orders = []; } _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(); }, handleBatchEdit() { diff --git a/frontend/src/business/components/performance/report/PerformanceTestReportList.vue b/frontend/src/business/components/performance/report/PerformanceTestReportList.vue index 0a6b4fd1b9..83c8cd8573 100644 --- a/frontend/src/business/components/performance/report/PerformanceTestReportList.vue +++ b/frontend/src/business/components/performance/report/PerformanceTestReportList.vue @@ -249,10 +249,8 @@ export default { } else { this.condition.testId = null; } - let orderArr = this.getSortField(); - if(orderArr){ - this.condition.orders = orderArr; - } + this.condition.orders = getLastTableSortField(this.tableHeaderKey); + if (!getCurrentProjectID()) { return; } @@ -351,18 +349,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; - }, handleSelectAll(selection) { if (selection.length > 0) { this.tableData.forEach(item => { diff --git a/frontend/src/business/components/performance/test/PerformanceTestList.vue b/frontend/src/business/components/performance/test/PerformanceTestList.vue index c591bf1ed4..7d89840e0f 100644 --- a/frontend/src/business/components/performance/test/PerformanceTestList.vue +++ b/frontend/src/business/components/performance/test/PerformanceTestList.vue @@ -179,10 +179,8 @@ export default { }); }, initTableData() { - let orderArr = this.getSortField(); - if(orderArr){ - this.condition.orders = orderArr; - } + this.condition.orders = getLastTableSortField(this.tableHeaderKey); + this.condition.projectId = getCurrentProjectID(); this.condition.workspaceId = getCurrentWorkspaceId(); this.result = this.$post(this.buildPagePath('/performance/list'), this.condition, response => { @@ -243,7 +241,7 @@ export default { this.condition.orders = []; } _sort(column, this.condition); - this.saveSortField(this.tableHeaderKey,this.condition.orders); + saveLastTableSortField(this.tableHeaderKey, JSON.stringify(this.condition.orders)); this.initTableData(); }, filter(filters) { @@ -266,21 +264,6 @@ export default { return; } 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; } } }; diff --git a/frontend/src/business/components/track/case/components/TestCaseList.vue b/frontend/src/business/components/track/case/components/TestCaseList.vue index 053300b696..0745b0dca0 100644 --- a/frontend/src/business/components/track/case/components/TestCaseList.vue +++ b/frontend/src/business/components/track/case/components/TestCaseList.vue @@ -14,12 +14,12 @@ :operators="operators" :screen-height="screenHeight" :batch-operators="batchButtons" + :remember-order="true" @handlePageChange="initTableData" @handleRowClick="handleEdit" :fields.sync="fields" :field-key="tableHeaderKey" @refresh="initTableData" - @saveSortField="saveSortField" :custom-fields="testCaseTemplate.customFields" ref="table"> @@ -199,7 +199,7 @@ import { getCustomTableWidth, getLastTableSortField, getPageInfo, getTableHeaderWithCustomFields, - initCondition, saveLastTableSortField, + initCondition, } from "@/common/js/tableUtils"; import HeaderLabelOperate from "@/business/components/common/head/HeaderLabelOperate"; import PlanStatusTableItem from "@/business/components/track/common/tableItems/plan/PlanStatusTableItem"; @@ -378,10 +378,8 @@ export default { }else { this.condition.filters = {reviewStatus: ["Prepare", "Pass", "UnPass"]}; } - let orderArr = this.getSortField(); - if(orderArr){ - this.condition.orders = orderArr; - } + this.condition.orders = getLastTableSortField(this.tableHeaderKey); + this.initTableData(); let redirectParam = this.$route.query.dataSelectRange; this.checkRedirectEditPage(redirectParam); @@ -791,21 +789,6 @@ export default { this.$refs.testBatchMove.close(); 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; } } }; diff --git a/frontend/src/business/components/track/issue/IssueList.vue b/frontend/src/business/components/track/issue/IssueList.vue index e17e51c52c..1e39ebf5b2 100644 --- a/frontend/src/business/components/track/issue/IssueList.vue +++ b/frontend/src/business/components/track/issue/IssueList.vue @@ -25,10 +25,10 @@ :operators="operators" :show-select-all="false" :screen-height="screenHeight" + :remember-order="true" @handlePageChange="getIssues" :fields.sync="fields" :field-key="tableHeaderKey" - @saveSortField="saveSortField" @refresh="getIssues" :custom-fields="issueTemplate.customFields" ref="table" @@ -290,10 +290,8 @@ export default { }, getIssues() { this.page.condition.projectId = this.projectId; - let orderArr = this.getSortField(); - if(orderArr){ - this.page.condition.orders = orderArr; - } + this.page.condition.orders = getLastTableSortField(this.tableHeaderKey); + this.page.result = getIssues(this.page); }, handleEdit(data) { @@ -321,25 +319,10 @@ export default { } return true; }, - saveSortField(key,orders){ - saveLastTableSortField(key,JSON.stringify(orders)); - }, syncIssues() { this.page.result = syncIssues(() => { this.getIssues(); }); - }, - getSortField(){ - let orderJsonStr = getLastTableSortField(this.tableHeaderKey); - let returnObj = null; - if(orderJsonStr){ - try { - returnObj = JSON.parse(orderJsonStr); - }catch (e){ - return null; - } - } - return returnObj; } } }; diff --git a/frontend/src/business/components/track/plan/components/TestPlanList.vue b/frontend/src/business/components/track/plan/components/TestPlanList.vue index 4b1c8262d4..a2a1f41d64 100644 --- a/frontend/src/business/components/track/plan/components/TestPlanList.vue +++ b/frontend/src/business/components/track/plan/components/TestPlanList.vue @@ -326,10 +326,8 @@ export default { this.projectId = getCurrentProjectID(); } this.hasEditPermission = hasPermission('PROJECT_TRACK_PLAN:READ+EDIT'); - let orderArr = this.getSortField(); - if(orderArr){ - this.condition.orders = orderArr; - } + this.condition.orders = getLastTableSortField(this.tableHeaderKey); + this.initTableData(); }, methods: { @@ -454,18 +452,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; - }, handleCommand(cmd, row) { switch (cmd) { case "delete": diff --git a/frontend/src/business/components/track/report/components/TestPlanReportList.vue b/frontend/src/business/components/track/report/components/TestPlanReportList.vue index 9e678e6bd8..611067ed9f 100644 --- a/frontend/src/business/components/track/report/components/TestPlanReportList.vue +++ b/frontend/src/business/components/track/report/components/TestPlanReportList.vue @@ -156,10 +156,8 @@ export default { methods: { initTableData() { initCondition(this.condition, this.condition.selectAll); - let orderArr = this.getSortField(); - if(orderArr){ - this.condition.orders = orderArr; - } + this.condition.orders = getLastTableSortField(this.tableHeaderKey); + this.selectRows = new Set(); if (this.planId) { this.condition.planId = this.planId; @@ -272,18 +270,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; - } } } diff --git a/frontend/src/business/components/track/review/components/TestCaseReviewList.vue b/frontend/src/business/components/track/review/components/TestCaseReviewList.vue index 2e7a7eccf2..1becf7fbaa 100644 --- a/frontend/src/business/components/track/review/components/TestCaseReviewList.vue +++ b/frontend/src/business/components/track/review/components/TestCaseReviewList.vue @@ -178,10 +178,8 @@ export default { }, created() { this.isTestManagerOrTestUser = true; - let orderArr = this.getSortField(); - if(orderArr){ - this.condition.orders = orderArr; - } + this.condition.orders = getLastTableSortField(this.tableHeaderKey); + this.initTableData(); }, computed: { @@ -271,18 +269,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; - } } }; diff --git a/frontend/src/common/js/tableUtils.js b/frontend/src/common/js/tableUtils.js index 7670767713..7ba2a3ba3a 100644 --- a/frontend/src/common/js/tableUtils.js +++ b/frontend/src/common/js/tableUtils.js @@ -385,8 +385,15 @@ export function saveLastTableSortField(key, field) { } export function getLastTableSortField(key) { - let fieldStr = localStorage.getItem(key+"_SORT"); - return fieldStr; + let orderJsonStr = localStorage.getItem(key+"_SORT"); + if(orderJsonStr){ + try { + return JSON.parse(orderJsonStr); + }catch (e){ + return []; + } + } + return []; }