1 Star 8 Fork 2

zxj / BeUpload

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
MIT

:airplane: 2024年4月3日13:03:32 还活着

示例地址

https://zhang_xing_ju.gitee.io/be-upload/index.html

使用说明

//查询文件详情
@PostMapping("/findFileById")
@ResponseBody
public ResponseEntity findFileById(@RequestBody String[] ids) {
    List<File> files = fileService.queryForList(ids);
    return ResponseEntity.ok(files);
}

//文件上传
@PostMapping({"/upload"})
public ResponseEntity<File> upload(@RequestParam MultipartFile file) {
    return ResponseEntity.ok(ileService.upload(file));
}


//文件下载
@GetMapping({"/download"})
public ResponseEntity<Void> download(String fileId) throws Exception {
 
}
  1. 修改文件相关的后台接口地址 common.js
let global = {
    //上传文件地址
    uploadUrl: "/file/upload",
    //下载文件地址
    downLoadUrl: "/file/download?id=",
    //查询文件的详情信息
    findFileByIdUrl: "/file/findById"
}

2.引入相关的css js

<link href="be-upload/common/common.css" rel="stylesheet">
    <script src="be-upload/common/common.js"></script>
  1. 像layui的其他组件一样使用即可
layui.use(['BeImgUpload'], function () {
    let beImgUpload = layui.BeImgUpload;

    //图片上传,会把图片的id通过逗号拼接成字符串,保存时通过name属性发送
    beImgUpload.render({
        id: "#imgupload",
        name: "imgIds",
        num: 5,   //图片数量限制
        size: 10, //10M, 大小限制
        readonly: false, //非只读
        type: ".png,.jpg,.jpeg",
        value: ['fileId1', 'fileId2']   //图片初始化,是图片id可以是数组,也可以是以,拼接的字符串
    });
})

使用示例 见下方代码

file-upload-demo.html img-upload-demo.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>文件上传示例</title>
    <!-- 引入 layui.css -->
    <link href="./layui/css/layui.css" rel="stylesheet">
    <link href="be-upload/common/common.css" rel="stylesheet">
</head>
<body>
<div id="fileupload"></div>
</body>
<!-- 引入 layui.js -->
<script src="./layui/layui.js"></script>
<script src="be-upload/common/common.js"></script>
<script>
    layui.use(['BeImgUpload'], function () {
        let beImgUpload = layui.BeImgUpload;

        //图片上传,会把图片的id通过逗号拼接成字符串,保存时通过name属性发送
        beImgUpload.render({
            id: "#imgupload",
            name: "imgIds",
            num: 5,   //图片数量限制
            size: 10, //10M, 大小限制
            readonly: false, //非只读
            type: ".png,.jpg,.jpeg",
            value: ['fileId1', 'fileId2']   //图片初始化,是图片id可以是数组,也可以是以,拼接的字符串
        });
    })
</script>
</html>

效果图

img.png img_1.png img_2.png

MIT License Copyright (c) 2023 zxj Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

基于layui实现的上传组件,实现上传附件数量、类型、大小、回显、删除、放大、只读的功能 expand collapse
Cancel

Contributors

All

Activities

Load More
can not load any more
JavaScript
1
https://gitee.com/zhang_xing_ju/be-upload.git
git@gitee.com:zhang_xing_ju/be-upload.git
zhang_xing_ju
be-upload
BeUpload
master

Search