parseTime(date,fmt)
参数 | 类型 | 说明 |
---|---|---|
date | string/Date/number | 日期字符串、new Date()类型或时间戳 |
fmt | string | 默认值:yyyy-MM-dd hh:mm:ss |
返回值说明: 返回 fmt 格式化时间
const time = parseTime("2023-01-01 08:00:00", "yyyy-MM-dd hh:mm:ss");
const time2 = parseTime(new Date().getTime());
formatTime(time,fmt)
参数 | 类型 | 说明 |
---|---|---|
time | number | 时间戳 |
fmt | string | 默认值:yyyy 年 MM 月 dd 日 |
返回值说明: 距当前时间<30s 返回"刚刚" 距当前时间<1h 返回"xx 分钟前" 距当前时间<1d 返回"xx 小时前" 距当前时间<2d 返回"1 天前" 其他时间返回 fmt 格式化时间
numberTime(date,day,fmt)
参数 | 类型 | 说明 |
---|---|---|
date | string/Date/number | 日期字符串、new Date()类型或时间戳 |
day | number | 默认值:0 |
fmt | string | 默认值:yyyy-MM-dd hh:mm:ss |
返回值说明: 返回 fmt 格式化时间
numberTime(new Date("2023-10-11 00:00:00"), -7); //返回7天前 2023-10-04 00:00:00
返回值说明: 返回对象结构
//示例url:http://xxx.xx.com?a=123&b=456
console.log(getUrlQuery()); //{a:'123',b:'456'}
devicePlatform()
返回值说明:
字段名 | 值 | 说明 |
---|---|---|
trident | true/false | 是否为 ie 内核 |
webKit | true/false | 是否为谷歌内核 |
presto | true/false | 是否为 opera 内核 |
gecko | true/false | 是否为火狐内核 |
mobile | true/false | 是否为移动终端 |
ios | true/false | 是否为 ios 系统 |
android | true/false | 是否为安卓系统 |
iphone | true/false | 是否为 iphone |
iPad | true/false | 是否为 ipad |
true/false | 是否为微信 |
//示例在pc端运行
console.log(utils.devicePlatform().ios); //false
console.log(utils.devicePlatform().webKit); //true
removeNullObj(obj)
参数说明:
参数 | 类型 | 说明 |
---|---|---|
obj | object | 传入一个对象 |
返回说明: 返回处理之后的对象
const obj = {
a: null,
b: "",
c: undefined,
d: "123",
};
console.log(removeNullObj(obj)); //{d: '123'}
参数说明:
参数 | 类型 | 说明 |
---|---|---|
fn | function | 执行的方法 |
delay | number | 延迟的时长 默认 1000ms |
const func = throttle(function () {
console.log("throttle click");
}, 5000);
参数说明:
参数 | 类型 | 说明 |
---|---|---|
fn | function | 执行的方法 |
delay | number | 延迟的时长 默认 1000ms |
const func = debounce(function () {
console.log("debounce click");
}, 1000);
flattenArray(arr: any[], key?: string)
参数说明:
参数 | 类型 | 说明 |
---|---|---|
arr | any[] | 任意的数组类型 |
key | string | 可选,对象数组的 key |
返回说明: 返回扁平化之后的数组
const flattenNumberArray = [1, [2, [3, 4], 5], 6];
const flattenedNumberArray = flattenArray(flattenNumberArray);
console.log(flattenedNumberArray); //[1,2,3,4,5,6]
const flattenObjArray = [{ a: 1 }, [{ b: 1 }, [{ c: 1 }]]];
const flattenedObjArray = flattenArray(flattenObjArray);
console.log(flattenedObjArray); //{a:1,b:1,c:1}
const nestChildObj = [
{
name: "11",
children: [
{
name: "111",
},
{
name: "112",
},
],
},
{
name: "12",
children: [
{
name: "121",
},
{
name: "122",
},
],
},
];
const flattenedChildObj = flattenArray(nestChildObj, "children");
console.log(flattenedChildObj); //[{name:'11'},{name:'111'},{name:'112'},{name:'12'},{name:'121'},{name:'122'}]