惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
S
Securelist
MyScale Blog
MyScale Blog
Jina AI
Jina AI
罗磊的独立博客
The Cloudflare Blog
美团技术团队
博客园 - 叶小钗
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
月光博客
月光博客
雷峰网
雷峰网
小众软件
小众软件
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
博客园 - 聂微东
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
T
Tailwind CSS Blog
Attack and Defense Labs
Attack and Defense Labs
博客园_首页
Latest news
Latest news
Apple Machine Learning Research
Apple Machine Learning Research
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
The Hacker News
The Hacker News
G
GRAHAM CLULEY
Simon Willison's Weblog
Simon Willison's Weblog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Proofpoint News Feed
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
U
Unit 42
D
Docker
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
B
Blog
Recent Announcements
Recent Announcements
GbyAI
GbyAI
Microsoft Azure Blog
Microsoft Azure Blog
Security Latest
Security Latest
V2EX - 技术
V2EX - 技术
N
News | PayPal Newsroom
Microsoft Security Blog
Microsoft Security Blog

博客园 - 浊浊然

kkfileview5 安装 css毛玻璃效果 createjs 实现场景拖动、滚轮放大缩小 createjs 实现图片拖动 node-sass 安装不上的问题 nodejs 搭建本地服务器 微信小程序,真机上接口调不通 mysql 去除字段中 空格 制表符等 用jeesite做后台开发,新写了个前端业务系统的权限问题 uniapp 打包app 用到地图相关 升级node最新版本18.x .Error: error:0308010C js 读取url中参数值 linux php 安装oci8 electron nativefier打包网址 electron-winstaller制作安装包 phpword 导出word,文件已损坏问题 Vscode 右键 open with code 没有的情况,使用以下注册表脚本 PhpSpreadsheet导出excel apache https小程序android ssl error js获取url参数,以及中文乱码问题 微信js上传图片并 展示,iphone下预览
h5+ 上传图片(选择图片、拍照)
浊浊然 · 2020-05-29 · via 博客园 - 浊浊然
$(document).on('click','.upimgbtn', function() {
    var pos = $(this).data('pos');
    var posTxt = {'photo1':'照片1','photo2':'照片2','photo3':'照片3'};
    var that = this;
    if(mui.os.plus) {
        var a = [{
            title: "拍照"
        }, {
            title: "从手机相册选择"
        }];
        plus.nativeUI.actionSheet({
            title: posTxt[pos]+"上传",
            cancel: "取消",
            buttons: a
        }, function(b) { /*actionSheet 按钮点击事件*/
            switch(b.index) {
                case 0:
                    break;
                case 1:
                    getImage(that,pos); /*拍照*/
                    break;
                case 2:
                    galleryImg(that,pos); /*打开相册*/
                    break;
                default:
                    break;
            }
        })
    }
});


//拍照
function getImage(that,pos) {
    var cmr = plus.camera.getCamera();
    cmr.captureImage(function(p) {
        //alert(p);//_doc/camera/1467602809090.jpg
        plus.io.resolveLocalFileSystemURL(p, function(entry) {
            //alert(entry.toLocalURL());//file:///storage/emulated/0/Android/data/io.dcloud...../doc/camera/1467602809090.jpg
            //alert(entry.name);//1467602809090.jpg
            var path = (entry.toLocalURL());
            $(that).html("<img src='" + path + "' style='display:block;' />")

            zoomImage(path,pos)
            // upload(path,pos)
        }, function(e) {
            plus.nativeUI.toast("读取拍照文件错误:" + e.message);
        });
    }, function(e) {}, {
        filename: "_doc/camera/",
        index: 1
    });
}
//本地相册选择
function galleryImg(that,pos) {
    plus.gallery.pick(function(path) {
        // alert("get image success: " + path);
        $(that).html("<img src='" + path + "' style='display:block;' />")

        zoomImage(path,pos)
        // upload(path,pos)

    }, function(e) {
        console.log("取消选择图片");
    }, {
        filter: "image"
    });
};


function upload(path,pos){
    var wt=plus.nativeUI.showWaiting();
    var task=plus.uploader.createUpload(baseUrl+'/upload',
        {method:"POST"},
        function(t,status){ //上传完成
            if(status==200){
    //             var data=JSON.parse(t.responseText);
                // if(data.code == 1){
                    switch(pos){
                        case 'photo1':
                                                            // 上传结果(服务器图片地址)处理
                                                           break;

                // }
                // alert("上传成功:"+t.responseText);
                wt.close(); //关闭等待提示按钮
            }else{
                // alert("上传失败:"+status);
                wt.close();//关闭等待提示按钮
            }
        }
    );
    //添加其他参数
    // task.addData("name","test");
    task.addFile(path,{key:"file"});
    task.start();
}

//缩放图片
function zoomImage(path,pos){
    plus.zip.compressImage({
            src:path,
            dst:path,
            width:'800px',        // 缩小
            overwrite: true
        },
        function() {
            upload(path,pos)
            // alert("Compress success!");
        },function(error) {
            // alert("Compress error!");
    });
}