|
我按例子使用com.synconset.imagepicker,打包发布,选择相片时不能选择,在调试模式行时不行。点上传先要调出摄像头拍照?请大神帮忙看看
代码如下:
define(function(require){
var $ = require("jquery");
var justep = require("$UI/system/lib/justep");
require("cordova!com.synconset.imagepicker");
//require("$UI/system/lib/cordova/cordova");
//require("cordova!cordova-plugin-camera");
//var ImagesZoom = require("$UI/weboa/m/upold/scale");
var pgdh="",pid="",xzid=0,type="",username="";
var Model = function(){
this.callParent();
//this.id = 0;
//this.ownerID =justep.Date.toString(new Date(), 'yyyyMMdd');
//this.user =localStorage.getItem("username");
};
Model.prototype.modelLoad = function(event){
// 初始化商品图片大图展示
//ImagesZoom.init({ "elem" : (".showBigImgClass"), "rootdom" : this.getElementByXid("panel1") });
//$("div[xid=panel2]").hide();
//$("div[xid=divUploadImages]").show();
};
Model.prototype.modelParamsReceive = function(event){
var context = this.getContext(),wjpah,m=this;
pgdh=event.params.data.pgdh;
// pgdh=context.getRequestParameter('pgdh');//接收?pgdh=&方式的参数
type="WX";
username=localStorage.getItem("username");
//m.comp("imgData").clear();
// m.comp("imgData").setFilter("filter","tbvalue='"+pgdh+"'");
// m.comp("imgData").refreshData();
// id = m.comp("imgData").getValue("id");
// if(id.substring(0,8)===justep.Date.toString(new Date(), 'yyyyMMdd')){pid= String(parseInt(id)+1);}
//if(parseInt(id.substring(0,8))<parseInt(justep.Date.toString(new Date(), 'yyyyMMdd'))){
// pid=justep.Date.toString(new Date(), 'yyyyMMdd')+"0001";}
// if(type.equals("WX")){wjpah="WXJL"}
//if( m.comp("imgData").)
// m.comp("imgData").each(p){
//$("div[xid=divUploadImages]").html("<div xid='"+p.row.val("id")+"' style='height:40px;width:40px;'> <img src='$UI/lsqlupold/img/"+wjpah+"/"+p.row.val("filename2")+"' alt='"+p.row.val("fname")+"' xid='"+p.row.val("id")+"'></img></div>")
// }
};
Model.prototype.button1Click = function(event){
var $divUploadImages = $(this.getElementByXid("divUploadImages"));
function onSuccess(imageURI) {
window.resolveLocalFileSystemURI(imageURI, function(entry) {
console.log(entry);
var arr = entry.name.split(".");
var imgname = (new justep.UUID()).valueOf() + '.' + arr[arr.length-1];
var imgtey = arr[arr.length-1];
var name = (new justep.UUID());
entry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
var aRemove = '<a class="x-remove-barget" onclick="javascript(this).parent().remove();"></a>';
var imghtml = '<div class="weui_uploader_image_div"><img class="weui_uploader_image" src="'
+ entry.toInternalURL()+ '" onclick="javascript:void(0);" imgname="'+ imgname
+ '" base64str="' + e.target.result +' imgtey="'+imgtey+' name="'+name+'"></img>' + aRemove + '</div>';
$divUploadImages.prepend(imghtml);
};
reader.readAsDataURL(file);
}, function(e) {
justep.Util.hint("读写出现异常: " + e.message);
})
}, function() {
justep.Util.hint("打开图片出现异常!");
});
}
function onFail(message) {
justep.Util.hint(message);
}
navigator.camera.getPicture(onSuccess, onFail, {
quality : 50,
sourceType : 1 // 0、2为从相册文件中选择,1为拍照
});
};
//图库选择图片
Model.prototype.button2Click = function(event){
var $divUploadImages = $(this.getElementByXid("divUploadImages"));
document.addEventListener("deviceready", androidOnDeviceReady, false);
function androidOnDeviceReady() {
imagePicker.getPictures(androidSuccessCallback, errorCallback,{
"maximumImagesCount" : 20,//最大图片选择数量
"width" : 200,//图片的高度和宽度限定,如果都写成0,则按照图片大小显示,不为0且大于该值则进行等比例压缩
"height" : 200,
"quallity" : 100,//图片质量,取值为0-100
"outputType" : 0//导出图片的类型,默认为FILE_URI(实际值为0),BASE64_STRING (实际值为1)
});
}
function androidSuccessCallback(result) {
if (result.length > 0) {
for (var i = 0; i < result.length; i++) {
window.resolveLocalFileSystemURI(result[i], function(entry) {
console.log(entry);
var arr = entry.name.split(".");
var imgname = (new justep.UUID()).valueOf() + '.' + arr[arr.length-1];
var imgtey = arr[arr.length-1];
var name = (new justep.UUID()).valueOf()
//alert(arr+"|"+imgname+"|"+imgtey+"|"+name);
entry.file(function(file) {
var reader = new FileReader();
reader.onloadend = function(e) {
var aRemove = '<a class="x-remove-barget" onclick="javascript(this).parent().remove();"></a>';
var imghtml = '<div class="weui_uploader_image_div"><img class="weui_uploader_image" src="'
+ entry.toInternalURL()+ '" onclick="javascript:void(0);" imgname="'+ imgname
+ '" base64str="' + e.target.result +' imgtey="'+imgtey+' name="'+name+'"></img>' + aRemove + '</div>';
$divUploadImages.prepend(imghtml);
};
reader.readAsDataURL(file);
}, function(e) {
justep.Util.hint("读写出现异常: " + e.message);
})
}, function() {
justep.Util.hint("打开图片出现异常!");
});
}
} else {
console.log("没有选择图片");
}
}
function errorCallback(error) {
justep.Util.hint("错误信息: " + JSON.stringify(error));
}
};
//提交
Model.prototype.savClick = function(event){
var self = this;
//var description = self.comp("suggestTextarea").val();
//if(!description){
// justep.Util.hint("请填写处理文字描述!");
// return;
//}
//self.popOverZz = self.comp("popOverZz");//遮罩
//self.popOverZz.show();
//上传图片数据封装
var $imgs = $(this.getElementByXid("divUploadImages")).find("img.weui_uploader_image");
var imageUrlsArr = [];
alert("ok");
for(var i=0; i<$imgs.length; i++){
var $img = $imgs.eq(i);
var imageData = $img.attr("base64str");
var imageName = $img.attr("imgname");
var Name = $img.attr("name");
var imgtey = $img.attr("imgtey");
var params = {
"imageName" : imageName,
"imageData" : imageData,
"Name":Name,
"imgtey":imgtey,
"pgdh":pgdh
};
imageUrlsArr.push(params);
}
//保存
justep.Baas.sendRequest({
"url" : "/lsqlupold/img",
"action" : "imgSav",
"async" : true,
"params" : {imageUrlsArr:imageUrlsArr, id:pgdh, username:username,pgdh:pgdh },
"success" : function(data) {
if(data.ok){
justep.Util.hint("文件上传完成!");
justep.Shell.closePage();
}else{
justep.Util.hint(data.errorMsg);
}
}
});
};
return Model;
}); |
|