'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.routeid = sp.getUrlName("routeid"); self.routeinfoid = sp.getUrlName("routeinfoid"); self.directionid = sp.getUrlName("directionid"); self.formeditid = sp.getUrlName("formeditid"); self.docmode = sp.getUrlName("docmode"); self.dotype = sp.getUrlName("dotype"); self.get_lastReturnPageno = sp.getUrlName("lastReturnPageno"); self.get_lastReturnPage = sp.getUrlName("lastReturnPage"); self.get_type = sp.getUrlName("type"); if (self.get_lastReturnPage != "") { self.return = "../../../" + self.get_lastReturnPage + "?lastReturnPageno=" + self.get_lastReturnPageno + "&type=" + self.get_type } else { self.return = "../list.html?lastReturnPageno=" + self.get_lastReturnPageno + "&type=" + self.get_type } var postCfg = { headers: { 'Content-Type': 'application/json', 'Authorization': "Bearer " + self.get_AccessToken } }; //初始化右上角按钮 self.buttonList = [] self.getSwenList = function () { self.SwenList = []; var data = { directionid: self.directionid, userid: self.userId, routeinfoid: self.routeinfoid, routeid: self.routeid, formeditid: "" } $http.post(apiurljs.login + "g2app/abase/queryDataLink", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); $.each(res.data.LINKS, function (index, item) { if (item.TEMPFORM.indexOf("feedback.html") > -1) { self.Title = item.VNAME; } if (item.TEMPFORM.indexOf("?docmode") > 0) { if (item.TEMPFORM.indexOf("attachlist") > -1 || item.TEMPFORM.indexOf("feedback") > -1) { item.TEMPFORM = item.TEMPFORM + "&dotype=" + self.dotype + "&type=" + self.get_type + "&lastReturnPageno=" + self.get_lastReturnPageno + "&lastReturnPage=" + self.get_lastReturnPage; } else { item.TEMPFORM = "../" + item.TEMPFORM + "&dotype=" + self.dotype + "&type=" + self.get_type + "&lastReturnPageno=" + self.get_lastReturnPageno + "&lastReturnPage=" + self.get_lastReturnPage; } } else { item.TEMPFORM = "#"; } self.SwenList.push(item) }) self.SwenList.push({ VNAME: "流程图", DIRECTIONID: self.SwenList[0].DIRECTIONID, TEMPFORM: "modeler_read.html?" + self.SwenList[0].TEMPFORM.split("?")[1] }) self.getFuncList() }) } self.getSwenList(0) self.getFuncList = function () { var data = { formeditid: self.formeditid, billkey: "FILE_ATTACH" } $http.post(apiurljs.login + "g2work/formedit/queryDataFormEditFunc", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.buttonList = res.data self.getData() }) } self.getData = function () { var data = { tablename: "SX_XF", colums: "*", order: "ID desc", sqlwhere: { ROUTEINFOID: self.routeinfoid }, 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)); var FJ = res.data[0].FJ != "" && res.data[0].FJ != null ? JSON.parse(res.data[0].FJ) : []; var JGFJ = res.data[0].JGFJ != "" && res.data[0].JGFJ != null ? JSON.parse(res.data[0].JGFJ) : []; FJ.forEach(function (item) { item.COLID = "FJ" }) JGFJ.forEach(function (item) { item.COLID = "JGFJ" }) self.arrayFile = FJ.concat(JGFJ); console.log(self.arrayFile) self.getData1() }) } self.getData1 = function () { var data = { routeinfoid: self.routeinfoid, routeid: "", tableid: "SX_XF", colid: "", } $http.post(apiurljs.login + "g2app/abase/queryFileWithRouteAttach", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); self.arrayFile1 = res.data; console.log(self.arrayFile1) }) } self.uploading = false; self.upload = function () { $('#fileupload').fileupload({ url: apiurljs.login + 'g2app/abase/saveUploadFileName', dataType: 'json', beforeSend: function (xhr, data) { xhr.setRequestHeader("Authorization", "Bearer " + self.get_AccessToken); xhr.setRequestHeader("File-Argument", s4.encryptData_CBC("tablename=SX_XF,column=FJ,routeinfoid=" + self.routeinfoid + ",loaded=" + data.loaded + ",total=" + data.total)); }, // 上传完成后的执行逻辑 done: function (e, data) { self.uploading = false; self.getData() } }) } self.downLoad = function (item,n) { window.open(apiurljs.login + "g2work/files/" + (n == 1 ? item.FILEURL.slice(7) : item.FILEPATH.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 = { tablename: "SX_XF", column: file.COLID, routeinfoid: self.routeinfoid, fileid: file.FILEID, filenames: file.FILENAMES } $http.post(apiurljs.login + "g2app/abase/deleteUploadFileName", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfg) .success(function (obj) { var res = strToJson(s4.decryptData_CBC(obj.data)); sp.dialoghide(); if (res.success == true) { self.getData(); } else { sp.dialog("删除失败,请联系管理员!"); } }) }); } self.browseItem = null; self.browse = function (item, n) { self.browseItem = item; var set_convertType = 0; if (item.FILEEXT == "doc") { set_convertType = 0; } else if (item.FILEEXT == "pdf") { set_convertType = 20; } else if (item.FILEEXT == "ofd") { set_convertType = 570; } else { set_convertType = 0; } let postData = { convertType: set_convertType, fileUrl: apiurljs.login + "g2work/files2/inline/" + (n == 1 ? item.FILEURL.slice(7) : item.FILEPATH.slice(7)) }; console.log("路径:" + postData.fileUrl) 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) { if (res.errorcode === 0) { $("#iframe_browse").attr("src", res.data.viewUrl); } else { sp.dialog(res.message); } }); } self.editItem = null; self.Edit = function (item) { self.editItem = item; var data = { method: 1, params: { userId: self.userName, fileId: item.FILEID, fileName: item.FILENAME, filePath: apiurljs.login + "g2work" + item.FILEPATH, userRight: 0, // 用户权限 编辑:UserRightEdit = 0; 只读:UserRightReadonly = 1; 临时只读:UserRightTempReadonly = 2;此时页面上编辑—临时只读按钮,打开只能临时只读,不打开可以进行编辑 saveFlag: false, /// true:自动保存文档 false:不自动保存文档 (默认为true) callbackUrl: apiurljs.login + "g2app/xinfang/uploadFile?fileId=" + item.FILEID + "&fileUrl=" + item.FILEPATH } }; console.log("路径:" + data.params.filePath) console.log("参数:" + JSON.stringify(data.params)) $.ajax({ url: apiurljs.yzFileWo + "api.do", data: { jsonParams: encodeURIComponent(JSON.stringify(data)) }, type: "POST", dataType: "json", general: false, async: false, success: function (data) { console.log(data); if (data) { if (data.errorCode === "0") { let rst = data.result; console.log(rst.urls); if (rst && rst.urls) { var get_urls = rst.urls; console.log(get_urls); if (typeof (get_urls) === "string") { $timeout(function () { $("#iframe_edit").attr("src", get_urls); //window.open(get_urls) }) } else { console.warn("无效的urls:" + get_urls); } } else { console.warn("ajax响应内容data.result有问题:" + rst); } } else { alert(data.errorMessage); } } else { console.warn("ajax响应内容为空!"); } }, }); } self.btnSave = function () { var data = { method: 2, params: { fileId: self.editItem.FILEID } }; $.ajax({ url: apiurljs.yzFileWo + "api.do", data: { jsonParams: encodeURIComponent(JSON.stringify(data)) }, type: "POST", dataType: "json", general: false, async: false, success: function (data) { console.log(data); if (data && data.errorCode === "0") { sp.dialog("保存成功"); } }, }); } self.editFlag = function (str) { if (str == "wps" || str == "doc" || str == "docx" || str == "xls" || str == "xlsx" || str == "et") { return true } else { return false } } //右上角按钮调用方法 self.btnEvent = function (item) { switch (item.CODE) { case "SENDLOG": self.RouteList(); break; case "PRINTITEM": self.btnPrint(); break; case "MEETITEM": self.Meet(); break; case "SAVESIGN": self.Qian(); break; default: self.forward(item); break; } } //头部下滚冻结 $(function () { //页面高度撑满 setTimeout(function () { if ($(".ibox-content").height() < $(window).height() - 31) { $(".ibox-content").css("height", $(window).height() - 31) } $("#iframe_browse").css("height", $(".ibox-content").height() - 48) $("#iframe_edit").css("height", $(".ibox-content").height() - 48) }, 1) }) }])