|
3.3框架写的调用拍照代码改了引用插件后放到3.5框里面调用不了拍照功能,也不报错,拍照的文件js代码我全贴上
define(function(require) {
var $ = require("jquery");
var justep = require("$UI/system/lib/justep");
require("$UI/system/lib/cordova/cordova");
require("cordova!org.apache.cordova.camera");
require("cordova!org.apache.cordova.file");
require("cordova!org.apache.cordova.file-transfer");//这里是引用了3.3插件的方式, 我在3.5框架使用的时候改成了3.5使用方式,在这里没改
var Model = function() {
this.callParent();
};
var fishtype='';
Model.prototype.closeWin = function(event){
justep.Shell.closePage();
};
/**文件上传start***/
Model.prototype.uploadImage = function(imageURI) {
var self=this;
var serverUri = encodeURI("");
function fileTransferSuccess(result) {
$(self.comp('panel1').domNode).find('.imgUl').prepend("<li style='width:27%;height:70px'><img src='"+result.response+"' width='100%' height='100%'/></li>");
}
function fileTransferError(error) {
}
var fileUploadOptions = new FileUploadOptions();
fileUploadOptions.fileKey = "file";
fileUploadOptions.fileName = imageURI.substr(imageURI.lastIndexOf('/')+1);
fileUploadOptions.mimeType = "image/jpeg";
var fileTransfer = new FileTransfer();
fileTransfer.onprogress = function(progressEvent) {
if (progressEvent.lengthComputable) {
// loadingStatus.setPercentage(progressEvent.loaded / progressEvent.total);//这里隐藏了
} else {
}
};
fileTransfer.upload(imageURI, serverUri,fileTransferSuccess, fileTransferError, fileUploadOptions);
};
Model.prototype.a1Click = function(event) {
event.currentTarget.parentNode.remove();
};
Model.prototype.button3Click = function(event) {
this.comp("popOver2").show();
};
Model.prototype.image1Click = function(event) {
var me = this;
window.closeP = function() {
me.closeP();
};
var src = event.currentTarget.currentSrc;
var img = $("<a href='javascript:closeP()' style='position: absolute;top:10px;'>关闭</a><img src='" + src + "'/>");
$(".img_content").contents().remove();
justep.Bind.addNodes(this.getElementByXid("div2"), img);
this.comp("popOver1").show();
};
Model.prototype.closeP = function() {
this.comp("popOver1").hide();
};
// 拍照
Model.prototype.button9Click = function(event) {
this.picSource(50, 1);
};
// 从相册选择
Model.prototype.button10Click = function(event) {
this.picSource(25, 2);
};
Model.prototype.picSource = function(quality, source) {
var self = this;
this.comp("popOver2").hide();
function onSuccess(imageURI) {
self.uploadImage(imageURI);
}
function onFail(message) {
return message;
}
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.FILE_URI,//存储照片的数据/路径
sourceType : source ,//打开系统的图片库
encodingType: Camera.EncodingType.JPEG,
mediaType:Camera.MediaType.PICTURE,
popoverOptions : CameraPopoverOptions,
saveToPhotoAlbum: true
});
};
//发表
Model.prototype.button1Click = function(event){
var img=$(this.comp('panel1').domNode).find('.imgUl li:not(:last) img');
var imgUrls='';
if(img.length!==0){
$(img).each(function(){
var imgUrl=$(this).attr('src');
imgUrls+=imgUrl+',';
});
}
var userid = localStorage.getItem("userid");
var newsData = this.comp("newsData");
var useLevel = this.getElementByXid("select11").value;
var content=$.trim(this.comp('content').val());
if(useLevel===''){
justep.Util.hint('请选择分类!');
}else if($.trim(this.comp('title').val())===''){
justep.Util.hint('请填写标题!');
}else if(content===''){
justep.Util.hint('请填写内容!');
}else{
var title=$.trim(this.comp('title').val());
$.ajax({
type : 'post',
url : "",
dataType : 'jsonp',
jsonpCallback : 'callback',
data : {
"userid" : userid,
"content" : encodeURIComponent(content),
"useLevel" : encodeURIComponent(useLevel),
"title" : encodeURIComponent(title),
"imgUrls" : imgUrls.substring(0, imgUrls.length-1)
},
async : false,// 使用同步方式,目前data组件有同步依赖
cache : false,
success : function(data) {
newsData.loadData(data, false);
if(data[0].tip=='success'){
justep.Util.hint('发表成功');
window.setTimeout(function(){
justep.Shell.closePage();
}, 1000);
}else{
justep.Util.hint('发表失败');
}
},
error : function(data) {
justep.Util.hint('发表失败');
}
});
}
};
return Model;
}); |
|