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

推荐订阅源

T
Tenable Blog
S
SegmentFault 最新的问题
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 聂微东
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
美团技术团队
Recorded Future
Recorded Future
Microsoft Security Blog
Microsoft Security Blog
博客园 - 叶小钗
P
Proofpoint News Feed
aimingoo的专栏
aimingoo的专栏
博客园_首页
宝玉的分享
宝玉的分享
C
Check Point Blog
爱范儿
爱范儿
MyScale Blog
MyScale Blog
Microsoft Azure Blog
Microsoft Azure Blog
The Register - Security
The Register - Security
U
Unit 42
T
Tailwind CSS Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
D
Docker
博客园 - Franky
博客园 - 【当耐特】
腾讯CDC
N
Netflix TechBlog - Medium
Jina AI
Jina AI
博客园 - 司徒正美
Last Week in AI
Last Week in AI
PCI Perspectives
PCI Perspectives
GbyAI
GbyAI
Security Archives - TechRepublic
Security Archives - TechRepublic
J
Java Code Geeks
Cloudbric
Cloudbric
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Y
Y Combinator Blog
F
Full Disclosure
TaoSecurity Blog
TaoSecurity Blog
N
News and Events Feed by Topic
L
LINUX DO - 最新话题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
小众软件
小众软件
O
OpenAI News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
Security Affairs
Recent Announcements
Recent Announcements
Attack and Defense Labs
Attack and Defense Labs
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Secure Thoughts

博客园 - 浊浊然

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