common.wxs 1.2 KB
function strSlice(str, maxLen) {
    var num = 6;
    var newStr = str;
    if (str) {
        if (maxLen) {
            num = maxLen
        };
        if (str.length > num) {
            newStr = str.slice(0, num) + '...'
        };
        return (newStr)
    }
};

function saveDecimal(num, type) {
    if (num) {
        var numType = 2;
        var afterNum = '';
        var result = '';
        if (type) {
            numType = type
        };
        result = Math.round(num * 100) / 100;
        result = result.toString();
        if (result.indexOf('.') >= 0) {
            afterNum = result.split('.');
            if (afterNum[(1)].length == 1) {
                result = result + '0'
            }
        } else {
            result = result + '.00'
        };
        return (result)
    } else {
        return ('0.00')
    }
};

function inArray(str, arr) {
    if (!str) {
        return (false)
    };
    var m = arr || [];
    var n = arr.some((function(value, index, array) {
        return (value == str)
    }));
    if (n) {
        return (true)
    } else {
        return (false)
    }
};
module.exports.strSlice = strSlice;
module.exports.saveDecimal = saveDecimal;
module.exports.inArray = inArray;