帖子
帖子
用户
博客
课程
显示全部楼层
1
帖子
0
勋章
9
Y币

[superwebview] api.getPicture无法调起相机和图库

[复制链接]
发表于 2022-3-18 09:24:29
  1. api.getPicture({
  2.     sourceType: 'camera',
  3.     encodingType: 'jpg',
  4.     mediaValue: 'pic',
  5.     destinationType: 'url',
  6.     allowEdit: true,
  7.     quality: 100,
  8.     saveToPhotoAlbum: true
  9. }, function(ret, err) {
  10. });
复制代码
权限都给予了,但是都不能调起,回调也没反应,里面alert也没弹出。后来更新了一下jar,然后第一次选相机的话,能调起相机,后面相机和图库都没反应了。第一次选图库能调起图库,后面相机和图库也都没反应了。(就只能调起一次,并且选择的吐图片还拿不到地址)


上周我测试了一下是可以的,我再看下是不是有问题
有示例,拿着去学习吧,我们线上项目都在用。不可能用不了
1
帖子
0
勋章
9
Y币
_(:з」∠)_我也不知道是什么问题,都是之前别人写好的。我现在想试试重新集成,文档内容太多,应该看哪个?有没有Gradle集成方式的?
特特法爷 · 2022-3-18 09:41上周我测试了一下是可以的,我再看下是不是有问题
你看看是不是其他地方影响了,单纯地调用这个方法,没问题的
1
帖子
0
勋章
9
Y币
不知道诶,我不是很会js,就使用过程中,只有这里出了问题,我把完整代码贴出来你看看:
  1. var sj_id,modularType,sj_name

  2. var nav_h
  3. apiready = function() {
  4.         nav_h=api.safeArea.top
  5.         $api.fixStatusBar($api.dom('.header'));
  6. $api.fixTabBar($api.dom('.pinglun_wra'))
  7. $api.css($api.dom(".tijiao"),"bottom:"+api.safeArea.bottom+"px")
  8.         $api.css($api.dom(".djs"),"height:"+(nav_h+45)+"px")
  9.         $api.css($api.dom(".back"),"top:"+nav_h+"px")
  10.        
  11.         sj_id=api.pageParam.id
  12.         modularType=api.pageParam.modularType
  13.         sj_name=api.pageParam.name
  14.         $api.html($api.dom(".dx_r"),sj_name)
  15.        
  16.         api.ajax({
  17.                     url: host_p+"select",
  18.                     method: 'get',                                 //返回类型
  19.                     returnAll:true,                                    //是否全部返回(包括请求头)
  20.                     data:{
  21.                         values:{
  22.                                         type:6
  23.                                 }                          //传递参数,body如果传json类型,header中必须加上传参类型'Content-Type': "application/json"
  24.                     }
  25.                 }, function(ret, err) {
  26.                     if(ret){
  27.                                 var baocuo_list=ret.body.data
  28.                                 var tmpltxt2=doT.template(document.getElementById("label_wra").innerHTML);//生成模板方法
  29.                                 document.querySelector(".label_wra").innerHTML=tmpltxt2(baocuo_list);//数据渲染
  30.                                 // alert(JSON.stringify(ret))
  31.                                 api.parseTapmode();
  32.                     } else {
  33.                                        
  34.                     }
  35.                 });
  36. }
  37. // 错误选择
  38. var cw_radio=null;
  39. function radiochange(self){
  40.         $api.removeCls($api.dom(".label_wra .icon.active"),"active")
  41.         cw_radio=self.value
  42.         $api.addCls(self.parentNode.childNodes[1],"active")
  43. }
  44. // 备注
  45. function text_change(self){
  46.         if(self.value.length>300){
  47.                 self.value=self.value.slice(0,300)
  48.                 $api.html($api.dom(".zishu"),"<span style='color:#f00;'>"+self.value.length+"</span>/300")
  49.         }else{
  50.                 $api.html($api.dom(".zishu"),self.value.length+"/300")
  51.         }
  52. }
  53. // 提交
  54. document.querySelector(".pinglun_wra").onsubmit=function(e){
  55.         if(cw_radio==null){
  56.                 api.toast({
  57.                         msg: '请先选择错误类型',
  58.                         duration: 2000,
  59.                         location: 'middle'
  60.                 });
  61.                 return false;
  62.         }
  63.         if($api.dom(".text_area").value==""){
  64.                 api.toast({
  65.                         msg: '请先填写错误描述',
  66.                         duration: 2000,
  67.                         location: 'middle'
  68.                 });
  69.                 return false;
  70.         }
  71.         api.showProgress({
  72.                                 title: '正在提交...',
  73.                                 text: '请稍等...',
  74.                                 modal: false
  75.                         });
  76.         api.ajax({
  77.             url: host_p+"saveErrorcorrection",
  78.             method: 'post',                                 //返回类型
  79.             returnAll:true,                                    //是否全部返回(包括请求头)
  80.             data:{
  81.                 values:{
  82.                                 type:cw_radio,
  83.                                 errorDescribe:$api.dom(".text_area").value,
  84.                                 shopId:sj_id,
  85.                                 userId:$api.getStorage("userinfo").userId,
  86.                                 modularType:modularType,
  87.                                 shopType:api.pageParam.shopType
  88.                         }                          //传递参数,body如果传json类型,header中必须加上传参类型'Content-Type': "application/json"
  89.             }
  90.         }, function(ret, err) {
  91.                 if (ret.body.data) {
  92.                         // 上传图片
  93.                         if (pic_arr != "") {
  94.                                 for(let i=0;i<pic_arr.length;i++){
  95.                                         api.ajax({
  96.                                                 report: false,
  97.                                                 url: host_p + "upload",
  98.                                                 //这里是我们约定好的后台上传图片的位置 ,你可以根据你的需求来改
  99.                                                 method: 'post',
  100.                                                 cache: 'false',
  101.                                                 timeout: 3000,
  102.                                                 data: {
  103.                                                         values: {
  104.                                                                 id:ret.body.data,
  105.                                                                 modularType:0,
  106.                                                                 type:1
  107.                                                         },
  108.                                                         files: {
  109.                                                                 file: pic_arr[i],
  110.                                                         },
  111.                                                 }
  112.                                         }, function(res, err) {
  113.                                                 if (res.code == 1) {
  114.                        
  115.                                                 } else {
  116.                        
  117.                                                 }
  118.                                                 if(i==pic_arr.length-1){
  119.                                                         api.hideProgress();
  120.                                                         setTimeout(function(){
  121.                                                                 api.closeWin()
  122.                                                         },2000)
  123.                                                         api.toast({
  124.                                                                 msg: '提交成功',
  125.                                                                 duration: 2000,
  126.                                                                 location: 'middle'
  127.                                                         });
  128.                                                 }
  129.                                         })
  130.                                 }
  131.                         }else{
  132.                                 api.hideProgress();
  133.                                 setTimeout(function(){
  134.                                         api.closeWin()
  135.                                 },2000)
  136.                                 api.toast({
  137.                                         msg: '提交成功',
  138.                                         duration: 2000,
  139.                                         location: 'middle'
  140.                                 });
  141.                         }
  142.                 } else {
  143.                        
  144.                 }
  145.         });
  146.         return false;
  147. }

  148. // 返回
  149. function back() {
  150.         api.closeWin()
  151. }
  152. // 是否匿名
  153. function niming(self){
  154.   if($api.hasCls(self, 'notniming')){
  155.           $api.removeCls(self, 'notniming')
  156.           $api.addCls(self, 'niming')
  157.   }else{
  158.           $api.removeCls(self, 'niming')
  159.           $api.addCls(self, 'notniming')
  160.   }
  161. }
  162. // 选择上传方式
  163.                   function sc_tupian(){
  164.                           quanxian('camera',function(){
  165.                                   quanxian('photos',function(){
  166.                                           api.actionSheet({  
  167.                                               title: '上传图片',
  168.                                               cancelTitle: '取消',
  169.                                               buttons: ['拍照','从手机相册选择']
  170.                                           }, function(ret, err) {
  171.                                               if (ret) {
  172.                                                   getPicture(ret.buttonIndex);
  173.                                               }
  174.                                           });
  175.                                   })
  176.                           })
  177.                     
  178.                 }
  179.                 var pic_arr=[];
  180.                 // 上传图片
  181.                 function getPicture(sourceType){
  182.                     if(sourceType==1){ // 拍照
  183.                       api.getPicture({
  184.                         sourceType: 'camera',
  185.                         encodingType: 'jpg',
  186.                         mediaValue: 'pic',
  187.                         allowEdit: false,
  188.                         quality: 100,
  189.                         saveToPhotoAlbum: true
  190.                           }, function(ret, err) {
  191.                                 if (ret.data!="") {
  192.                                         if(pic_arr!=[]&&pic_arr!=""&&pic_arr){
  193.                                                 if(pic_arr.length>6){
  194.                                                         api.toast({
  195.                                                                 msg: '图片最多上传6张',
  196.                                                                 duration: 2000,
  197.                                                                 location: 'middle'
  198.                                                         });
  199.                                                         return false;
  200.                                                 }
  201.                                         }
  202.                                         var img=`<div class="scpic_wra" style="background-image:url(${ret.data})" data-url="${ret.data}" tapmode onclick="pic(this)"><span data-url="${ret.data}" class="icon iconfont " tapmode onclick="del_pic(this)">&#xe62b;</span></div>`
  203.                                         $api.append($api.dom(".img_wra"),img)
  204.                                         pic_arr.push(ret.data)
  205.                                 } else {

  206.                                 }
  207.                           });
  208.                     }else if(sourceType==2){
  209.                       api.getPicture({
  210.                           sourceType: 'library',
  211.                           encodingType: 'jpg',
  212.                           mediaValue: 'pic',
  213.                           destinationType: 'url',
  214.                           allowEdit: true,
  215.                           quality: 100,
  216.                           saveToPhotoAlbum: false
  217.                       }, function(ret, err) {
  218.                           if (ret.data!="") {
  219.                                           if(pic_arr!=[]&&pic_arr!=""&&pic_arr){
  220.                                                   if(pic_arr.length>6){
  221.                                                           api.toast({
  222.                                                                   msg: '图片最多上传6张',
  223.                                                                   duration: 2000,
  224.                                                                   location: 'middle'
  225.                                                           });
  226.                                                           return false;
  227.                                                   }
  228.                                           }
  229.                                                 var img=`<div class="scpic_wra" style="background-image:url(${ret.data})" data-url="${ret.data}" tapmode onclick="pic(this)"><span data-url="${ret.data}" class="icon iconfont" tapmode onclick="del_pic(this)">&#xe62b;</span></div>`
  230.                                          $api.append($api.dom(".img_wra"),img)
  231.                             pic_arr.push(ret.data)
  232.                           } else {
  233.                           }
  234.                       });
  235.                     }
  236.                
  237.                
  238.                         }
  239.                         //删除图片
  240.                         function del_pic(self){
  241.                                 event.preventDefault();
  242.                                 event.stopPropagation();
  243.                                 $api.remove(self.parentNode)
  244.                                 var index = pic_arr.indexOf($api.attr(self,'data-url'));

  245.                                 if (index > -1) {
  246.                                         pic_arr.splice(index, 1);
  247.                                 }
  248.                         }
  249.                         // 图片查看
  250.                         function pic(self){
  251.                                 api.openWin({
  252.                                         name:"pic",
  253.                                         url:"./pic.html",
  254.                                         pageParam:{
  255.                                                 pics:[$api.attr(self,'data-url')]
  256.                                         }
  257.                                 })
  258.                         }
  259.                   // 上传图片
  260.                   function sctp(){
  261.                       api.ajax({
  262.                           url: "",
  263.                           method: 'get',                                   //是否全部返回(包括请求头)
  264.                           data:{
  265.                                 values:{
  266.                                   avatar:$api.getStorage('userinfo').avatar.replace("http://dkcs**.**",""),
  267.                                   nickname:$api.getStorage('userinfo').nickname,
  268.                                   id:$api.getStorage("userinfo").id,
  269.                                   token:$api.getStorage("token")
  270.                                 }                         //传递参数,body如果传json类型,header中必须加上传参类             型'Content-Type': "application/json"
  271.                           }
  272.                       }, function(ret, err) {
  273.                           api.hideProgress();
  274.                           if (ret) {
  275.                           
  276.                           }else{
  277.                
  278.                           }
  279.                         });
  280.                   }
  281. }
复制代码
特特法爷 · 2022-3-18 14:14你看看是不是其他地方影响了,单纯地调用这个方法,没问题的
你可以自己一步一步调试下
您需要登录后才可以回帖 登录

本版积分规则