首页 > 其他分享 >vue实现文件夹的上传和下载

vue实现文件夹的上传和下载

时间:2023-08-08 16:11:06浏览次数:40  
标签:vue String pid 文件夹 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。在使用前需要配置一下数据库

​编辑

​编辑

​编辑

​编辑

 

视频演示:

 

windows控件安装,,linux-deb控件包安装,linux-rpm控件包安装,php7测试,php5测试,vue-cli-测试,asp.net-IIS测试,asp.net-阿里云(oss)测试,asp.net-华为云(obs)测试,jsp-springboot测试,ActiveX(x86)源码编译,ActiveX(x64)源码编译,Windows(npapi)源码编译,macOS源码编译,Linux(x86_64)源码编译,Linux(arm)源码编译,Linux(mips-uos)源码编译,Linux(mips-kylin-涉密环境)源码编译,sm4加密传输,压缩传输,

示例下载地址

源代码文档

asp.net源码下载jsp-springboot源码下载jsp-eclipse源码下载jsp-myeclipse源码下载php源码下载csharp-winform源码下载vue-cli源码下载c++源码下载

详细配置信息及思路

标签:vue,String,pid,文件夹,pidRoot,new,上传,id,se
From: https://www.cnblogs.com/songsu/p/17614651.html

相关文章

  • vue-pdf 在vue中展示pdf
    老规矩先看效果图: 这玩意的坑是相当的多,如果只是单纯的网页浏览,真心建议直接使用<iframe>来进行嵌入pdf吧,省心也省事我这边的web页面是需要放到客户端里面的,然后由于某些原因吧,不支持显示iframe嵌入的pdf网页,只能使用vue-pdf来进行实现了下面就说一下实现步骤吧,我尽量说的......
  • 前端实现文件夹的上传和下载
    ​ 以ASP.NETCoreWebAPI 作后端 API ,用 Vue 构建前端页面,用 Axios 从前端访问后端 API,包括文件的上传和下载。 准备文件上传的API #region 文件上传  可以带参数        [HttpPost("upload")]        publicJsonResultuploadProject(I......
  • 数字滚动插件vue-countup-v2
    参考博客https://blog.csdn.net/weixin_44948981/article/details/123544242options参数说明duration:2,//动画持续时间(秒)useEasing:true,//使用缓动效果useGrouping:true,//使用分组分隔符(如1,000)separator:',',//分组分隔符decimal:'.',//小数点符号pref......
  • python打包成sdk上传到私有仓库和使用
    我们已经学习了如何运行一个python项目(当我们有它的源码文件py文件的时候)。python的使用和运行我们有一个项目,需要打包到其他机器上运行,如果每次都是复制整个项目源码就显得有点笨拙。实现这个需求有很多种方案。例如:PyInstaller可参考链接:https://ningyu1.github.io/site/po......
  • 百度ueditor富文本--配置图片上传
    我们在之前的文章中已经学习了如何初始化百度ueditor富文本编辑器:百度ueditor富文本--PC端单个,PC端多个,mobile单个,mobile多个官网对编辑器的初始化和使用文档是比较详细的,这里就不多说了。本小节主要记录一下在初始化完编辑器之后 配置启用编辑器中的图片上传插件。项目路......
  • Git上传本地项目文件到远程仓库
    为了标识身份,建议先完成Git全局设置gitconfig--globaluser.name"xxxxxx"gitconfig--globaluser.email"[email protected]"方式一:克隆仓库gitclonehttps://xxx.xxxxx.com/xxxxxx/xxx.gitcdxxxtouchREADME.mdgitaddREADME.mdgitcommit-m"addRE......
  • vue 线上环境 开启 vue-devtools
      vue项目打包正式环境时,是没有vue-devtools选项卡的,没法看vue内部的数据 选中Source选项卡,找到打包好的app.js,并格式化 ctrl+f搜索$mount并在new那里打断点,new后面的对象就是Vue对象,需要记住该变量名,下一步要用到F5刷新页面就就会进入断点,并在控制台......
  • CMD批处理所有子文件夹中的文件按子文件夹名称命名并提取到一个文件夹中
    我有一个名叫 baiyin的文件夹里面有一些按日期命名的子文件夹 子文件夹下有相同命名为screen_035800.png的图片 现在我想把图片按照子文件夹的日期名称重命名后 移到另一个文件夹allbaiyin中  并删除空文件夹 如果不删除去掉Rd/q"%%i"如果不移动只是复制则......
  • html实现文件夹的上传和下载
    ​ 对于大文件的处理,无论是用户端还是服务端,如果一次性进行读取发送、接收都是不可取,很容易导致内存问题。所以对于大文件上传,采用切块分段上传,从上传的效率来看,利用多线程并发上传能够达到最大效率。 本文是基于springboot+vue实现的文件上传,本文主要介绍服务端实现文件......
  • uniapp vuex用法详细讲解
    uni-app小程序项目三1.商品列表、过滤器、封装商品item组件、上拉加载、节流阀、下拉刷新、2.商品详情、轮播图、商品价格闪烁问题3.加入购物车、vuex、持久化存储、mixiins_小程序商品列表加载_Hyman-ya的博客-CSDN博客......