赞
踩
乱码问题
获取项目当前路径 ftp.printWorkingDirectory() 乱码,因为已经是转码的了,再转回来即可
new String(ftp.printWorkingDirectory().getBytes("iso8859-1"), "UTF-8")
ftp.retrieveFile(ftp.printWorkingDirectory()+"/"
+new String((fileName).getBytes(LOCAL_CHARSET),"ISO-8859-1"), is);
思路:
1、ftp.printWorkingDirectory() 不要放在new String里,否则再次转码,获取不到地址
2、文件路径连接符用"/",不要用File.separator
效果
ftp文件浏览
后台代码
- package com.hljtx.eip.contorller;
-
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Map;
- import java.util.zip.ZipOutputStream;
-
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
- import org.apache.commons.lang.StringUtils;
- import org.apache.commons.net.ftp.FTPClient;
- import org.apache.commons.net.ftp.FTPFile;
- import org.apache.commons.net.ftp.FTPReply;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.ResponseBody;
-
- import com.hljtx.eip.service.impl.IntelligentReportSecondServiceImpl;
- import com.hljtx.eip.util.FTPUtil;
- import com.hljtx.eip.util.Prop;
- import com.hljtx.eip.util.PropUtils;
-
- @Controller
- @RequestMapping("/FTPTool")
- public class FTPToolController {
- private static String LOCAL_CHARSET = "GBK";
- @Resource
- IntelligentReportSecondServiceImpl reportSecondServiceImpl;
- @RequestMapping("/showFileDirectory.do")
- public String showFileDirectory(HttpServletRequest request,HttpServletResponse response) {
- try{
- String ftpHost = request.getParameter("ftpHost");
- String ftpPortStr= request.getParameter("ftpPort");
- int ftpPort =0;
- if(StringUtils.isNotBlank(ftpPortStr)){
- ftpPort = Integer.parseInt(request.getParameter("ftpPort"));
- }
- String ftpUserName = request.getParameter("ftpUserName");
- String ftpPassword = request.getParameter("ftpPassword");
- String url = request.getParameter("url");
- String rootUrl = request.getParameter("root");
- if(StringUtils.isBlank(url)){
- url = rootUrl;
- }
- if(StringUtils.endsWith(rootUrl,"/")){
- rootUrl=rootUrl.substring(0,rootUrl.lastIndexOf("/"));
- }
- request.setAttribute("ftpHost", ftpHost);
- request.setAttribute("ftpPort", ftpPort);
- request.setAttribute("ftpUserName", ftpUserName);
- request.setAttribute("ftpPassword", ftpPassword);
- request.setAttribute("root", rootUrl);
-
- FTPUtil ftpUtil = new FTPUtil();
- FTPClient ftp = ftpUtil.getFTPClient(ftpHost, ftpPort, ftpUserName, ftpPassword);
- if (FTPReply.isPositiveCompletion(
- ftp.sendCommand("OPTS UTF8", "ON"))) {// 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码,否则就使用本地编码(GBK).
- LOCAL_CHARSET= "UTF-8";
- }
- ftp.setControlEncoding(LOCAL_CHARSET);
- //设置FTP连接模式
- ftp.enterLocalPassiveMode();
- if(StringUtils.isNotBlank(url)){
- ftp.changeWorkingDirectory(new String(url.getBytes(LOCAL_CHARSET),"ISO-8859-1"));
- if(ftp.printWorkingDirectory().equals("/")){
- request.setAttribute("msg", "文件打开发生错误,请检查文件权限");
- return "jsp/ftptool/ftplist";
- }
-
- }
- FTPFile[] fileList=ftp.listFiles();
- //返回文件列表
- request.setAttribute("fileList", fileList);
- System.out.println(ftp.printWorkingDirectory());
- System.out.println(new String(ftp.printWorkingDirectory().getBytes("iso8859-1"), "UTF-8"));
- System.out.println(new String(ftp.printWorkingDirectory().getBytes(LOCAL_CHARSET),"ISO-8859-1"));
- System.out.println(ftp.getCharsetName());
- System.out.println(rootUrl);
- if(StringUtils.isNotBlank(rootUrl)){
- url = url.replace(rootUrl, "");
- }
- request.setAttribute("url", url);
-
- }catch(Exception e){
- e.printStackTrace();
- }
-
- return "jsp/ftptool/ftplist";
- }
-
- @RequestMapping("/downFtpFile.do")
- @ResponseBody
- public Map<String,Object> downFtpFile(HttpServletRequest request,HttpServletResponse response) {
- Map<String,Object> map= new HashMap<String, Object>();
- String AccessApacheUrl ="";
- //获取项目路径
- Prop prop = PropUtils.use("config.properties");
- String fileUploadPath = prop.get("fileUploadPath");
- String fileAccessApacheUrl = prop.get("fileAccessApacheUrl");
- //文件夹名称
- String tempFileName="ftpTempFile";
- //文件夹路径
- String tempFileUrl= fileUploadPath + File.separator + tempFileName ;
- try {
- String ftpHost = request.getParameter("ftpHost");
- String ftpPortStr= request.getParameter("ftpPort");
- int ftpPort =0;
- if(StringUtils.isNotBlank(ftpPortStr)){
- ftpPort = Integer.parseInt(request.getParameter("ftpPort"));
- }
- String ftpUserName = request.getParameter("ftpUserName");
- String ftpPassword = request.getParameter("ftpPassword");
- String url = request.getParameter("url");
- String fileName = request.getParameter("fileName");
- String folder = request.getParameter("folder");
- FTPUtil ftpUtil = new FTPUtil();
- FTPClient ftp = ftpUtil.getFTPClient(ftpHost, ftpPort, ftpUserName, ftpPassword);
- if (FTPReply.isPositiveCompletion(
- ftp.sendCommand("OPTS UTF8", "ON"))) {// 开启服务器对UTF-8的支持,如果服务器支持就用UTF-8编码,否则就使用本地编码(GBK).
- LOCAL_CHARSET= "UTF-8";
- }
- ftp.setControlEncoding(LOCAL_CHARSET);
- //设置FTP连接模式
- ftp.enterLocalPassiveMode();
- //打不开文件夹
- if(StringUtils.isNotBlank(url)){
- ftp.changeWorkingDirectory(new String(url.getBytes(LOCAL_CHARSET),"ISO-8859-1"));
- System.out.println(ftp.printWorkingDirectory());
- if(ftp.printWorkingDirectory().equals("/")){
- return map;
- }
- }
-
-
- //时间戳
- String time=String.valueOf(new Date().getTime());
- tempFileUrl = tempFileUrl+File.separator+time;
- File tempFile = new File(tempFileUrl);
- tempFile.mkdirs();
- //下载文件
- if(StringUtils.isNotBlank(fileName)){
- String temfileName = tempFileUrl+File.separator+fileName;
- File localFile = new File(temfileName);
- localFile.deleteOnExit();
-
- OutputStream is = new FileOutputStream(localFile);
- ftp.setFileType(ftp.BINARY_FILE_TYPE);
- ftp.retrieveFile(ftp.printWorkingDirectory()+"/"+new String((fileName).getBytes(LOCAL_CHARSET),"ISO-8859-1"), is);
- is.close();
- AccessApacheUrl = fileAccessApacheUrl + tempFileName+File.separator+time +File.separator+fileName;
-
- }else{
- //下载文件夹
- FTPFile[] fileList=ftp.listFiles();
-
- if(fileList.length>0){
- String fileDi= tempFileUrl+File.separator +folder;
- File fileDIF = new File(fileDi);
- fileDIF.mkdirs();
- for(FTPFile ftpFile:fileList){
- if(ftpFile.getType() == 1){
- downLoadFile(ftp, ftpFile, fileDi+File.separator+ftpFile.getName());
- }else{
- downLoadFile(ftp, ftpFile, fileDi);
- }
-
- }
- String zipUrl = tempFileUrl+".zip";
- // 实例化 FileOutputStream 对象
- FileOutputStream fileOutputStream = new FileOutputStream(zipUrl);
- // 创建 ZipOutputStream
- ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
- reportSecondServiceImpl.makeZip(zipOutputStream,tempFile,"");
- //关闭各种流
- zipOutputStream.closeEntry();
- zipOutputStream.close();
- fileOutputStream.close();
- AccessApacheUrl = fileAccessApacheUrl+ tempFileName+File.separator+time+".zip";
- //压缩完成删除压缩前的文件
- File srcFiles = new File(tempFileUrl);
- reportSecondServiceImpl.deleteAllFile(srcFiles);
- }
-
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- AccessApacheUrl="";
- }
- map.put("AccessApacheUrl", AccessApacheUrl);
- return map;
- }
-
- public void downLoadFile(FTPClient ftp,FTPFile ftpFile,String loaclFileUrl) {
- try{
- File localFile = new File(loaclFileUrl);
- localFile.mkdirs();
- //文件夹类型
- if(ftpFile.getType() == 1){
- if(ftp.changeWorkingDirectory(ftpFile.getName())){
- System.out.println(ftp.printWorkingDirectory());
-
- //下载文件夹
- FTPFile[] fileList=ftp.listFiles();
- for(FTPFile nextftpFile:fileList){
- System.out.println(ftpFile.getType() );
- if(nextftpFile.getType() == 1){
- downLoadFile(ftp, nextftpFile, loaclFileUrl+File.separator+nextftpFile.getName());
- }else{
- downLoadFile(ftp, nextftpFile, loaclFileUrl);
-
- }
- }
- }
- }else{
- localFile.deleteOnExit();
- OutputStream is = new FileOutputStream(localFile+File.separator+ftpFile.getName());
- ftp.setFileType(ftp.BINARY_FILE_TYPE);
- ftp.retrieveFile(ftp.printWorkingDirectory()+"/"+new String(ftpFile.getName().getBytes(LOCAL_CHARSET),"ISO-8859-1"), is);
- is.close();
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- @RequestMapping("/downFile.do")
- public void downFile(HttpServletRequest request,HttpServletResponse response) {
- try {
- String url = request.getParameter("url");
- if(StringUtils.isNotBlank(url)){
- //获取项目路径
- Prop prop = PropUtils.use("config.properties");
- String fileUploadPath = prop.get("fileUploadPath");
- String fileAccessApacheUrl = prop.get("fileAccessApacheUrl");
- String temfileName = url.replace(fileAccessApacheUrl, fileUploadPath);
- File file = new File(temfileName);
- String fileName=temfileName.substring(temfileName.lastIndexOf("\\")+1, temfileName.length());
-
- // 以流的形式下载文件。
- InputStream fis = new BufferedInputStream(new FileInputStream(temfileName));
- byte[] buffer = new byte[fis.available()];
- fis.read(buffer);
- fis.close();
- // 清空response
- response.reset();
- // 设置response的Header
- response.addHeader("Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("gbk"), "iso8859-1"));
- //设置文件打下
- response.addHeader("Content-Length", "" + file.length());
- OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
- response.setContentType("application/octet-stream");
- toClient.write(buffer);
- toClient.flush();
- toClient.close();
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
前端页面代码
ftplist.jsp
- <%@page pageEncoding="utf-8" import="java.util.*,com.hljtx.eip.util.ConsumerStyleChange,com.hljtx.eip.util.SsoUtils"%>
- <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
- <%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
- <%@ taglib prefix="fun" uri="http://java.sun.com/jsp/jstl/functions"%>
- <%
- String path = request.getContextPath();
- String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
- %>
-
- <!DOCTYPE html>
- <html lang="zh-CN" style="background: #fff;">
- <head>
- <head>
- <base href="<%=basePath%>">
- <title>ftp文件浏览</title>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="<%=path %>/css/folder.css" />
- <link rel="stylesheet" href="<%=path %>/css/bootstrap.min.css" />
- <script src="<%=path %>/js/jquery.min.js"></script>
- <script src="<%=path %>/js/database.js"></script>
- <script src="<%=path %>/js/dblist.js"></script>
- <script src="<%=path %>/js/jquery.contextmenu.r2.js"></script>
- <script src="<%=path %>/js/folder.js"></script>
- <script src="<%=path%>/js/newlayer/layer.js"></script>
- <script type="text/javascript">
- $(function(){
- //初始化
- var id = "1";
- init(id, 0);
- //textarea_bind();
- });
- </script>
- <script type="text/javascript">
- $(function(){
-
- //双击功能
- $("#divall li.folder").dblclick(function() {
- openFile($(this));
- });
-
- var url = $("[name='url']").val()
- if("${msg}" !=""){
- alert("${msg}");
- if( url !="" && url !="/"){
- openRootFile();
- }
- }
- })
-
- //进入文件夹
- function openFile(obj){
- var folder = $(obj).children("input.changename").val();
- var root = $("[name='root']").val();
- var oldUrl = $("[name='url']").val();
- if(oldUrl.trim()=="/" || oldUrl.trim()==""){
- $("[name='url']").val(root+"/"+folder);
- }else{
- $("[name='url']").val(root+"/"+oldUrl+"/"+folder);
- }
-
- $("#ftpForm").submit()
- }
- /**
- *打开根目录
- */
- function openRootFile(){
- var root = $("[name='root']").val();
- $("[name='url']").val(root);
- $("#ftpForm").submit()
- }
- //点击导航事件
- function openNavigationFile(obj){
- var root = $("[name='root']").val();
- var newUrl=""
- $(obj).prevAll(".childFolder").each(function(){
- newUrl +="/"+$(this).text().trim();
- })
- newUrl +="/" + $(obj).text().trim();
- $("[name='url']").val(root+newUrl);
- $("#ftpForm").submit()
- }
- var layerIndex;
- //下载文件
- function downFTPFile(param){
- layer.load({
- shade: [0.1,'#fff'] //0.1透明度的白色背景
- });
- var root = $("[name='root']").val();
- var oldUrl = $("[name='url']").val();
- var newUrl="";
- var filename="";
- var data={};
-
- if(param.is_directory ==1){
- if(oldUrl.trim()=="/" || oldUrl.trim()==""){
- newUrl=root+"/"+param.folder_name
- }else{
- newUrl=root+"/"+oldUrl+"/"+param.folder_name;
- }
- //文件夹类型
- data.url = newUrl;
- data.folder =param.folder_name;
- }else{
- //文件类型
- if(oldUrl.trim()=="/" || oldUrl.trim()==""){
- newUrl=root
- }else{
- if(oldUrl.startsWith("/")){
- newUrl=root+oldUrl;
- }else{
-
- newUrl=root+"/"+oldUrl;
- }
- }
- data.url = newUrl;
-
- filename=param.folder_name;
- }
-
- data.fileName = filename;
- data.ftpHost=$("[name='ftpHost']").val();
- data.ftpPort=$("[name='ftpPort']").val();
- data.ftpUserName=$("[name='ftpUserName']").val();
- data.ftpPassword=$("[name='ftpPassword']").val();
- $.ajax({
- type:'post',
- url:'<%=path %>/FTPTool/downFtpFile.do',
- data:data,
- success:function(d){
- layer.closeAll('loading');
- if(d.AccessApacheUrl && d.AccessApacheUrl !=""){
- //询问框
- layerIndex = layer.confirm('文件地址:'+d.AccessApacheUrl+',是否下载?', {
- closeBtn: 0,
- btn: ['是','否'] //按钮
- }, function(){
- window.open(d.AccessApacheUrl, '_blank');
- <%-- if(param.is_directory ==1){
- window.open(d.AccessApacheUrl, '_self');
- }else{
- window.open("<%=path %>/FTPTool/downFile.do?url="+d.AccessApacheUrl,"下载",)
- } --%>
-
- }, function(){
- layer.close(layerIndex);
- });
- }else{
- alert("没有可下载文件")
- }
-
- }
- })
- }
- </script>
- </head>
-
- <body>
- <!-- 导航 -->
- <div class="navigation-bar">
- <div class="forward-backward">
- <button type="button" class="backward flipy-y btn-xs k-btn btn" title="后退" onclick="history.go(-1)"></button>
- </div>
- <button type="button" class="home btn-xs k-btn btn" title="返回根目录" onclick="openRootFile()"></button>
- <div class="folder-navigation" id="folder-navigation">
- <a class="foldername" data-id="1" onclick="openRootFile()">根目录</a>
- <c:forEach items="${fun:split(url,'/') }" var="fileName" varStatus="i">
- <c:if test="${!empty fileName }">
- <img class="triangle" src="<%=path %>/images/triangle.png"><a class="foldername childFolder" data-id="2" onclick="openNavigationFile(this)">${fileName }</a>
- </c:if>
- </c:forEach>
- </div>
-
- </div>
- <form action="<%=path %>/FTPTool/showFileDirectory.do" method="post" id="ftpForm" name="ftpForm">
- <input type="hidden" value="${root}" name="root">
- <input type="hidden" value="${url}" name="url">
- <input type="hidden" value="${ftpHost}" name="ftpHost">
- <input type="hidden" value="${ftpPort}" name="ftpPort">
- <input type="hidden" value="${ftpUserName}" name="ftpUserName">
- <input type="hidden" value="${ftpPassword}" name="ftpPassword">
-
- </form>
- <div class="alldom" id="all_folder">
- <ul id="divall">
-
- <c:forEach items="${fileList }" var="file">
- <c:set var="fileTypeName" value="${fun:substringAfter(file.name,'.') }" />
- <c:set var="fileType" value="${fun:toLowerCase(fileTypeName) }" />
- <li
- <c:choose>
- <c:when test="${file.type eq 1}">
- class="folder"
- </c:when>
- <c:when test="${fileType eq 'docx' || fileType eq 'doc'}">
- class="file docx"
- </c:when>
- <c:when test="${fileType eq 'xls' || fileType eq 'xlsx'}">
- class="file xlsx"
- </c:when>
- <c:when test="${fileType eq 'pdf'}">
- class="file pdf"
- </c:when>
- <c:when test="${fileType eq 'png'}">
- class="file png"
- </c:when>
- <c:when test="${fileType eq 'jpg'}">
- class="file jpg"
- </c:when>
- <c:when test="${fileType eq 'mp3'}">
- class="file mp3"
- </c:when>
- <c:when test="${fileType eq 'mp4'}">
- class="file mp4"
- </c:when>
- <c:when test="${fileType eq 'rar' || fileType eq 'zip'}">
- class="file rar"
- </c:when>
- <c:when test="${fileType eq 'txt'}">
- class="file txt"
- </c:when>
- <c:otherwise>
- class="file other-filetype"
- </c:otherwise>
- </c:choose>
- title="${file.name }" index="0"><input type="text" class="changename" value="${file.name }" data-id="2" disabled="disabled" data-last-value="${file.name }"></li>
- </c:forEach>
- </ul>
- </div>
- <div style="clear: both;"></div>
-
- <!-- 在文件夹上右键菜单 -->
- <div class="contextMenu" id="myMenu2">
- <ul>
- <li id="open" >打开</li>
- <li id="download">下载</li>
- <!-- <li id="copy">复制</li>
- <li id="cut">剪切</li>
- <li id="paste">黏贴</li>
- <li id="rename">重命名</li>
- <li id="delete">删除</li>-->
- </ul>
- </div>
- <!-- 在文件上面右键菜单 -->
- <div class="contextMenu" id="myMenu3">
- <ul>
- <li id="download">下载</li>
- <!-- <li id="copy">复制</li>
- <li id="cut">剪切</li>
- <li id="rename">重命名</li>
- <li id="delete">删除</li>-->
- </ul>
- </div>
- </body>
-
-
- </html>
folder.css
- @CHARSET "UTF-8";
- * {
- margin:0;
- padding:0;
- }
- body,html {
- width:100%;
- height:100%;
- }
- .alldom {
-
- }
- .alldom ul {
- padding:0;
- list-style:none;
- }
- .folder {
- background:url(../images/213125.png) center top no-repeat;
- }
- .doc,.docx {
- background:url(../images/DOC_File_Extension.png) center top no-repeat;
- }
- .pdf {
- background:url(../images/pdf.png) center top no-repeat;
- }
- .xls,.xlsx {
- background:url(../images/XLS_File_Extension.png) center top no-repeat;
- }
- .other-filetype {
- background:url(../images/qita.png) center top no-repeat;
- }
- .png {
- background:url(../images/png.png) center top no-repeat;
- }
- .jpg {
- background:url(../images/jpg.png) center top no-repeat;
- }
- .txt {
- background:url(../images/file.png) center top no-repeat;
- }
- .mp3 {
- background:url(../images/mp3.png) center top no-repeat;
- }
- .mp4 {
- background:url(../images/mp4.png) center top no-repeat;
- }
- .rar {
- background:url(../images/rar.png) center top no-repeat;
- }
- .alldom ul li {
- overflow:hidden;
- width:100px;
- height:115px;
- float:left;
- margin: 0px 25px;
- border:1px solid #fff;
- position:relative;
- transition:all 0.2s ease-in 0.1s;
- white-space:nowrap;
- text-overflow:ellipsis
- }
- .alldom ul li.focus {
-
- }
- .alldom ul li:hover {
- background-color:#ddd;
- cursor: pointer;
-
- }
- input.changename {
- position:absolute;
- border-radius:0px;
- left:-25px;
- bottom:10px;
- overflow:hidden;
- width:98px;
- height:20px;
- color:#595c5f;
- line-height:20px;
- text-align:center;
- font-size:12px;
- z-index:0;
- border:0;
- border-radius:8px;
- transition:all 0.2s ease-in 0.1s;
- margin-left:25px;
- background:none;
- }
- input.changename:hover {
- background:none;
- color:#F33;
- }
- input.changename:focus {
- background-color:#fff;
- }
- .info-bar {
- height:65px;
- }
- .info-icon {
- width:60px;
- height:90%;
- display:inline-block;
- background-size:cover;
- }
- .info-detail {
- display:inline-block;
- height:90%;
- width:90%;
- margin-left:10px;
- }
- .detail-form .detail-field {
- float:left;
- width:300px;
- }
- .detail-field2 {
- font-size:large;
- margin-left:10px;
- }
- .detail-var {
- margin-right:10px;
- }
- .navigation-bar .home {
- width:24px;
- height:24px;
- background-image:url(../images/blue_home.png);
- background-repeat:no-repeat;
- background-size:cover;
- margin:0 3px;
- position:relative;
- display:inline-block;
- }
- .navigation-bar .home:hover {
- background-color:#ccc;
- }
- .navigation-bar .gotopre {
- width:24px;
- height:24px;
- background-image:url(../images/return.png);
- background-repeat:no-repeat;
- background-size:cover;
- margin:0 3px;
- position:relative;
- display:inline-block;
- background-color:ghostwhite;
- }
- .navigation-bar .gotopre:hover {
- background-color:#0ce2ea;
- }
- .folder-navigation .foldername {
- cursor:pointer;
- text-decoration:none;
- }
- .folder-navigation .triangle {
- width:8px;
- margin:0 5px 3px 5px;
- }
- .navigation-bar .folder-navigation {
- height:20px;
- position:relative;
- display:inline-block;
- margin-left:10px;
- }
- .navigation-bar .forward-backward {
- width:30px;
- display:inline-block;
- }
- .navigation-bar .forward-backward .backward {
- background-image:url(../images/forward.png);
- background-repeat:no-repeat;
- background-size:contain;
- margin:5px 3px;
- border:0;
- width:24px;
- height:24px;
-
- }
- .navigation-bar .forward-backward .backward:hover,.navigation-bar .forward-backward .backward:focus {
- background-color:#ccc;
- }
- .navigation-bar .forward-backward .forward {
- background-image:url(../images/forward.png);
- background-repeat:no-repeat;
- background-size:contain;
- margin:0 3px;
- border:0;
- width:24px;
- height:24px;
- background-color:#1da71d;
- }
- .navigation-bar .forward-backward .forward:hover,.navigation-bar .forward-backward .forward:focus {
-
- }
- .flipy-x {
- -moz-transform:scaleY(-1);
- -webkit-transform:scaleY(-1);
- -o-transform:scaleY(-1);
- transform:scaleY(-1);
- filter:FlipV;
- }
- .flipy-y {
-
- filter:FlipH;
- }
- .folder-navigation a{ color:#5d5d5d}
- .navigation-bar{
- border-bottom: solid 1px #eee;
- margin-bottom: 15px;
- }
folder.js(大部分没用上,只有绑定菜单用到了)
- //定义双向链表存放浏览历史
- var operation_history = new DbList({
- "parent_id": "-1",
- "is_active": false
- }),
- timeOutFn = null,
- is_ctrl_down = false,
- is_shift_down = false,
- focus_index = -1;
- /*mode:1->复制 2->剪切
- * id:被复制或剪切的文件或文件夹的id
- * parent_id:被复制文件的上级目录id
- * can_paste:false->不能黏贴 true->能黏贴
- * */
- oprate_param = {
- "mode": "",
- "id": "",
- "parent_id": "",
- "can_paste": false
- };
-
- function init(parent_id, mode) {
- //初始化导航栏
- //navigation(parent_id);
- //将当前页面插入历史记录链表里面
- /*mode
- *0:初始化进入页面
- *1:新建文件夹
- *2:删除文件夹或文件
- *3:刷新当前文件夹
- *4:将当前目录下的文件夹和文件排序
- *5:上传文件
- *6:打开文件夹
- *7:点击后退按钮
- *8:点击前进按钮
- *9:点击主页
- *10:返回上一层目录
- *11:点击地址栏
- *
- */
- if (mode == 0) {
- operation_history.insertLast({
- "parent_id": parent_id,
- "is_active": true
- });
- } else if (mode == 1) {
- //新建文件夹不插入历史记录
- } else if (mode == 2) {
- //删除文件夹或文件不会改变历史记录
- } else if (mode == 3) {
- //刷新当前文件夹不插入历史记录
- } else if (mode == 4) {
- //排序不插入历史记录
- } else if (mode == 5) {
- //上传文件现在会重新进入页面,这个之后改
- } else if (mode == 6) {
- //打开文件夹会删除父目录(也就是当前激活的目录)往后的所有记录,再插入新的子目录记录
- var currNode = find_active_node();
- operation_history.removeAfter(currNode);
- currNode.element.is_active = false;
- operation_history.insertLast({
- "parent_id": parent_id,
- "is_active": true
- });
- } else if (mode == 7) {
- var currNode = find_active_node();
- currNode.element.is_active = false;
- currNode.previous.element.is_active = true;
- } else if (mode == 8) {
- var currNode = find_active_node();
- currNode.element.is_active = false;
- currNode.next.element.is_active = true;
- } else if (mode == 9) {
- //返回主页会删除父目录(也就是当前激活的目录)往后的所有记录,再插入新的子目录(主页)记录
- var currNode = find_active_node();
- operation_history.removeAfter(currNode);
- currNode.element.is_active = false;
- operation_history.insertLast({
- "parent_id": parent_id,
- "is_active": true
- });
- } else if (mode == 10) {
- //返回上级目录会删除父目录(也就是当前激活的目录)往后的所有记录,再插入新的子目录(上级目录)记录
- var currNode = find_active_node();
- operation_history.removeAfter(currNode);
- currNode.element.is_active = false;
- operation_history.insertLast({
- "parent_id": parent_id,
- "is_active": true
- });
- } else if (mode == 11) {
- //点击地址栏仅仅往历史记录里面加一条记录,如果链表里面最后一条记录
- //与将要添加的相同则不添加记录而是把最后一条记录设为激活状态
- var currNode = find_active_node(),
- lastNode = operation_history.findLast();
- currNode.element.is_active = false;
- if (lastNode.element.parent_id == parent_id) {
- lastNode.element.is_active = true;
- } else {
- operation_history.insertLast({
- "parent_id": parent_id,
- "is_active": true
- });
- }
- }
- //载入文件夹
- //load();
- //载入信息栏 第一个参数-> 1:展示文件夹的记录数 2:展示选中的文件信息 3:展示选中的文件夹数目
- // 第二个参数-> 展示的文件的id
- info(1, 0);
- //绑定右键菜单
- contextMenu();
- //绑定左键事件
- leftClick();
- //绑定获取焦点事件
- //focus();
- //绑定失去焦点事件
- //blur();
- //定义文件名更改事件
- // change();
- //定义双击事件
- dbclick();
- //定义键盘按键按下事件
- //keydown();
- //定义键盘按键弹起事件
- //keyup();
- //将元素绑定拖拽方法--还没开发完
- //drag();
- }
-
- //在历史记录中找到当前的节点
- function find_active_node() {
- var currNode = operation_history.getHead();
- while (currNode.element.is_active != true) {
- currNode = currNode.next;
- }
- return currNode;
- }
-
- function contextMenu() {
- contextMenu_folder();
- contextMenu_blank();
- contextMenu_file();
- }
-
- function contextMenu_folder() {
- $("#divall li.folder").contextMenu('myMenu2', {
- bindings: {
- 'open': function(t) {
- openFile(t);
- },
- 'rename': function(t) {
- //重命名
- var folder = $(t).children("input.changename"),
- folder_name = folder.val(),
- id = folder.attr("data-id"),
- is_directory = $(t).hasClass("folder") ? 1 : 0;
- doc_type = $(t).hasClass("folder") ? "" : folder.attr("data-filetype"),
- parent_id = $("#navigation").val(),
- params = {
- "folder_name": folder_name,
- "id": id,
- "is_directory": is_directory,
- "doc_type": doc_type,
- "parent_id": parent_id,
- "description": ""
- };
- K.form.setparams($("#M8610F001"), params);
- K.popup($("#M8610P001"));
- },
- 'delete': function(t) {
- //删除文件夹
- var id = $(t).children("input.changename").attr("data-id"),
- is_directory = $(t).hasClass("folder") ? 1 : 0,
- params = {
- "id": id,
- "is_directory": is_directory
- };
- dele(params);
- },
- 'download': function(t) {
- //将文件夹打包下载
- var folder = $(t).children("input.changename"),
- id = folder.attr("data-id"),
- is_directory = $(t).hasClass("folder") ? 1 : 0,
- folder_name = folder.val(),
- parent_id = $("#navigation").val(),
- params = {
- "id": id,
- "is_directory": is_directory,
- "folder_name": folder_name,
- "parent_id": parent_id
- };
- downFTPFile(params);
- // Tools.alert("下载成功!");
- }/*,
- 'copy': function(t) {
- //复制
- var focus_id = [];
- $("#divall").find("li").each(function(i) {
- if ($(this).hasClass("focus")) {
- focus_id.push($(this).children("input.changename").attr("data-id"));
- }
- });
- oprate_param.mode = 1;
- oprate_param.id = focus_id;
- oprate_param.parent_id = $("#navigation").val();
- oprate_param.can_paste = true;
- alert("copy了:" + focus_id);
- },
- 'cut': function(t) {
- //剪切
- var focus_id = [];
- $("#divall").find("li").each(function(i) {
- if ($(this).hasClass("focus")) {
- focus_id.push($(this).children("input.changename").attr("data-id"));
- }
- });
- oprate_param.mode = 2;
- oprate_param.id = focus_id;
- oprate_param.parent_id = $("#navigation").val();
- oprate_param.can_paste = true;
- alert("cut了:" + focus_id);
- },
- 'paste': function(t) {
- var folder = $(t).children("input.changename"),
- id = folder.attr("data-id");
- if (oprate_param.can_paste != true) {
- alert("剪切板中无内容!");
- } else {
- if (oprate_param.parent_id == id) {
- alert("文件已存在!");
- } else {
- //黏贴
-
- }
- }
- }*/
- },
- onContextMenu: function(e) {
- var i_index = $(e.target).attr("index"),
- all_focus_index = [];
- $("#divall").find("li").each(function(i) {
- if ($(this).hasClass("focus")) {
- all_focus_index.push($(this).attr("index"));
- }
- });
- if ($.inArray(i_index, all_focus_index) == -1) {
- $("#divall").find("li").each(function(i) {
- $(this).removeClass("focus");
- });
- $(e.target).addClass("focus");
- }
- return true;
- }
- });
- }
-
- function contextMenu_file() {
- $("#divall li.file").contextMenu('myMenu3', {
- bindings: {
- /*'rename': function(t) {
- //重命名
- var folder = $(t).children("input.changename"),
- folder_name = folder.val(),
- id = folder.attr("data-id"),
- is_directory = $(t).hasClass("folder") ? 1 : 0,
- doc_type = $(t).hasClass("folder") ? "" : folder.attr("data-filetype"),
- parent_id = $("#navigation").val(),
- params = {
- "folder_name": folder_name,
- "id": id,
- "is_directory": is_directory,
- "doc_type": doc_type,
- "parent_id": parent_id,
- "description": ""
- };
- K.form.setparams($("#M8610F001"), params);
- K.popup($("#M8610P001"));
- },*/
- /*'copy': function(t) {
- //复制
- var focus_id = [];
- $("#divall").find("li").each(function(i) {
- if ($(this).hasClass("focus")) {
- focus_id.push($(this).children("input.changename").attr("data-id"));
- }
- });
- oprate_param.mode = 1;
- oprate_param.id = focus_id;
- oprate_param.parent_id = $("#navigation").val();
- oprate_param.can_paste = true;
- alert("copy了:" + focus_id);
- },
- 'cut': function(t) {
- //剪切
- var focus_id = [];
- $("#divall").find("li").each(function(i) {
- if ($(this).hasClass("focus")) {
- focus_id.push($(this).children("input.changename").attr("data-id"));
- }
- });
- oprate_param.mode = 2;
- oprate_param.id = focus_id;
- oprate_param.parent_id = $("#navigation").val();
- oprate_param.can_paste = true;
- alert("cut了:" + focus_id);
- },*/
- 'delete': function(t) {
- //删除单个文件
- var id = $(t).children("input.changename").attr("data-id"),
- is_directory = $(t).hasClass("folder") ? 1 : 0,
- params = {
- "id": id,
- "is_directory": is_directory
- };
- dele(params);
- },
- 'download': function(t) {
- //下载单个文件
- var folder = $(t).children("input.changename"),
- id = folder.attr("data-id"),
- is_directory = $(t).hasClass("folder") ? 1 : 0,
- folder_name = folder.val() //+ "." + folder.attr("data-filetype"),
- parent_id = $("#navigation").val(),
- params = {
- "id": id,
- "is_directory": is_directory,
- "folder_name": folder_name,
- "parent_id": parent_id
- };
- downFTPFile(params);
- // Tools.alert("下载成功!");
- }
- },
- onContextMenu: function(e) {
- var i_index = $(e.target).attr("index"),
- all_focus_index = [];
- $("#divall").find("li").each(function(i) {
- if ($(this).hasClass("focus")) {
- all_focus_index.push($(this).attr("index"));
- }
- });
- if ($.inArray(i_index, all_focus_index) == -1) {
- $("#divall").find("li").each(function(i) {
- $(this).removeClass("focus");
- });
- $(e.target).addClass("focus");
- }
- return true;
- }
- });
- }
-
- function contextMenu_blank() {
- $("#all_folder").contextMenu('myMenu1', {
- bindings: {
- 'newfolder': function(t) {
- //获取新文件夹的名称
- var folder_names = [],
- newfolder_name = "";
- $("#all_folder").find("ul").eq(0).find("li.folder").each(function(index) {
- folder_names.push($(this).children("input.changename").val());
- });
- for (var i = 0; i < 100; i++) {
- if (i == 0) {
- newfolder_name = "新文件夹";
- } else {
- newfolder_name = "新文件夹[" + i + "]";
- }
- if ($.inArray(newfolder_name, folder_names) == -1) {
- break;
- };
- }
- //调用新增文件夹代码
- var params = {
- "id": $("#navigation").val(),
- "discription": "",
- "folder_name": newfolder_name
- };
- var flag = add_folder(params);
- if (flag) {
- init($("#navigation").val(), 1);
- }
- },
- /*'paste': function(t) {
- //黏贴
- var parent_id = $("#navigation").val();
- if (oprate_param.can_paste != true) {
- Tools.alert("无黏贴内容");
- } else {
- if (oprate_param.parent_id == parent_id) {
- Tools.alert("文件已存在!");
- paste(oprate_param);
- } else {
- Tools.alert("正在黏贴");
- paste(oprate_param);
- }
- }
- //oprate_param.can_paste = false;
- //init($("#navigation").val(),3);
- },*/
- 'flush': function(t) {
- //刷新
- init($("#navigation").val(), 3);
- },
- 'sort': function(t) {
- init($("#navigation").val(), 4);
- },
- 'upload': function(t) {
- //上传文件
- var $M8610F002 = $("#M8610F002");
- K.form.reset($M8610F002);
- K.field.value($('#upload_id'), $("#navigation").val());
- K.popup($("#M8610P002"));
- }
- }
- });
- }
-
- //加载文件夹和文件
- function load() {
- var parentid = $("#navigation").val(),
- rows = select("M8610EQ006",{"id":parentid});
- $("#divall").empty();
- if(rows.length > 0){
- var str = "";
- for(var i = 0; i < rows.length; i++){
- if(rows[i].is_directory == "1"){
- str += "<li class='folder' title='" + rows[i].folder_name + "' index='" + i + "'><input type='text' class='changename' value='";
- str += rows[i].folder_name;
- str += "' data-id='" + rows[i].id + "' disabled='disabled' data-last-value='" + rows[i].folder_name + "'/></li>";
- }else if(rows[i].is_directory == "0"){
- var doc_fullname = rows[i].folder_name,
- doc_name = doc_fullname.substring(0, doc_fullname.lastIndexOf('.')),
- doc_type = doc_fullname.substring(doc_fullname.lastIndexOf('.') + 1),
- doc_type_class = $.inArray(doc_type, ["doc", "docx", "xls", "xlsx", "pdf"]) != -1 ? doc_type : "other-filetype";
- str += "<li class='file " + doc_type_class + "' title='" + rows[i].folder_name + "' index='" + i + "'><input type='text' class='changename' value='";
- str += doc_name;
- str += "' data-id='" + rows[i].id + "' data-filetype='" + doc_type + "' disabled='disabled' data-last-value='" + rows[i].folder_name + "'/></li>";
- }
- }
- $("#divall").append(str);
- }
- }
-
- function info(mode, id) {
- var str = "";
- if (mode == 1) { //展示目录下的对象数目
- $("#info-bar").empty();
- str += '<div class="folder info-icon"></div>';
- str += '<div class="info-detail"><form class="detail-form"><div class="detail-field detail-field2" ><span><var class="detail-var">';
- str += $("#divall").children("li").length;
- str += '</var>个对象</span></div>';
- str += '</form></div>';
- $("#info-bar").append(str);
- } else if (mode == 2) {
- $("#info-bar").empty();
- var rows = select("M8610EQ008",{"id":id});
- if(rows.length > 0){
- var row = rows[0],
- folder_name = row.folder_name,
- is_directory = row.is_directory,
- file_type = is_directory == "1" ? "" : folder_name.substring(folder_name.lastIndexOf('.') + 1),
- file_type_class = file_type == "" ? "folder" : ($.inArray(file_type, ["doc", "docx", "xls", "xlsx", "pdf"]) != -1 ? file_type : "other-filetype"),
- file_type_info = is_directory == "1" ? "文件夹" : folder_name.substring(folder_name.lastIndexOf('.') + 1) + "文件",
- crt_username = row.crt_username,
- upd_username = row.upd_username,
- crt_date = row.crt_date,
- crt_time = row.crt_time,
- upd_date = row.upd_date,
- upd_time = row.upd_time;
- str += '<div class="' + file_type_class + ' info-icon"></div><div class="info-detail"><form class="detail-form"><div class="detail-field" ><label>文件名:</label><span>';
- str += folder_name;
- str += '</span></div><div class="detail-field" ><label>创建人:</label><span>';
- str += crt_username != null ? crt_username : '';
- str += '</span></div><div class="detail-field" ><label>修改人:</label><span>';
- str += upd_username != null ? upd_username : '';
- str += '</span></div><div class="detail-field" ><label>文件类型:</label><span>';
- str += file_type_info;
- str += '</span></div><div class="detail-field" ><label>创建时间:</label><span>';
- str += crt_date != "" && crt_date != null ? crt_date.substring(0, 4) + '/' + crt_date.substring(4, 6) + "/" + crt_date.substring(6, 8) : "";
- str += crt_time != "" && crt_time != null ? " " + crt_time.substring(0, 2) + ":" + crt_time.substring(2, 4) + ":" + crt_time.substring(4, 6) : "";
- str += '</span></div><div class="detail-field" ><label>修改时间:</label><span>';
- str += upd_date != "" && upd_date != null ? upd_date.substring(0, 4) + '/' + upd_date.substring(4, 6) + "/" + upd_date.substring(6, 8) : "";
- str += upd_time != "" && upd_time != null ? " " + upd_time.substring(0, 2) + ":" + upd_time.substring(2, 4) + ":" + upd_time.substring(4, 6) : "";
- str += '</span></div></form></div>';
- $("#info-bar").append(str);
- }
- } else if (mode == 3) {
- $("#info-bar").empty();
- str += '<div class="folder info-icon"></div>';
- str += '<div class="info-detail"><form class="detail-form"><div class="detail-field detail-field2" ><span>已选中<var class="detail-var">';
- str += $("#divall").children("li.focus").length;
- str += '</var>个对象</span></div>';
- str += '</form></div>';
- $("#info-bar").append(str);
- }
- }
-
- function navigation(parent_id) {
- $("#navigation").val(parent_id);
- //查询文件路径
- var id = parent_id,
- flag = true,
- path = [],
- str = "";
- do {
- var rows = select("M8610EQ005",{"id":id});
- if(rows.length > 0){
- var row = rows[0];
- if(row.parent_id != 0){
- path.unshift({
- "folder_name": row.folder_name,
- "parent_id": id
- });
- id = row.parent_id;
- }else{
- flag = false;
- path.unshift({
- "folder_name": row.folder_name,
- "parent_id": id
- });
- }
- }
- } while (flag);
- $("#folder-navigation").empty();
- for (var i = 0; i < path.length; i++) {
- str += '<a class="foldername" data-id="' + path[i].parent_id + '">' + path[i].folder_name + '</a>';
- if (i != path.length - 1) {
- str += '<img class="triangle" src="images/triangle.png"/>';
- }
- }
- $("#folder-navigation").append(str);
- }
-
- function paste(param) {
- Util.ajaxRequest({
- url: "pasteDocManage.json",
- params: param,
- async: false,
- afterSuccess: function(json) {
- alert(3);
- var msg = json.returnmsg;
- var success = json.success;
- if (success == false) {
- if (msg == "windows") {
- Tools.alert("请检查windows的文档上传路径配置是否正确!");
- }
- }
- if (success == true) {
-
- }
- return false;
- }
- }, false);
- }
-
- function drag() {
- $("#divall li").each(function(i) {
- //$(".item_content .item").each(function(i) {
- this.init = function() { // 初始化
- this.box = $(this);
- console.log("left: " + this.box.offset().left + " top: " + this.box.offset().top);
- $(this).attr("index", i);
- /*.css({
- position : "absolute",
- left : this.box.offset().left,
- top : this.box.offset().top
- }).appendTo("#divall")*/
- this.drag();
- },
- this.move = function(callback) { // 移动
- $(this).stop(true).animate({
- left: this.box.offset().left,
- top: this.box.offset().top
- }, 500, function() {
- if (callback) {
- callback.call(this);
- }
- });
- },
- this.collisionCheck = function() {
- var currentItem = this;
- var direction = null;
- $(this).siblings(".item").each(function() {
- if (
- currentItem.pointer.x > this.box.offset().left &&
- currentItem.pointer.y > this.box.offset().top &&
- (currentItem.pointer.x < this.box.offset().left + this.box.width()) &&
- (currentItem.pointer.y < this.box.offset().top + this.box.height())
- ) {
- // 返回对象和方向
- if (currentItem.box.offset().top < this.box.offset().top) {
- direction = "down";
- } else if (currentItem.box.offset().top > this.box.offset().top) {
- direction = "up";
- } else {
- direction = "normal";
- }
- this.swap(currentItem, direction);
- }
- });
- },
- this.swap = function(currentItem, direction) { // 交换位置
- if (this.moveing) return false;
- var directions = {
- normal: function() {
- var saveBox = this.box;
- this.box = currentItem.box;
- currentItem.box = saveBox;
- this.move();
- $(this).attr("index", this.box.index());
- $(currentItem).attr("index", currentItem.box.index());
- },
- down: function() {
- // 移到上方
- var box = this.box;
- var node = this;
- var startIndex = currentItem.box.index();
- var endIndex = node.box.index();;
- for (var i = endIndex; i > startIndex; i--) {
- var prevNode = $(".item_container .item[index=" + (i - 1) + "]")[0];
- node.box = prevNode.box;
- $(node).attr("index", node.box.index());
- node.move();
- node = prevNode;
- }
- currentItem.box = box;
- $(currentItem).attr("index", box.index());
- },
- up: function() {
- // 移到上方
- var box = this.box;
- var node = this;
- var startIndex = node.box.index();
- var endIndex = currentItem.box.index();;
- for (var i = startIndex; i < endIndex; i++) {
- var nextNode = $(".item_container .item[index=" + (i + 1) + "]")[0];
- node.box = nextNode.box;
- $(node).attr("index", node.box.index());
- node.move();
- node = nextNode;
- }
- currentItem.box = box;
- $(currentItem).attr("index", box.index());
- }
- };
- directions[direction].call(this);
- },
- this.drag = function() { // 拖拽
- var oldPosition = new Position();
- var oldPointer = new Pointer();
- var isDrag = false;
- var currentItem = null;
- $(this).mousedown(function(e) {
- e.preventDefault();
- oldPosition.left = this.box.offset().left;
-
- oldPosition.top = this.box.offset().top;
- console.log("oldleft" + oldPosition.left + "oldtop" + oldPosition.top);
- oldPointer.x = e.clientX;
- oldPointer.y = e.clientY;
- isDrag = true;
-
- currentItem = this;
-
- });
- /*$(document).mousemove(function(e) {
- var currentPointer = new Pointer(e.clientX, e.clientY) ;
- if(!isDrag) return false ;
- $(currentItem).css({
- "opacity" : "0.8",
- "z-index" : 999
- }) ;
- var left = currentPointer.x - oldPointer.x + oldPosition.left ;
- var top = currentPointer.y - oldPointer.y + oldPosition.top ;
- $(currentItem).css({
- left : left,
- top : top
- }) ;
- currentItem.pointer = currentPointer ;
- // 开始交换位置
-
- //currentItem.collisionCheck() ;
-
-
- }) ;
- $(document).mouseup(function() {
- if(!isDrag) return false ;
- isDrag = false ;
- currentItem.move(function() {
- $(this).css({
- "opacity" : "1",
- "z-index" : 0
- }) ;
- }) ;
- }) ;*/
- };
- this.init();
- });
- }
-
- function leftClick() {
- //点击文件夹
- $("#divall li").click(function(event) {
- var $this = $(this),
- folder_name = $this.children("input.changename"),
- index = $this.attr("index");
- if (is_ctrl_down == true && is_shift_down == false) { //按下ctrl
- event.stopPropagation();
- focus_index = index;
- $("#divall").find("li").each(function(index) {
- $(this).children("input.changename").attr("disabled", "disabled");
- });
- if ($this.hasClass("focus")) {
- $this.removeClass("focus");
- } else {
- $this.addClass("focus");
- }
- info(3, 0);
- } else if (is_ctrl_down == false && is_shift_down == true) { //按下shift
- event.stopPropagation();
- if (focus_index == -1) {
- focus_index = index;
- $this.addClass("focus");
- } else {
- var index_min = Math.min(index, focus_index),
- index_max = Math.max(index, focus_index);
- $("#divall").find("li").each(function(i) {
- var i_index = $(this).attr("index");
- $(this).removeClass("focus");
- $(this).children("input.changename").attr("disabled", "disabled");
- if (i_index >= index_min && i_index <= index_max) {
- $(this).addClass("focus");
- }
- });
- }
- info(3, 0);
- } else {
- event.stopPropagation();
- $("#divall").find("li").each(function(index) {
- $(this).removeClass("focus");
- $(this).children("input.changename").attr("disabled", "disabled");
- });
- $this.addClass("focus");
- focus_index = index;
- clearTimeout(timeOutFn);
- timeOutFn = setTimeout(function() {
- folder_name.removeAttr("disabled");
- info(2, folder_name.attr("data-id"));
- }, 300);
- }
-
- });
- //点击文件名称
- /*$("#divall li input.changename").click(function(event) {
- if (is_ctrl_down == false) { //没有按下ctrl
- event.stopPropagation();
- console.log("input click");
- }
-
- });*/
- //点击空白的地方
- $("#all_folder").click(function() {
- console.log("blank click");
- $("#divall").find("li").each(function(index) {
- $(this).removeClass("focus");
- $(this).children("input.changename").attr("disabled", "disabled");
- });
- info(1, 0);
- });
- //点击后退按钮
- $("button.backward").off("click").click(function() {
- console.log("backward click");
- var currNode = find_active_node();
- if (currNode.previous.previous != null) {
- var preNode = currNode.previous,
- parent_id = preNode.element.parent_id;
- init(parent_id, 7);
- }
- });
- //点击前进按钮
- $("button.forward").off("click").click(function() {
- console.log("forward click");
- var currNode = find_active_node();
- if (currNode.next != null) {
- var nextNode = currNode.next,
- parent_id = nextNode.element.parent_id;
- init(parent_id, 8);
- }
- });
- //点击主页按钮
- $("button.home").off("click").click(function() {
- console.log("home click");
- if ($("#navigation").val() != 1) {
- init(1, 9);
- }
- });
- //点击返回上级目录
- $("button.gotopre").off("click").click(function() {
- console.log("gotopre click");
- if ($("#navigation").val() != 1) {
- //查询上级目录的parent_id
- var rows = select("M8610EQ005",{"id": $("#navigation").val()});
- if(rows.length > 0){
- var parent_id = rows[0].parent_id;
- if (parent_id != 0) {
- init(parent_id, 10);
- }
- }
- }
- });
- //点击地址栏地址
- $("a.foldername").off("click").click(function() {
- var parent_id = $(this).attr("data-id");
- if ($("#navigation").val() != parent_id) {
- init(parent_id, 11);
- }
- });
- }
-
- function focus() {
- $("#divall li input.changename").focus(function() {
- console.log("input focus");
- });
-
- $("#divall li").focus(function() {
- console.log("li focus");
- });
- }
-
- function blur() {
- $("#divall li").blur(function() {
- console.log("li blur");
- });
-
- $("#divall li input.changename").blur(function() {
- console.log("input blur");
- $(this).attr("disabled", "disabled");
- });
-
- }
-
- function change() {
- $("#divall li input.changename").change(function() {
- console.log("input change");
- var folder = $(this).parent("li"),
- data_last_value = $(this).attr("data-last-value"),
- folder_name = $(this).val(),
- id = $(this).attr("data-id"),
- is_directory = folder.hasClass("folder") ? 1 : 0,
- doc_type = folder.hasClass("folder") ? "" : $(this).attr("data-filetype"),
- parent_id = $("#navigation").val(),
- params = {
- "folder_name": folder_name,
- "id": id,
- "is_directory": is_directory,
- "doc_type": doc_type,
- "parent_id": parent_id,
- "description": ""
- };
- if (update_folder_name(params)) {
- $(this).attr("data-last-value", folder_name);
- info(2, $(this).attr("data-id"));
- } else {
- $(this).val(data_last_value);
- }
- });
- }
-
- function dbclick() {
- /* $("#divall li.folder").dblclick(function() {
- clearTimeout(timeOutFn);
- console.log("li dblclick");
- var folder = $(this).children("input.changename");
- init(folder.attr("data-id"), 6);
- });*/
- }
-
- function keydown() {
- $(document).keydown(function(event) {
- if (event.which == '17') {
- is_ctrl_down = true;
- } else if (event.which == '16') {
- is_shift_down = true;
- }
- });
- }
-
- function keyup() {
- $(document).keyup(function(event) {
- if (event.which == '17') {
- is_ctrl_down = false;
- } else if (event.which == '16') {
- is_shift_down = false;
- }
- });
- }
-
- //新增目录
- var add_folder = function(params) {
- var flag = false;
- if (!testFolderName(params.folder_name)) {
- Tools.alert("文件夹名不能包括\\\/:*?\"<>|等特殊符号");
- return flag;
- }
- if (judgeDocExist(params.id, params.folder_name)) {
- Tools.alert("该目录已存在,不能添加");
- return flag;
- }
- var param = {
- description: params.description,
- folder_name: params.folder_name,
- is_directory: 1,
- parent_id: params.id,
- port_level: 1,
- username: "semitree",
- date: new Date().Format("yyyyMMdd"),
- time: new Date().Format("hhmmss")
- };
- insert("M8610ES001",param);
- return true;
- };
- //修改文件名称
- var update_folder_name = function(params) {
- var folder_name = "",
- flag = false;
- if (params.is_directory == 1) {
- folder_name = params.folder_name;
- } else {
- folder_name = params.folder_name + '.' + params.doc_type;
- }
- if (!testFolderName(params.folder_name)) {
- Tools.alert("文件名不能包括\\\/:*?\"<>|等特殊符号");
- return flag;
- }
- if (judgeDocUpdate(params.id, folder_name)) {
- Tools.alert("该目录/文档已存在,请重新输入!");
- return flag;
- }
- var current_date = new Date(),
- date = current_date.Format("yyyyMMdd"),
- time = current_date.Format("hhmmss");
- update("M8610EU001",{"description":params.description,
- "folder_name":params.folder_name,
- "username":"semitree",
- "date":date,
- "time":time,
- "id":params.id
- });
- flag = true;
- // K.popup.close($("#M8610P001"));
- //修改文件名
- $("#divall").find("input[data-id=" + params.id + "]").val(params.folder_name);
- return flag;
- };
-
- //上传文档
- var uploadFile = function(params) {
- var $need_appendix = $('#M8610F002').find('input[name=need_appendix]'),
- fileList = $need_appendix.get(0).files,
- fileNameWithSuffixList = [],
- fileNameList = [];
-
- $.each(fileList,function(index,file){
- var name = file.name;
- fileNameWithSuffixList.push(name);
- fileNameList.push(name.substring(0, name.lastIndexOf('.')));
- });
- if(fileNameWithSuffixList.length == 0){
- $.pt({
- target: $need_appendix,
- position: 'r',
- align: 't',
- width: 'auto',
- height: 'auto',
- content:"请先选择文件"
- });
- return;
- }else{
- $.each(fileNameList,function(index,fileName){
- //文件名真实长度不能超过100
- var blen = 0;
- for (var i = 0; i < fileName.length; i++) {
- if ((fileName.charCodeAt(i) & 0xff00) != 0) {
- blen++;
- }
- blen++;
- }
- if (blen > 100) {
- $.pt({
- target: $need_appendix,
- position: 'r',
- align: 't',
- width: 'auto',
- height: 'auto',
- content:"文件名过长!(支持50个中文或100个英文)"
- });
- console.log("文件名过长!(支持50个中文或100个英文)");
- return false;
- }
- });
- $.each(fileNameWithSuffixList,function(index,docName){
- var param = {
- description: "",
- folder_name: docName,
- is_directory: 0,
- parent_id: params.id,
- port_level: 1,
- username: "semitree",
- date: new Date().Format("yyyyMMdd"),
- time: new Date().Format("hhmmss")
- };
- insert("M8610ES001",param);
- });
- }
- init($("#navigation").val(), 1);
- K.popup.close($("#M8610P002"));
- return true;
- };
-
- var dele = function(params) {
- //查询该目录下是否存在子目录/文档
- var rows = select("M8610EQ004",{"id":params.id}),
- desc = rows.length > 0 ? "删除整个文件夹(包含所有子目录和子文档)?" : "确认删除?";
- Tools.confirm(desc, function(ok) {
- if (ok) {
- deleteDoc(params);
- init($("#navigation").val(), 2);
- }
- });
- };
-
- //删除文档或目录
- var deleteDoc = function(params) {
- var is_directory = params.is_directory,
- id = params.id;
- if(is_directory == 0){//删除单个文件
- del("M8610ED001",{"id":id});
- }else{//删除文件夹
- //递归删除文件夹下所有的子文件和文件夹
- var rows = select("M8610EQ006",{"id":id});
- if(rows.length > 0){
- for(var i = 0; i < rows.length; i++){
- deleteDoc(rows[i]);
- }
- }
- del("M8610ED001",{"id":id});
- }
- };
-
- //打包下载文件夹或文件
- var download = function(params) {
- var $M8610F003 = $("#M8610F003");
- K.form.reset($M8610F003);
- K.field.value($('#_id'), params.id);
- K.field.value($('#p_id'), params.parent_id);
- K.field.value($('#f_name'), params.folder_name);
- K.field.value($('#i_directory'), params.is_directory);
- if (params.is_directory == 1) {
- Tools.confirm("是否打包下载整个文件夹?(可能需要较长时间,请耐心等待)", function(ok) {
- if (ok) {
- //判断所下载的目录是否为空
- Util.ajaxRequest({
- url: "directoryIsNull.json",
- params: params,
- async: false,
- afterSuccess: function(json) {
- var msg = json.returnmsg;
- if (msg == "目录为空") {
- Tools.alert("请不要下载空目录");
- }
- if (msg == "目录不为空") {
- K.submit($('#M8610F003'), null, true);
- }
- return false;
- }
- }, false);
- }
- });
- } else {
- K.submit($('#M8610F003'), null, true);
- }
- };
-
- var testFolderName = function(folderName) {
- var reg = new RegExp('^[^\\\\\\/:*?\\"<>|]+$');
- return reg.test(folderName);
- };
-
- //同一父目录下不能有同名目录或同名文档
- function judgeDocUpdate(id, name) {
- var pd = false;
- /*var rows = select("M8610EQ002",{"id":id,"folder_name":name});
- if(rows.length > 0){
- if (rows[0].count > 0) {
- pd = true;
- } else {
- pd = false;
- }
- }*/
- return pd;
- };
-
- //新增目录、上传文档时校验同目录下是否有同名目录/文档
- function judgeDocExist(id, folder_name) {
- var pd = false;
- /*var rows = select("M8610EQ003",{"id":id,"folder_name":folder_name});
- if(rows.length > 0){
- if (rows[0].count > 0) {
- pd = true;
- } else {
- pd = false;
- }
- }*/
- return pd;
- }
-
- //选择文件时动态加载信息框
- function select_file(ele){
- var $this = $(ele),
- fileList = $this.get(0).files,
- fileNameList = [],
- fieldsetNameList = [];
- //获取所有选择文件的文件名
- for(var i = 0; i < fileList.length; i++){
- fileNameList.push(fileList[i].name);
- }
- //获取所有已有的图片fieldset名
- $("#M8610F002").children("fieldset.picture-fieldset").each(function(){
- var $this = $(this),
- $legend = $this.children("legend"),
- legend_name = $legend.text();
- fieldsetNameList.push(legend_name);
- });
- for(var index in fieldsetNameList){
- if($.inArray(fieldsetNameList[index],fileNameList) == -1){
- $("#M8610F002").find("legend.picture-legend:contains("+fieldsetNameList[index]+")").parent().remove();
- }
- }
- var first = true;
- $.each(fileNameList,function(index,fileName){
- if($.inArray(fileName,fieldsetNameList) == -1){
-
- //添加一个对应的fieldset
- var html = "",checked = "";
- if(first){
- checked = "checked";
- }
- html += '<fieldset class="single-fieldset picture-fieldset">'+
- '<legend class="picture-legend">'+fileName+'</legend>'+
- '<input class="hide" name="picture_name" value="'+fileName+'">'+
- '<div>'+
- '<label class="my-label">标题:</label>'+
- '<input class="my-input" type="text" name="picture_title" placeholder="请输入图片标题" maxlength="16"/>'+
- '<input type="radio" '+checked+' name="cover" value="'+fileName+'">设为封面'+
- '</div><div>'+
- '<label class="my-textarea-label">描述:</label>'+
- '<textarea class="my-textarea" name="picture_desc" placeholder="请输入图片描述" maxlength="100"></textarea>'+
- '</div></fieldset>';
- $("#M8610F002").append(html);
- textarea_bind();
- first = false;
- }
- });
- //K.init($("#M8610F002"));
- }
-
- function textarea_bind(){
- $("#M8610F002").find("textarea").each(function(index){
- $(this).unbind('input').bind('input',function(){
- var self =this,
- maxLength = parseInt($(this).attr("maxlength")),
- curLength = $(this).val().length,
- span_html = "";
- span_html += '<span><var class="word">'+(maxLength-curLength)+'</var>/'+maxLength+'</span>';
- console.log(span_html);
- $.pt({
- target: self,
- position: 'r',
- align: 't',
- width: 'auto',
- height: 'auto',
- content:span_html
- });
- });
- });
- }
-
- /*
- * 定义拖动类
- */
- function Pointer(x, y) {
- this.x = x;
- this.y = y;
- }
-
- function Position(left, top) {
- this.left = left;
- this.top = top;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。