zoukankan      html  css  js  c++  java
  • 巧妙的新订单提醒功能

    人不能时刻盯着屏幕,需要提醒。
    或者语音提醒,或者短信提醒。短信提醒成本高,二是手机马上被塞满。
    通过JS定时刷新,调取接口,巧妙的解决了这个问题。
    定时去数据库查询,最近一天,是否有已支付,未处理的订单,如果有的话,播放音频文件。
    音频文件可以去网上找。叮咚,你有新订单,请及时处理。
    巧妙的运用JS,生成灵活的音频模块,并播放,有点意思。

    var func = function (){
        $.ajax({
            type:'POST',
            url:'/admin.php/Order/get_new_order',
            dataType:'json',
            success:function(data){
                console.log(JSON.stringify(data));
                if(data.errno == 0)
                {
                    playSound();
                }
            }
        });
    }
    
    var playSound = function () {
        var borswer = window.navigator.userAgent.toLowerCase();
        if ( borswer.indexOf( "ie" ) >= 0 )
        {
            //IE内核浏览器
            var strEmbed = '<embed name="embedPlay" src="/admin/image/voice.mp3" autostart="true" hidden="true" loop="false"></embed>';
            if ( $( "body" ).find( "embed" ).length <= 0 )
                $( "body" ).append( strEmbed );
            var embed = document.embedPlay;
    
            //浏览器不支持 audion,则使用 embed 播放
            embed.volume = 100;
            //embed.play();这个不需要
        } else
        {
            //非IE内核浏览器
            var strAudio = "<audio id='audioPlay' src='/admin/image/voice.mp3' hidden='true'>";
    
            if($("#audioPlay").length<=0){
                $( "body" ).append( strAudio );
            }
    
            var audio = document.getElementById( "audioPlay" );
    
            //浏览器支持 audio
            audio.play();
        }
    }
    
    //主动调用
    setInterval("func()", 30000);
    
  • 相关阅读:
    [BZOJ2431] [HAOI2009]逆序对数列
    [Luogu2323] [HNOI2006]公路修建问题
    [Luogu2455] [SDOI2006]线性方程组
    [BZOJ3550] [Sdoi2014]数数
    [Noip2017] 列队
    [Luogu2824] [HEOI2016/TJOI2016]排序
    [BZOJ1060] [ZJOI2007]时态同步
    P1036 选数 题解
    快速幂取模算法详解
    同余定理及其应用
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/9115952.html
Copyright © 2011-2022 走看看