<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" trimDirectiveWhitespaces="true" %>
|
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
|
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
|
<%
|
String path = request.getContextPath();
|
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
|
+ path + "/";
|
%>
|
|
<!DOCTYPE HTML>
|
<html>
|
<head>
|
<base href="<%=basePath%>">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
<title>附件管理</title>
|
<link href="static/plugins/font-awesome/css/font-awesome.css" rel="stylesheet" type="text/css">
|
<link href="static/plugins/jquery-easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css">
|
<link rel="stylesheet" href="static/styles/material-teal.css" type="text/css">
|
<link rel="stylesheet" href="static/styles/initialize.css" type="text/css">
|
<link rel="stylesheet" href="static/styles/common.css" type="text/css">
|
<link rel="stylesheet" href="static/plugins/layer/skin/default/layer.css" type="text/css">
|
<link rel="stylesheet" href="static/plugins/webuploader/webuploader.css" type="text/css">
|
|
<script type="text/javascript" src="static/plugins/jquery/jquery.min.js"></script>
|
<script type="text/javascript" src="static/plugins/jquery-easyui/jquery.easyui.min.js"></script>
|
<script type="text/javascript" src="static/plugins/jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
|
<script type="text/javascript" src="static/plugins/slimScroll/jquery.slimscroll.min.js"></script>
|
<script type="text/javascript" src="static/plugins/layer/layer.js"></script>
|
|
<script type="text/javascript" src="static/plugins/spinjs/spin.js"></script>
|
<script type="text/javascript" src="static/plugins/spinjs/jquery.spin.js"></script>
|
<script type="text/javascript" src="static/plugins/jquery.blockUI.js"></script>
|
|
<script type="text/javascript" src="static/plugins/webuploader/webuploader.js"></script>
|
<script src="static/plugins/webuploader/webuploader.min.js"></script>
|
<script src="static/plugins/ptfileupload/pt.fileupload.js"></script>
|
|
<script type="text/javascript" src="static/wcp/scripts/wcp.js"></script>
|
<script type="text/javascript" src="static/wcp/scripts/libs/wcp.layer.js"></script>
|
<script type="text/javascript" src="static/wcp/scripts/libs/wcp.blockUI.js"></script>
|
<script type="text/javascript" src="static/wcp/scripts/libs/wcp.spin.js"></script>
|
<script type="text/javascript" src="static/wcp/scripts/libs/wcp.jquery.js"></script>
|
|
<!--[if lt IE 9]>
|
<script type="text/javascript" src="static/plugins/json2.js"></script>
|
<![endif]-->
|
<script type="text/javascript" src="static/wcp/scripts/libs/wcp.infoPicker.js"></script>
|
<style>
|
html, body {
|
height: 100%;
|
width: 100%;
|
overflow: hidden;
|
}
|
|
/*------------------------------- 上传按钮样式 --------------------------------*/
|
.webuploader-pick {
|
font-size: 12px;
|
line-height: 1.5;
|
padding: 5px 10px;
|
border-color: #00acd6;
|
}
|
|
.webuploader-pick .fa {
|
margin-right: 4px;
|
font-size: 13px;
|
}
|
</style>
|
</head>
|
|
<div>
|
<div class="pt-main-top clear" style="padding: 5px;">
|
<div class="pt-box-tools pt-box-tools-xs" style="float:none;">
|
<c:if test="${isSave}">
|
<c:if test="${module.enableAttachBody}">
|
<div id="pickerAttachBody"
|
style="display: inline-block;line-height: 1;vertical-align: middle;margin: 2px 4px 0 0;">
|
<i class="fa fa-cloud-upload"></i>
|
<c:if test="${module.uploadBodyOtherName!=null&&!''.equals(module.uploadBodyOtherName)}">${module.uploadBodyOtherName}</c:if>
|
<c:if test="${module.uploadBodyOtherName==null||''.equals(module.uploadBodyOtherName)}">上传正文</c:if>
|
</div>
|
</c:if>
|
<c:if test="${module.enableAttachOrigin}">
|
<div id="pickerAttachOrigin"
|
style="display: inline-block;line-height: 1;vertical-align: middle;margin: 2px 4px 0 0;">
|
<i class="fa fa-cloud-upload"></i>
|
<c:if test="${module.uploadOriginOtherName!=null&&!''.equals(module.uploadOriginOtherName)}">${module.uploadOriginOtherName}</c:if>
|
<c:if test="${module.uploadOriginOtherName==null||''.equals(module.uploadOriginOtherName)}">上传源件</c:if>
|
</div>
|
</c:if>
|
<c:if test="${module.enableAttach}">
|
<div id="pickerAttach"
|
style="display: inline-block;line-height: 1;vertical-align: middle;margin: 2px 4px 0 0;">
|
<i class="fa fa-cloud-upload"></i>
|
<c:if test="${module.uploadAttachOtherName!=null&&!''.equals(module.uploadAttachOtherName)}">${module.uploadAttachOtherName}</c:if>
|
<c:if test="${module.uploadAttachOtherName==null||''.equals(module.uploadAttachOtherName)}">上传附件</c:if>
|
</div>
|
</c:if>
|
</c:if>
|
|
<button id="btnBatchDownload" class="pt-btn pt-btn-primary">
|
<i class="fa fa-download"></i>批量下载
|
</button>
|
|
<c:if test="${keyId != null && keyId != 0 && isSave}">
|
<button id="btnToPdfAndOfd" class="pt-btn pt-btn-primary">
|
<i class="fa fa-file-pdf-o"></i>转PDF
|
</button>
|
<button id="btnPdfSign" class="pt-btn pt-btn-primary">
|
<i class="fa fa-sign-in"></i>PDF签名
|
</button>
|
</c:if>
|
</div>
|
</div>
|
<div class="pt-form-inline" style="margin:0px 5px;">
|
<div id="right">
|
<div>
|
<table id="dg_attachlist" style="width:100%;">
|
</table>
|
</div>
|
</div>
|
</div>
|
</div>
|
</body>
|
<script type="text/javascript" src="static/scripts/ResizeScroll.js"></script>
|
<script type="text/javascript">
|
var moduleId = "${module.moduleId}";
|
var tableId = "${tableId}";
|
var keyId = "${keyId}";
|
var attachCount = 0;//附件数量
|
var mainAttachCount = 0;//正文数量
|
var attachOriginCount = 0;//源文件数量
|
var fileUpload = null;
|
var fileUploadBody = null;
|
var fileUploadOrigin = null;
|
var wh = $(window).height();
|
|
$(function () {
|
initAttachDataGrid();
|
initUploader();
|
initBtnEvent();
|
|
if (window.parent) {
|
window.parent.addAttachFun = addAttach;
|
window.parent.getMainBodyFun = getMainBody;
|
window.parent.getAttachListFun = getAttachList;
|
window.parent.getModifyAttachListFun = getModifyAttachList;
|
window.parent.refreshAttachListFun = refreshData;
|
}
|
});
|
|
function initBtnEvent() {
|
$("#btnBatchDownload").click(function () {
|
fileBatchDownload();
|
});
|
|
$("#btnToPdfAndOfd").click(function () {
|
fileToPdfAndOfd();
|
|
});
|
|
$("#btnPdfSign").click(function () {
|
pdfSign();
|
});
|
}
|
|
function initAttachDataGrid() {
|
//初始化表格
|
$('#dg_attachlist').datagrid({
|
url: "general/getAttachList?moduleId=" + moduleId + "&keyId=" + keyId,
|
fitColumns: true,
|
striped: true,
|
idField: "attachId",
|
height: 300,
|
rownumbers: true,
|
pagination: false,
|
checkOnSelect: false,
|
selectOnCheck: false,
|
singleSelect: true,
|
remoteSort: false,
|
columns: [[
|
{
|
field: 'ck',
|
checkbox: true,
|
align: 'center'
|
},
|
{
|
field: 'attachType',
|
title: '附件类型',
|
align: 'center',
|
width: 50,
|
formatter: function (value, row, index) {
|
var ret = "附件";
|
if (value == 0) {
|
ret = "附件";
|
} else if (value == 1) {
|
ret = "正文";
|
} else if (value == 2) {
|
ret = "源件";
|
}
|
return ret;
|
}
|
},
|
{
|
field: 'mainAttach',
|
title: '是否为主件',
|
width: 50,
|
align: 'center',
|
hidden: true,
|
formatter: function (value, row, index) {
|
var ret = "否";
|
if (value) {
|
ret = "是";
|
}
|
|
return ret;
|
}
|
},
|
{
|
field: 'physicalName',
|
title: '附件名',
|
width: 200,
|
align: 'left',
|
halign: 'center'
|
},
|
{
|
field: 'createUserName',
|
title: '上传人',
|
width: 100,
|
align: 'center',
|
},
|
{
|
field: 'createDate',
|
title: '上传时间',
|
width: 100,
|
align: 'center'
|
},
|
{
|
field: 'fileSize',
|
title: '大小(KB)',
|
width: 100,
|
align: 'center',
|
formatter: function (value, row, index) {
|
var ret = value / 1024;
|
return ret.toFixed(2);
|
}
|
},
|
{
|
field: 'extension',
|
title: '格式',
|
width: 50,
|
align: 'center',
|
formatter: function (value, row, index) {
|
var ret = '<img src="static/styles/images/' + getImg(value.toLowerCase()) + '" style="width:20px;height:20px;">';
|
return ret;
|
}
|
},
|
{
|
field: 'attachId',
|
title: '操作',
|
width: 100,
|
align: 'center',
|
formatter: function (value, row, index) {
|
var attachViewUrl = row.attachViewUrl.replace(/\\/g, "\\\\");
|
var attachId = row.attachId ? row.attachId : "0";
|
var attachType = row.attachType;
|
var mainAttach = row.mainAttach;
|
var extension = row.extension.toLowerCase();
|
var uploadName = row.uploadName;
|
var ret = "";
|
if (attachId.indexOf('WU_FILE') > -1) {
|
ret = "<li id='" + attachId + "'>"
|
+ "<div class=\"pt-process-bar\"><div class=\"bar\"><div class=\"subbar\"></div></div><span class=\"state\">等待上传...</span></div></li>";
|
} else {
|
if (mainAttach == false) {
|
ret += "<a onclick=\"setMainFile('" + attachId + "');\" class='pt-color-success' style='cursor:pointer'><i class='fa fa-check-square-o' title='设为主件'></i>设为主件</a> ";
|
}
|
ret += "<a onclick=\"viewFile('" + attachId + "','" + attachViewUrl + "');\" class='pt-color-success' style='cursor:pointer'><i class='fa fa-eye' title='浏览'></i>浏览</a> ";
|
if (extension == ".doc" || extension == ".docx" || extension == ".xls" || extension == ".xlsx") {
|
ret += "<a onclick=\"editFile('" + attachId + "','" + attachViewUrl + "');\" class='pt-color-success' style='cursor:pointer'><i class='fa fa-edit' title='编辑'></i>编辑</a> ";
|
}
|
<c:if test="${isSave}">
|
ret += "<a onclick=\"removeFile('" + attachId + "','" + uploadName + "'," + attachType + ");\" class='pt-color-danger' style='cursor:pointer'><i class='fa fa-trash-o' title='删除'></i>删除</a> ";
|
</c:if>
|
ret += "<a class=\"pt-color-primary\" onclick=\"downLoadFile('" + attachId + "')\"><i class=\"fa fa-download\" title=\"下载\"></i>下载</a></div>";
|
}
|
return ret;
|
}
|
}
|
]],
|
rowStyler: function (index, row) {
|
if (row.mainAttach == true) {
|
return 'background-color:#FFF8DC;'
|
}
|
}
|
});
|
}
|
|
function initUploader() {
|
<c:if test="${module.enableAttachBody}">
|
//上传正文
|
fileUploadBody = new FileUpload({
|
auto: true,
|
serverPath: 'general/uploadFile?moduleId=${module.moduleId}&tableId=${tableId}&keyId=' + keyId + '&attachType=1',
|
pick: {
|
id: "#pickerAttachBody", //指定选择文件的按钮容器,不指定则不创建按钮。id {Seletor|dom} 指定选择文件的按钮容器,不指定则不创建按钮。
|
//注意 这里虽然写的是 id, 但是不是只支持 id, 还支持 class, 或者 dom 节点。
|
innerHTML: "" //指定按钮文字。不指定时优先从指定的容器中看是否自带文字。
|
},
|
uploadSuccess: function (file, response) {
|
//如果上传出错,则删除附件,并提示
|
if (!response.success) {
|
var rowIndex = -1;
|
for (var i = 0; i < data.length; i++) {
|
if (data[i]["attachId"] == file.id) {
|
rowIndex = i;
|
break;
|
}
|
}
|
$('#dg_attachlist').datagrid('deleteRow', rowIndex);
|
|
wcp.message.error(response.error.message);
|
|
return;
|
}
|
|
mainAttachCount++;
|
$('#' + file.id).find('.pt-process-bar').fadeOut();
|
$('#' + file.id).find('span.state').text('已上传');
|
var data = $('#dg_attachlist').datagrid('getRows');
|
for (var i = 0; i < data.length; i++) {
|
if (data[i]["attachId"] == file.id) {
|
$('#dg_attachlist').datagrid("deleteRow", i);
|
}
|
}
|
|
addAttach(response.result);
|
},
|
beforeAddQueue: function (file) {
|
//判断文件是否重名
|
var data = $('#dg_attachlist').datagrid('getRows');
|
for (var i = 0; i < data.length; i++) {
|
if (data[i]["physicalName"] == file.name) {
|
wcp.message.error("已存在相同名称的附件,请检查后再上传!");
|
return false;
|
}
|
}
|
|
//判断是否存在上传前函数,若存在则执行
|
try {
|
if (typeof beforeUploadMainFile === "function") {
|
var result = eval("beforeUploadMainFile('" + file.name + "')");
|
if (result == false) {
|
return result;
|
}
|
}
|
} catch (e) {
|
}
|
},
|
fileQueued: function (file) {
|
$('#dg_attachlist').datagrid('appendRow', {
|
physicalName: file.name,
|
fileSize: file.size,
|
extension: file.ext,
|
attachUrl: '',
|
attachViewUrl: '',
|
attachType: 1,
|
attachId: file.id
|
});
|
},
|
uploadProgress: function (file, percentage) {
|
|
},
|
uploadError: function (file, reason) {
|
|
},
|
uploadComplete: function (file) {
|
|
}
|
});
|
</c:if>
|
<c:if test="${module.enableAttachOrigin}">
|
//上传源件
|
fileUploadOrigin = new FileUpload({
|
auto: true,
|
serverPath: 'general/uploadFile?moduleId=${module.moduleId}&tableId=${tableId}&keyId=' + keyId + '&attachType=2',
|
pick: {
|
id: "#pickerAttachOrigin", //指定选择文件的按钮容器,不指定则不创建按钮。id {Seletor|dom} 指定选择文件的按钮容器,不指定则不创建按钮。
|
//注意 这里虽然写的是 id, 但是不是只支持 id, 还支持 class, 或者 dom 节点。
|
innerHTML: "" //指定按钮文字。不指定时优先从指定的容器中看是否自带文字。
|
},
|
<c:if test="${module.attachOriginSizeLimit!=null&&module.attachOriginSizeLimit>0}">
|
fileSingleSizeLimit: (${module.attachOriginSizeLimit}) * (1024 * 1024),
|
</c:if>
|
<c:if test="${module.attachOriginSizeLimit==null||module.attachOriginSizeLimit<0}">
|
fileSingleSizeLimit: 0,//0代表不限制
|
</c:if>
|
<c:if test="${module.attachOriginFormatLimit!=null}">
|
accept: {
|
title: 'Files',
|
extensions: '${module.attachOriginFormatLimit.replace(".", "")}',
|
mimeTypes: '${module.attachOriginFormatLimit}'
|
},
|
</c:if>
|
uploadSuccess: function (file, response) {
|
//如果上传出错,则删除附件,并提示
|
if (!response.success) {
|
var rowIndex = -1;
|
for (var i = 0; i < data.length; i++) {
|
if (data[i]["attachId"] == file.id) {
|
rowIndex = i;
|
break;
|
}
|
}
|
$('#dg_attachlist').datagrid('deleteRow', rowIndex);
|
|
wcp.message.error(response.error.message);
|
|
return;
|
}
|
|
attachOriginCount++;
|
$('#' + file.id).find('.pt-process-bar').fadeOut();
|
$('#' + file.id).find('span.state').text('已上传');
|
var data = $('#dg_attachlist').datagrid('getRows');
|
for (var i = 0; i < data.length; i++) {
|
if (data[i]["attachId"] == file.id) {
|
$('#dg_attachlist').datagrid("deleteRow", i);
|
}
|
}
|
|
addAttach(response.result);
|
},
|
beforeAddQueue: function (file) {
|
//判断文件是否重名
|
var data = $('#dg_attachlist').datagrid('getRows');
|
for (var i = 0; i < data.length; i++) {
|
if (data[i]["physicalName"] == file.name) {
|
wcp.message.error("已存在相同名称的附件,请检查后再上传!");
|
return false;
|
}
|
}
|
|
//判断是否存在上传前函数,若存在则执行
|
try {
|
if (typeof beforeUploadMainFile === "function") {
|
var result = eval("beforeUploadOriginFile('" + file.name + "')");
|
if (result == false) {
|
return result;
|
}
|
}
|
} catch (e) {
|
}
|
},
|
fileQueued: function (file) {
|
$('#dg_attachlist').datagrid('appendRow', {
|
physicalName: file.name,
|
fileSize: file.size,
|
extension: file.ext,
|
attachUrl: '',
|
attachViewUrl: '',
|
attachType: 2,
|
attachId: file.id
|
});
|
},
|
uploadProgress: function (file, percentage) {
|
|
},
|
uploadError: function (file, reason) {
|
|
},
|
//捕捉加入队列前的错误
|
uploadBeforeError: function (type) {
|
if (type == "Q_TYPE_DENIED") {
|
wcp.notify.error('请上传${module.attachOriginFormatLimit}格式文件!');
|
} else if (type == "Q_EXCEED_SIZE_LIMIT") {
|
wcp.notify.error('文件总大小不能超过10M!');
|
} else if (type == "F_EXCEED_SIZE") {
|
wcp.notify.error('单个文件大小不能超过${module.attachOriginSizeLimit}M!');
|
} else {
|
wcp.notify.error("上传出错!请检查后重新上传!错误代码" + type);
|
}
|
},
|
uploadComplete: function (file) {
|
|
}
|
});
|
</c:if>
|
<c:if test="${module.enableAttach}">
|
//上传附件
|
fileUpload = new FileUpload({
|
auto: true,
|
serverPath: 'general/uploadFile?moduleId=${module.moduleId}&tableId=${tableId}&keyId=' + keyId + '&attachType=0',
|
pick: {
|
id: "#pickerAttach", //指定选择文件的按钮容器,不指定则不创建按钮。id {Seletor|dom} 指定选择文件的按钮容器,不指定则不创建按钮。
|
//注意 这里虽然写的是 id, 但是不是只支持 id, 还支持 class, 或者 dom 节点。
|
innerHTML: "" //指定按钮文字。不指定时优先从指定的容器中看是否自带文字。
|
},
|
<c:if test="${module.attachSizeLimit!=null&&module.attachSizeLimit>0}">
|
fileSingleSizeLimit: (${module.attachSizeLimit}) * (1024 * 1024),
|
</c:if>
|
<c:if test="${module.attachSizeLimit==null||module.attachSizeLimit<0}">
|
fileSingleSizeLimit: 0,//0代表不限制
|
</c:if>
|
<c:if test="${module.attachFormatLimit!=null}">
|
accept: {
|
title: 'Files',
|
extensions: '${module.attachFormatLimit.replace(".", "")}',
|
mimeTypes: '${module.attachFormatLimit}'
|
},
|
</c:if>
|
uploadSuccess: function (file, response) {
|
//如果上传出错,则删除附件,并提示
|
if (!response.success) {
|
var rowIndex = -1;
|
for (var i = 0; i < data.length; i++) {
|
if (data[i]["attachId"] == file.id) {
|
rowIndex = i;
|
break;
|
}
|
}
|
$('#dg_attachlist').datagrid('deleteRow', rowIndex);
|
|
wcp.message.error(response.error.message);
|
|
return;
|
}
|
|
attachCount++;
|
$('#' + file.id).find('.pt-process-bar').fadeOut();
|
$('#' + file.id).find('span.state').text('已上传');
|
var data = $('#dg_attachlist').datagrid('getRows');
|
for (var i = 0; i < data.length; i++) {
|
if (data[i]["attachId"] == file.id) {
|
$('#dg_attachlist').datagrid("deleteRow", i);
|
}
|
}
|
|
addAttach(response.result);
|
//$('#dg_attachlist').datagrid("appendRow", response.result);
|
},
|
beforeAddQueue: function (file) {
|
//判断文件是否重名
|
var data = $('#dg_attachlist').datagrid('getRows');
|
for (var i = 0; i < data.length; i++) {
|
if (data[i]["physicalName"] == file.name) {
|
wcp.message.error("已存在相同名称的附件,请检查后再上传!");
|
return false;
|
}
|
}
|
|
//判断是否存在上传前函数,若存在则执行
|
try {
|
if (typeof beforeUploadFile === "function") {
|
var result = eval("beforeUploadFile('" + file.name + "')");
|
if (result == false) {
|
return result;
|
}
|
}
|
} catch (e) {
|
}
|
},
|
fileQueued: function (file) {
|
$('#dg_attachlist').datagrid('appendRow', {
|
physicalName: file.name,
|
fileSize: file.size,
|
extension: file.ext,
|
attachUrl: '',
|
attachViewUrl: '',
|
attachType: 0,
|
attachId: file.id
|
});
|
},
|
uploadProgress: function (file, percentage) {
|
|
},
|
uploadError: function (file, reason) {
|
|
},
|
//捕捉加入队列前的错误
|
uploadBeforeError: function (type) {
|
if (type == "Q_TYPE_DENIED") {
|
wcp.notify.error('请上传${module.attachFormatLimit}格式文件!');
|
} else if (type == "Q_EXCEED_SIZE_LIMIT") {
|
wcp.notify.error('文件总大小不能超过10M!');
|
} else if (type == "F_EXCEED_SIZE") {
|
wcp.notify.error('单个文件大小不能超过${module.attachSizeLimit}M!');
|
} else {
|
wcp.notify.error("上传出错!请检查后重新上传!错误代码" + type);
|
}
|
},
|
uploadComplete: function (file) {
|
|
}
|
});
|
</c:if>
|
}
|
|
//添加附件
|
function addAttach(attach) {
|
//判断是否第1个附件,如果是第1个附件就设置为主件
|
var rows = $('#dg_attachlist').datagrid("getRows");
|
if (rows.length == 0) {
|
attach.mainAttach = true;
|
} else {
|
//判断附件是否已经存在列表,如果存在,则直接更新
|
if (attach.attachId != 0) {
|
for (var i = 0; i < rows.length; i++) {
|
var row = rows[i];
|
if (attach.attachId == row.attachId) {
|
if (i == 0 && !attach.mainAttach) {
|
attach.mainAttach = true;
|
}
|
$('#dg_attachlist').datagrid("updateRow", {index: i, row: attach});
|
return;
|
}
|
}
|
}
|
}
|
|
$('#dg_attachlist').datagrid("appendRow", attach);
|
}
|
|
/**
|
* 获取正文附件
|
* @returns {null|*}
|
*/
|
function getMainBody() {
|
var rows = $('#dg_attachlist').datagrid("getRows");
|
if (rows.length > 0) {
|
for (var i = 0; i < rows.length; i++) {
|
var row = rows[i];
|
//取主件,而不是取正文
|
if (row.mainAttach === true) {
|
return row;
|
}
|
}
|
}
|
|
return null;
|
}
|
|
//显示图片
|
function getImg(ext) {
|
var ret = "";
|
switch (ext) {
|
case ".docx":
|
case ".doc":
|
ret = "formats-word.png";
|
break;
|
case ".xlsx":
|
case ".xls":
|
ret = "formats-excel.png";
|
break;
|
case ".pptx":
|
case ".ppt":
|
ret = "formats-ppt.png";
|
break;
|
case ".pdf":
|
ret = "formats-pdf.png";
|
break;
|
case ".zip":
|
ret = "formats-zip.png";
|
break;
|
case ".png":
|
case ".jpg":
|
case ".jpeg":
|
case ".bmp":
|
case ".gif":
|
ret = "formats-img.png";
|
break;
|
default:
|
ret = "formats-lcurrency.png";
|
break;
|
}
|
return ret;
|
}
|
|
//设置主件
|
function setMainFile(attachId) {
|
var data = $('#dg_attachlist').datagrid('getRows');
|
for (var i = 0; i < data.length; i++) {
|
var row = Object.assign({}, data[i]);
|
if (data[i]["attachId"] == attachId) {
|
row.mainAttach = true;
|
} else {
|
row.mainAttach = false;
|
}
|
$('#dg_attachlist').datagrid("updateRow", {index: i, row: row});
|
wcp.notify.info("设置主件成功!");
|
}
|
$('#dg_attachlist').datagrid('sort', {
|
sortName: 'mainAttach',
|
sortOrder: 'desc'
|
});
|
}
|
|
//编辑附件
|
function editFile(attachId, attachViewUrl) {
|
|
}
|
|
//浏览附件
|
function viewFile(attachId, attachViewUrl, type) {
|
var url = 'general/viewFile?attachId=' + attachId + '&isEdit=0&attachViewUrl=' + encodeURIComponent(attachViewUrl);
|
//弹出层方式打开
|
if (type == 1) {
|
if (top.addPanel) {
|
top.addPanel(url, "附件浏览" + attachId);
|
} else {
|
window.open(url);
|
}
|
} else {
|
var openUrlWidth = 1000;
|
var openUrlHeight = 600;
|
top.layer.open({
|
title: '附件浏览',
|
type: 2,
|
area: [openUrlWidth + "px", openUrlHeight + "px"],
|
fixed: false,
|
maxmin: true,
|
content: url,
|
success: function (layero, index) {
|
}
|
});
|
}
|
|
}
|
|
//移除附件,临时上传文件暂时未删除
|
function deleteFile(attachId, uploadName, rowIndex) {
|
layer.confirm("确定要删除该附件吗?", {
|
icon: 3,
|
title: '提示'
|
}, function (index) {
|
removeFile(attachId, uploadName, rowIndex);
|
|
layer.close(index);
|
});
|
}
|
|
//移除附件,临时上传文件暂时未删除
|
function removeFile(attachId, uploadName, attachType) {
|
if (attachType == "attachBody") {
|
mainAttachCount--;
|
} else if (attachType == "attachOrigin") {
|
attachOriginCount--;
|
} else {
|
attachCount--;
|
}
|
|
var data = $('#dg_attachlist').datagrid('getRows');
|
var rowIndex = -1;
|
for (var i = 0; i < data.length; i++) {
|
if (data[i]["attachId"] == attachId) {
|
rowIndex = i;// $('#dg_attachlist').datagrid('getRowIndex', row);
|
break;
|
}
|
}
|
$('#dg_attachlist').datagrid('deleteRow', rowIndex);
|
}
|
|
//下载附件
|
function downLoadFile(attachId, attachUrl, physicalName) {
|
//下载服务端附件需先判断是否存在和是否有权限,在表单页面弹出错误提示
|
if (attachId > 0) {
|
$.ajax({
|
type: 'POST',
|
url: "general/beforeDownloadAttach?attachId=" + attachId,
|
async: false,
|
success: function (data) {
|
if (data == "noAuthorize") {
|
wcp.message.error('对不起,您无权限下载此附件!');
|
} else if (data == "noFile") {
|
wcp.message.error('对不起,不存在此附件!');
|
} else {
|
dowloadAttachFunction(attachId, attachUrl, physicalName);
|
}
|
}
|
});
|
} else {
|
dowloadAttachFunction(attachId, attachUrl, physicalName);
|
}
|
}
|
|
function dowloadAttachFunction(attachId, attachUrl, physicalName) {
|
//创建form
|
var url = 'general/downLoadAttach?attachId=' + attachId;
|
var form = document.getElementById('#downLoadForm');
|
if (form == null) {
|
form = $("<form>");
|
form.attr("id", "downLoadForm");
|
form.attr("style", "display:none");
|
form.attr("target", "");
|
form.attr("method", "post");
|
$("body").append(form);
|
}
|
form.attr("action", url);
|
//附件地址
|
var inputAttachUrl = document.getElementById('#iptAttachUrl');
|
if (inputAttachUrl == null) {
|
inputAttachUrl = $("<input>");
|
inputAttachUrl.attr("id", "iptAttachUrl");
|
form.append(inputAttachUrl);
|
}
|
//inputAttachUrl.attr("type", "hidden");
|
inputAttachUrl.attr("name", "attachUrl");
|
inputAttachUrl.val(attachUrl);
|
//附件物理名称
|
var inputPhysicalName = document.getElementById('#iptphysicalName');
|
if (inputPhysicalName == null) {
|
inputPhysicalName = $("<input>");
|
inputPhysicalName.attr("id", "iptphysicalName");
|
form.append(inputPhysicalName);
|
}
|
//inputPhysicalName.attr("type", "hidden");
|
inputPhysicalName.attr("name", "physicalName");
|
inputPhysicalName.val(physicalName);
|
form.submit();
|
}
|
|
function dowloadFunction(fileName) {
|
//创建form
|
var url = "general/download";
|
var form = document.getElementById('#downLoadForm');
|
if (form == null) {
|
form = $("<form>");
|
form.attr("id", "downLoadForm");
|
form.attr("style", "display:none");
|
form.attr("target", "");
|
form.attr("method", "post");
|
$("body").append(form);
|
}
|
form.attr("action", url);
|
// //附件物理名称
|
var inputPhysicalName = document.getElementById('#iptphysicalName');
|
if (inputPhysicalName == null) {
|
inputPhysicalName = $("<input>");
|
inputPhysicalName.attr("id", "iptphysicalName");
|
form.append(inputPhysicalName);
|
}
|
inputPhysicalName.attr("type", "hidden");
|
inputPhysicalName.attr("name", "fileName");
|
inputPhysicalName.val(fileName);
|
form.submit();
|
}
|
|
function resizeDataGrid() {
|
$("#dg_attachlist").datagrid("resize");
|
}
|
|
function setKeyId(val) {
|
keyId = val;
|
}
|
|
//获取修改过的附件列表
|
function getModifyAttachList() {
|
var addAttachList = $('#dg_attachlist').datagrid('getChanges', 'inserted');
|
addAttachList = addAttachList.concat($('#dg_attachlist').datagrid('getChanges', 'updated'));
|
var deleteAttachList = $('#dg_attachlist').datagrid('getChanges', 'deleted');
|
var obj = {
|
addAttachList: addAttachList,
|
deleteAttachList: deleteAttachList
|
};
|
|
return obj;
|
}
|
|
/**
|
* 获取附件列表
|
* @returns {*|jQuery}
|
*/
|
function getAttachList() {
|
var attachList = $('#dg_attachlist').datagrid('getRows');
|
return attachList;
|
}
|
|
|
//刷新列表
|
function refreshData() {
|
$('#dg_attachlist').datagrid("acceptChanges");
|
$('#dg_attachlist').datagrid("reload");
|
}
|
|
//
|
function getSaveDataAjax_NoUse() {
|
var obj = getAttachList();
|
|
var saveDataAjax = $.ajax({
|
type: 'POST',
|
contentType: "application/json; charset=utf-8",
|
url: "general/saveAttachs?moduleId=" + moduleId + "&keyId=" + keyId,
|
dataType: 'json',
|
data: JSON.stringify(obj),
|
success: function (data) {
|
$('#dg_attachlist').datagrid("acceptChanges");
|
$('#dg_attachlist').datagrid("reload");
|
}
|
});
|
return saveDataAjax;
|
}
|
|
function fileBatchDownload() {
|
var ids = new Array();
|
var checkRows = $("#dg_attachlist").datagrid("getChecked");
|
var _ok = true;
|
var _attachUrl, _physicalName;
|
$.each(checkRows, function (index, value) {
|
if (value.attachId < 0) {
|
_ok = false;
|
}
|
ids.push(value.attachId);
|
_attachUrl = value.attachUrl;
|
_physicalName = value.physicalName;
|
});
|
if (!_ok) {
|
wcp.notify.error('请选择要下载的文件!');
|
return;
|
}
|
if (ids.length == 0) {
|
wcp.notify.error('请选择要下载的文件!');
|
return;
|
} else if (ids.length == 1) {
|
$.ajax({
|
type: 'POST',
|
url: "general/beforeDownloadAttach?attachId=" + ids[0],
|
async: false,
|
success: function (data) {
|
if (data == "noAuthorize") {
|
wcp.message.error('对不起,您无权限下载此附件!');
|
} else if (data == "noFile") {
|
wcp.message.error('对不起,不存在此附件!');
|
} else {
|
dowloadAttachFunction(ids[0], _attachUrl, _physicalName);
|
}
|
}
|
});
|
} else {
|
//批量下载
|
wcp.ui.setBusy("body", wcp.ajax({
|
url: "general/downloadAttachBatch",
|
data: JSON.stringify(ids)
|
}).done(function (result) {
|
dowloadFunction(result);
|
}));
|
}
|
|
}
|
|
function fileToPdfAndOfd() {
|
var ids = new Array();
|
var checkRows = $("#dg_attachlist").datagrid("getChecked");
|
var _ok = true;
|
$.each(checkRows, function (index, value) {
|
if (value.attachId < 0) {
|
_ok = false;
|
}
|
ids.push(value.attachId);
|
});
|
if (!_ok) {
|
wcp.notify.error('请先保存文件再操作!');
|
return;
|
}
|
if (ids.length == 0) {
|
wcp.notify.error('请选择待要转换的文件!');
|
return;
|
}
|
//console.info(ids);
|
wcp.ui.setBusy("body", wcp.ajax({
|
url: "general/fileToPdfAndOfd?optionType=PDF",
|
data: JSON.stringify(ids)
|
}).done(function (result) {
|
wcp.notify.success('转换成功!');
|
$('#dg_attachlist').datagrid('reload');
|
$('#dg_attachlist').datagrid('clearSelections');
|
$('#dg_attachlist').datagrid('clearChecked');
|
}));
|
}
|
|
function pdfSign() {
|
var ids = new Array();
|
var checkRows = $("#dg_attachlist").datagrid("getChecked");
|
var _ok = true;
|
$.each(checkRows, function (index, value) {
|
if (value.attachId < 0) {
|
_ok = false;
|
}
|
ids.push(value.attachId);
|
});
|
if (!_ok) {
|
wcp.notify.error('请先保存文件再操作!');
|
return;
|
}
|
if (ids.length == 0 || ids.length > 1) {
|
wcp.notify.error('请选择一个待要签名的文件!');
|
return;
|
}
|
//console.info(ids);
|
|
var url = "general/signPdfView?attachId=" + ids[0] + "&rd=" + randomRange(1, 100);
|
var title = "pdf签名";
|
top.layer.open({
|
title: title,
|
type: 2,
|
area: ["1000px", "700px"],
|
fixed: false,
|
isOutAnim: false,
|
content: url,
|
success: function (layero, index) {
|
var body = window.top.layer.getChildFrame('body', index);
|
var iframeWin = window.top[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象
|
|
//将回调函数传给子页面
|
iframeWin.params.callBack = refreshData;
|
}
|
});
|
}
|
|
//刷新表格数据
|
function refreshData() {
|
$('#dg_attachlist').datagrid('reload');
|
$('#dg_attachlist').datagrid('clearSelections');
|
$('#dg_attachlist').datagrid('clearChecked');
|
}
|
|
function randomRange(min, max) { // min最小值,max最大值
|
return Math.floor(Math.random() * (max - min)) + min;
|
}
|
</script>
|
</html>
|