zhanghua
2022-10-17 d22f9b9278303f340e2f8efd6f5a98f0b614c05c
src/utils/helper.js
@@ -1,7 +1,6 @@
import { hash } from "immutable";
import myrequest from './request'
// 深拷贝
function deepClone(obj) {
export function deepClone(obj) {
    let objClone = Array.isArray(obj) ? [] : {};
    if (obj && typeof obj === 'object' && obj != null) {
        for (let key in obj) {
@@ -17,10 +16,22 @@
    return objClone;
}
// 计算限制时间
function computeTime(time2) {
export function computeTime(time2) {
    const t1 = new Date();
    const t2 = new Date(time2);
    return filterTime(t2.getTime() - t1.getTime());
}
// 获取字典表
export async function getTypeList(level,code){
    let arr;
    await myrequest({
        method:'get',
        url:`sccg/dict/query_type?level=${level}&typeCode=${code}`
    })
    .then(res=>{
        arr = res.data;
    })
    return arr;
}
function filterTime(time) {
    if (time < 0) {
@@ -29,7 +40,6 @@
    let dd = Math.floor(time/24/60/60/1000),
        hh = Math.floor(time/60/60/1000-dd*24),
        mi = Math.floor(time/60/1000-dd*24*60-hh*60);
    console.log(dd, hh, mi)
    return addDay(fillTime(dd)) + addHour(fillTime(hh)) + addMin(fillTime(mi));
}
function fillTime(num) {
@@ -40,23 +50,22 @@
}
function addDay(str) {
    str = parseFloat(str);
    if (str <= 0) {
    if (str <0) {
        return;
    }
    return str + '天'
}
function addHour(str) {
    str = parseFloat(str);
    if (str <= 0) {
    if (str <0) {
        return;
    }
    return str + '小时'
}
function addMin(str) {
    str = parseFloat(str);
    if (str <= 0) {
    if (str < 0) {
        return;
    }
    return str + '分钟'
}
export { deepClone, computeTime };