|
@@ -96,6 +96,7 @@ import useFetch from '@/hooks/useFetch'
|
|
|
import useTableCheck from '@/hooks/useTableCheck'
|
|
|
import RightKeyMenu from './RightKeyMenu.vue'
|
|
|
import useMainStore from '@/store/main'
|
|
|
+import { cloneDeep } from 'lodash-es'
|
|
|
import type { EChartsOption } from 'echarts'
|
|
|
import type { ExtractApiResponse, ExtractApiParams } from '@/api/api'
|
|
|
import type { EpTableColumn } from 'global-type'
|
|
@@ -324,42 +325,83 @@ const myDbClick = (row: any) => {
|
|
|
}
|
|
|
}
|
|
|
const sortTableData = ref<any[]>([])
|
|
|
-const originalTableData = ref<any[]>([])
|
|
|
-const sortChange = (params: any) => {
|
|
|
- console.log('params:', params)
|
|
|
- const { column, prop, order } = params
|
|
|
- if (order === 'ascending') {
|
|
|
- sortTableData.value.sort((a: any, b: any) => {
|
|
|
- if (a.markingGroupNumber == 0) {
|
|
|
- return -1
|
|
|
- } else if (b.markingGroupNumber == 0) {
|
|
|
- return 1
|
|
|
+const sortByCutGroup = (prop: string, order: string) => {
|
|
|
+ let arr = cloneDeep(originalTableData.value)
|
|
|
+ let groupNodeIndexes: any = arr
|
|
|
+ .map((item: any, index: number) => {
|
|
|
+ if (!item.markerId) {
|
|
|
+ return index
|
|
|
} else {
|
|
|
- if (typeof a[prop] === 'string') {
|
|
|
- let aa = a[prop] || '',
|
|
|
- bb = b[prop] || ''
|
|
|
- return aa.localeCompare(bb)
|
|
|
- } else {
|
|
|
- return a[prop] - b[prop]
|
|
|
- }
|
|
|
+ return null
|
|
|
}
|
|
|
})
|
|
|
- } else if (order === 'descending') {
|
|
|
- sortTableData.value.sort((a: any, b: any) => {
|
|
|
- if (a.markingGroupNumber == 0) {
|
|
|
- return -1
|
|
|
- } else if (b.markingGroupNumber == 0) {
|
|
|
- return 1
|
|
|
- } else {
|
|
|
+ .filter((item: any) => item !== null)
|
|
|
+ console.log('groupNodeIndexes', groupNodeIndexes)
|
|
|
+ let newArr = []
|
|
|
+ let targetIndex = 0
|
|
|
+ for (let i = 0; i < groupNodeIndexes.length; i++) {
|
|
|
+ if (i == 0) {
|
|
|
+ newArr.push(arr[groupNodeIndexes[i]])
|
|
|
+ } else {
|
|
|
+ let subArr = arr.slice(targetIndex + 1, groupNodeIndexes[i])
|
|
|
+ subArr.sort((a: any, b: any) => {
|
|
|
if (typeof a[prop] === 'string') {
|
|
|
let aa = a[prop] || '',
|
|
|
bb = b[prop] || ''
|
|
|
- return bb.localeCompare(aa)
|
|
|
+ return order === 'ascending' ? aa.localeCompare(bb) : bb.localeCompare(aa)
|
|
|
} else {
|
|
|
- return b[prop] - a[prop]
|
|
|
+ return order === 'ascending' ? a[prop] - b[prop] : b[prop] - a[prop]
|
|
|
}
|
|
|
+ })
|
|
|
+ newArr.push(...subArr)
|
|
|
+ newArr.push(arr[groupNodeIndexes[i]])
|
|
|
+ targetIndex = groupNodeIndexes[i]
|
|
|
+ if (i == groupNodeIndexes.length - 1) {
|
|
|
+ newArr.push(...arr.slice(targetIndex + 1))
|
|
|
}
|
|
|
- })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sortTableData.value = newArr
|
|
|
+}
|
|
|
+const originalTableData = ref<any[]>([])
|
|
|
+const sortChange = (params: any) => {
|
|
|
+ console.log('params:', params)
|
|
|
+ const { column, prop, order } = params
|
|
|
+ if (order === 'ascending') {
|
|
|
+ sortByCutGroup(prop, order)
|
|
|
+ // sortTableData.value.sort((a: any, b: any) => {
|
|
|
+ // if (a.markingGroupNumber == 0) {
|
|
|
+ // return -1
|
|
|
+ // } else if (b.markingGroupNumber == 0) {
|
|
|
+ // return 1
|
|
|
+ // } else {
|
|
|
+ // if (typeof a[prop] === 'string') {
|
|
|
+ // let aa = a[prop] || '',
|
|
|
+ // bb = b[prop] || ''
|
|
|
+ // return aa.localeCompare(bb)
|
|
|
+ // } else {
|
|
|
+ // return a[prop] - b[prop]
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ } else if (order === 'descending') {
|
|
|
+ sortByCutGroup(prop, order)
|
|
|
+
|
|
|
+ // sortTableData.value.sort((a: any, b: any) => {
|
|
|
+ // if (a.markingGroupNumber == 0) {
|
|
|
+ // return -1
|
|
|
+ // } else if (b.markingGroupNumber == 0) {
|
|
|
+ // return 1
|
|
|
+ // } else {
|
|
|
+ // if (typeof a[prop] === 'string') {
|
|
|
+ // let aa = a[prop] || '',
|
|
|
+ // bb = b[prop] || ''
|
|
|
+ // return bb.localeCompare(aa)
|
|
|
+ // } else {
|
|
|
+ // return b[prop] - a[prop]
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // })
|
|
|
} else if (order == null) {
|
|
|
sortTableData.value = JSON.parse(JSON.stringify(originalTableData.value))
|
|
|
}
|
|
@@ -372,12 +414,11 @@ function initSortTableData(sortKey?: any) {
|
|
|
data.unshift(last)
|
|
|
}
|
|
|
sortTableData.value = JSON.parse(JSON.stringify(data))
|
|
|
+
|
|
|
+ originalTableData.value = JSON.parse(JSON.stringify(data))
|
|
|
if (sortKey) {
|
|
|
- sortTableData.value.sort((a: any, b: any) => {
|
|
|
- return b[sortKey] - a[sortKey]
|
|
|
- })
|
|
|
+ sortByCutGroup(sortKey, 'descending')
|
|
|
}
|
|
|
- originalTableData.value = JSON.parse(JSON.stringify(data))
|
|
|
}
|
|
|
}
|
|
|
initSortTableData()
|