• 文件上传


           function createImageUploadItem(succ, errr) {
                    var setting = {};
                    setting.phoneSucc = function (result) {
                        //加载完毕
                        $scope.$apply(function () {
                            var data = JSON.parse(result.currentTarget.response);
                            if (data != null && data.Datas != null && data.Datas.length > 0) {
                                if (succ) succ(data.Datas[0].ImgUrl);
                                else {
                                    this.model.PicUrl = data.Datas[0].ImgUrl;
                                }
                            }
                            model.com.closeloading();
                        }.bind(obj));
                    }.bind(obj);
    
                    setting.phoneError = function () {
                        this.picaddclick = this.picaddclickbase;
                        if (errr) errr();
                    }.bind(obj);
    
                    var obj = {
                        exp: function () {
                        },
                        model: {
                            isshowpicchoose: false,
                            PicUrl: '',//图片地址
                        },
                        picaddclick: function () {//图片添加点击
                            this.picaddclickbase();
                        },
                        picaddclickbase: function () {
                            console.log("clickbase")
                            //alert("clickabase4");
                            if (!this.filedom) {
                                var file = document.createElement("input");
                                file.type = "file";
                                file.accept = "image/*";//微信的话,只能这么调用
                                //"image/gif,image/jpeg,image/x-png";//限制选择的文件类型
                                //file.capture = "camera";//camera-拍照 
                                file.onchange = function () {
                                    //alert("onchange")
                                    if (this.files) {
                                        model.com.loading();
                                        //选择完毕了呗,那就上传呗
                                        var fd = new FormData();
                                        fd.append("fileToUpload", this.files[0]);
                                        var xhr = new XMLHttpRequest();
                                        xhr.upload.addEventListener("progress", function () {
                                            //加载中。。。
                                        }, false);
                                        xhr.addEventListener("load", function (result) {
                                            console.log("load");
                                            setting.phoneSucc(result);
                                        }, false);
                                        xhr.addEventListener("error", function () {
                                            console.log(setting);
                                            model.com.alert("网络错误")
                                        }, false);
                                        xhr.addEventListener("abort", function () {
                                            //中断上传
                                        }, false);
                                        xhr.open("POST", 'http://upload.eggworld.com.cn/' + 'api/uploadimage/eggworld_product_0_0_0_true');
                                        xhr.send(fd);
                                    }
                                }
                                this.filedom = file;
                            }
                            this.filedom.click();
                        },
                        cancepicclick: function () {
                            this.model.isshowpicchoose = false;
                            this.picaddclick = this.picaddclickbase;
                        }
                    };
                    return obj;
                }
  • 相关阅读:
    线程数与多核CPU的关系,VMware中核数的设置
    shell基础编程
    MySql中join基础
    OneNote发布至博客园
    java获取系统换行符,路径分割符
    使用shell实现简单的词频统计
    Kylin系列之二:原理介绍
    MySQL 配置文件my.cnf
    SQLServer LinkServer 链接服务器
    sp_tableoption
  • 原文地址:https://www.cnblogs.com/zspbolg/p/9648006.html
Copyright © 2020-2023  润新知