lookPicture.html 9.78 KB
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<meta charset="utf-8">
<head th:include="include :: header"></head>
<style>
    .picdiv{
        width:45%;
        height:200px;
        margin: 15px;
        border: 1px solid #ddd;
        white-space: nowrap;
        float: left;

    }
</style>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <div class="container-fluid">
        <div class="row-fluid">
            <div class="col-sm-12">
                <ul class="thumbnails">
                    <li class="col-sm-6">
                        <div class="thumbnail">
                            <img alt="车辆入厂照片" id="carIn"  >
                            <div class="caption">
                                <p>
                                    <span>车辆入厂拍照</span><a class="btn btn-primary" onclick="scan(1)">拍照</a>
                                </p>
                            </div>
                        </div>
                    </li>
                    <li class="col-sm-6">
                        <div class="thumbnail">
                            <img alt="身份证拍照" id="file2">
                            <div class="caption">
                                <p>
                                    <span>身份证拍照</span><button class="btn btn-primary" onclick="scan(2)">拍照</button>
                                </p>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
            <div class="col-sm-12">
                <ul class="thumbnails">
                    <li class="col-sm-6">
                        <div class="thumbnail">
                            <img alt="驾驶证拍照" id="file3">
                            <div class="caption">
                                <p>
                                    <span>驾驶证拍照</span><button class="btn btn-primary" onclick="scan(3)">拍照</button>
                                </p>
                            </div>
                        </div>
                    </li>
                    <li class="col-sm-6">
                        <div class="thumbnail">
                            <img alt="行驶证拍照" id="file4">
                            <div class="caption">
                                <p>
                                    <span>行驶证拍照</span><button class="btn btn-primary" onclick="scan(4)">拍照</button>
                                </p>
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </div>
<!--    <form class="form-horizontal m" id="form-camera-cameraReset">-->
<!--        <input name="id"  type="hidden"  />-->
<!--        -->

        <div class="form-group">
            <div class="form-control-static col-sm-offset-9">
                <input id="vehicleName" name="vehicleName" class="form-control" type="hidden" th:value="${vehicleName}" >
                <input id="cardNumber" name="cardNumber" class="form-control" type="hidden" th:value="${cardNumber}" >
                <input id="carNumber" name="carNumber" class="form-control" type="hidden" th:value="${carNumber}" >
                <input id="driverNumber" name="driverNumber" class="form-control" type="hidden" th:value="${driverNumber}" >
                <button type="submit" class="btn btn-primary" onclick="select()">提交</button>
                <button onclick="$.modal.close()" class="btn btn-danger" type="button">关闭</button>
            </div>
        </div>
<!--    </form>-->
</div>
<div th:include="include :: footer"></div>
<script type="text/javascript">
    $("#file2").attr("src", "http://127.0.0.1:38088/video=stream&camidx=0");
    $("#file3").attr("src", "http://127.0.0.1:38088/video=stream&camidx=0");
    $("#file4").attr("src", "http://127.0.0.1:38088/video=stream&camidx=0");
    // $("#view2").attr("src", "http://127.0.0.1:38088/video=stream&camidx=1");

    // 加载主头视频模式
    view1_mode_data1 = { "camidx": "0", "mode": "0" };
    view1_mode_data2 = { "camidx": "0", "mode": "1" };
    $.post("http://127.0.0.1:38088/device=getresolution", JSON.stringify(view1_mode_data2), function(res){

    })

    // 加载副头视频模式
    view2_mode_data1 = { "camidx": "1", "mode": "0" };
    view2_mode_data2 = { "camidx": "1", "mode": "1" };
    $.post("http://127.0.0.1:38088/device=getresolution", JSON.stringify(view2_mode_data2), function(res){

    })
    function getData(){
        let url = "/wms/img/Capture/carIn.jpg?" + Date.parse(new Date());
        if (!CheckImgExists(url)) {
            window.setTimeout(function(){getData();},2000);
        };
        $("#carIn").attr('src',url);
    }
    //判断图片是否存在
    function CheckImgExists(imgurl) {
        var ImgObj = new Image(); //判断图片是否存在
        ImgObj.src = imgurl;
        //没有图片,则返回-1
        if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
            return true;
        } else {
            return false;
        }
    }


    function scan(num){
        if(num==1){
            $.ajax({
                cache : false,
                type : "POST",
                url : ctx + "API/WMS/v2/cameraLogin",
                dataType: 'json',
                data : {
                    "cameraId": "1"
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("请求失败!");
                },
                success : function(result) {
                    if (result.code == web_status.SUCCESS) {
                        getData();
                    }else{
                        $.modal.alertError(result.data);
                    }
                }
            });
        }
        if(num==2){
            $.ajax({
                cache : false,
                type : "POST",
                url : "http://127.0.0.1:38088/card=idcard",
                dataType: 'json',
                data : {},
                async : false,
                error : function(request) {
                    $.modal.alertError("请求失败!");
                },
                success : function(result) {
                    if(result.code == '0'){
                        downloadIamge("data:image/png;base64," + result.IDCardInfo.photoBase64_Z,$("#cardNumber").val())
                        $.modal.msgSuccess("下载成功");
                    }else{
                        $.modal.msgError("请将证件放对位置!!!")
                    }
                }
            });
        }else if(num==3){
            $.ajax({
                cache : false,
                type : "POST",
                url : "http://127.0.0.1:38088/video=grabimage",
                dataType: 'json',
                data : {
                    "filepath": "base64",
                    "rotate": "0",
                    "deskew": "0",
                    "camidx": "0",
                    "ColorMode": "3",
                    "quality": "0"
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("请求失败!");
                },
                success : function(result) {
                    if(result.code == '1' ){
                        $.modal.msgError(result.message)
                    }else{
                        downloadIamge("data:image/png;base64," + result['photoBase64'],$("#carNumber").val())
                        $.modal.msgSuccess("下载成功");
                    }
                }
            });
        }else if(num==4){
            $.ajax({
                cache : false,
                type : "POST",
                url : "http://127.0.0.1:38088/video=grabimage",
                dataType: 'json',
                data : {
                    "filepath": "base64",
                    "rotate": "0",
                    "deskew": "0",
                    "camidx": "0",
                    "ColorMode": "3",
                    "quality": "0"
                },
                async : false,
                error : function(request) {
                    $.modal.alertError("请求失败!");
                },
                success : function(result) {
                    if(result.code == '1' ){
                        $.modal.msgError(result.message)
                    }else{
                        downloadIamge("data:image/png;base64," + result['photoBase64'],$("#driverNumber").val())
                        $.modal.msgSuccess("下载成功");
                    }
                }
            });
        }
    }
    function select() {
        $.modal.close();
    }

    function downloadIamge(selector, name) {
        var image = new Image()
        // 解决跨域 Canvas 污染问题
        image.setAttribute('crossOrigin', 'anonymous')
        image.onload = function () {
            var canvas = document.createElement('canvas')
            canvas.width = image.width
            canvas.height = image.height

            var context = canvas.getContext('2d')
            context.drawImage(image, 0, 0, image.width, image.height)
            var url = canvas.toDataURL('image/png')

            // 生成一个a元素
            var a = document.createElement('a')
            // 创建一个单击事件
            var event = new MouseEvent('click')

            // 将a的download属性设置为我们想要下载的图片名称,若name不存在则使用‘下载图片名称’作为默认名称
            a.download = name || new Date()
            // 将生成的URL设置为a.href属性
            a.href = url

            // 触发a的单击事件
            a.dispatchEvent(event)
        }

        image.src = selector
    }
</script>
</body>

</html>