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

推荐订阅源

CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
罗磊的独立博客
MyScale Blog
MyScale Blog
博客园 - 叶小钗
U
Unit 42
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
有赞技术团队
有赞技术团队
F
Fortinet All Blogs
WordPress大学
WordPress大学
美团技术团队
GbyAI
GbyAI
L
LangChain Blog
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
Y
Y Combinator Blog
V
Visual Studio Blog
小众软件
小众软件
D
Docker
量子位
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
C
CERT Recently Published Vulnerability Notes
AI
AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
C
Check Point Blog
I
InfoQ
NISL@THU
NISL@THU
Webroot Blog
Webroot Blog
S
Security Affairs
Stack Overflow Blog
Stack Overflow Blog
V
Vulnerabilities – Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
TaoSecurity Blog
TaoSecurity Blog
L
Lohrmann on Cybersecurity
Hacker News: Ask HN
Hacker News: Ask HN
C
CXSECURITY Database RSS Feed - CXSecurity.com
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
W
WeLiveSecurity
V2EX - 技术
V2EX - 技术
SecWiki News
SecWiki News
PCI Perspectives
PCI Perspectives
S
Secure Thoughts
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - 浊浊然

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!");
    });
}