@@ -6,7 +6,6 @@
.lr-select {
width: 150px;
}
</style>
<div class="lr-layout ">
<div class="lr-layout-center">
@@ -17,7 +16,7 @@
<input id="txt_Keyword" type="text" class="form-control" placeholder="考生号/准考证号/姓名/身份证号" />
</div>
<div class="lr-layout-tool-item">
<div id="RegisterStatus" type="lrselect" class="lr-select" ></div>
<div id="RegisterStatus" type="lrselect" class="lr-select"></div>
</div>
<div class="lr-layout-tool-item">
<a id="btn_Search" class="btn btn-primary btn-sm"><i class="fa fa-search"></i> 查询</a>
@@ -29,8 +28,8 @@
</div>
<div class=" btn-group btn-group-sm" learun-authorize="yes">
<a id="lr_printlc" class="btn btn-default"><i class="fa fa-print"></i> 打印报道流程单</a>
<a id="lr_view" class="btn btn-default"><i class="fa fa-pencil-square-o"></i> 查看</a>
<a id="lr_register" class="btn btn-default"><i class="fa fa-plus"></i> 确认报到</a>
<a id="lr_view" class="btn btn-default"><i class="fa fa-pencil-square-o"></i> 查看</a>
<a id="lr_register" class="btn btn-default"><i class="fa fa-plus"></i> 确认报到</a>
<a id="lr_cancelRegister" class="btn btn-default"><i class="fa fa-trash-o"></i> 取消报到</a>
</div>
<div class=" btn-group btn-group-sm" learun-authorize="yes">
@@ -39,7 +38,226 @@
</div>
</div>
<div class="lr-layout-body" id="gridtable"></div>
<!--图片裁剪框 start-->
<div style="display: none" class="tailoring-container">
<div class="black-cloth" onclick="closeTailor(this)"></div>
<style>
.userPhotoBox {
width: 127px;
height: 178px;
overflow: hidden;
margin: 10px auto 10px!important
}
.userPhotoBox img{
width: 100%
}
</style>
<div class="tailoring-content">
<div class="tailoring-content-one">
<label title="上传图片" for="chooseImg" class="l2-btn choose-btn">
<input type="file" accept="image/jpg,image/jpeg,image/png" name="file" id="chooseImg" class="hidden" onchange="selectImg(this)">
本地上传
</label>
<label title="拍照" class="l2-btn choose-btn" id='capture' style="margin-left: 2%;">拍照</label>
<label title="重拍" class="l2-btn choose-btn" id='takeAgain' style="margin-left: 2%;">重拍</label>
<div class="close-tailoring" onclick="closeTailor(this)">×</div>
</div>
<div class="tailoring-content-two">
<div class="tailoring-box-parcel">
<video id="video" width="100%" height="100%" style="float: left;"></video>
<canvas id="canvas" width="482px" height="448px" style="float: left;" hidden="hidden"></canvas>
<div id="showImg" hidden="hidden" style="width: 100%; height: 100%;">
<img id="tailoringImg">
</div>
</div>
<div class="preview-box-parcel">
<p>原照片:</p>
<div class="userPhotoBox">
<img id="userPhoto">
</div>
<p>拍照预览:</p>
<div class="square previewImg"></div>
</div>
</div>
<div class="tailoring-content-three">
<button class="l2-btn cropper-reset-btn">复位</button>
<button class="l2-btn cropper-rotate-btn">旋转</button>
<button class="l2-btn cropper-scaleX-btn">换向</button>
<button class="l2-btn sureCut" id="sureReport">确定报道</button>
<button class="l2-btn sureCut" id="sureCut">确定照片</button>
</div>
</div>
</div>
<!--图片裁剪框 end-->
</div>
</div>
</div>
@Html.AppendJsFile("/Areas/EducationalAdministration/Views/StuInfoFresh/RegisterIndex.js")
@Html.AppendJsFile("/Areas/EducationalAdministration/Views/StuInfoFresh/RegisterIndex.js", "/Content/camera/cropper.min.js",
"/Areas/EducationalAdministration/Views/StuEnroll/LodopFuncs.js")
@Html.AppendCssFile("/Content/camera/cropper.min.css", "/Content/camera/ImgCropping.css")
<script>
//弹出框水平垂直居中
(window.onresize = function () {
var win_height = $(window).height();
var win_width = $(window).width();
if (win_width <= 768) {
$(".tailoring-content").css({
"top": (win_height - $(".tailoring-content").outerHeight()) / 2,
"left": 0
});
} else {
$(".tailoring-content").css({
"top": (win_height - $(".tailoring-content").outerHeight()) / 2,
"left": (win_width - $(".tailoring-content").outerWidth()) / 2
});
}
})();
//图像上传
function selectImg(file) {
if (!file.files || !file.files[0]) {
return;
}
var reader = new FileReader();
reader.onload = function (evt) {
var replaceSrc = evt.target.result;
//更换cropper的图片
$('#tailoringImg').cropper('replace', replaceSrc, false);//默认false,适应高度,不失真
}
reader.readAsDataURL(file.files[0]);
mediaStreamTrack && mediaStreamTrack.stop();
$("#video").hide();
$("#showImg").show();
}
//cropper图片裁剪
$('#tailoringImg').cropper({
aspectRatio: 5 / 7,//默认比例
preview: '.previewImg',//预览视图
guides: false, //裁剪框的虚线(九宫格)
autoCropArea: 0.5, //0-1之间的数值,定义自动剪裁区域的大小,默认0.8
movable: false, //是否允许移动图片
dragCrop: true, //是否允许移除当前的剪裁框,并通过拖动来新建一个剪裁框区域
movable: true, //是否允许移动剪裁框
resizable: true, //是否允许改变裁剪框的大小
zoomable: false, //是否允许缩放图片大小
mouseWheelZoom: false, //是否允许通过鼠标滚轮来缩放图片
touchDragZoom: true, //是否允许通过触摸移动来缩放图片
rotatable: true, //是否允许旋转图片
crop: function (e) {
// 输出结果数据裁剪图像。
}
});
//旋转
$(".cropper-rotate-btn").on("click", function () {
$('#tailoringImg').cropper("rotate", 45);
});
//复位
$(".cropper-reset-btn").on("click", function () {
$('#tailoringImg').cropper("reset");
});
//换向
var flagX = true;
$(".cropper-scaleX-btn").on("click", function () {
if (flagX) {
$('#tailoringImg').cropper("scaleX", -1);
flagX = false;
} else {
$('#tailoringImg').cropper("scaleX", 1);
flagX = true;
}
flagX != flagX;
});
//裁剪后的处理
$("#sureCut").on("click", function () {
var cas = $('#tailoringImg').cropper('getCroppedCanvas');//获取被裁剪后的canvas
var base64url = cas.toDataURL('image/png'); //转换为base64地址形式
base64url = base64url.replace("\r", "");
top.learun.postForm(top.$.rootUrl + '/EducationalAdministration/StuInfoFresh/IsPhoto', { stuId: StuId, base64url: base64url },
function (res) {
//关闭裁剪框
StuId = "";
//closeTailor();
//refreshGirdData();
});
});
//关闭裁剪框
function closeTailor() {
StuId = "";
$(".tailoring-container").toggle();
mediaStreamTrack && mediaStreamTrack.stop();
}
let video = document.getElementById('video');
let canvas = document.getElementById('canvas');
let context = canvas.getContext('2d');
var mediaStreamTrack;
document.getElementById('capture').addEventListener('click',
function () {
context.drawImage(video, 0, 0, 518, 420);
mediaStreamTrack && mediaStreamTrack.stop();
$('#tailoringImg').cropper('replace', canvas.toDataURL("image/png"), false); //默认false,适应高度,不失真
$("#video").hide(); //隐藏拍照框
$("#showImg").show(); //将拍照结果显示
});
//请求拍照
$("#takeAgain").bind("click", function () {
takePhoto();
});
//开始拍照
function takeImg() {
$(".tailoring-container").toggle();
takePhoto();
}
//请求摄像头
function takePhoto() {
// 老的浏览器可能根本没有实现 mediaDevices,所以我们可以先设置一个空的对象
if (navigator.mediaDevices === undefined) {
navigator.mediaDevices = {};
}
if (navigator.mediaDevices.getUserMedia === undefined) {
navigator.mediaDevices.getUserMedia = function (constraints) {
// 首先,如果有getUserMedia的话,就获得它
var getUserMedia = navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
// 一些浏览器根本没实现它 - 那么就返回一个error到promise的reject来保持一个统一的接口
if (!getUserMedia) {
return Promise.reject(new Error('不支持此浏览器,请更换Chrome或360浏览器'));
}
// 否则,为老的navigator.getUserMedia方法包裹一个Promise
return new Promise(function (resolve, reject) {
getUserMedia.call(navigator, constraints, resolve, reject);
});
}
}
const constraints = {
video: true,
audio: false
};
let videoPlaying = false;
let promise = navigator.mediaDevices.getUserMedia(constraints);
promise.then(stream => {
// 旧的浏览器可能没有srcObject
if ("srcObject" in video) {
video.srcObject = stream;
mediaStreamTrack = stream.getTracks()[0];
} else {
// 防止再新的浏览器里使用它,应为它已经不再支持了
video.src = window.URL.createObjectURL(stream);
}
video.onloadedmetadata = function (e) {
video.play();
videoPlaying = true;
};
}).catch(err => {
console.error(err.name + ": " + err.message);
});
$("#showImg").hide();//隐藏拍照结果显示框
//$('#showImg').html('<img id="tailoringImg" hidden="hidden">')
$("#video").show();//开启拍照框
}
</script>