Vue项目,实现获取本地的 绝对文件夹 路径的解决 方案
一、前端代码
vue项目下的index中代码如下
1.弹框样式代码
<el-dia LOG t IT le="" :ap PE nd -t o-body="true" :visible.sync="routeDialogVisible" width="600px" :close-on-click-modal="false" > <el-form :model="routeDialog"> <el-form -i tem label="" PR op="path"> <el-input style="width:450px; padding-left:20px" size="mini" v-model="routeDialog.path"> </el-input> <el-button style="float: right; m arg in: 5px 40px 0 0" size="mini" @click="backRoute()" >向上</el-button > </el-form-item> <el -s crollbar style="h ei ght: 350px"> <el-table :data="tableData" stripe highlight- current -row style="width:520px; mar gin -left:15px" @row-click="clickData" > <el-table-column prop="n am e" label="名称"> </el-table-column> </el-table> </el-scrollbar> </el-form> <!-- 内容底部区域 --> <span slot="footer" class="dialog-footer"> <el-button @click="closeGetPath()">取 消</el-button> <el-button type=" Primary " @click="confirmRoute()">确 定</el-button> </span> </el-dialog>
2.导入方法(不要忘记了导入方法和data定义)
import { getMiddlePath } From "@/api/ config ";
3.方法区代码
//获取路径的方法 handleGetPath(path) { this.routeDialogVisible = true; }, //关闭窗口 closeGetPath() { this.routeDialogVisible = false; }, //确定按钮 confirmRoute() { this.settingForm.resultPath = this.routeDialog.path; this.routeDialogVisible = false; }, //点击进入文件列表 clickData(row, event) { console.log(row); getMiddlePath({ orderKey: row.path }).then(response => { this.tableData = response.data.list; this.routeDialog = row; console.log(this.routeDialog); }); }, //向上一级 backRoute() { if (this.routeDialog.path.endsWith("\\")) { VAR len = this.routeDialog.path.lastIndexOf("\\"); var s ub = this.routeDialog.path.substring(0, len); getMiddlePath({}).then(response => { this.tableData = response.data.list; }); } else { var len = this.routeDialog.path.lastIndexOf("\\"); if (len == 2) { var sub = this.routeDialog.path.substring(0, len); getMiddlePath({ orderKey: sub + "\\" }).then(response => { this.tableData = response.data.list; this.routeDialog.path = sub + "\\"; }); } else { var sub = this.routeDialog.path.substring(0, len); console.log(sub); this.routeDialog.path = sub; getMiddlePath({ orderKey: sub }).then(response => { this.tableData = response.data.list; }); } } },
4.api接口中的config.js代码
export function getMiddlePath(data) { return request({ url: '/config/fileList', method: 'post', data }) }
二、 后端 代码
controller层代码
@PostMapping("fileList") @NoLogin @ResponseBody public ListRes<FileInfo> fileList(@RequestBody BaseListReq req) { return configService.fileList(req); }
service接口interface
ListRes<FileInfo> fileList(BaseListReq req);
service层代码impl
@ override public ListRes<FileInfo> fileList(BaseListReq req) { String path = req.getOrderKey(); List<FileInfo> list; if (StringUtils.isNullOrEmpty(path) || ROOT_PATH.equals(path)) { File[] subFiles = File.listRoots(); list = new ArrayList<>(subFiles.length); for (File subFile : subFiles) { FileInfo fileInfo = new FileInfo(subFile); list.add(fileInfo); } } else { File folder = new File(path); if (!folder.exists()) { return new ListRes<>(ResponseEnum.FILE_NOT_EXIST); } if (!folder.isDirectory()) { return new ListRes<>(ResponseEnum.PARAM_ERROR); } File[] subFiles = folder.listFiles(); if (subFiles == null) { return new ListRes<>(ResponseEnum.PARAM_ERROR); } list = new ArrayList<>(subFiles.length); for (File subFile : subFiles) { if (subFile.isDirectory()) { FileInfo fileInfo = new FileInfo(subFile); list.add(fileInfo); } } } ListRes<FileInfo> res = new ListRes<>(ResponseEnum.SUCCESS); res.setList(list); return res; }
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。
您可能感兴趣的 文章 : 解决vue-cli 配置资源引用的绝对路径问题 vue 如何实现配置@绝对路径 vue cli使用绝对路径引用图片问题的解决
总结
以上是 为你收集整理的 Vue项目如何获取本地文件夹绝对路径 全部内容,希望文章能够帮你解决 Vue项目如何获取本地文件夹绝对路径 所遇到的问题。
如果觉得 网站内容还不错, 推荐好友。
查看更多关于Vue项目如何获取本地文件夹绝对路径的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did203875