From 2b94ea8798ea6e1c2f1d789307deb60b7df9906e Mon Sep 17 00:00:00 2001 From: yufei0306 <13417315+yufei0306@user.noreply.gitee.com> Date: Wed, 17 Apr 2024 14:12:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E5=AD=90=E8=A1=A8=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E5=B1=9E=E6=80=A7sortDefault=EF=BC=9A?= =?UTF-8?q?=E5=80=BC=E8=B6=8A=E5=B0=8F=E8=B6=8A=E6=8E=92=E5=9C=A8=E5=89=8D?= =?UTF-8?q?=E9=9D=A2=EF=BC=8C=E4=B8=8D=E9=85=8D=E7=BD=AE=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC999?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Table/src/Table.vue | 21 +++++++++++++++++++++ src/components/rowDrop/index.vue | 28 +++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/src/components/Table/src/Table.vue b/src/components/Table/src/Table.vue index 15b93be06..a7a988359 100644 --- a/src/components/Table/src/Table.vue +++ b/src/components/Table/src/Table.vue @@ -247,6 +247,25 @@ export default defineComponent({ }) } + // 默认排序 + const updateSort= (val)=>{ + val.forEach(item=>{ + if(!item.sortDefault){ + if(item.fixed=='left'){ + item.sortDefault = 0 + }else if(item.fixed=='right'){ + item.sortDefault = 9999 + }else{ + item.sortDefault = 999 // 默认999 + } + } + }) + val.sort((column1,column2)=>{ + return column1.sortDefault - column2.sortDefault + }) + } + + const rnderTableColumn = (columnsChildren?: TableColumn[]) => { const { columns, @@ -258,6 +277,8 @@ export default defineComponent({ showOverflowTooltip, border } = unref(getProps) + //默认排序 + updateSort(columns) return [...[renderTableExpand()], ...[renderTableSelection()]].concat( (columnsChildren || columns).map((v) => { // 自定生成序号 diff --git a/src/components/rowDrop/index.vue b/src/components/rowDrop/index.vue index f02a935b8..a8333f833 100644 --- a/src/components/rowDrop/index.vue +++ b/src/components/rowDrop/index.vue @@ -84,10 +84,12 @@ const save = () => { saveDate.push(props.allSchemas.tableColumns[0]) allData.value.forEach((item) => { const _item:any = props.allSchemas.tableColumns.find(itemColumns => (itemColumns.label == item )) - _item.isTable = false - if (checkedDataList.value.indexOf(_item.label) > -1) { - _item.isTable = true - saveDate.push(_item) + if(_item){ + _item.isTable = false + if (checkedDataList.value.indexOf(_item.label) > -1) { + _item.isTable = true + saveDate.push(_item) + } } }) // 默认操作列 @@ -130,6 +132,7 @@ const initSelectSta = () => { if(props.detailAllSchemas){ _myTableColumns = [...props.allSchemas?.tableColumns,...props.detailAllSchemas?.tableMainColumns] } + updateSort(_myTableColumns) // 有缓存 if (res) { checkedDataList.value = [] @@ -197,7 +200,22 @@ const initSelectSta = () => { console.log(err) }) } - +const updateSort= (val)=>{ + val.forEach(item=>{ + if(!item.sortDefault){ + if(item.fixed=='left'){ + item.sortDefault = 0 + }else if(item.fixed=='right'){ + item.sortDefault = 9999 + }else{ + item.sortDefault = 999 // 默认999 + } + } + }) + val.sort((column1,column2)=>{ + return column1.sortDefault - column2.sortDefault + }) +} // 更新主列表字段 const updataTableColumns = (val) => { emit('updataTableColumns', val)