更新hbuilder后解决了,醉了,希望越做越好
直接贴代码吧,麻烦帮忙看下,十分感谢
//修改头像,原生模式actionsheet
document.getElementById("picture").addEventListener('tap', function() {
plus.nativeUI.actionSheet({
cancel: "取消",
buttons: [{
title: "拍照"
}, {
title: "相册"
}]
}, function(e) {
var index = e.index;
switch(index) { //case 0: 取消
case 1:
getImage(); //拍照
break;
case 2:
appendByGallery(); //相册
break;
}
});
});
// 拍照添加文件
function getImage() {
var cmr = plus.camera.getCamera();
cmr.captureImage(function(p) {
plus.io.resolveLocalFileSystemURL(p, function(entry) {
var localurl = entry.toLocalURL(); //把拍照的目录路径,变成本地url路径,例如file:///........之类的。
compressImage(localurl);
});
}, function(error) {
alert("Capture image failed: " + error.message);
});
}
// 从相册添加文件
function appendByGallery() {
plus.gallery.pick(function(path) {
compressImage(path); //处理图片的地方
});
}
//压缩图片
function compressImage(imgsrc) {
var dst_img = "_documents/a"+Math.round(Math.random()*100)+".jpg";
plus.zip.compressImage({
src: imgsrc,
dst: dst_img,
overwrite: true,
width:"500px"
},
function(e) {
createUpload(e.target,dst_img, e.height);
},
function(error) {
alert("Compress error!" + JSON.stringify(error));
});
}
//上传源文件
function createUpload(path) {
plus.nativeUI.showWaiting();**//一直卡在这里**
var task = plus.uploader.createUpload(loadimg,
{ method:"POST"},
function ( t, status ) {
// 上传完成
plus.nativeUI.closeWaiting();
if ( status == 200 ) {
//console.log(t.responseText);
var location_user_img = t.responseText.replace(/\//g,"");
$("#picture").attr("src",path);
lset("user_picture",path);
var ws = plus.webview.currentWebview();
wo = ws.opener();
wo.evalJS("info_shuaxin('"+path+"')");
} else {
alert( "Upload failed: " + status );
}
}
);
task.addData('token', token);
task.addFile(path, {key:"image"});
task.start();
}
明明航 (作者)
求帮忙啊
2017-02-27 17:23