功能实现

作者: 强哥总司令 | 来源:发表于2017-04-03 10:55 被阅读0次

    一.页面处理

    1.获取textarea的文本内容

    function getQQText(){
    
    }
    

    2.设置textarea的文本内容

    function setEditText(regularText){
    
    }
    

    3.添加数据到订单表格

    function setOrderTable(orderPersonList){
    
    }
    

    4.添加数据到订单列表

    function setfoodOrderList(foodOrderList){
    
    }
    

    二.数据处理

    1.数据优化、文本排版

    注意:
    1.该功能无法识别图片。
    2.高级优化需要提供餐品全名。

    (1).简单优化

    a.删掉无用数据

    • 纯日期数据,如:2017/3/31 17:34:10
    • 纯时间数据,如:18:00:25
    • 单行超过指定的长度的数据(不包括title)
    • 以特定字符串开头的数据,如:http://
    • 因为数据被删除后的空title

    b.为文本换行

    • 删除多余的空行
    • 为了查看和编辑方便,在每条订单数据之间加入换行符
    • 订单数据内容为:title+content
      格式为:
      name time
      foodA
      foodB
    <script type="text/javascript">
    /*排版和优化---------------------------------------------------------------------------*/
    function simpleRuleQQText(qqText){
        var mutilLineText = qqText.split("\n");
        var regularTextArray = new Array();
        for(var i=0;i<mutilLineText .length;i++){
            var singleLineText = mutilLineText[i];
            // console.log(singleLineText);
            if(isTitle(singleLineText)){
                regularTextArray.push(singleLineText);
            }else{
                if(!isNeedDelete(singleLineText)){              
                    regularTextArray.push(singleLineText);
                }
            }
        }
    
        //将无内容的标题至为空
        for(var i=0;i<regularTextArray.length;i++){
            if(isTitle(regularTextArray[i])){
                if(i == regularTextArray.length-1||isTitle(regularTextArray[i+1])){
                    regularTextArray[i] = "";
                }
            }else{
                //对字符串中的加号和空格进行处理
                regularTextArray[i] = regularTextArray[i].replace(/\+|+/g,"\n");
                regularTextArray[i] = regularTextArray[i].replace(/ /g,"");
                console.log(regularTextArray[i]);
            }
        }
    
        //再次排版,清除空行,转换为段落
        var regularText ="";
        for(var i=0;i<regularTextArray.length;i++){
            if(i!=0&&isTitle(regularTextArray[i])){
                regularText = regularText+"\n";
            }
    
            if(regularTextArray[i]!=""){            
                regularText = regularText+regularTextArray[i]+"\n"
                
            }
        }
        return regularText;
    }
    //数据是否为标题(格式为:name datetime),这里只是判断是否有包含日期,而且日期不在开头
    function isTitle(text){
        var reDateTime = /\d{4}\/\d{1,2}\/\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}/;
        if(text.search(reDateTime)>0){
            return true;
        }else{
            return false;
        }
    }
    //数据是否需要删除
    function isNeedDelete(text){
        var bigLength = 30;
        var littleLength = 0;
        var contain = "http://|下单|吃饭|饭到了|撤回了一条消息|还有人要点吗";
        if(isDateTime(text)||isTime(text)||isTextBigThan(text,bigLength)||isTextLittleThan(text,littleLength)||isTextContainWith(text,contain)){
            return true;
        }else{
            return false;
        }
    }
    //是否是日期时间格式
    function isDateTime(text){
        var reDateTime = /^\d{4,}\/(?:0?\d|1[12])\/(?:[012]?\d|3[01]) (?:[01]?\d|2[0-4]):(?:[0-5]?\d|60):(?:[0-5]?\d|60)$/;
        var isDateTime = reDateTime.test(text);
        return isDateTime;
    }
    //是否是时间格式
    function isTime(text){
        var reTime = /^(?:[01]?\d|2[0-4]):(?:[0-5]?\d|60):(?:[0-5]?\d|60)$/;
        var isTime = reTime.test(text);
        return isTime;
    }
    //文本长度是否超过指定的长度
    function isTextBigThan(text,length){
        if(text.length>length){
            return true;
        }
        return false;
    }
    //文本长度是否小于或等于指定的长度
    function isTextLittleThan(text,length){
        if(text.length<=length){
            return true;
        }
        return false;
    }
    //文本是否包含了指定的字符串
    function isTextContainWith(text,contain){
        var reContain = new RegExp(contain);
        if(text.search(reContain)>=0){
            return true;
        }else{
            return false;
        }
    }
    </script>
    

    (2).高级优化(能匹配套餐)(后期版本加入)

    2.合并订单

    (1).获取订单列表

    <script type="text/javascript">
    /*获取订单列表---------------------------------------------------------------------------*/
    function getTimeOrderArray(regularText){
        var mutilLineText = regularText.split("\n");
        var timeOrderArray = new Array();
    
        for(var i = 0;i<mutilLineText.length;i++){
            if(isTitle(mutilLineText [i])){
                var title =mutilLineText[i];
                var length = title.length;
                var dateTime = title.match(/\d{4}\/\d{1,2}\/\d{1,2} \d{1,2}:\d{1,2}:\d{1,2}/)[0];
                var dateTimeLength = dateTime.length;
                var name = title.substring(0,length-dateTimeLength-1);
                var time = title.substring(length-dateTimeLength,length);
                var food = new Array();
    
                for(var j =i+1;j<mutilLineText.length;j++){
    
                    if(isTitle(mutilLineText[j])){
                        break;
                    }else{
                        if(mutilLineText[j]!="")food.push(mutilLineText[j]);
                    }
                }
    
                var timeOrder ={ordername:name,orderfood:food,ordertime:time};
                timeOrderArray.push(timeOrder);
            }
        }   
        return timeOrderArray;
    }
    </script>
    

    (2).合并订单列表

    <script type="text/javascript">
    /*合并订单---------------------------------------------------------------------------*/
    function mergeOrder(orderTimeArray){
        var orderPersonArray= new Array();
        for(var i = 0;i<orderTimeArray.length;i++){
            var name = orderTimeArray[i].ordername;
            var time = orderTimeArray[i].ordertime;
            var foodArray = orderTimeArray[i].orderfood;
    
            var isInOrder = false;
            for(var j=0;j<orderPersonArray.length;j++){
                var personOrder = orderPersonArray[j];
                ordername = personOrder.ordername;
                if(name == ordername){
                    isInOrder = true;
                    break;
                }
            }
            if(!isInOrder) {
                var foodAndTimeArray = new Array();
                for(var j=0;j<orderTimeArray.length;j++){
                    var timeOrder = orderTimeArray[j];
                    if(name == orderTimeArray[j].ordername){
                        var timeAndFood = {orderfood:timeOrder.orderfood,ordertime:timeOrder.ordertime};
                        foodAndTimeArray.push(timeAndFood);
                    }
                }
                var personOrder = {ordername:name,orderfoodandtimearray:foodAndTimeArray};
                orderPersonArray.push(personOrder);
            }
        }
        return orderPersonArray;
    }
    </script>
    

    2.统计订单

    (1).获取订单内容

    <script type="text/javascript">
    /*获取订单内容---------------------------------------------------------------------------*/
    function getFoodArray(regularText){
        var mutilLineText = regularText.split("\n");
        var foodArray = new Array();
        for(var i = 0;i<mutilLineText .length;i++){
            if(!isTitle(mutilLineText [i])&&mutilLineText [i]!=""){
                foodArray.push(mutilLineText [i]);
            }
        }
        return foodArray;
    }
    </script>
    

    (2).统计订单

    <script type="text/javascript">
    /*订单统计---------------------------------------------------------------------------*/
    function countFood(foodArray){
        var foodOrderArray = new Array();
        for(var i = 0;i<foodArray.length;i++){
            var food = foodArray[i];
            var isInOrder = false;
            for(var j=0;j<foodOrderArray.length;j++){
                var order = foodOrderArray[j];
                orderfood = order.orderfood;
                if(food == orderfood){
                    isInOrder = true;
                    break;
                }
            }
            if(!isInOrder) {
                var foodCount = 0;
                for(var j=0;j<foodArray.length;j++){
                    if(food == foodArray[j]){
                    foodCount++;
                    }
                }
                var order = {orderfood:food,orderCount:foodCount};
                foodOrderArray.push(order);
            }
        }
        return foodOrderArray;
    }
    </script>
    

    相关文章

      网友评论

        本文标题:功能实现

        本文链接:https://www.haomeiwen.com/subject/obinottx.html