一些常用的方法等


for of 用法
for (const _key of Object.keys(formItem[0])) {
}



获取两个字符串之间的值 getNum(str, firstStr, secondStr) { if (str === "" || str === null || str === undefined) { // "",null,undefined return ""; } if (str.indexOf(firstStr)
< 0) { return ""; } let subFirstStr = str.substring(str.indexOf(firstStr) + firstStr.length, str.length); let subSecondStr = subFirstStr.substring(0, subFirstStr.indexOf(secondStr)); return subSecondStr; }

 





// 获取后一天日期
export function getNextDate(date, day) {
    let dd = new Date(date);
    dd.setDate(dd.getDate() + day);
    let y = dd.getFullYear();
    let m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
    let d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
    return y + "-" + m + "-" + d;
}

export function RandomNum(Min, Max) {
    // 数字以内的随机数
    let Range = Max - Min;
    let Rand = Math.random();
    let num = Min + Math.round(Rand * Range);
    return num;
}



// console.log("会议室订单", meetingResourceOrder);
let meetingResourceOrder.Items = [{"CustomerID":1389187961978897,"CustomerName":"华润置地华东大区","MemberName":"丁岭","BindTableName":"BIResource","BindTableID":1969220443177079,"OrderNo":"ZYD20190923071324","ResourceName":"苏河 ","ResourceID":1969220443177079,"ResourceType":3,"ContactPerson":"丁岭","ContactMobile":"13917476908","ContactEmail":"dingling59@crland.com.cn","Subject":"招采例会","StartDate":"2019-09-24T09:30:00","EndDate":"2019-09-24T12:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":4,"Inputer":"丁岭(SM_139FDCL6908)","InputerID":1713469954981896,"InputTime":"2019-09-23T07:13:24","Adress":"V5写字楼","CommentStatus":2,"RoomID":1969220426400067,"InvitationCode":"1205034","RoomNo":"601","Floor":6,"ID":1972792631230578},{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969221785354323,"OrderNo":"ZYD20190920215710","ResourceName":"牛津街 ","ResourceID":1969221785354323,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"开大会","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:57:10","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969221768577499,"InvitationCode":"4014342","RoomNo":"605","Floor":6,"ID":1969333605498898},{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969222406111459,"OrderNo":"ZYD20190920214022","ResourceName":"607 ","ResourceID":1969222406111459,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"中秋庆佳节","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:40:22","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969222389334324,"InvitationCode":"4200253","RoomNo":"607","Floor":6,"ID":1969316694065855},{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969222087344211,"OrderNo":"ZYD20190920213914","ResourceName":"606 ","ResourceID":1969222087344211,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"国庆活动","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:39:14","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969222070567407,"InvitationCode":"5560244","RoomNo":"606","Floor":6,"ID":1969315553214655},{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969220443177079,"OrderNo":"ZYD20190920213526","ResourceName":"601 ","ResourceID":1969220443177079,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"季缃绮","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:35:26","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969220426400067,"InvitationCode":"6333066","RoomNo":"601","Floor":6,"ID":1969311728009340}]

meetingScreen.model.ts:85 data [{"ResourceName":"苏河","RoomNo":"601","origin":[]},{"ResourceName":"浦江","RoomNo":"602","origin":[]},{"ResourceName":"六本木","RoomNo":"603","origin":[]},{"ResourceName":"牛津街","RoomNo":"605","origin":[]},{"ResourceName":"香榭丽","RoomNo":"606","origin":[]},{"ResourceName":"铜锣湾","RoomNo":"607","origin":[]},{"ResourceName":"第五大道","RoomNo":"608","origin":[]},{"ResourceName":"南湖","RoomNo":"609","origin":[]},{"ResourceName":"秦淮","RoomNo":"610","origin":[]},{"ResourceName":"西子","RoomNo":"611","origin":[]},{"ResourceName":"外滩","RoomNo":"612","origin":[]}]
meetingScreen.model.ts:86 afterData [{"ResourceName":"苏河 ","RoomNo":"601","origin":[{"CustomerID":1389187961978897,"CustomerName":"华润置地华东大区","MemberName":"丁岭","BindTableName":"BIResource","BindTableID":1969220443177079,"OrderNo":"ZYD20190923071324","ResourceName":"苏河 ","ResourceID":1969220443177079,"ResourceType":3,"ContactPerson":"丁岭","ContactMobile":"13917476908","ContactEmail":"dingling59@crland.com.cn","Subject":"招采例会","StartDate":"2019-09-24T09:30:00","EndDate":"2019-09-24T12:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":4,"Inputer":"丁岭(SM_139FDCL6908)","InputerID":1713469954981896,"InputTime":"2019-09-23T07:13:24","Adress":"V5写字楼","CommentStatus":2,"RoomID":1969220426400067,"InvitationCode":"1205034","RoomNo":"601","Floor":6,"ID":1972792631230578},{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969220443177079,"OrderNo":"ZYD20190920213526","ResourceName":"601 ","ResourceID":1969220443177079,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"季缃绮","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:35:26","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969220426400067,"InvitationCode":"6333066","RoomNo":"601","Floor":6,"ID":1969311728009340}]},{"ResourceName":"牛津街 ","RoomNo":"605","origin":[{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969221785354323,"OrderNo":"ZYD20190920215710","ResourceName":"牛津街 ","ResourceID":1969221785354323,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"开大会","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:57:10","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969221768577499,"InvitationCode":"4014342","RoomNo":"605","Floor":6,"ID":1969333605498898}]},{"ResourceName":"607 ","RoomNo":"607","origin":[{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969222406111459,"OrderNo":"ZYD20190920214022","ResourceName":"607 ","ResourceID":1969222406111459,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"中秋庆佳节","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:40:22","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969222389334324,"InvitationCode":"4200253","RoomNo":"607","Floor":6,"ID":1969316694065855}]},{"ResourceName":"606 ","RoomNo":"606","origin":[{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969222087344211,"OrderNo":"ZYD20190920213914","ResourceName":"606 ","ResourceID":1969222087344211,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"国庆活动","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:39:14","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969222070567407,"InvitationCode":"5560244","RoomNo":"606","Floor":6,"ID":1969315553214655}]}]
meetingScreen.model.ts:65 beforeData [{"CustomerID":1389187961978897,"CustomerName":"华润置地华东大区","MemberName":"丁岭","BindTableName":"BIResource","BindTableID":1969220443177079,"OrderNo":"ZYD20190923071324","ResourceName":"苏河 ","ResourceID":1969220443177079,"ResourceType":3,"ContactPerson":"丁岭","ContactMobile":"13917476908","ContactEmail":"dingling59@crland.com.cn","Subject":"招采例会","StartDate":"2019-09-24T09:30:00","EndDate":"2019-09-24T12:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":4,"Inputer":"丁岭(SM_139FDCL6908)","InputerID":1713469954981896,"InputTime":"2019-09-23T07:13:24","Adress":"V5写字楼","CommentStatus":2,"RoomID":1969220426400067,"InvitationCode":"1205034","RoomNo":"601","Floor":6,"ID":1972792631230578},{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969221785354323,"OrderNo":"ZYD20190920215710","ResourceName":"牛津街 ","ResourceID":1969221785354323,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"开大会","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:57:10","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969221768577499,"InvitationCode":"4014342","RoomNo":"605","Floor":6,"ID":1969333605498898},{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969222406111459,"OrderNo":"ZYD20190920214022","ResourceName":"607 ","ResourceID":1969222406111459,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"中秋庆佳节","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:40:22","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969222389334324,"InvitationCode":"4200253","RoomNo":"607","Floor":6,"ID":1969316694065855},{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969222087344211,"OrderNo":"ZYD20190920213914","ResourceName":"606 ","ResourceID":1969222087344211,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"国庆活动","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:39:14","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969222070567407,"InvitationCode":"5560244","RoomNo":"606","Floor":6,"ID":1969315553214655},{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969220443177079,"OrderNo":"ZYD20190920213526","ResourceName":"601 ","ResourceID":1969220443177079,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"季缃绮","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:35:26","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969220426400067,"InvitationCode":"6333066","RoomNo":"601","Floor":6,"ID":1969311728009340}]

let data = [{"ResourceName":"苏河","RoomNo":"601","origin":[{"CustomerID":1389187961978897,"CustomerName":"华润置地华东大区","MemberName":"丁岭","BindTableName":"BIResource","BindTableID":1969220443177079,"OrderNo":"ZYD20190923071324","ResourceName":"苏河 ","ResourceID":1969220443177079,"ResourceType":3,"ContactPerson":"丁岭","ContactMobile":"13917476908","ContactEmail":"dingling59@crland.com.cn","Subject":"招采例会","StartDate":"2019-09-24T09:30:00","EndDate":"2019-09-24T12:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":4,"Inputer":"丁岭(SM_139FDCL6908)","InputerID":1713469954981896,"InputTime":"2019-09-23T07:13:24","Adress":"V5写字楼","CommentStatus":2,"RoomID":1969220426400067,"InvitationCode":"1205034","RoomNo":"601","Floor":6,"ID":1972792631230578},{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969220443177079,"OrderNo":"ZYD20190920213526","ResourceName":"601 ","ResourceID":1969220443177079,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"季缃绮","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:35:26","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969220426400067,"InvitationCode":"6333066","RoomNo":"601","Floor":6,"ID":1969311728009340}]},{"ResourceName":"浦江","RoomNo":"602","origin":[]},{"ResourceName":"六本木","RoomNo":"603","origin":[]},{"ResourceName":"牛津街","RoomNo":"605","origin":[{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969221785354323,"OrderNo":"ZYD20190920215710","ResourceName":"牛津街 ","ResourceID":1969221785354323,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"开大会","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:57:10","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969221768577499,"InvitationCode":"4014342","RoomNo":"605","Floor":6,"ID":1969333605498898}]},{"ResourceName":"香榭丽","RoomNo":"606","origin":[{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969222087344211,"OrderNo":"ZYD20190920213914","ResourceName":"606 ","ResourceID":1969222087344211,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"国庆活动","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:39:14","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969222070567407,"InvitationCode":"5560244","RoomNo":"606","Floor":6,"ID":1969315553214655}]},{"ResourceName":"铜锣湾","RoomNo":"607","origin":[{"CustomerID":1826735859433489,"CustomerName":"上海朝隆贸易有限公司","MemberName":"张柚子","BindTableName":"BIResource","BindTableID":1969222406111459,"OrderNo":"ZYD20190920214022","ResourceName":"607 ","ResourceID":1969222406111459,"ResourceType":3,"ContactPerson":"张柚子","ContactMobile":"13681906334","Subject":"中秋庆佳节","StartDate":"2019-09-24T08:00:00","EndDate":"2019-09-24T09:00:00","IsEnd":false,"IsCharge":true,"DayPrice":0,"DayPriceType":31,"Pcs":1,"TotalAmount":0,"PaidAmount":0,"OrderStatus":32,"Inputer":"张柚子(SM_136RFTK6334)","InputerID":1957466778632366,"InputTime":"2019-09-20T21:40:22","Adress":"V5写字楼","CommentStatus":1,"RoomID":1969222389334324,"InvitationCode":"4200253","RoomNo":"607","Floor":6,"ID":1969316694065855}]},{"ResourceName":"第五大道","RoomNo":"608","origin":[]},{"ResourceName":"南湖","RoomNo":"609","origin":[]},{"ResourceName":"秦淮","RoomNo":"610","origin":[]},{"ResourceName":"西子","RoomNo":"611","origin":[]},{"ResourceName":"外滩","RoomNo":"612","origin":[]}]

            let tempArr: any = [];
            let afterData: any = [];
            let beforeData = meetingResourceOrder.Items;
            // 所有订单按照会议室编号分类整合
            for (let i = 0; i < beforeData.length; i++) {
                if (tempArr.indexOf(beforeData[i].RoomNo) === -1) {
                    afterData.push({
                        ResourceName: beforeData[i].ResourceName,
                        RoomNo: beforeData[i].RoomNo,
                        origin: [beforeData[i]]
                    });
                    tempArr.push(beforeData[i].RoomNo);
                } else {
                    for (let j = 0; j < afterData.length; j++) {
                        if (+afterData[j].RoomNo === +beforeData[i].RoomNo) {
                            afterData[j].origin.push(beforeData[i]);
                            break;
                        }
                    }
                }
            }

            // 所有订单整合到会议室列表对应的会议室下
            for (let i = 0; i < data.length; i++) {
                for (let y = 0; y < afterData.length; y++) {
                    if (+data[i].RoomNo === +afterData[y].RoomNo) {
                        data[i].origin = afterData[y].origin;
                        break;
                    }
                }
            }

 




----------------数据格式化

js将数组对象中某个值相同的对象合并成一个新对象

初始数据-beforeData: [
{ name: "tony", id: "1", age: "20" },
{ name: "jack", id: "2", age: "21" },
{ name: "tony", id: "3", age: "50" },
{ name: "jack", id: "4", age: "10" },
{ name: "mark", id: "5", age: "22" },
{ name: "mark", id: "6", age: "40" }
]

整合后数据-afterData: [
{name: "tony",origin: [{ name: "tony", id: "1", age: "20" },{ name: "tony", id: "3", age: "50" }]},
{name: "jack",origin: [{ name: "jack", id: "2", age: "21" },{ name: "jack", id: "4", age: "10" }]},
{name: "mark",origin: [{ name: "mark", id: "5", age: "22" },{ name: "mark", id: "6", age: "40" }]}
]

let tempArr = [];
let beforeData= [
{ name: "tony", id: "1", age: "20" },
{ name: "jack", id: "2", age: "21" },
{ name: "tony", id: "3", age: "50" },
{ name: "jack", id: "4", age: "10" },
{ name: "mark", id: "5", age: "22" },
{ name: "mark", id: "6", age: "40" }
]
let
afterData = [];
for (let i = 0; i < beforeData.length; i++) {   

if (tempArr.indexOf(beforeData[i].name) === -1) {     

afterData.push({       name: beforeData[i].name,       origin: [beforeData[i]]   });     tempArr.push(beforeData[i].name);   } else { for (let j = 0; j < afterData.length; j++) {   if (afterData[j].name == beforeData[i].name) {       afterData[j].origin.push(beforeData[i]);       break;     }   }   } }

 

 

 





 //两个时间相差天数 兼容firefox chrome   
function datedifference(sDate1, sDate2) {    //sDate1和sDate2是2006-12-18格式  
        var dateSpan,
            tempDate,
            iDays;
        sDate1 = Date.parse(sDate1);
        sDate2 = Date.parse(sDate2);
        dateSpan = sDate2 - sDate1;
        dateSpan = Math.abs(dateSpan);
        iDays = Math.floor(dateSpan / (24 * 3600 * 1000));
        return iDays
    };

获取当前日期前后N天的日期数组 

const temp = [];
for (let i = 0; i < 5; i++) {

// 加1为不含当天之后日期数组,如果为减则算上当前日期前几天
const time = new Date(new Date().setDate((new Date().getDate() + i) + 1));
const year = time.getFullYear();
const month = `0${time.getMonth() + 1}`.slice(-2);
const strDate = `0${time.getDate()}`.slice(-2);
temp.push(`${year}-${month}-${strDate}`)
}
console.log('222222', temp);
//["2019-08-29", "2019-08-30", "2019-08-31", "2019-09-01", "2019-09-02"]


function getMonDate() {
let d = new Date(),
day = d.getDay(),
date = d.getDate();
if (day == 1)
return d;
if (day == 0)
d.setDate(date - 6);
else
d.setDate(date - day + 1);
return d;
}
// 0-6转换成中文名称
function getDayName(days) {
let day = parseInt(days);
if (isNaN(day) || day < 0 || day > 6)
return false;
let weekday = ["周日", "周一", "周二", "周三", "周四", "周五", "周六"];
return weekday[day];
}

// 获取当前天所在的一周列表

function getDayWeek() {
// d是当前星期一的日期对象
let d = getMonDate();
let arr = [];
for (let i = 0; i < 7; i++) {
arr.push({ index: i, date: d.getFullYear() + '-' + ((d.getMonth() + 1) <= 9 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1)) + '-' + (d.getDate() <= 9 ? '0' + (d.getDate()) : d.getDate()), day: (d.getMonth() + 1) + '月' + d.getDate() + '号', week: getDayName(d.getDay()) });
d.setDate(d.getDate() + 1);
}
return arr;
}
// 获取当前天所在的一周列表
function getNewDayWeek() {
// d是当前星期一的日期对象
let d = getMonDate();
let arr = [];
for (let i = 0; i < 5; i++) {
arr.push({ index: i, date: d.getFullYear() + '-' + ((d.getMonth() + 1) <= 9 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1)) + '-' + (d.getDate() <= 9 ? '0' + (d.getDate()) : d.getDate()),
day: (d.getMonth() + 1) + '月' + d.getDate() + '号',
title: getDayName(d.getDay()) });
d.setDate(d.getDate() + 1);
}
return arr;
}
console.log('getDayWeek', getDayWeek())
console.log('getDayWeek', getNewDayWeek())

function getWeekDate(i) {
const now = new Date();
const firstDay = new Date(now - (now.getDay() - 1) * 86400000);
firstDay.setDate(firstDay.getDate() + i - 1);
const mon = Number(firstDay.getMonth()) + 1;
return now.getFullYear() + "." + mon + "." + firstDay.getDate();
}
console.log('当前周第几天', getWeekDate(2))

 

function WeekLastDay() {
const Nowdate = new Date();
const WeekFirstDay = new Date(Nowdate - (Nowdate.getDay() - 1) * 86400000);
const M = Number(WeekFirstDay.getMonth()) + 1;
const day = WeekFirstDay.getYear() + "-" + M + "-" + WeekFirstDay.getDate();
const da = day.split("-");
console.log('当前周最后一天日期', WeekFirstDay)
const firstDay = da && da.length && +da[da.length - 1];
return +firstDay + 6;
}
console.log('当前周最后一天日期(日)', WeekLastDay())
function WeekFirstDay() {
const Nowdate = new Date();
const WeekFirstDay = new Date(Nowdate - (Nowdate.getDay() - 1) * 86400000);
const M = Number(WeekFirstDay.getMonth()) + 1;
const day = WeekFirstDay.getYear() + "-" + M + "-" + WeekFirstDay.getDate();
const da = day.split("-");
console.log('当前周第一天日期', WeekFirstDay)
const firstDay = da && da.length && +da[da.length - 1];
return +firstDay;
}
console.log('当前周第一天日期(日)', WeekFirstDay())

// 座机*号加密
export function geTel(tel) {
let reg = /^(\d{3})\d{4}(\d{4})$/;
return tel.replace(reg, "$1****$2");
}
// 判断是否是手机号
export function isMobilePhone(tel) {
let reg = /^0?1[3|4|5|6|7|8][0-9]\d{8}$/;
return reg.test(tel);
}
export function hideTel(tel) {
const data =
tel &&
tel.replace(/^(.{3})(.*)(.{3})$/g, function (_, m1, m2, m3) {
return m1 + "*".repeat(m2.length) + m3;
});
return data;
}
// 身份证*号加密
export function hideIdCard(tel) {
const data =
tel &&
tel.replace(/^(.{3})(.*)(.{3})$/g, function (_, m1, m2, m3) {
return m1 + "*".repeat(m2.length) + m3;
});
return data;
}

 

0-70以内的随机数

RandomNum(1,70)
RandomNum(Min, Max) {
// 数字以内的随机数
let Range = Max - Min;
let Rand = Math.random();
let num = Min + Math.round(Rand * Range);
return num;
}

获取微信授权之后的code

let ic = location.href.indexOf("code="),
code = ic >= 0 ? location.href.substring(ic + 5, 37 + ic) : "";
params = code;
 
 

获取url上&后面的值

export function getQueryString(search: string, name: string) {
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
let r = search.substr(1).match(reg);
if (r != null) return r[2];
return null;
}
getQueryString(this.props.location.search, "key")
 
去html标签正则
matchReg(str) {
let reg = /<\/?.+?\/?>/g;
let detail = str.replace(reg, '')
return detail;
}
 
matchReg(‘<div>888</div>’)
 
 
 
 

// 将评论传过来的数据格式化
let newArry = [];
let newArry1 = []
let dataArr = changeCounters.myTopicCommentList;
for (let z = 0; z < dataArr.length; z++) {
dataArr[z].Child = [];
}
for (let i = 0; i < dataArr.length; i++) {
if (!dataArr[i].ReplyID) {
newArry1.push(dataArr[i])
} else {
newArry.push(dataArr[i]);
};
}
for (let i = 0; i < newArry1.length; i++) {
for (let b = 0; b < newArry.length; b++) {
let newAr = [];
if (newArry1[i].ID == newArry[b].ReplyID) {
newArry1[i].Child.push(newArry[b]);
}
}
}

 
 
 
 
 
 
 
 
 
 
 
 
function getQueryString(search: string, name: string) {
let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
let r = search.substr(1).match(reg);
if (r != null) return r[2];
return null;
}
let key = decodeURI((getQueryString(this.props.location.search, "key"))) != 'null' ? decodeURI((getQueryString(this.props.location.search, "key"))) : '';

 

 

<!DOCTYPE html>
<html><head>

<body onselectstart="return false;">
<div id="content" class="content">
  <div class="touchArea">
    <p class="item-subtitle">长按事件</p>
    <div className="jubao">
      <Grid avg={2} className="more-gridlist">
        <Col>举报</Col>
        <Col>取消</Col>
      </Grid>
      <span></span>
    </div>
  </div>
</div>

  <input type="text" name="" id="search-key" value="" />
</body>

1//时间戳变成日期格式

function parseStandard(time, format) {
    let t = new Date(time);
    let tf = function(i) {
    return(i < 10 ? '0' : '') + i
};
return format.replace(/yyyy|MM|dd|hh|mm|ss/g, function(a) {
 switch(a) {
  case 'yyyy':
  return tf(t.getFullYear());

  case 'MM':
  return tf(t.getMonth() + 1);

  case 'mm':
  return tf(t.getMinutes());

  case 'dd':
  return tf(t.getDate());

  case 'hh':
  return tf(t.getHours());

  case 'ss':
  return tf(t.getSeconds());
  default:
  return
    }
    })
  }
console.log(parseStandard(1625648542516, "yyyy-MM-dd hh:mm:ss"))

2,时间友好显示

function getDate(date) {
   return date instanceof Date ?date :date &&new Date(date.replace(/\-/g, "/").replace(/T/g, " ").substr(0, 19));}

function getTime(date) {return typeof date === "number" ? date : getDate(date).getTime();}
const preMinute = 1000 * 60,preHour = preMinute * 60,preDay = preHour * 24,halfamonth = preDay * 15;

function friendlyTime(startDate, endDate) {
  if(!startDate) return "";
  const dates = getDate(startDate),
  start = getTime(dates),
  end = getTime(endDate || Date.now());
  if(isNaN(start)) return startDate;
  const det = end - start;
  if(det < preMinute) return "刚刚";
  else if(det < preHour) return Math.round(det / preMinute) + "分钟前";
  else if(det < preDay) return Math.round(det / preHour) + "小时前";
  else if(det < preDay * 7) return Math.round(det / preDay) + "天前";
  else if(dates.getFullYear() !== new Date().getFullYear()) return dates.format("yyyy-MM-dd hh:mm");
  else return parseStandard(dates, "yyyy-MM-dd hh:mm:ss");
}
//参数一 开始时间 参数二 与一相差时间
    console.log('friendlyTime', friendlyTime('2018-04-19T9:00:00', ''))

 

3半角转全角

function toDBC(txtstring) {
   var tmp = "";
  for(var i = 0; i < txtstring.length; i++) {
    if(txtstring.charCodeAt(i) == 32) {
    tmp = tmp + String.fromCharCode(12288);
  }
if(txtstring.charCodeAt(i) < 127) {
  tmp = tmp + String.fromCharCode(txtstring.charCodeAt(i) + 65248);
  }
}
return tmp;
}
console.log('半角转全角', toDBC('song'))

4获取AddDayCount天后的日期

function GetDateStr(days) {
  var dd = new Date();
    dd.setDate(dd.getDate() + days); //获取AddDayCount天后的日期
  var y = dd.getFullYear();
  var m = dd.getMonth() + 1; //获取当前月份的日期
  var d = dd.getDate();
    m = (m < 10 ? '0' : '') + m;
    d = (d < 10 ? '0' : '') + d;
    console.log('年,月,日', y, m, d)
  return dd
}
console.log('获取3天后的日期', GetDateStr(3))

5保留2位小数并4舍5入方法

function toDecimal(x) {
  var f = parseFloat(x);
    if(isNaN(f)) {
    return;
  }
    f = Math.round(x * 100) / 100;
  return f;
}
console.log('保留2位小数并4舍5入方法', toDecimal(0.125))

6两个时间相差几小时 保留2位小数

function getHour(s1, s2) {
  var reDate = /\d{4}-\d{1,2}-\d{1,2} /;
  s1 = new Date((reDate.test(s1) ? s1 : '2017-1-1 ' + s1).replace(/-/g, '/'));
  s2 = new Date((reDate.test(s2) ? s2 : '2017-1-1 ' + s2).replace(/-/g, '/'));
  var ms = s2.getTime() - s1.getTime();
  console.log('ms', ms)
  if(ms < 0) return 0;
  return toDecimal(ms / 1000 / 60 / 60);
}
console.log('两个时间相差几小时', getHour('2018-04-24 15:10:00', '2018-04-24 16:00:00'))

7格式化时间日期


Date.prototype.Format = function(fmt) { //author: meizz
var o = {
    "M+": this.getMonth() + 1, //月份
    "d+": this.getDate(), //日
    "h+": this.getHours(), //小时
    "m+": this.getMinutes(), //分
    "s+": this.getSeconds(), //秒
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度
    "S": this.getMilliseconds() //毫秒
};
if(/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for(var k in o)
    if(new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
  }
console.log('格式还日期', new Date().Format("yyyy-MM-dd hh:mm:ss"))

8数组去重

Array.prototype.unique3 = function() {
var res = [];
var json = {};
for(var i = 0; i < this.length; i++) {
console.log('数组啧啧啧', this[i], json[this[i]])
if(!json[this[i]]) {
console.log('json', json)
res.push(this[i]);
json[this[i]] = 1;
}
}
return res;
}
console.log('数组去重', [1, 2, 12, 2, 1, 12, 2, 12, 3, 4, 6, 3].unique3())

9对数组数字进行排序

function sortNumber(a, b) {
return a - b
}
var arr = [10, 5, 40, 25, 1];

console.log('对数组数字大小进行排序', arr.sort(sortNumber))

10对象排序同时按照两种方式排序。需求是这样的:“active”为1的排在前面,“active”为0的排在后面,然后分别按照“name”的字母顺序进行排序

var arr = [

{
  "name": "Alfredo",
  "active": 0
}, {
  "name": "Alexander",
  "active": 0
}, {
  "name": "Ronald",
  "active": 1
}, {
  "name": "salvador",
  "active": 0
}, {
  "name": "Saryn",
  "active": 1
}

];

arr.sort(function(a, b) {
    return b.name < a.name;
  }).sort(function(a, b) {
    return b.active - a.active
  });
console.log('对象排序', arr)


11时间戳化时间

function formatDuring(mss) {
var days = parseInt(mss / (1000 * 60 * 60 * 24));
var hours = parseInt((mss % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = parseInt((mss % (1000 * 60 * 60)) / (1000 * 60));
var seconds = parseInt((mss % (1000 * 60)) / 1000);
return hours + "时" + minutes + "分" + seconds + "秒";
}
console.log('时间戳化时间', formatDuring(352425367425))


12设置随机字符

function createVerifyCode() {
var code = '';
var codeLength = 4;
//设置随机字符
  var random = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z');
  //循环codeLength
  for(var i = 0; i < codeLength; i++) {
    var index = Math.floor(Math.random() * 36);
    code += random[index];
    }
  return code;
}
console.log('随机数', createVerifyCode())

13验证手机号 邮箱

function isCellphone(value) {
  var CELLPHONE_REGEXP = /^1[3|4|5|7|8][0-9]{9}$/;
  value = value.replace(/\s/gi, "");
  return value && CELLPHONE_REGEXP.test(value);
}

function isEmail(value) {
  var EMAIL_REGEXP = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
  return value && EMAIL_REGEXP.test(value);
}
console.log('手机号', isCellphone('183216500'))
console.log('邮箱', isEmail('98184'))

 

var arrObj = [{a: 1,c: 2,d: 3}, {a: 2,c: 2,d: 4}]
console.log('筛选数组对象', arrObj.filter(c => c.a == 1))

14存在则去除,不存在则添加

var isExist = false;
var choseTimeNew = [

  {id: 1,time: '时间1'},

  {id: 2,time: '时间2'},

  {id: 1,time: '时间1'}

]
for(var i = 0; i < choseTimeNew.length; i++) {
  if((choseTimeNew[i].id == 1)) {
    choseTimeNew.splice(i, 1);
    isExist = true;
    break;
  }
 }
if(!isExist) {
    choseTimeNew.push({id: 3,time: '时间3'});
}
console.log('choseTimeNew', choseTimeNew)

15数组对象去重


var arr2 = [

{
  name: "name1",
  num: "1"
},
{
  name: "name2",
  num: "11"
},
{
  name: "name3",
  num: "12"
},
{
  name: "name4",
  num: "13"
},
{
  name: "name2",
  num: "1"
},
{
  name: "name6",
  num: "12"
}
]

function arrayUnique2(arr, name) {
    var hash = {};
      return arr.reduce(function(item, next) {
      hash[next[name]] ? '' : hash[next[name]] = true && item.push(next);
    return item;
  }, []);
}
console.log('根据name去重', arrayUnique2(arr2, "name"));
console.log('根据num去重', arrayUnique2(arr2, "num"));

16获取某年某月天数

function getLastDay(year, month) {
  var new_year = year; //取当前的年份 
  var new_month = month++; //取下一个月的第一天,方便计算(最后一天不固定) 
  if(month > 12) //如果当前大于12月,则年份转到下一年 
  {
    new_month -= 12; //月份减 
    new_year++; //年份增 
  }
    var new_date = new Date(new_year, new_month, 1);
  console.log('new_date', new_date) //取当年当月中的第一天
    return(new Date(new_date.getTime() - 1000 * 60 * 60 * 24)).getDate(); //获取当月最后一天日期 
}

17数组累加

console.log('时间', getLastDay('2018', '2')) //28
var arr = [1, 2, 3, 4, 5, 6];
  console.time("ruduce");
Array.prototype.ruduceSum = function() {
  for(var i = 0; i < 10000; i++) {
  return this.reduce(function(preValue, curValue) {
  console.log(preValue, curValue)
  return preValue + curValue;
});
}
}
  arr.ruduceSum();
  console.log('最终的值:' + arr.ruduceSum()); // 21 
  console.timeEnd("ruduce");

18长按事件

var _this = this;
var timeOutEvent = 0;
$(".touchArea .item-subtitle").on({
  touchstart: function(e) {
  $(".subarea .sub-commenting-item").find('.subjubao').css({
  display: 'none'
})
$(".subarea .sub-commenting-item p").css({
  backgroundColor: '#f5f5f5'
})
timeOutEvent = setTimeout(() => {
  longPress($(this))
}, 1000);
  e.preventDefault();
},
touchmove: function(e) {
// clearTimeout(timeOutEvent);
// timeOutEvent = 0;
},
  touchend: function(e) {
    clearTimeout(timeOutEvent);
    if(timeOutEvent != 0) {
      $(".touchArea").find('.jubao').css({
      display: 'none'
})
$(".touchArea .item-subtitle").css({
  backgroundColor: '#fff'
})
  console.log('点击', $(this).siblings('.jubao'))
}
  return false;
}
});

function longPress(_that) {
  timeOutEvent = 0;
  $(".touchArea").find('.jubao').css({
  display: 'none'
});
_that.css({
  backgroundColor: '#999'
})
_that.siblings('.jubao').css({
  display: 'block'
})
console.log('长按', $(this).siblings('.jubao'))
};

19输入法

var cpLock = false;
var _this = this;
$('#search-key').on('compositionstart', function() {
  cpLock = true;
});
$('#search-key').on('compositionend', function() {
  cpLock = false;
if(!cpLock) {
  console.log('查询')
  //中文输入法 当还是拼音时不执行这个地方,拼音转为汉字时执行
  // _this.props.contactStore.Result=[];
  // _this.props.dispatch(ContactAction.getContactList(localStorage.CompanyID,$('#search-key').val(),5));
}
});
$('#search-key').on('input', function() {
  if(!cpLock) {
  console.log('查询');
  //输入法 除了中文输入法 当输入任何字符时都执行
  // _this.props.contactStore.Result=[];
  // _this.props.dispatch(ContactAction.getContactList(localStorage.CompanyID,$('#search-key').val(),5));
}
});
</script>

20手机号码中间加*正则

'18321640664'.replace(/\d{4}(?=\d{4}$)/, '****')

</html>

 

21:获取当前日期的一周时间

    function getMonDate(){
        var d=new Date(),
        day=d.getDay(),
        date=d.getDate();
        if(day==1)
            return d;
            if(day==0)
                d.setDate(date-6);
                else
                d.setDate(date-day+1);
                return d;
        }
        // 0-6转换成中文名称
        function getDayName(day)
        {
            var day=parseInt(day);
            if(isNaN(day) || day<0 || day>6)
            return false;
            var weekday=["周日","周一","周二","周三","周四","周五","周六"];
            return weekday[day];
        }
        // d是当前星期一的日期对象
        var d=getMonDate();
        var arr=[];
        for(var i=0; i<7; i++)
        {
            arr.push(d.getFullYear()+'年'+(d.getMonth()+1)+'月'+d.getDate()+'日 ('+getDayName(d.getDay())+')');
            d.setDate(d.getDate()+1);
        }
        console.log('arr',arr)








// 数组对象 整合
for (let k = 0; k < datas.length - 1; k++) {
for (let m = k + 1; m < datas.length; m++) {
if (datas[k].SourcesKey === datas[m].SourcesKey) {
datas[k].areaList = datas[k].areaList.concat(datas[m].Data);
datas.splice(m, 1);
m--;
}
}
}

 

posted @ 2018-05-10 10:16  小宋宋  阅读(423)  评论(0编辑  收藏  举报