Commit bfebc0c9 by 胡畅

fix upload

parent e001842b
...@@ -355,6 +355,8 @@ var signupObj = { ...@@ -355,6 +355,8 @@ var signupObj = {
"tag": "input", "tag": "input",
"attr": { "attr": {
"type": "file", "type": "file",
"id": "uploadImage",
"accept": "image/*",
"name": "photo", "name": "photo",
"class": "c-read-only", "class": "c-read-only",
"style": [ "style": [
...@@ -399,10 +401,22 @@ var signupObj = { ...@@ -399,10 +401,22 @@ var signupObj = {
"tag": "div", "tag": "div",
"attr": { "attr": {
"id": "act31419345204861", "id": "act31419345204861",
"class": "upload-pic" "class": [
"upload-pic",
"global-none"
]
},
"child": [
{
"node": "element",
"tag": "img",
"attr": {
"src": ""
} }
} }
] ]
}
]
}, },
{ {
"node": "text", "node": "text",
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
<link rel="stylesheet" href="css/toast.css"> <link rel="stylesheet" href="css/toast.css">
<script type="text/javascript" src="js/jquery-3.4.1.min.js"></script> <script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
<script type="text/javascript" src="js/toast.js"></script> <script type="text/javascript" src="js/toast.js"></script>
<script type="text/javascript" src="js/exif.js"></script>
<script type="text/javascript" src="js/html2Json.js"></script> <script type="text/javascript" src="js/html2Json.js"></script>
<script type="text/javascript" src="js/pageJson/signupJson.js"></script> <script type="text/javascript" src="js/pageJson/signupJson.js"></script>
<script type="text/javascript" src="js/modalJson/shareModal.js"></script> <script type="text/javascript" src="js/modalJson/shareModal.js"></script>
...@@ -29,7 +30,7 @@ ...@@ -29,7 +30,7 @@
</script> </script>
</head> </head>
<body> <body>
<!-- <img class="test1" style="width: 100%" src="images/test.jpeg" /> -->
</body> </body>
</html> </html>
<script type="text/javascript"> <script type="text/javascript">
...@@ -47,6 +48,7 @@ ...@@ -47,6 +48,7 @@
btnBindClick();// 绑定点击事件 btnBindClick();// 绑定点击事件
$('#act11739232574395').attr({'readonly':'readonly'}); $('#act11739232574395').attr({'readonly':'readonly'});
wxpermission(); wxpermission();
// selectFileImage()
}) })
// 微信鉴权 // 微信鉴权
...@@ -117,6 +119,24 @@ ...@@ -117,6 +119,24 @@
$('#html-template-8').addClass('global-none') $('#html-template-8').addClass('global-none')
}); });
// 上传图片
$("#uploadImage").on('change',function() {
var formData = new FormData()
formData.append('file',this.files[0])
selectFileImage(this)
$.ajax({
type:'POST',
url:'http://api-admin-manage.check.icaremgt.com/system/components/upload',
headers:{'x-token':'admin.725.b9d085900b8546fcb26e1683e8f4e7bb'},
data:formData,
contentType:false,
processData:false,
success:function(data) {
$("#act31419345204861").removeClass('global-none')
}
})
})
// 确认提交 // 确认提交
$("#act21359468086634").off("click").on("click", function(){ $("#act21359468086634").off("click").on("click", function(){
var userName = $('#act11738585285947') var userName = $('#act11738585285947')
...@@ -188,6 +208,148 @@ ...@@ -188,6 +208,148 @@
} }
}); });
} }
function selectFileImage(fileObj) {
var file = fileObj.files['0'];
//图片方向角 added by lzk
var Orientation = null;
if (file) {
console.log("正在上传,请稍后...");
var rFilter = /^(image\/jpeg|image\/png|image\/jpg|image\/gif)$/i; // 检查图片格式
if (!rFilter.test(file.type)) {
showMessage('请选择jpeg/jpg/gif/png格式的图片',3000,true);
return;
}
//获取照片方向角属性,用户旋转控制
EXIF.getData(file, function() {
EXIF.getAllTags(this);
Orientation = EXIF.getTag(this, 'Orientation');
//return;
});
var oReader = new FileReader();
oReader.onload = function(e) {
//var blob = URL.createObjectURL(file);
//_compress(blob, file, basePath);
var image = new Image();
image.src = e.target.result;
image.onload = function() {
var expectWidth = this.naturalWidth;
var expectHeight = this.naturalHeight;
if (this.naturalWidth > this.naturalHeight && this.naturalWidth > 800) {
expectWidth = 800;
expectHeight = expectWidth * this.naturalHeight / this.naturalWidth;
} else if (this.naturalHeight > this.naturalWidth && this.naturalHeight > 1200) {
expectHeight = 1200;
expectWidth = expectHeight * this.naturalWidth / this.naturalHeight;
}
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
canvas.width = expectWidth;
canvas.height = expectHeight;
ctx.drawImage(this, 0, 0, expectWidth, expectHeight);
var base64 = null;
//修复ios
if (navigator.userAgent.match(/iphone/i)) {
//如果方向角不为1,都需要进行旋转
if(Orientation != "" && Orientation != 1){
switch(Orientation){
case 6://需要顺时针(向左)90度旋转
rotateImg(this,'left',canvas);
break;
case 8://需要逆时针(向右)90度旋转
rotateImg(this,'right',canvas);
break;
case 3://需要180度旋转
rotateImg(this,'right',canvas);//转两次
rotateImg(this,'right',canvas);
break;
}
}
base64 = canvas.toDataURL("image/jpeg", 0.8);
}else if (navigator.userAgent.match(/Android/i)) {// 修复android
var encoder = new JPEGEncoder();
base64 = encoder.encode(ctx.getImageData(0, 0, expectWidth, expectHeight), 80);
}else{
if(Orientation != "" && Orientation != 1){
switch(Orientation){
case 6://需要顺时针(向左)90度旋转
rotateImg(this,'left',canvas);
break;
case 8://需要逆时针(向右)90度旋转
rotateImg(this,'right',canvas);
break;
case 3://需要180度旋转
rotateImg(this,'right',canvas);//转两次
rotateImg(this,'right',canvas);
break;
}
}
base64 = canvas.toDataURL("image/jpeg", 0.8);
}
$("#act31419345204861 img").attr("src", base64);
};
};
oReader.readAsDataURL(file);
}
}
//对图片旋转处理 added by lzk
function rotateImg(img, direction,canvas) {
//最小与最大旋转方向,图片旋转4次后回到原方向
var min_step = 0;
var max_step = 3;
//var img = document.getElementById(pid);
if (img == null)return;
//img的高度和宽度不能在img元素隐藏后获取,否则会出错
var height = img.height;
var width = img.width;
//var step = img.getAttribute('step');
var step = 2;
if (step == null) {
step = min_step;
}
if (direction == 'right') {
step++;
//旋转到原位置,即超过最大值
step > max_step && (step = min_step);
} else {
step--;
step < min_step && (step = max_step);
}
//旋转角度以弧度值为参数
var degree = step * 90 * Math.PI / 180;
var ctx = canvas.getContext('2d');
switch (step) {
case 0:
canvas.width = width;
canvas.height = height;
ctx.drawImage(img, 0, 0);
break;
case 1:
canvas.width = height;
canvas.height = width;
ctx.rotate(degree);
ctx.drawImage(img, 0, -height);
break;
case 2:
canvas.width = width;
canvas.height = height;
ctx.rotate(degree);
ctx.drawImage(img, -width, -height);
break;
case 3:
canvas.width = height;
canvas.height = width;
ctx.rotate(degree);
ctx.drawImage(img, -width, 0);
break;
}
}
// 验证身份证 // 验证身份证
function validateIDNumber(card) { function validateIDNumber(card) {
var vcity = { var vcity = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment