layui导出表格科学计数问题

layui导出表格科学计数问题

直接修改layui源代码,找到 exportFile 下的 eachCols 方法,在 var o = a[l.field]; 后面加上一句代码就可以了

/^[0-9]{10,}$/.test(o) ? ( o += '\t' ) : "";

完整代码

d.exportFile = function (e, t, i) {
    var a = this;
    t = t || d.clearCacheKey(d.cache[e]), i = i || "csv";
    var l = c.config[e] || {}, n = {csv: "text/csv", xls: "application/vnd.ms-excel"}[i],
        s = document.createElement("a");
    return r.ie ? o.error("IE_NOT_SUPPORT_EXPORTS") : (s.href = "data:" + n + ";charset=utf-8,\ufeff" + encodeURIComponent(function () {
        var i = [], l = [], n = [];
        return layui.each(t, function (t, a) {
            var n = [];
            "object" == typeof e ? (layui.each(e, function (e, a) {
                0 == t && i.push(a || "")
            }), layui.each(d.clearCacheKey(a), function (e, t) {
                n.push('"' + (t || "") + '"')
            })) : d.eachCols(e, function (e, l) {
                if (l.field && "normal" == l.type && !l.hide) {
                    var o = a[l.field];
                    // 代码加在这里----------------------------------
                    /^[0-9]{10,}$/.test(o)?(o+='\t'):"";
                    // --------------------------------------------
                    void 0 !== o && null !== o || (o = ""), 0 == t && i.push(l.title || ""), n.push('"' + u(l, o, a, "text") + '"')
                }
            }), l.push(n.join(","))
        }), layui.each(a.dataTotal, function (e, t) {
            n.push(t)
        }), i.join(",") + "\r\n" + l.join("\r\n") + "\r\n" + n.join(",")
    }()), s.download = (l.title || "table_" + (l.index || "")) + "." + i, document.body.appendChild(s), s.click(), void document.body.removeChild(s))
}

0前缀丢失问题

/^([0-9]{10,}|0+\d+)$/.test(o)?(o+='\t'):"";

版权声明:本文为yu57955原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。