首页 > 其他分享 >文件夹上传组件webupload插件

文件夹上传组件webupload插件

时间:2022-08-19 11:12:53浏览次数:75  
标签:插件 String pid webupload 文件夹 pidRoot new id se

文件夹数据库处理逻辑

public class DbFolder

{

    JSONObject root;

   

    public DbFolder()

    {

        this.root = new JSONObject();

        this.root.put("f_id", "");

        this.root.put("f_nameLoc", "根目录");

        this.root.put("f_pid", "");

        this.root.put("f_pidRoot", "");

    }

   

    /**

     * 将JSONArray转换成map

     * @param folders

     * @return

     */

    public Map<String, JSONObject> toDic(JSONArray folders)

    {

        Map<String, JSONObject> dt = new HashMap<String, JSONObject>();

        for(int i = 0 , l = folders.size();i<l;++i)

        {

            JSONObject o = folders.getJSONObject(i);

            String id = o.getString("f_id");

            dt.put(id, o);

        }

        return dt;

    }

   

    public Map<String, JSONObject> foldersToDic(String pidRoot)

    {

        //默认加载根目录

        String sql = String.format("select f_id,f_nameLoc,f_pid,f_pidRoot from up6_folders where f_pidRoot='%s'", pidRoot);

 

        SqlExec se = new SqlExec();

        JSONArray folders = se.exec("up6_folders", sql, "f_id,f_nameLoc,f_pid,f_pidRoot","");

        return this.toDic(folders);

    }

   

    public ArrayList<JSONObject> sortByPid( Map<String, JSONObject> dt, String idCur, ArrayList<JSONObject> psort) {

 

        String cur = idCur;

        while (true)

        {

            //key不存在

            if (!dt.containsKey(cur)) break;

 

            JSONObject d = dt.get(cur);//查父ID

            psort.add(0, d);//将父节点排在前面           

            cur = d.getString("f_pid").trim();//取父级ID

 

            if (cur.trim() == "0") break;

            if ( StringUtils.isBlank(cur) ) break;

        }

        return psort;

    }

   

 

    public JSONArray build_path_by_id(JSONObject fdCur) {

 

        String id = fdCur.getString("f_id").trim();//

        String pidRoot = fdCur.getString("f_pidRoot").trim();//

 

        //根目录

        ArrayList<JSONObject> psort = new ArrayList<JSONObject>();

        if (StringUtils.isBlank(id))

        {

            psort.add(0, this.root);

 

            return JSONArray.fromObject(psort);

        }

 

        //构建目录映射表(id,folder)

        Map<String, JSONObject> dt = this.foldersToDic(pidRoot);

 

        //按层级顺序排列目录

        psort = this.sortByPid(dt, id, psort);

 

        SqlExec se = new SqlExec();

        //是子目录->添加根目录

        if (!StringUtils.isBlank(pidRoot))

        {

            JSONObject root = se.read("up6_files"

                    , "f_id,f_nameLoc,f_pid,f_pidRoot"

                    , new SqlParam[] { new SqlParam("f_id", pidRoot) });

            psort.add(0, root);

        }//是根目录->添加根目录

        else if (!StringUtils.isBlank(id) && StringUtils.isBlank(pidRoot))

        {

            JSONObject root = se.read("up6_files"

                    , "f_id,f_nameLoc,f_pid,f_pidRoot"

                    , new SqlParam[] { new SqlParam("f_id", id) });

            psort.add(0, root);

        }

        psort.add(0, this.root);

 

        return JSONArray.fromObject(psort);

    }

   

    public FileInf read(String id) {

        SqlExec se = new SqlExec();

        String sql = String.format("select f_pid,f_pidRoot,f_pathSvr from up6_files where f_id='%s' union select f_pid,f_pidRoot,f_pathSvr from up6_folders where f_id='%s'", id,id);

        JSONArray data = se.exec("up6_files", sql, "f_pid,f_pidRoot,f_pathSvr","");

        JSONObject o = (JSONObject)data.get(0);

 

        FileInf file = new FileInf();

        file.id = id;

        file.pid = o.getString("f_pid").trim();

        file.pidRoot = o.getString("f_pidRoot").trim();

        file.pathSvr = o.getString("f_pathSvr").trim();

        return file;

    }

   

    public Boolean exist_same_file(String name,String pid)

    {

        SqlWhereMerge swm = new SqlWhereMerge();

        swm.equal("f_nameLoc", name.trim());

        swm.equal("f_pid", pid.trim());

        swm.equal("f_deleted", 0);

 

        String sql = String.format("select f_id from up6_files where %s ", swm.to_sql());

 

        SqlExec se = new SqlExec();

        JSONArray arr = se.exec("up6_files", sql, "f_id", "");

        return arr.size() > 0;

    }

   

    /**

     * 检查是否存在同名目录

     * @param name

     * @param pid

     * @return

     */

    public Boolean exist_same_folder(String name,String pid)

    {

        SqlWhereMerge swm = new SqlWhereMerge();

        swm.equal("f_nameLoc", name.trim());

        swm.equal("f_deleted", 0);

        swm.equal("LTRIM (f_pid)", pid.trim());

        String where = swm.to_sql();

 

        String sql = String.format("(select f_id from up6_files where %s ) union (select f_id from up6_folders where %s)", where,where);

 

        SqlExec se = new SqlExec();

        JSONArray fid = se.exec("up6_files", sql, "f_id", "");

        return fid.size() > 0;     

    }

   

    public Boolean rename_file_check(String newName,String pid)

    {

        SqlExec se = new SqlExec();           

        JSONArray res = se.select("up6_files"

            , "f_id"

            ,new SqlParam[] {

                new SqlParam("f_nameLoc",newName)

                ,new SqlParam("f_pid",pid)

            },"");

        return res.size() > 0;

    }

   

    public Boolean rename_folder_check(String newName, String pid)

    {

        SqlExec se = new SqlExec();

        JSONArray res = se.select("up6_folders"

            , "f_id"

            , new SqlParam[] {

                new SqlParam("f_nameLoc",newName)

                ,new SqlParam("f_pid",pid)

            },"");

        return res.size() > 0;

    }

 

    public void rename_file(String name,String id) {

        SqlExec se = new SqlExec();

        se.update("up6_files"

            , new SqlParam[] { new SqlParam("f_nameLoc", name) }

            , new SqlParam[] { new SqlParam("f_id", id) });

    }

   

    public void rename_folder(String name, String id, String pid) {

        SqlExec se = new SqlExec();

        se.update("up6_folders"

            , new SqlParam[] { new SqlParam("f_nameLoc", name) }

            , new SqlParam[] { new SqlParam("f_id", id) });

    }

}

 

1.在webuploader.js大概4880行代码左右,在动态生成的input组件的下面(也可以直接搜索input),增加webkitdirectory属性。

function FileUploader(fileLoc, mgr)

{

    var _this = this;

    this.id = fileLoc.id;

    this.ui = { msg: null, process: null, percent: null, btn: { del: null, cancel: null,post:null,stop:null }, div: null};

    this.isFolder = false; //不是文件夹

    this.app = mgr.app;

    this.Manager = mgr; //上传管理器指针

    this.event = mgr.event;

    this.Config = mgr.Config;

    this.fields = jQuery.extend({}, mgr.Config.Fields, fileLoc.fields);//每一个对象自带一个fields幅本

    this.State = this.Config.state.None;

    this.uid = this.fields.uid;

    this.fileSvr = {

          pid: ""

        , id: ""

        , pidRoot: ""

        , f_fdTask: false

        , f_fdChild: false

        , uid: 0

        , nameLoc: ""

        , nameSvr: ""

        , pathLoc: ""

        , pathSvr: ""

        , pathRel: ""

        , md5: ""

        , lenLoc: "0"

        , sizeLoc: ""

        , FilePos: "0"

        , lenSvr: "0"

        , perSvr: "0%"

        , complete: false

        , deleted: false

    };//json obj,服务器文件信息

    this.fileSvr = jQuery.extend(this.fileSvr, fileLoc);

2.可以获取路径

     this.open_files = function (json)

     {

         for (var i = 0, l = json.files.length; i < l; ++i)

        {

             this.addFileLoc(json.files[i]);

         }

         setTimeout(function () { _this.PostFirst(); },500);

     };

     this.open_folders = function (json)

    {

        for (var i = 0, l = json.folders.length; i < l; ++i) {

            this.addFolderLoc(json.folders[i]);

        }

         setTimeout(function () { _this.PostFirst(); }, 500);

     };

     this.paste_files = function (json)

     {

         for (var i = 0, l = json.files.length; i < l; ++i)

         {

             this.addFileLoc(json.files[i]);

         }

     };

 

编辑

后端代码逻辑大部分是相同的,目前能够支持MySQL,Oracle,SQL。在使用前需要配置一下数据库,可以参考我写的这篇文章:http://blog.ncmem.com/wordpress/2019/08/07/java超大文件上传与下载/
 

可以入群一起讨论:374992201

 

标签:插件,String,pid,webupload,文件夹,pidRoot,new,id,se
From: https://www.cnblogs.com/zyzzz/p/16601334.html

相关文章

  • 大文件上传组件webupload插件
    ​需求:项目要支持大文件上传功能,经过讨论,初步将文件上传大小控制在500M内,因此自己需要在项目中进行文件上传部分的调整和配置,自己将大小都以501M来进行限制。 第一步:......
  • linux下无法进入外加移动硬盘文件夹 No such file or directory
    (36条消息)linux下无法进入文件夹Nosuchfileordirectory_Katzelala的博客-CSDN博客_linux无法进入文件夹用Ubuntu系统遇到的一个小错误我们要进入一个文件夹,使用......
  • pytest系列——自定义用例执行顺序(插件:pytest-ordering)(只针对单个测试.py文件有效)
    前言设计测试用例有时候需要自定义测试用例的执行顺序,我们使用pytest的插件pytest-ordering来控制测试用例的执行顺序。【pytest_ordering插件,但是只能针对某一个t......
  • 记一次油泼猴插件制作
    制作1、使用油泼猴插件后台编写油泼猴插件下载地址编写2、使用前端语言编写,主流JavaScript上传3、使用git版本管理同步4、WebHooks同步更新5、GreasyFork进行......
  • 解决TortoiseSVN或者TortoiseGit拉取的文件夹不能完整显示绿色打钩、黄色、红色感叹号
    某天突然发现用SVNCheckout过的文件夹不显示任何SVN相关的小图标了,例如:绿色打钩,红色感叹等 排查发现是我更新了某个软件(微软的OneDrive),于是它的注册表排在了SVN的前面,......
  • MP-分页插件配置以及实现原理
    1.MP配置类@ConfigurationpublicclassMybatisPlusConfig{@BeanpublicMybatisPlusInterceptormybatisPlusInterceptor(){MybatisPlusIntercept......
  • Vue开发常见插件
    Vue项目无论是前端项目还是移动端项目,优先推荐使用VSCode作为编译工具。VSCode从使用的角度来说没有IDEA用着方便,但是从Vue的支持程度来说,还是不错的,所以优先推荐大家使......
  • Dynamic CRM插件程序集中引入第三方dll合并打包
    有时候在插件程序集不可避免的需要使用第三方的dlll但crm插件平台注册时只能注册一个dll即项目自身的dll第三方的dll无法正常在注册后使用查找官方资料找到如下方法......
  • Vue学习笔记4-项目开发规范及插件
    Vue学习笔记4-项目开发规范及插件一、安装插件首先搜索安装ESLint和Prettier这两个插件。这里对开发规范的配置仅配置ESLint,对代码格式的配置仅配置Prettier,用于代......
  • 认识Vue扩展插件
    众所周知,在Vue开发中,实现一个功能可以有很多种方式可以选择,这依赖于Vue强大的功能(指令、混合、过滤等)Vue插件插件通常用来为Vue添加全局功能。插件的功能范围没......