起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3821|回复: 12

[处理中3] 3.3框架写的调用拍照代码改了引用插件后放到3.5框里面调用不了拍照功能

[复制链接]

134

主题

417

帖子

844

积分

高级会员

Rank: 4

积分
844
QQ
发表于 2016-8-12 08:51:07 | 显示全部楼层 |阅读模式
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;
});

56

主题

370

帖子

963

积分

高级会员

Rank: 4

积分
963
QQ
发表于 2016-8-12 08:57:58 | 显示全部楼层
本帖最后由 负暄 于 2016-8-12 09:01 编辑

cordova引用已变,要改成        :
require("cordova!cordova-plugin-camera");

require("cordova!cordova-plugin-file");

require("cordova!cordova-plugin-file-transfer");





回复 支持 反对

使用道具 举报

134

主题

417

帖子

844

积分

高级会员

Rank: 4

积分
844
QQ
 楼主| 发表于 2016-8-12 09:01:03 | 显示全部楼层
负暄 发表于 2016-8-12 08:57
cordova引用已变。
要改成         require("cordova!cordova-plugin-camera");

我上面代码已经备注了,引用的方式已经改为3.5框架的了,但是用3.5打包还是不能调用。这里是我从3.3框架直接拷过来的,所以没改,谢谢
回复 支持 反对

使用道具 举报

发表于 2016-8-12 11:08:21 | 显示全部楼层
我是猿 发表于 2016-8-12 09:01
我上面代码已经备注了,引用的方式已经改为3.5框架的了,但是用3.5打包还是不能调用。这里是我从3.3框架 ...

注:cordova升级到5.4.1后,原插件的引用名称需要调整,调用方法不变,
      V3.4 提供了相应的升级工具,下载地址:http://pan.baidu.com/s/1gfEsSaZ
qq:1912779713
WeX5教程--WeX5下载
回复 支持 反对

使用道具 举报

134

主题

417

帖子

844

积分

高级会员

Rank: 4

积分
844
QQ
 楼主| 发表于 2016-8-12 12:13:04 | 显示全部楼层
liangyongfei 发表于 2016-8-12 11:08
注:cordova升级到5.4.1后,原插件的引用名称需要调整,调用方法不变,
      V3.4 提供了相应的升级工 ...

我用的是3.5的插件,应该是比较新的,代码是从3.3拷过来的,把引用方式改成了require("cordova!cordova-plugin-camera");

require("cordova!cordova-plugin-file");

require("cordova!cordova-plugin-file-transfer");
但是点击拍照还没反应,我调试了看,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
                });
这里没有返回成功或者失败的?应该怎么改?谢谢
回复 支持 反对

使用道具 举报

发表于 2016-8-12 14:01:46 | 显示全部楼层
我是猿 发表于 2016-8-12 12:13
我用的是3.5的插件,应该是比较新的,代码是从3.3拷过来的,把引用方式改成了require("cordova!cordova-p ...

http://docs.wex5.com/wex5-app-question-list-2007/
这个插件的用法是一样的啊!你可以看下它的API 文档写法!应该没有变化的!

真机调试看看有没有报错信息呢??插件是否真的打包进去了!
qq:1912779713
WeX5教程--WeX5下载
回复 支持 反对

使用道具 举报

134

主题

417

帖子

844

积分

高级会员

Rank: 4

积分
844
QQ
 楼主| 发表于 2016-8-12 14:09:49 | 显示全部楼层
liangyongfei 发表于 2016-8-12 14:01
http://docs.wex5.com/wex5-app-question-list-2007/
这个插件的用法是一样的啊!你可以看下它的API 文档 ...

我就是直接打包苹果应用部署到服务器,没有报错信息,我看了配置文件打包进来了,,怎么办?
回复 支持 反对

使用道具 举报

发表于 2016-8-12 14:45:17 | 显示全部楼层
我是猿 发表于 2016-8-12 14:09
我就是直接打包苹果应用部署到服务器,没有报错信息,我看了配置文件打包进来了,,怎么办? ...

Android 是正常的吗??打包苹果APP是直接在mac环境中打包的吗??
在windows上 连接打包服务器进行打包!可能是插件没打进去吧!
建议在mac环境直接打包再试试!
qq:1912779713
WeX5教程--WeX5下载
回复 支持 反对

使用道具 举报

134

主题

417

帖子

844

积分

高级会员

Rank: 4

积分
844
QQ
 楼主| 发表于 2016-8-12 15:01:50 | 显示全部楼层
liangyongfei 发表于 2016-8-12 14:45
Android 是正常的吗??打包苹果APP是直接在mac环境中打包的吗??
在windows上 连接打包 ...

Android手机可以拍照,打包苹果是用虚拟机打包的。插件打进去了,我看到了配置文件。mac环境的框架好像不是最新的,,,应该跟在哪里打包没关系吧,我用3.3框架打包就可以拍照,,
回复 支持 反对

使用道具 举报

发表于 2016-8-12 17:40:28 | 显示全部楼层
我是猿 发表于 2016-8-12 15:01
Android手机可以拍照,打包苹果是用虚拟机打包的。插件打进去了,我看到了配置文件。mac环境的框架好像不 ...

不确定!你先试试!平台案例,比如综合演示!可以正常拍照吗??
qq:1912779713
WeX5教程--WeX5下载
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-9-28 23:36 , Processed in 0.062536 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表