驾驶舱知识整理..

 获取上传文件路径等信息

/*js
获取表单信息*/
result.data.diseaseControlReportFile.xxxx
    //控制器
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(NewDiseaseControlParam newDiseaseControlParam) {
        NewDiseaseControl detail = this.newDiseaseControlService.getById(newDiseaseControlParam.getId());
        if (ToolUtil.isNotEmpty(detail.getDiseaseControlReportFileId()))//获取文件id
             {
            FileInfo diseaseControlReportFile = fileInfoService.getOne(new QueryWrapper<FileInfo>().eq("file_id", detail.getDiseaseControlReportFileId()));//mybaitspuls
            newDiseaseControlParam.setDiseaseControlReportFile(diseaseControlReportFile);
        }
        BeanUtil.copyProperties(detail, newDiseaseControlParam);
        return ResponseData.success(newDiseaseControlParam);
    }
//model类param  NewDiseaseControlParam   
 private FileInfo diseaseControlReportFile;

上传下载文件 

js:
    upload.render({
        elem: '#upload'
        ,url:  Feng.ctxPath + '/system/upload'
        ,accept: 'file'
        ,number: 1
        ,choose: function(obj){
            obj.preview(function(index, file, result){
                NewDiseaseControlInfoDlg.data.fileName = file.name;

            })
        }
        ,done: function(res, index, upload){ //成功的回调
            Feng.success("上传文件成功")
            $("#upload").css("display","none")
            NewDiseaseControlInfoDlg.data.diseaseControlReportFileId = res.data.fileId
            $("#diseaseControlReportFileId").append('<div class="setFile" id="'+NewDiseaseControlInfoDlg.data.diseaseControlReportFileId+'">'+NewDiseaseControlInfoDlg.data.fileName +
                '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete" type="button" style="margin: 7px;">删除</button></div>')
            //删除
            $('.demo-delete').click(function (){
                $(this).parent("div").remove();
                $("#upload").css("display","block")
                NewDiseaseControlInfoDlg.data.diseaseControlReportFileId = "";
                // NewDiseaseControlInfoDlg.data.approveStatisticalReportFileIds.splice($(this).parent("div").attr("id"),1);
                Feng.success("文件删除成功");
            })
        }
        ,error: function(index, upload){ //错误回调
            Feng.error("上传文件失败!");
        }

    });



    //获取详情信息,填充表单
    var ajax = new $ax(Feng.ctxPath + "/newDiseaseControl/detail?id=" + Feng.getUrlParam("id"));
    var result = ajax.start();
    if(result.data.diseaseControlReportFileId !=null && result.data.diseaseControlReportFileId !=undefined && result.data.diseaseControlReportFileId !=""){
        $("#diseaseControlReportFileId").append('<div><a class="setdiseaseControlReportFileId" itemAttr='+result.data.diseaseControlReportFile.filePath+'>'+result.data.diseaseControlReportFile.fileName+'</a>' +
            '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete1" type="button" style="margin: 7px;">删除</button></div>')
    }else {
        $("#diseaseControlReportFileId").append('<div class="setdiseaseControlReportFileId">'+'无附件'+
            '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete1" type="button" style="margin: 7px;">删除</button></div>')
    };
    $('.demo-delete1').click(function (){
        $(this).parent("div").remove();
        $("#upload").css("display","block");
        NewDiseaseControlInfoDlg.data.diseaseControlReportFileId = "";
        Feng.success("文件删除成功");
    })
    form.val('newDiseaseControlForm', result.data);



   //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        data.field.diseaseControlReportFileId = NewDiseaseControlInfoDlg.data.diseaseControlReportFileId;

 

//网页
<button type="button" class="layui-btn layui-btn-normal" id="upload">点击上传</button>
<div class="file" id="diseaseControlReportFileId" name="diseaseControlReportFileId">
</div>

多文件上传根据html,div判断是否上传,先转jQuery

        data.field.approveStatisticalReportFileIds=","
        var fileDivs = $(".setword-show")
        $.each(fileDivs, function (index,item) {
            data.field.approveStatisticalReportFileIds += ($(item).attr(("data-file-id")))+","
        })
        console.log(data.field.approveStatisticalReportFileIds);

layui 字典,下拉选择

    NewTageSchoolInfoDlg.initDict = function (dictTypeCode, selectName) {
        return new Promise(function (door, err) {
            $.post(Feng.ctxPath + "/dict/listDictsByCode", {"dictTypeCode": dictTypeCode}, function (response) {
                console.log(response);
                $.each(response.data, function (index, item) {
                    $("[name=" + selectName + "]").append("<option value='" + item.name + "'>" + item.name + "</option>")
                })
                form.render("select");
                door(true);
            })
        })
    }
    Promise.all([
        NewTageSchoolInfoDlg.initDict("SCHOOL_TYPE","schoolType"),
    ]).then(res => {
        form.val('newTageSchoolForm', result.data);
        form.render("select");
    })

日期范围限定layui 

var startTime = laydate.render({
    elem: '#startMonth'
    ,type:'month'
    , done: function (value,date) {
        console.log(value,date)
        endTime.config.min = {
            year: date.year,
            month: date.month - 1,//关键
            date: date.date,
            hours: date.hours,
            minutes: date.minutes,
            seconds: date.seconds
        };
    }
});

var endTime = laydate.render({
    elem:'#endMonth'
    ,type:'month'
    , done: function (value,date) {
        startTime.config.max = {
            year: date.year,
            month: date.month - 1,//关键
            date: date.date,
            hours: date.hours,
            minutes: date.minutes,
            seconds: date.seconds
        };
    }
})

 

上一篇:Element-ui upload上传组件的具体使用


下一篇:el-upload 上传图片