app中使用html5+实现一键分享多张图片到朋友圈

浏览1350
                                            系统分享                设置本地图片
             * imgId 图片标签的id
             * relativePath 本地相对路径 例如:"_downloads/logo.jpg"
             */
            function setImgFromLocal(imgId, relativePath) {
                //本地相对路径("_downloads/logo.jpg")转成SD卡绝对路径("/storage/emulated/0/Android/data/io.dcloud.HBuilder/.HBuilder/downloads/logo.jpg");
                var sd_path = plus.io.convertLocalFileSystemURL(relativePath);
                pictures.push("file://"+sd_path);
                picNum++;

                console.log(picLength);
                console.log(picNum);                //这里要注意picNu ++的地方,要在图片下载完成后或者失败后;

               if(picLength == picNum){
                    console.log("开始分享")                    //确定全部图片都下载到本地后调分享
                    var msg = {
                        pictures:pictures
                    };

                    plus.share.sendWithSystem(msg, function(){

                        for(var i=0;i*/
            function setImgFromNet (imgId,loadUrl,relativePath) {
                //先设置下载中的默认图片
                //创建下载任务
                var dtask = plus.downloader.createDownload(loadUrl, {}, function(d, status) {
                    if (status == 200) {                        //下载成功//                      console.log("下载成功");
                        setImgFromLocal(imgId, d.filename);
                    } else {
                            picNum++;//                          console.log("下载失败");
                        //下载失败,需删除本地临时文件,否则下次进来时会检查到图片已存在
                        //dtask.abort();//文档描述:取消下载,删除临时文件;(但经测试临时文件没有删除,故使用delFile()方法删除);
                        if (relativePath!=null)
                            delFile(relativePath);
                    }
                });                //启动下载任务
                dtask.start();
            }            /*删除指定文件*/
            function delFile(relativePath) {
                plus.io.resolveLocalFileSystemURL(relativePath, function(entry) {
                    entry.remove(function(entry) {
                        console.log("文件删除成功");
                    }, function(e) {
                        console.log("文件删除失败" + relativePath);
                    });
                });
            }            /*根据id查找元素*/
            function $id(id) {
                return document.getElementById(id);
            }        " _ue_custom_node_="true">                            点我一键分享朋友圈

  • 暂无任何回答