func.js 5.17 KB
// 不命中统一返回
const NOT_MATCH_OBJ = {
    beautyNum: "",
    index: -1,
    len: 0
}

// 验证AABB
export function checkBeautyNumberAAA(phone) {
    var reg = new RegExp('(.)\\1{2}', "g");
    if (phone.match(reg) != null) {
        var result = phone.match(reg)[0].toString();
        return {
            beautyNum: result,
            index: phone.indexOf(result),
            len: result.length,
            type: "AAA+",
        }
    }
    return NOT_MATCH_OBJ
}

// 验证AABB
export function checkBeautyNumberAABB(phone) {
    var reg = new RegExp("(\\d)\\1((?!\\1)\\d)\\2", "g");
    if (phone.match(reg) != null) {
        var result = phone.match(reg)[0].toString();
        return {
            beautyNum: result,
            index: phone.indexOf(result),
            len: result.length,
            type: "AABB+",
        }
    }
    return NOT_MATCH_OBJ
}

// 验证ABAB
export function checkBeautyNumberABAB(phone) {
    var reg = new RegExp("(\\d)((?!\\1)\\d)\\1\\2", "g");
    if (phone.match(reg) != null) {
        var result = phone.match(reg)[0].toString();
        return {
            beautyNum: result,
            index: phone.indexOf(result),
            len: result.length,
            type: "ABAB+"
        }
    }
    return NOT_MATCH_OBJ
}


// 验证AABB
export function checkBeautyNumberABBA(phone) {
    var reg = new RegExp("(\\d)((?!\\1)\\d)\\2[\\d]", "g");
    if (phone.match(reg) != null) {
        var result = phone.match(reg)[0].toString();
        if (result.substring(0, 1) == result.substring(3, 4)) {
            return {
                beautyNum: result,
                index: phone.indexOf(result),
                len: result.length,
                type: "ABBA"
            }
        }
    }
    return NOT_MATCH_OBJ
}


// 验证ABCAB
export function checkBeautyNumberABCAB(phone) {
    var reg = new RegExp("(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){2}\\d{3}", "g");
    if (phone.match(reg) != null) {
        var result = phone.match(reg)[0].toString();
        if (result.substring(0, 2) == result.substring(3, 5)) {
            return {
                beautyNum: result,
                index: phone.indexOf(result),
                len: result.length,
                type: "ABCAB"
            }
        }
    }
    return NOT_MATCH_OBJ
}



// 验证ABCD
export function checkBeautyNumberABCD(phone) {
    var reg = new RegExp("(?:0123|1234|2345|3456|4567|5678|6789|7890|0987|9876|8765|7654|6543|5432|4321|3210)\\d", "g");
    if (phone.match(reg) != null) {
        var result = phone.match(reg)[0].toString()
        result = result.substring(0, 4);
        return {
            beautyNum: result,
            index: phone.indexOf(result),
            len: result.length,
            type: "ABCD"
        }
    }
    return NOT_MATCH_OBJ
}


// // 最后一位是6/8/9
export function checkBeautyNumberLast(phone) {
    const reg = new RegExp("\\d+[689]$");
    if (phone.match(reg) != null) {
        return {
            beautyNum: phone.slice(-1),
            index: phone.length - 1,
            len: 1,
            type: "LAST689"
        }
    }
    return NOT_MATCH_OBJ
}

// 获取吉祥口号
export function getFeatureName(mobile) {
    let featureName = {
        0: "寓意圆满",
        1: "大吉大利",
        2: "成双成对",
        3: "三生万物",
        4: "四季来财",
        5: "五福临门",
        6: "六六大顺",
        7: "升职加薪",
        8: "发财旺运",
        9: "富贵长久"
    }
    let num = mobile.slice(-1);
    let result = featureName[num + ''];
    return result;
}

export function sortByLength(array) {
    array.sort((a, b) => a.beautyList.length > 0 ? -1 : 1);
}

// 支付宝省市区结构
export function addressToTree(address) {
    let districtssheng = address.province_list;
    let districtsShi = address.city_list;
    let districtsQu = address.county_list;
    let newArrSheng = [];
    for (var i in districtssheng) {
        // 第一层循环遍历出省份
        let districtsShengObj = {}
        districtsShengObj.id = i
        districtsShengObj.name = districtssheng[i]
        let newArrShi = []
        for (var s in districtsShi) {
            //第二层循环出市
            if (i.substring(0, 2) === s.substring(0, 2)) {
                // 以城市编码的前两位作为匹配项
                let shiobj = {};
                shiobj.id = s
                shiobj.name = districtsShi[s]
                let newArrQU = []
                for (var q in districtsQu) {
                    //第三层循环遍历出区
                    if (s.substring(0, 4) == q.substring(0, 4)) {
                        //市与区以编码的前四位作为匹配
                        let quobj = {};
                        quobj.id = q
                        quobj.name = districtsQu[q]
                        newArrQU.push(quobj);
                        shiobj.subList = newArrQU;
                    }
                }
                newArrShi.push(shiobj);
                districtsShengObj.subList = newArrShi;
                //添加到所需的对象里
            }
        }
        newArrSheng.push(districtsShengObj) // 最后添加到数组里
    }
    return newArrSheng;
}