index.js 1.02 KB
/**
 * 工具类 
 * import utils from "@/utils";
 */

/**
 * table滚动
 */
const tableScroll = (columns, y) => {

    let _y = (typeof y == "string" || typeof y == 'number') ? y : document.body.clientHeight - y.getBoundingClientRect().top - 150;

    let opt = {
        x: (typeof columns == "string" || typeof columns == 'number') ? columns : columns.reduce((c, n) => {

            let cn = typeof c == "number" ? c : parseInt(c['width'] || 300);
            let nn = parseInt(n['width'] || 300);

            return cn + nn;
        }),
        y: Math.max(_y, 300)
    }
    // console.log(opt);
    return opt
}

// table 表格各项配置
const tableConfig = {
    align: 'center', // 表格内容排列方式
    ellipsis: true, // 表格内容超出宽度,省略显示
}

// 封装接口返回数据
const handlePromise = (promise) => {
    return promise.then(res => {
        return Promise.resolve(res)
    }).catch(e => {
        return Promise.resolve(res)
    })
}

export {
    tableScroll,
    tableConfig,
    handlePromise
}