From dad10a883e2995704b17132f50474107f5a45a9a Mon Sep 17 00:00:00 2001 From: Riku <risaku@163.com> Date: 星期六, 28 九月 2024 20:38:58 +0800 Subject: [PATCH] 1. 修改评估记录排序功能 --- src/components/table/FYTable.vue | 11 +++-- src/components.d.ts | 4 -- src/views/fysp/evaluation/EvalutationRecord.vue | 65 +++++++++++++++++++++++++++----- 3 files changed, 62 insertions(+), 18 deletions(-) diff --git a/src/components.d.ts b/src/components.d.ts index 893003c..d0e2d80 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -29,7 +29,6 @@ ElDescriptionsItem: typeof import('element-plus/es')['ElDescriptionsItem'] ElDialog: typeof import('element-plus/es')['ElDialog'] ElDivider: typeof import('element-plus/es')['ElDivider'] - ElDrawer: typeof import('element-plus/es')['ElDrawer'] ElEmpty: typeof import('element-plus/es')['ElEmpty'] ElForm: typeof import('element-plus/es')['ElForm'] ElFormItem: typeof import('element-plus/es')['ElFormItem'] @@ -37,7 +36,6 @@ ElIcon: typeof import('element-plus/es')['ElIcon'] ElImage: typeof import('element-plus/es')['ElImage'] ElInput: typeof import('element-plus/es')['ElInput'] - ElInputNumber: typeof import('element-plus/es')['ElInputNumber'] ElMain: typeof import('element-plus/es')['ElMain'] ElMenu: typeof import('element-plus/es')['ElMenu'] ElMenuItem: typeof import('element-plus/es')['ElMenuItem'] @@ -45,7 +43,6 @@ ElOption: typeof import('element-plus/es')['ElOption'] ElPageHeader: typeof import('element-plus/es')['ElPageHeader'] ElPagination: typeof import('element-plus/es')['ElPagination'] - ElPopconfirm: typeof import('element-plus/es')['ElPopconfirm'] ElPopover: typeof import('element-plus/es')['ElPopover'] ElRadioButton: typeof import('element-plus/es')['ElRadioButton'] ElRadioGroup: typeof import('element-plus/es')['ElRadioGroup'] @@ -56,7 +53,6 @@ ElStep: typeof import('element-plus/es')['ElStep'] ElSteps: typeof import('element-plus/es')['ElSteps'] ElSubMenu: typeof import('element-plus/es')['ElSubMenu'] - ElSwitch: typeof import('element-plus/es')['ElSwitch'] ElTable: typeof import('element-plus/es')['ElTable'] ElTableColumn: typeof import('element-plus/es')['ElTableColumn'] ElTag: typeof import('element-plus/es')['ElTag'] diff --git a/src/components/table/FYTable.vue b/src/components/table/FYTable.vue index 42c7a99..3e5da08 100644 --- a/src/components/table/FYTable.vue +++ b/src/components/table/FYTable.vue @@ -91,7 +91,7 @@ fontSize: 'default' }; }, - emits: ['search', 'cellClick', 'tablePaste'], + emits: ['search', 'cellClick', 'tablePaste', 'sortChange'], watch: { currentPage(nValue, oValue) { if (nValue != oValue) { @@ -177,11 +177,14 @@ handlePaste(event) { this.$emit('tablePaste', event); }, - doLayout(){ + doLayout() { this.$refs.tableRef.doLayout(); }, - handleSortChange({column, prop, order }){ - + handleSortChange({ column, prop, order }) { + this.$emit('sortChange', { column, prop, order }); + }, + clearSort(){ + this.$refs.tableRef.clearSort(); } }, mounted() { diff --git a/src/views/fysp/evaluation/EvalutationRecord.vue b/src/views/fysp/evaluation/EvalutationRecord.vue index 0d61791..41338ec 100644 --- a/src/views/fysp/evaluation/EvalutationRecord.vue +++ b/src/views/fysp/evaluation/EvalutationRecord.vue @@ -6,6 +6,7 @@ @cell-click="cellClick" :cell-class-name="cellClassName" @table-paste="handlePaste" + @sort-change="handleSortChange" > <template #options> <!-- 鍖哄幙 --> @@ -42,7 +43,7 @@ </template> <template #table-column> - <el-table-column fixed="left" sortable prop="sceneIndex" label="缂栧彿" width="80"> + <el-table-column fixed="left" sortable="custom" prop="sceneIndex" label="缂栧彿" width="80"> </el-table-column> <el-table-column prop="sceneName" :show-overflow-tooltip="true" label="鍚嶇О" width="300"> </el-table-column> @@ -50,16 +51,10 @@ prop="subTaskTime" label="宸℃煡鏃ユ湡" width="110" - sortable + sortable="custom" :formatter="timeFormat" /> - <el-table-column - prop="evaluation.resultscorebef" - label="寰楀垎" - width="90" - sortable - :sort-method="sortScore" - /> + <el-table-column prop="evaluation.resultscorebef" label="寰楀垎" width="90" sortable="custom" /> <el-table-column prop="evaluation.resultscorebef" label="鐜俊鐮�" width="100"> <template #default="{ row }"> <span :style="`color: ${toCode(row).color};`">{{ toCode(row).name }}</span> @@ -107,6 +102,7 @@ import { envCreditCode } from '@/constants/index'; import CompReport from './components/CompReport.vue'; import { useTablePaste } from '@/composables/tablePaste'; +import { useCloned } from '@vueuse/core'; export default { setup() { @@ -125,7 +121,9 @@ scenetype: {}, time: dayjs().add(-1, 'M').date(1).toDate() }, - townFilters: [] + townFilters: [], + // 鍘熷鏁版嵁锛岀敤浜庢帓搴忓彇娑堝悗 + orginData: [] }; }, methods: { @@ -152,10 +150,13 @@ this.$refs.tableRef.onSearch(); }, onSearch(page, func) { + this.$refs.tableRef.clearSort(); const area = this._getParam(); evaluateApi.fetchAutoEvaluation(area).then((res) => { if (res.data) { this.tableData = res.data; + this.orginData = useCloned(this.tableData).cloned; + console.log(this.orginData); this.getFilters(res.data); if (typeof func === 'function') { func({ data: this.tableData }); @@ -210,6 +211,50 @@ const s2 = b.evaluation ? parseInt(b.evaluation.resultscorebef) : 0; return s1 - s2; }, + handleSortChange({ column, prop, order }) { + console.log(column, prop, order); + if (order == null) { + this.orginData.forEach((e, i) => { + this.tableData[i] = e; + }); + } else if (prop == 'evaluation.resultscorebef') { + this.tableData.sort((a, b) => { + const s1 = a.evaluation ? parseInt(a.evaluation.resultscorebef) : 0; + const s2 = b.evaluation ? parseInt(b.evaluation.resultscorebef) : 0; + if (order == 'ascending') { + return s1 - s2; + } else if (order == 'descending') { + return s2 - s1; + } + }); + } else if (prop == 'sceneIndex') { + this.tableData.sort((a, b) => { + if (order == 'ascending') { + if (a.sceneIndex === b.sceneIndex) { + return a.subTaskTime > b.subTaskTime ? 1 : -1; + } else { + return a.sceneIndex - b.sceneIndex; + } + } else if (order == 'descending') { + if (a.sceneIndex === b.sceneIndex) { + return b.subTaskTime > a.subTaskTime ? 1 : -1; + } else { + return b.sceneIndex - a.sceneIndex; + } + } + }); + } else if (prop == 'subTaskTime') { + this.tableData.sort((a, b) => { + if (order == 'ascending') { + return a[prop] > b[prop] ? 1 : -1; + // return dayjs(a).isAfter(dayjs(b)) ? 1 : -1; + } else if (order == 'descending') { + return b[prop] > a[prop] ? 1 : -1; + // return dayjs(b).isAfter(dayjs(a)) ? 1 : -1; + } + }); + } + } }, mounted() { this.addRefreshEvent(this.$refs.tableRef.doLayout); -- Gitblit v1.9.3