Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Fedex
/
imac-vue
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Elements-SY
2023-09-21 17:10:10 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
08e38ca37baaae57b8b070b2415e5e4dec3f8b63
08e38ca3
1 parent
45fcee50
modify
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
6 deletions
src/utils/index.js
src/views/basicInformation/queryCargo/dialog.vue
src/utils/index.js
View file @
08e38ca
...
...
@@ -461,12 +461,12 @@ export function restTableHeight($refs) {
* @param {string || Object} keys
* @description 对数组中指定的JSON字段去重和指定的字段进行排序
* @example
* 当指定一个字段去重时:removeDuplicates(arr, "
flightRout
e")
* 当指定一个字段去重时:removeDuplicates(arr, "
nam
e")
* 当指定一个字段去重并且排序如下:
*
const result = removeDuplicates(arr
, {
* duplicate: "
flightRout
e", // 去重字段
* sortType: "Number", // 排序类型
:number、string
* sortAttr: "
routePriority
", // 排序字段
*
removeDuplicates(res.data.list
, {
* duplicate: "
nam
e", // 去重字段
* sortType: "Number", // 排序类型
* sortAttr: "
id
", // 排序字段
* })
*/
export
function
removeDuplicates
(
arr
,
keys
)
{
...
...
@@ -500,6 +500,7 @@ export function removeDuplicates(arr, keys) {
if
(
result
.
unique
.
length
)
{
result
.
unique
=
sortFn
(
"unique"
);
}
// 返回排序去重结果
return
result
;
}
}
...
...
@@ -514,3 +515,40 @@ export function removeDuplicates(arr, keys) {
}
}
}
/**
* Array Json
* @param {Array} arr
* @param {string} key
* @description 把所有重复的过滤出来
* @example
* filterRepeat(arr, "name")
*/
export
function
filterRepeat
(
arr
,
key
)
{
const
duplicateIds
=
arr
.
map
((
item
)
=>
item
[
key
])
.
filter
((
key
,
index
,
array
)
=>
array
.
indexOf
(
key
)
!==
index
);
return
arr
.
filter
((
item
)
=>
duplicateIds
.
includes
(
item
[
key
]));
}
/**
* Array Json
* @param {Array} arr
* @param {string} key
* @param {string} time
* @description 把数组JSON字段重复的值过滤出来,并且根据时间戳返回最新的那一条且返回新的数组
* @example
* filterRepeatNewData(arr, "name", "createTime")
*/
export
function
filterRepeatNewData
(
arr
,
key
,
time
)
{
// 找出最大时间戳
const
maxDate
=
filterRepeat
(
arr
,
key
).
reduce
(
(
max
,
obj
)
=>
new
Date
(
obj
[
time
]).
getTime
()
>
max
?
new
Date
(
obj
[
time
]).
getTime
()
:
max
,
-
Infinity
);
// 找出最大时间戳对应的数据并且返回新的数组
const
result
=
filterRepeat
(
arr
,
key
).
filter
(
(
obj
)
=>
new
Date
(
obj
[
time
]).
getTime
()
===
maxDate
);
return
result
;
}
...
...
src/views/basicInformation/queryCargo/dialog.vue
View file @
08e38ca
...
...
@@ -17,7 +17,7 @@
</el-row>
</el-form>
<Tables ref="cargoLog" ductName="cargoLog" :order="false" :border='false' :data="data.tableData"
:headerData="tableHeader" tableAlign="center" :showOverflowTooltip="false"
:height="tableHeight"
:headerData="tableHeader" tableAlign="center" :showOverflowTooltip="false"
:page="selectData.page" :limitSize="selectData.size" :pageSizes="[100]" :pagination="false"
:loading="loading" @currentChange="currentChange">
</Tables>
...
...
Please
register
or
login
to post a comment