[working] add grid filter

This commit is contained in:
2023-04-24 15:07:36 +08:00
parent 530c687bd9
commit 4096068a62
8 changed files with 347 additions and 3060 deletions

View File

@ -27,10 +27,30 @@ function throttle(method, delay = 100, context = g, ...args) {
}
}
function debounce(method, delay = 100, context = g, ...args) {
if (method == null) {
return;
}
method.tiid && clearTimeout(method.tiid);
method.tiid = setTimeout(() => method.apply(context, args), delay);
}
function truncate(v) {
return (v > 0 ? Math.floor : Math.ceil)(v);
}
function distinct(array, key, filter) {
const dict = Object.create(null);
for (let item of array) {
const v = typeof filter === 'function' ? filter(item) : item[key];
const val = v?.value ?? v;
if (!Object.prototype.hasOwnProperty.call(dict, val)) {
dict[val] = v;
}
}
return Object.values(dict);
}
function isEmail(text) {
return /^\w[-\w.+]*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(text);
}
@ -65,7 +85,9 @@ export {
isMobile,
// functions
throttle,
debounce,
truncate,
distinct,
isEmail,
isPhone
}