'use strict';
var app = angular.module('app', [
]);
//定义一个全局的截图插件变量
var cropper;
app.controller("formeditCtrl", ["$scope", "$http", "$timeout", "$interval", "$sce", function ($scope, $http, $timeout, $interval, $sce) {
var self = this;
var s4 = new SM4Util();
self.userId = $.cookie("GlWorkPlatform-userid");
self.userName = $.cookie("GlWorkPlatform-chineseName");
self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno");
self.get_type = sp.getUrlName("type");
self.get_id = sp.getUrlName("ID");
self.return = "list1.html?lastReturnPageno=" + self.get_lastReturnPageno + "&type=" + self.get_type
var postCfg = {
headers: {
'Content-Type': 'application/json',
'Authorization': "Bearer " + self.get_AccessToken
}
};
self.Title = "附件"
self.SwenList = [{
VNAME: "表单",
TEMPFORM: "detail1.html?ID=" + self.get_id + "&type=" + self.get_type + "&lastReturnPageno=" + self.get_lastReturnPageno
}, {
VNAME: "附件",
TEMPFORM: "#"
}, {
VNAME: "稿件",
TEMPFORM: "detail3.html?ID=" + self.get_id + "&type=" + self.get_type + "&lastReturnPageno=" + self.get_lastReturnPageno
}];
self.getData = function () {
var data = {
tablename: "DOCELEMENT",
colums: "*",
order: "ID",
sqlwhere: { ID: self.get_id },
sqlorwhere: "",
sqlinwhere: "",
sqllikewhere: ""
};
$http.post(apiurljs.login + "g2app/dataabase/queryDataByCol", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
self.routeinfoid = res.data[0].ROUTEINFOID;
var data1 = {
routeinfoid: self.routeinfoid,
sqlwhere: "",
attachtype: ['FORM_PDF', 'CWG_PDF', 'GDZ_PDF', 'FLOWRECORD_PDF', 'ZLFILE_PDF']
}
$http.post(apiurljs.login + "g2app/DangAn/getAttachListNotAttachType", { data: s4.encryptData_CBC(JSON.stringify(data1)) }, postCfg)
.success(function (obj1) {
var res1 = strToJson(s4.decryptData_CBC(obj1.data));
self.arrayFile = res1.data;
self.getReturnList()
if (self.arrayFile.length > 0) {
self.browse(self.arrayFile[0])
}
})
})
}
self.returnList = [];
self.getReturnList = function () {
var data = {
routeinfoid: self.routeinfoid,
tablename: "DOCELEMENT_01"
}
$http.post(apiurljs.login + "g2app/DangAn/GetDataListForPid", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
self.returnList = res.data;
self.returnListShow = false;
self.selectReturn = self.returnList[0];
$.each(self.returnList, function (index, item) {
item.BACKDATE1 = sp.format(item.BACKDATE);
item.BACKDATE = sp.formatMinute(item.BACKDATE);
item.BACKOPINION1 = item.BACKOPINION.length > 12 ? item.BACKOPINION.slice(0, 12) + "..." : item.BACKOPINION;
})
})
}
self.getData()
self.uploading = false;
self.upload = function () {
$('#fileupload').fileupload({
url: apiurljs.login + 'g2app/abase/uploadFileWithForm',
dataType: 'json',
beforeSend: function (xhr, data) {
xhr.setRequestHeader("Authorization", "Bearer " + self.get_AccessToken);
xhr.setRequestHeader("File-Argument", s4.encryptData_CBC("tablename=DANGANATTACHFILE,routeinfoid=" + self.routeinfoid + ",ATTACHTYPE=FILEATTACH"));
},
add: function (e, data) {
var num = 0;
//文件类型判断
$.each(data.originalFiles, function (index, item) {
num++
})
if (num == data.originalFiles.length) {
self.uploading = true;
data.submit(); $scope.$apply();
}
},
// 上传完成后的执行逻辑
done: function (e, data) {
self.uploading = false;
self.getData()
}
})
}
self.downLoad = function (item) {
window.open(apiurljs.login + "g2work/files/" + item.FILEURL.slice(7))
}
self.deleteFile = function (file) {
var dialogHead = "温馨提示×";
var dialogBody = "
删除后不可恢复,您确认要删除吗?
";
var dialogFoot = "";
$('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
sp.openCenter(".sp-dialog");
///取消按钮
$('.sp-closeDialog').click(function (event) {
sp.closeCenter(".sp-dialog");
event.preventDefault();
event.stopPropagation();
});
//post消息的id
$("#delDataTrue").click(function () {
var data = {
id: file.ID
};
$http.post(apiurljs.login + "g2app/DangAn/deleteAttach", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg)
.success(function (obj) {
var res = strToJson(s4.decryptData_CBC(obj.data));
sp.dialoghide();
if (res.success) {
$.each(self.iframeList, function (index, item) {
if (item.title == file.FILENAMES && item.source == apiurljs.login + "g2work/files2/inline/" + file.FILEURL.slice(7)) {
self.closeItem(index);
return false;
}
})
self.getData();
} else {
sp.dialog("删除失败,请联系管理员!");
}
})
});
}
self.browse = function (obj) {
var n = 0;
self.iframeList.forEach(function (item) {
if (item.title == obj.FILENAMES && item.source == apiurljs.login + "g2work/files2/inline/" + obj.FILEURL.slice(7)) {
n++
}
})
if (n == 0) {
//console.log(obj);
///20230324---zyg ---永中转换-----start
var set_convertType = 0;
if (obj.FILEEXT == "doc") {
set_convertType = 0;
} else if (obj.FILEEXT == "pdf") {
set_convertType = 20;
} else if (obj.FILEEXT == "ofd") {
set_convertType = 570;
} else if (/(png|jpg|jpeg|gif|bmp|jfif|svg|tif|tiff)$/i.test(obj.FILEEXT) == true) {
set_convertType = 23;
} else {
set_convertType = 0;
}
let postData = {
convertType: set_convertType,
fileUrl: apiurljs.login + "g2work/files2/inline/" + obj.FILEURL.slice(7)
};
var postCfg_transfer = {
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
transformRequest: function (data) {
return $.param(data);
}
};
$http.post(apiurljs.login.split("glwork/")[0] + "fcscloud/composite/httpfile", postData, postCfg_transfer)
.success(function (res) {
//console.log(res);
if (res.errorcode === 0) {
let rst = res.data;
//console.log(rst.viewUrl);
self.iframeList.push({ id: self.iframeList.length + 1, title: obj.FILENAMES, url: $sce.trustAsResourceUrl(rst.viewUrl), source: apiurljs.login + "g2work/files2/inline/" + obj.FILEURL.slice(7) })
self.add()
} else {
sp.dialog(res.message);
}
});
///20230324---zyg ---永中转换-----end
}
}
self.openCJ = function (obj) {
var n = 0;
self.iframeList.forEach(function (item) {
if (item.title == obj.CNAME && item.source == obj.URL) {
n++
}
})
if (n == 0) {
self.iframeList.push({ id: self.iframeList.length + 1, title: obj.CNAME, url: $sce.trustAsResourceUrl(addToken(obj.URL) + "&routeinfoid=" + self.routeinfoid + "&pgcode=" + obj.PGCODE + "&bookmarkid=" + obj.ID), source: obj.URL, pgcode: obj.PGCODE })
self.add()
}
}
self.playItem = function (obj) {
var n = 0;
self.iframeList.forEach(function (item) {
if (item.title == obj.WATCHLIMIT && item.source == obj.URL) {
n++
}
})
if (n == 0) {
self.iframeList.push({ id: self.iframeList.length + 1, title: obj.WATCHLIMIT, url: $sce.trustAsResourceUrl(obj.FILEURL), source: obj.FILEURL })
self.add()
}
}
self.iframeList = []
self.add = function () {
if (self.iframeList.length == 1) {
self.iframeList[0].boxWidth = { width: $(".col-md-10").width() }
self.iframeList[0].iframeWidth = { width: $(".col-md-10").width() - 10 }
} else {
self.iframeList.forEach(function (item) {
item.boxWidth = { width: Math.trunc($(".col-md-10").width() / 4 * 2 / (self.iframeList.length - 1)) - 10 }
item.iframeWidth = { width: item.boxWidth.width - 10 }
})
self.iframeList[self.iframeList.length - 1].boxWidth = { width: Math.trunc($(".col-md-10").width() / 4 * 2) - 10 }
self.iframeList[self.iframeList.length - 1].iframeWidth = { width: self.iframeList[self.iframeList.length - 1].boxWidth.width - 10 }
}
}
self.openItem = function (obj) {
window.open(obj.url)
}
self.closeItem = function (n) {
self.iframeList.splice(n, 1)
if (self.iframeList.length == 0) {
} else if (self.iframeList.length == 1) {
self.iframeList[0].boxWidth = { width: $(".col-md-10").width() }
self.iframeList[0].iframeWidth = { width: $(".col-md-10").width() - 10 }
} else {
self.iframeList.forEach(function (item) {
item.boxWidth = { width: Math.trunc($(".col-md-10").width() / 4 * 2 / (self.iframeList.length - 1)) - 10 }
item.iframeWidth = { width: item.boxWidth.width - 10 }
})
self.iframeList[self.iframeList.length - 1].boxWidth = { width: Math.trunc($(".col-md-10").width() / 4 * 2) - 10 }
self.iframeList[self.iframeList.length - 1].iframeWidth = { width: self.iframeList[self.iframeList.length - 1].boxWidth.width - 10 }
}
}
self.reSize = function (n) {
var leftbox = document.getElementsByClassName("iframe-item")[n - 1];
var rightbox = document.getElementsByClassName("iframe-item")[n];
var line = document.getElementsByClassName("iframe-border-right")[n - 1];
document.getElementsByClassName("iframe-border-right")[n - 1].addEventListener("mousedown", function (event) {
$(".mousemove").show()
var leftboxW = leftbox.style.width.slice(0, leftbox.style.width.length - 2);
var rightboxW = rightbox.style.width.slice(0, rightbox.style.width.length - 2);
var x = event.pageX - line.offsetLeft;
document.addEventListener("mousemove", boxMove)
function boxMove(event) {
if (leftboxW * 1 + (event.pageX - x) * 1 <= 200) {
//document.removeEventListener("mousemove", boxMove)
} else if (rightboxW * 1 - (event.pageX - x) * 1 <= 200) {
//document.removeEventListener("mousemove", boxMove)
} else {
leftbox.style.width = leftboxW * 1 + (event.pageX - x) * 1 + "px";
//leftbox.getElementsByClassName("iframe-title")[0].style.width = leftboxW * 1 + (event.pageX - x) * 1 - 10 + "px";
leftbox.getElementsByTagName("iframe")[0].style.width = leftboxW * 1 + (event.pageX - x) * 1 - 10 + "px";
self.iframeList[n - 1].boxWidth.width = leftboxW * 1 + (event.pageX - x) * 1;
self.iframeList[n - 1].iframeWidth.width = leftboxW * 1 + (event.pageX - x) * 1 - 10;
rightbox.style.width = rightboxW * 1 - (event.pageX - x) * 1 + "px";
//rightbox.getElementsByClassName("iframe-title")[0].style.width = rightboxW * 1 - (event.pageX - x) * 1 - 10 + "px";
rightbox.getElementsByTagName("iframe")[0].style.width = rightboxW * 1 - (event.pageX - x) * 1 - 10 + "px";
self.iframeList[n].boxWidth.width = rightboxW * 1 - (event.pageX - x) * 1;
self.iframeList[n].iframeWidth.width = rightboxW * 1 - (event.pageX - x) * 1 - 10;
}
}
document.addEventListener("mouseup", function () {
$(".mousemove").hide()
document.removeEventListener("mousemove", boxMove)
})
})
}
//头部下滚冻结
$(function () {
//页面高度撑满
setTimeout(function () {
if ($(".ibox-content").height() < $(window).height() - 31) {
$(".ibox-content").css("height", $(window).height() - 31)
}
}, 1)
})
}])
app.directive("repeatFinish", function () {
return {
link: function (scope) {
if (scope.$last == true) {
$("#iframeList").css("height", $(window).height() - 110)
$(".mousemove").css("top", $("#iframeList").offset().top).css("left", $("#iframeList").offset().left).css("width", $("#iframeList").width()).css("height", $(window).height() - 110)
}
}
};
});
//插件路径添加token
function addToken(url) {
var newUrl = "";
if (url.indexOf("?") > -1) {
newUrl = url + "&token=" + localStorage.getItem("main-token")
} else {
newUrl = url + "?token=" + localStorage.getItem("main-token")
}
return newUrl
}