kun 9/26/20/10

This commit is contained in:
沈学坤
2019-09-26 20:08:08 +08:00
parent b457aee0ec
commit a9c8dff024
8 changed files with 114 additions and 79 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 7.4 KiB

View File

@@ -1,10 +1,58 @@
/** 筛选函数 */
export function multiFilter (array, filters) {
const filterKeys = Object.keys(filters)
return array.filter(item => {
return filterKeys.every(key => {
if (!filters[key].length) return true
return !!~filters[key].indexOf(item[key])
})
})
// 使用递归遍历所有属性判断是否 在对象里面匹配到值 借鉴js对象深拷贝的方式
function loopObj (searkey, obj) {
let bool = false
let loop = (searkey, obj) => {
for (let key in obj) {
if (
String(obj[key])
.trim()
.indexOf(searkey) !== -1
) {
bool = true
}
if (typeof obj[key] === 'object' && obj[key] !== null) {
loop(searkey, obj[key])
}
}
}
loop(searkey, obj)
return bool
}
let tool = {
/**
* 搜索函数
* @param {*} arr 搜索目标
* @param {*} str 搜索参数
*/
setSearch: function (arr, str) {
let arrTrueList = [] // 匹配的数据
let arrFalseList = [] // 不匹配数据
arr.forEach(item => {
// 判断输入值key 是否存在对象数组上面
if (loopObj(str, item)) {
arrTrueList.push(item)
} else {
arrFalseList.push(item)
}
})
return arrTrueList
},
/**
* 筛选函数
* @param {*} array 筛选参数
* @param {*} filters 筛选目标
*/
multiFilter: function (array, filters) {
const filterKeys = Object.keys(filters)
return array.filter(item => {
return filterKeys.every(key => {
if (!filters[key].length) return true
return !!~filters[key].indexOf(item[key])
})
})
}
}
export default tool