美文网首页
fileinput excel 文件上传 导出

fileinput excel 文件上传 导出

作者: LH8966 | 来源:发表于2019-02-11 15:52 被阅读0次
    name="excelFile" 这是和后台商定的,name="filePath" 很重要 否则会出现参数400  
    js部分
      // 批量导入
        var token = "";
        if (sessionStorage.token) {
            var token = sessionStorage.token;
        };
        $scope.data={};
        $('.imgFileMul').fileinput({
            language: 'zh', //设置语言
            allowedFileExtensions: ["xls", "xlsx"], //接收的文件后缀
            showClose:false,//是否显示关闭按钮
            uploadUrl:$rootScope.baseUrl+'laborage/importExcel',
            showRemove:true,
            maxFileCount: 1,
            showCaption: true,
            showBrowse: true,
            showPreview: false,
            maxFileSize:0, //单位为KB,如果为0表示不限制文件大小
            dropZoneEnabled:false,
            showUpload: true, //是否显示上传按钮
            enctype: 'multipart/form-data',
            validateInitialCount:false,
            previewFileIcon: "<iclass='glyphicon glyphicon-king'></i>",
            overwriteInitial:false,//预设图片 不会被覆盖
            ajaxSettings:{
            "headers" : {'token' : token}
          },
            previewFileIconSettings: {
                'docx': '<i class="glyphicon glyphicon-file"></i>',
                'xlsx': '<i class="glyphicon glyphicon-file"></i>',
                'pptx': '<i class="glyphicon glyphicon-file"></i>',
                'jpg': '<i class="glyphicon glyphicon-picture"></i>',
                'pdf': '<i class="glyphicon glyphicon-file"></i>',
                'zip': '<i class="glyphicon glyphicon-file"></i>',
            },
        }).on("fileuploaded", function (event, data, previewId, index){//上传成功
          $scope.data.monicker = data.files[index].name;
            if(data.response.code == 0) {
              $scope.data.information = "上传成功!";
            } else {
              $scope.data.information = "上传失败!";
            }
            $timeout(function() {
              $(".info-modal").modal('show');
            },1000)
        });
        $scope.goBackFun = function() {
          $(".info-modal").hide();
        }
    html 部分
      <form style="height:34px;padding:10px 0;">
         <div class="form-group" style="margin:0;">
             <label class="control-label" style="line-height:34px;padding:0;float:left;">批量导入:</label>
             <div class="col-sm-7" style="padding-left:5px;">
               <div class="row" style="display: flex;flex-wrap: wrap;" id="imgWrap">
                  <div class="col-sm-7">
                     <input id="input-b5" ng-model="banner.bannerFile" name="filePath" type="file" class="file imgFileMul">
                  </div>
                </div>
            </div>
         </div>
      </form>
    
    // 提示框
    <div class="modal fade in info-modal" id="alertModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="false" style="display: none;">
        <div class="modal-dialog modal-sm" style="margin-top:200px;">
            <div class="modal-content" style="border: 1px solid #dbdbdb;box-shadow: 3px 5px 10px #ccc;">
                <div class="modal-header">
                    <button type="button" class="close" ng-click="goBackFun()" data-dismiss="modal" aria-hidden="true">×</button>
                    <h5 class="modal-title">提示信息</h5>
                </div>
                <div class="modal-body">{{data.monicker}}{{data.information}}</div>
                <div class="modal-footer">
                    <button class="btn btn-primary okBtn" ng-click="goBackFun()" type="button" data-dismiss="modal">确定</button>
                </div>
            </div>
        </div>
    </div>
    

    相关文章

      网友评论

          本文标题:fileinput excel 文件上传 导出

          本文链接:https://www.haomeiwen.com/subject/bzpqeqtx.html