Files
addons
app_download_files
extend
hyhproject
admin
app
common
home
home2
mobile2
common
conf
controller
model
validate
view
default
articles
css
frozenui
goodsconsult
img
js
izimodal
laytpl
photoclip
hammer.js
iscroll-zoom.js
jquery.photoClip.min.js
upload.hpictures.js
share
brands.js
carts.js
common.js
common_xs.js
echo.min.js
forget_pass.js
goods_category.js
goods_detail.js
goods_list.js
index-lxy.js
index.js
jquery.min.js
login.js
qrcode.js
reg.js
self_shop.js
settlement.js
shop_goods_list.js
shop_home.js
shops_list.js
swiper.jquery.min.js
users
base.html
bash.html
brands.html
carts.html
day_new.html
demo.html
dialog.html
error_lost.html
error_switch.html
error_sys.html
footer.html
forget_pass.html
forget_pass2.html
forget_pass3.html
goods_category.html
goods_detail.html
goods_detail2.html
goods_list.html
goods_search.html
header.html
index.html
index2.html
index3.html
index┤°╧▐╩▒├ы╔▒.html
index鈹ぢ扳暓鈻愨暕鈻掆敎褘鈺斺枓.html
juhui.html
login.html
rebate.html
reg.html
register.html
self_shop.html
settlement.html
settlement_quick.html
shop_goods_list.html
shop_home.html
shop_index.html
shop_street.html
wechat2
.htaccess
command.php
mobile
oss
static
thinkphp
upload
vendor
wxtmp
.gitignore
.htaccess
.user.ini
404.html
H5436787D.wgt
admin.php
app-release.apk
app_download.html
cash.lock
demo.php
get_version.php
get_version_new.php
index.html
index.php
reg.lock
robots.txt
qlg.tsgz.moe/hyhproject/mobile2/view/default/js/photoclip/upload.hpictures.js
2019-09-06 23:53:10 +08:00

107 lines
3.6 KiB
JavaScript
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

jQuery.noConflict();
//关闭图片上传区
function closeUploadArea(){
var data='#upload_close,#upload_button,#upload_modal';
var data2='.return_users,.useri_info,#useri_info,#footer';
WST.showHide('',data);
WST.showHide(1,data2);
//清空图片上传区的内容
$('#clipArea').find('img').remove();
$('#file').val('');
$('#view').css('background-image','');
$('#imgData').val('');
}
jQuery('#uploadImg').on('change', function() {
var data='.return_users,.useri_info,#useri_info,#footer';
var data2='#upload_close,#upload_button,#upload_modal';
WST.showHide('',data);
WST.showHide(1,data2);
});
//头像上传
jQuery("#clipArea").photoClip({
width: 350,
height: 350,
file: "#uploadImg",
view: "#view",
ok: "#upload_button",
loadStart: function() {
$('#Load').show();
},
loadComplete: function() {
$('#Load').hide();
},
clipFinish: function(dataURL) {
jQuery('#imgData').val(dataURL);
var imgData = $('#imgData').val();
if(!imgData || imgData==''){
WST.msg('请先选择图片','info');
return false;
}
// 上传裁剪好的图片
funUploadFile(dataURL);
}
});
/**
* @param base64Codes
* 图片的base64编码
*/
funUploadFile=function(base64Codes){
var self = this;
var formData = new FormData();
//convertBase64UrlToBlob函数是将base64编码转换为Blob
//append函数的第一个参数是后台获取数据的参数名,在php中用$FILES['imageName']接收,
var imgSuffix = base64Codes.split(";")[0].split('/')[1];
// formData.append("imageName",self.convertBase64UrlToBlob(base64Codes),"image."+imgSuffix);
// 后台参数改为file mark 20180613 by zl
formData.append("file",self.convertBase64UrlToBlob(base64Codes),"image."+imgSuffix);
//ajax 提交form
$.ajax({
// 你后台的接收地址
url : WST.U('mobile/users/uploadPic',{'dir':'users','isTumb':1}),
type : "POST",
data : formData,
dataType:"json",
processData : false, // 告诉jQuery不要去处理发送的数据
contentType : false, // 告诉jQuery不要去设置Content-Type请求头
success:function(data){
var json = WST.toJson(data);
if(json.status==1){
$.post(WST.U('mobile/users/editUserInfo'), {userPhoto:json.savePath+json.name}, function(data){
if(json.status==1){
WST.msg("修改头像成功",'success');
jQuery('#imgurl').attr('src', WST.conf.IMGURL +'/'+json.savePath+json.name);
}else{
WST.msg('修改头像失败,请重试','warn');
return false;
}
});
}else{
WST.msg(json.msg,'warn');
}
closeUploadArea();
$('#Load').hide();
}
});
}
/**
* 将以base64的图片url数据转换为Blob
* @param urlData
* 用url方式表示的base64图片数据
*/
convertBase64UrlToBlob=function(urlData){
//去掉url的头并转换为byte
var bytes=window.atob(urlData.split(',')[1]);
//处理异常,将ascii码小于0的转换为大于0
var ab = new ArrayBuffer(bytes.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < bytes.length; i++) {
ia[i] = bytes.charCodeAt(i);
}
// 此处type注意与photoClip初始化中的outputType类型保持一致
return new Blob( [ab] , {type : 'image/jpeg'});
}