562 lines
20 KiB
JavaScript
Executable File
562 lines
20 KiB
JavaScript
Executable File
var sid; //全局变量
|
||
var pl_uuid;
|
||
var shape_uuid;
|
||
var type;
|
||
var repositoryName;
|
||
var appId;
|
||
var groupValue = "";
|
||
var fileValue = "";
|
||
var fileType = "";
|
||
var accessoryList = []; //所有自己的附件
|
||
var securityOptions = {}; // 三员管理密级选项
|
||
var isHighSecurity; //是否开启三员
|
||
var upfileAccessoryTmpObj = {};// 临时记录此次上传的附件
|
||
|
||
$(function() {
|
||
sid = $("#sid").val();
|
||
type = $("#type").val();
|
||
pl_uuid = $("#pl_uuid").val(); //file uuid
|
||
shape_uuid = $("#shape_uuid").val(); //图形uuid
|
||
repositoryName = $("#repositoryName").val();
|
||
isHighSecurity = $("#isHighSecurity").val();
|
||
appId = $("#appId").val();
|
||
|
||
if (isHighSecurity === "true"){
|
||
var jsonOptions = $("#securityOptions").val()
|
||
securityOptions = jQuery.parseJSON(jsonOptions);
|
||
}
|
||
|
||
//加载files
|
||
loadFiles();
|
||
loadRelationFiles();
|
||
//注册upfile
|
||
if (type == "file") {
|
||
groupValue = type;
|
||
fileValue = pl_uuid;
|
||
} else {
|
||
groupValue = pl_uuid;
|
||
fileValue = shape_uuid;
|
||
}
|
||
|
||
//tab
|
||
$("#tab a").off("click").on("click", function(){
|
||
var tit = $(this).attr("tit");
|
||
$("#tab a.active").removeClass("active");
|
||
$(this).addClass("active");
|
||
$("#content div.tab_content").hide();
|
||
$("#content div[tit=" + tit + "]").show();
|
||
})
|
||
|
||
//点击“新增”,显示新增页面
|
||
$("#showAddPage").off("click").on("click", function(){
|
||
clearUpfileAccessory();
|
||
$("#isDownload").check("check");
|
||
$("#accessoryList").hide();
|
||
$("#addAccessory").show();
|
||
if (isHighSecurity){
|
||
$("#security-select").val([""]).trigger("change"); //单选默认值
|
||
}
|
||
})
|
||
|
||
$("#cancel").off("click").on("click", function(){
|
||
$("#addAccessory").hide();
|
||
$("#accessoryList").show();
|
||
})
|
||
|
||
//初始化上传button
|
||
$("#upfile").upfile({
|
||
sid: sid,
|
||
appId: appId,
|
||
groupValue:groupValue,
|
||
fileValue:fileValue,
|
||
// filesToFilter: [["Images (*.jpg; *.jpeg; *.gif; *.png; *.bmp)","Document (*.doc;*.docx;*.xls;*.xlsx;*.ppt;*.pptx;*.pdf;)", "*.jpg; *.jpeg; *.gif; *.png; *.bmp; *.pdf; *.doc; *.docx; *.xls; *.xlsx; *.ppt; *.pptx; *.txt"]],
|
||
filesToFilter: [["Images (*.jpg; *.jpeg; *.gif; *.png; *.bmp),Document (*.doc;*.docx;*.xls;*.xlsx;*.ppt;*.pptx;*.pdf;), Video (*.mp3; *.mp4; *.avi; *.mpeg; *.flv; *.swf; *.wmv)",
|
||
"*.jpg; *.jpeg; *.gif; *.png; *.bmp; *.pdf; *.doc; *.docx; *.xls; *.xlsx; *.ppt; *.pptx; *.txt,*.mp3; *.mp4; *.avi; *.mpeg; *.flv; *.swf; *.wmv; *.xml; *.rtf;*.zip;*.rar;"]],
|
||
repositoryName: repositoryName,
|
||
numLimit : 0,
|
||
sizeLimit : 500 * 1024 * 1024,
|
||
complete:function(data, e){
|
||
//事件回调函数
|
||
},
|
||
add: function(e, data) { //附件被添加到上传列表时触发,当返回false时,可阻止上传
|
||
debugger;
|
||
if (data.files.length == 0) {
|
||
return false;
|
||
}
|
||
|
||
// 因为该组件支持批量上传但是只支持对单个文件的上传过程/结束事件处理,在此处单个文件上传时进行此次多个上传文件记录(不支持批量上传的结果返回,借助外部变量记录单个文件上传结果)
|
||
var allFiles = data.originalFiles;
|
||
var fileArr = [];
|
||
for (var i = 0; i < allFiles.length; i++) {
|
||
fileArr.push(allFiles[i].name);
|
||
}
|
||
// 此次上传的多个文件记录赋值
|
||
var tmpObj = {};
|
||
for (var i = 0; i < fileArr.length; i++) {
|
||
if (upfileAccessoryTmpObj[fileArr[i]]) {
|
||
tmpObj[fileArr[i]] = upfileAccessoryTmpObj[fileArr[i]];
|
||
} else {
|
||
tmpObj[fileArr[i]] = {
|
||
status: 'ok',
|
||
msg: '',
|
||
name: fileArr[i]
|
||
}
|
||
}
|
||
}
|
||
upfileAccessoryTmpObj = tmpObj;
|
||
|
||
// 开始校验
|
||
if (data.files[0].size > 500 * 1024 * 1024) {
|
||
upfileAccessoryTmpObj[data.files[0].name] = {
|
||
status: 'error',
|
||
msg: '文件过大, 不能大于500M',
|
||
name: data.files[0].name
|
||
}
|
||
return false;
|
||
}
|
||
//阻止非支持类型文件的上传
|
||
var suffix = data.files[0].name.substring(data.files[0].name.lastIndexOf(".") + 1);
|
||
var fileTypes = "jpg,jpeg,gif,png,bmp,pdf,doc,docx,ppt,pptx,xls,xlsx,txt,mp3,mp4,avi,mpeg,flv,swf,wmv,xml,rtf,zip,rar";
|
||
if (fileTypes.indexOf(suffix) < 0) {
|
||
upfileAccessoryTmpObj[data.files[0].name] = {
|
||
status: 'error',
|
||
msg: '不支持的文件后缀',
|
||
name: data.files[0].name
|
||
}
|
||
return false;
|
||
}
|
||
//不能添加名称相同的附件
|
||
if (accessoryList.length > 0) {
|
||
var fileName = data.files[0].name.substring(0, data.files[0].name.lastIndexOf("."));
|
||
for (var i = 0; i < accessoryList.length; i++) {
|
||
var obj = accessoryList[i];
|
||
if (obj.fileName.substring(0, obj.fileName.lastIndexOf(".")) == fileName) {
|
||
upfileAccessoryTmpObj[data.files[0].name] = {
|
||
status: 'error',
|
||
msg: '文件重名,不允许上传',
|
||
name: data.files[0].name
|
||
}
|
||
return false;
|
||
}
|
||
}
|
||
}
|
||
return true;
|
||
},
|
||
done: function(e, data) { //单个附件上传完毕后触发
|
||
var name = data.files[0].name;
|
||
if (data.textStatus != "success") {
|
||
upfileAccessoryTmpObj[name].status = 'error';
|
||
upfileAccessoryTmpObj[name].msg = data.message;
|
||
}
|
||
updateUpfileAccessoryName();
|
||
}
|
||
});
|
||
});
|
||
|
||
// 更新上传文件
|
||
function updateUpfileAccessoryName() {
|
||
if (upfileAccessoryTmpObj.length == 0) {
|
||
$('#upfileList').hide();
|
||
$('#upfileBlankMsg').show();
|
||
return false;
|
||
}
|
||
$('#upfileBlankMsg').hide();
|
||
$('#upfileList').show();
|
||
var successFiles = [];
|
||
var errFiles = [];
|
||
for (var name in upfileAccessoryTmpObj) {
|
||
var obj = upfileAccessoryTmpObj[name];
|
||
if (obj.status == 'ok') {
|
||
successFiles.push(name);
|
||
} else {
|
||
errFiles.push(name + '<span style="color:red;">'+ upfileAccessoryTmpObj[name].msg +'</span>');
|
||
}
|
||
}
|
||
var successCount = successFiles.length;
|
||
var errCount = errFiles.length;
|
||
var msg = "";
|
||
if (errCount == 0) {
|
||
msg = "文件校验:全部校验成功";
|
||
} else {
|
||
msg = "文件校验:" + successCount + "条成功,"+ errCount +"条校验失败(校验失败的文件不会上传)";
|
||
}
|
||
$('#upfileCheckResultMsg').html(msg);// 校验结果
|
||
|
||
// 校验成功列表
|
||
if (successCount == 0) {
|
||
$('#upfileSuccessList').html('无');
|
||
} else {
|
||
var successHtml = '';
|
||
for (var i = 0; i < successFiles.length; i++) {
|
||
successHtml += '' +
|
||
'<div style="padding-top: 5px;">' +
|
||
'<div style="display: inline-block;">' +
|
||
'<span>'+ (i+1) + '.' + successFiles[i] +'</span>' +
|
||
'</div>';
|
||
if (isHighSecurity === "true") {
|
||
successHtml += '' +
|
||
'<div style="display:inline-block;width: 100px;padding-left: 5px;">' +
|
||
'<select class="" data-name="' + successFiles[i] + '" id="security-select-' + i + '">' +
|
||
'</select>' +
|
||
'</div>';
|
||
}
|
||
successHtml += '</div>';
|
||
}
|
||
$('#upfileSuccessList').html(successHtml);
|
||
if (isHighSecurity === "true"){
|
||
var arr = [{
|
||
id:"",
|
||
text:"请选择密级"
|
||
}];
|
||
Object.keys(securityOptions).map(key =>{
|
||
let option= {
|
||
id: key,
|
||
text: securityOptions[key]
|
||
}
|
||
arr.push(option);
|
||
});
|
||
var opt = {
|
||
width : "100%",
|
||
data : arr
|
||
};
|
||
for (var i = 0; i < successFiles.length; i++) {
|
||
$("#security-select-" + i).select2($.extend({}, opt, {minimumResultsForSearch:-1}));
|
||
}
|
||
}
|
||
}
|
||
|
||
// 校验失败列表
|
||
if (errCount == 0) {
|
||
$('#upfileErrList').html('无');
|
||
} else {
|
||
var errHtml = '';
|
||
for (var i = 0; i < errFiles.length; i++) {
|
||
errHtml += '<div style="padding-top: 5px;"><div style="display: inline-block;"><span>' + (i+1) + '.' + errFiles[i] + '</span></div></div>';
|
||
}
|
||
$('#upfileErrList').html(errHtml);
|
||
}
|
||
|
||
}
|
||
|
||
// 清空上传附件
|
||
function clearUpfileAccessory() {
|
||
$("#upfileAccessoryName").val('');
|
||
upfileAccessoryTmpObj = {};
|
||
$('#upfileList').hide();
|
||
$('#upfileBlankMsg').show();
|
||
}
|
||
|
||
//业务处理
|
||
function loadFiles() { //加载附件,params参考引用
|
||
var params = {};
|
||
params.pl_uuid = pl_uuid;
|
||
if ("file" == type) { //文件
|
||
params.shape_uuid = shape_uuid;
|
||
params.type = type;
|
||
} else { //图形
|
||
params.uuids = parent.Utils.getSelected()[0].id;
|
||
}
|
||
awsui.ajax.request({
|
||
type: "POST",
|
||
url: "./jd?sid=" + encodeURIComponent(sid) + "&cmd=com.actionsoft.apps.coe.pal_processlevel_upfile_load",
|
||
data: params,
|
||
ok: function(msg) {
|
||
$("#selfAccessoryTable tbody").empty();
|
||
var accessoryHtml = "";
|
||
var list = msg.data.list;
|
||
list.sort(function(x,y){
|
||
if(x.fileName.substr(0,2)=='附件' && y.fileName.substr(0,2)=='附件') {
|
||
return Number(x.fileName.substr(2, 1)) - Number(y.fileName.substr(2, 1));
|
||
}
|
||
});
|
||
list.sort(function(x,y){
|
||
if(x.fileName.substr(0,2)!='附件' && y.fileName.substr(0,2)!='附件'){
|
||
return x.createTime -y.createTime;
|
||
}
|
||
|
||
});
|
||
accessoryList = list;
|
||
if (list.length > 0) {
|
||
$('#upfileAlert').hide();
|
||
$('#selfAccessoryTable').show();
|
||
var editable = parent.editable == "0" ? 0 : 1; //editable等于0,页面只读
|
||
for (var i = 0; i < list.length; i++) {
|
||
var obj = list[i];
|
||
var downloadIcon = "";
|
||
var deleteIcon = "";
|
||
if (editable == 1) {
|
||
deleteIcon = ' <img src="../apps/com.actionsoft.apps.coe.pal/img/icon/pal_delete.png" onclick="delFile(\'' + obj.uuid + '\', \'' + obj.fileName + '\', loadFiles)" awsui-qtip="删除">';
|
||
}
|
||
if (obj.download == 1 || obj.createUser == $("#userId").val()) {
|
||
downloadIcon = ' <img src="../apps/com.actionsoft.apps.coe.pal/img/icon/pal_download.png" onclick="downloadFile(\'' + obj.url + '\')" awsui-qtip="下载">';
|
||
}
|
||
accessoryHtml += '<tr>'
|
||
+ ' <td><div awsui-qtip="hBordercolor:\'#108ee9\',text:\''+obj.fileName+'\',position:\'bottom\'" class="text_overflow" widthpercent="60" style="max-width: 302px;display: inline-block;">' + obj.fileName ;
|
||
//开启三员,显示密级
|
||
if(isHighSecurity === "true"){
|
||
accessoryHtml += ' </div><div class="text_overflow" style="display: inline-block;">' + securityOptions[obj.securityLevel];
|
||
}
|
||
accessoryHtml += '</div>'
|
||
+ '</td>'
|
||
+ ' <td style="text-align: center;">'
|
||
+ ' <img src="../apps/com.actionsoft.apps.coe.pal/img/icon/pal_reading.png" onclick="readFile(\'' + obj.uuid + '\')" awsui-qtip="打开">'
|
||
+ downloadIcon
|
||
+ deleteIcon
|
||
+ ' </td>'
|
||
+ '</tr>';
|
||
}
|
||
} else {
|
||
$('#selfAccessoryTable').hide();
|
||
$('#upfileAlert').show();
|
||
}
|
||
$("#selfAccessoryTable tbody").html(accessoryHtml);
|
||
var width = $("#selfAccessoryTable").width();
|
||
$("#selfAccessoryTable div[widthPercent]").each(function(){
|
||
var _$this = $(this);
|
||
var percent = parseInt(_$this.attr("widthPercent"));
|
||
_$this.css({"width": width * percent/100});
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
|
||
//加载关联附件
|
||
function loadRelationFiles() { //加载附件,params参考引用
|
||
var params = {};
|
||
params.pl_uuid = pl_uuid;
|
||
if ("file" == type) { //文件
|
||
params.type = type;
|
||
} else { //图形
|
||
params.shape_uuid = parent.Utils.getSelected()[0].id;
|
||
}
|
||
awsui.ajax.request({
|
||
type: "POST",
|
||
url: "./jd?sid=" + encodeURIComponent(sid) + "&cmd=com.actionsoft.apps.coe.pal_processlevel_relation_upfile_load",
|
||
data: params,
|
||
ok: function(msg) {
|
||
$("#relationAccessoryTable tbody").empty();
|
||
var accessoryHtml = "";
|
||
var list = msg.data.list;
|
||
if (list.length > 0) {
|
||
$('#relationUpfileAlert').hide();
|
||
$("#relationAccessoryTable").show();
|
||
for (var i = 0; i < list.length; i++) {
|
||
var obj = list[i];
|
||
var downloadIcon = "";
|
||
if (obj.download == 1) {
|
||
downloadIcon = ' <img src="../apps/com.actionsoft.apps.coe.pal/img/icon/pal_download.png" onclick="downloadFile(\'' + obj.url + '\')" awsui-qtip="下载">';
|
||
}
|
||
var openIconClick = "readFile(\'" + obj.uuid + "\')";
|
||
//如果有权限限制,判断是否可以打开附件
|
||
if (parent.filePerms != undefined && parent.filePerms != "" && parent.filePerms != "-" && parent.filePerms.indexOf(obj.pl_uuid) == -1) {
|
||
downloadIcon = '';
|
||
openIconClick = "$.simpleAlert(\'没有浏览模型[" + obj.modelName + "]的权限\')";
|
||
}
|
||
accessoryHtml += '<tr>'
|
||
+ ' <td><div awsui-qtip="hBordercolor:\'#108ee9\',text:\''+obj.fileName+'\',position:\'bottom\'" class="text_overflow" widthpercent="60" style="max-width: 302px;display: inline-block;">' + obj.fileName;
|
||
//开启三员,显示密级
|
||
if(isHighSecurity === "true"){
|
||
accessoryHtml += ' </div><div class="text_overflow" style="display: inline-block;">' + securityOptions[obj.securityLevel];
|
||
}
|
||
accessoryHtml += '</div>'
|
||
+ '</td>'
|
||
+ ' <td style="text-align: center;">'
|
||
+ ' <img src="../apps/com.actionsoft.apps.coe.pal/img/icon/pal_reading.png" onclick="' + openIconClick + '" awsui-qtip="打开">'
|
||
+ downloadIcon
|
||
+ ' </td>'
|
||
+ '</tr>';
|
||
}
|
||
} else {
|
||
$("#relationAccessoryTable").hide();
|
||
$('#relationUpfileAlert').show();
|
||
}
|
||
$("#relationAccessoryTable tbody").html(accessoryHtml);
|
||
var width = $("#relationAccessoryTable").width();
|
||
$("#relationAccessoryTable div[widthPercent]").each(function(){
|
||
var _$this = $(this);
|
||
var percent = parseInt(_$this.attr("widthPercent"));
|
||
_$this.css({"width": width * percent/100});
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
|
||
function delFile(uuid, fileName, callback) { //删除单个附件,params参考引用
|
||
var options = {
|
||
title: "提示",
|
||
content: "确定要删除【" + fileName + "】吗?",
|
||
onConfirm: function() {
|
||
var params = {};
|
||
params.uuid = uuid;
|
||
jQuery.ajax({
|
||
type: "POST",
|
||
url: "./jd?sid=" + encodeURIComponent(sid) + "&cmd=com.actionsoft.apps.coe.pal_processlevel_upfile_del",
|
||
data: params,
|
||
success: function(msg) {
|
||
var dataJson = msg.data;
|
||
if (msg.result == "ok") {
|
||
if(type == "shape"){
|
||
delUpFileOfShape(dataJson.uuid);
|
||
callback();
|
||
}
|
||
$.simpleAlert("删除成功", "ok");
|
||
callback();
|
||
} else {
|
||
$.simpleAlert("删除失败", "error");
|
||
}
|
||
|
||
}
|
||
});
|
||
}
|
||
};
|
||
$.confirm(options);
|
||
}
|
||
|
||
//下载附件
|
||
function downloadFile(url) {
|
||
window.location.href = url;
|
||
}
|
||
|
||
//附件在线预览
|
||
function readFile(uuid) {
|
||
$.simpleAlert("文件正在处理", "loading");
|
||
awsui.ajax.request({
|
||
type: "POST",
|
||
url: "./jd?sid=" + encodeURIComponent(sid) + "&cmd=com.actionsoft.apps.coe.pal_processlevel_upfile_read",
|
||
data: {uuid: uuid},
|
||
ok: function(msg) {
|
||
$.simpleAlert("close");
|
||
var url = msg.data.url;
|
||
if (msg.data.noSupport) {
|
||
window.location.href = url;
|
||
} else {
|
||
window.open(url);
|
||
}
|
||
},
|
||
err: function(msg) {
|
||
$.simpleAlert("close");
|
||
}
|
||
});
|
||
}
|
||
|
||
function addFile(callback) { //开始上传,params参考引用
|
||
// 校验是否上传附件
|
||
var successFiles = [];
|
||
if (upfileAccessoryTmpObj.length == 0) {
|
||
$.simpleAlert("请上传文件", "warning");
|
||
return false;
|
||
} else {
|
||
for (var name in upfileAccessoryTmpObj) {
|
||
var obj = upfileAccessoryTmpObj[name];
|
||
if (obj.status == 'ok') {
|
||
var tmp = {
|
||
name: name,
|
||
securityLevel: ''
|
||
};
|
||
successFiles.push(tmp);
|
||
}
|
||
}
|
||
}
|
||
if (successFiles.length == 0) {
|
||
$.simpleAlert("文件全部校验失败,请上传正确的文件", "warning");
|
||
return false;
|
||
}
|
||
|
||
// 校验密级
|
||
if (isHighSecurity === "true") {
|
||
for (var i = 0; i < successFiles.length; i++) {
|
||
var name = successFiles[i].name;
|
||
var securityLevel = $('#security-select-' + i).val();
|
||
if(securityLevel==="" || securityLevel[0] === ""){
|
||
$.simpleAlert("请选择 " + name + " 的密级","warning",1500);
|
||
return false;
|
||
}
|
||
successFiles[i].securityLevel = securityLevel;
|
||
}
|
||
}
|
||
|
||
var params = {
|
||
"pl_uuid": pl_uuid,
|
||
"shape_uuid": shape_uuid,
|
||
"type": type,
|
||
"files": JSON.stringify(successFiles),
|
||
"download": 1
|
||
}
|
||
|
||
jQuery.ajax({
|
||
type: "POST",
|
||
url: "./jd?sid=" + encodeURIComponent(sid) + "&cmd=com.actionsoft.apps.coe.pal_processlevel_upfile_add2",
|
||
data: params,
|
||
success: function(msg) {
|
||
var dataJson = msg.data;
|
||
if (msg.result == "ok") {
|
||
if (type == "shape") {
|
||
addUpFileToShape(dataJson.uuids);
|
||
}
|
||
$.simpleAlert("添加成功", "ok");
|
||
$("span[class*='arrow-down']").parent().trigger("click");
|
||
callback();
|
||
clearUpfileAccessory();
|
||
$("#addAccessory").hide();
|
||
$("#accessoryList").show();
|
||
} else {
|
||
$.simpleAlert("添加失败", "error");
|
||
}
|
||
|
||
}
|
||
});
|
||
}
|
||
|
||
//获取选中图形的文件数组
|
||
function getUpFileArrayOfShareShape() {
|
||
var shape = parent.Utils.getSelected()[0];
|
||
var upFilesArray = [];
|
||
for (var i = 0; i < shape.dataAttributes.length; i++) {
|
||
var attr = shape.dataAttributes[i];
|
||
if (attr.upFilesArray) {
|
||
upFilesArray = attr.upFilesArray;
|
||
break;
|
||
}
|
||
}
|
||
|
||
return upFilesArray;
|
||
}
|
||
|
||
function addUpFileToShape(uuids) {
|
||
var upfilesArray = getUpFileArrayOfShareShape();
|
||
for (var i = 0; i < uuids.length; i++) {
|
||
upfilesArray.push(uuids[i]);
|
||
}
|
||
updateShape();
|
||
}
|
||
|
||
function delUpFileOfShape(uuid){//
|
||
var upfilesArray = getUpFileArrayOfShareShape();
|
||
for(var i =0,size = upfilesArray.length;i<size;i++){
|
||
if(uuid == upfilesArray[i]){
|
||
upfilesArray.remove(i);
|
||
}
|
||
}
|
||
updateShape();
|
||
}
|
||
|
||
function updateShape(){
|
||
var shape = parent.Utils.getSelected()[0];
|
||
parent.Model.update(shape);
|
||
}
|
||
|
||
|
||
Array.prototype.remove = function (dx) {
|
||
if (isNaN(dx) || dx > this.length) {
|
||
return false;
|
||
}
|
||
for (var i = 0, n = 0; i < this.length; i++) {
|
||
if (this[i] != this[dx]) {
|
||
this[n++] = this[i];
|
||
}
|
||
}
|
||
this.length -= 1;
|
||
}; |