123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- // 'use strict';
- var app = angular.module('app', [
- 'angularUtils.directives.dirPagination'
- ]);
- app.controller("fileListCtrl", ["$http", "$scope", "$timeout", function ($http, $scope, $timeout) {
- var self = this;
- var s4 = new SM4Util();
- self.userId = $.cookie("GlWorkPlatform-userid");
- self.userName = $.cookie("GlWorkPlatform-username");
- self.userChineseName = $.cookie("GlWorkPlatform-chineseName");
- self.get_AccessToken = localStorage.getItem("GlWorkPlatform-AccessToken");
- self.CrossPage = window.parent.CrossPage;
- //声明
- self.noDataTip = 1;
- self.rows = []; //声明空数组
- self.pageno = 1; // 初始化 当前页为 1
- self.total_count = 0;
- self.itemsPerPage = 10;
- self.pageOptions = [10, 15, 20, 25, 30];
- var postCfgJson = {
- headers: {
- 'Content-Type': 'application/json',
- 'Authorization': "Bearer " + self.get_AccessToken
- }
- };
- //文件上传用到的变量
- self.finishUploadArray = [];
- self.uploadTypeName = "";
- self.uploadTypeCode = "";
- self.uploadTypeList = [];
- //搜索参数
- self.search = {
- FILESNAME: "",
- TYPECODE: sp.getUrlName("CODE") || ""
- }
- //打开上传弹出层
- self.openUploadLayer = function () {
- var time1 = sp.getLocalDate1();
- self.journalRecord(time1, sp.getLocalDate1(), "上传", "接入日志", window.location.pathname)
- self.finishUploadArray = [];
- if (self.uploadTypeList.length == 0) {
- self.getResourceType();
- } else {
- self.uploadTypeName = self.uploadTypeList[0].CNAME;
- self.uploadTypeCode = self.uploadTypeList[0].CODE;
- }
- $(".warninfo").html("");
- $(".uploadBtn").val("");
- $(".fileList tbody").html("");
- $(".noFileWarning").show();
- sp.layer("#layer_uploadFile");
- }
- //部署文件上传服务
- self.setFileUpload = function () {
- var $form = null;
- var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
- var collection = {};
- var fileaddr = ""; //标记文件地址
- $('#fileupload').fileupload({
- dataType: 'json',
- maxChunkSize: 10000000,
- autoUpload: false,
- limitConcurrentUploads: 1,
- sequentialUploads: true,
- url: apiurljs.login + "g2work/files/upLoad",
- complete: function (e, data) {
- console.log(e);
- if (e.responseJSON.files[0].size > 0) {
- var itemFile = {
- ID: "0",
- ROUTEINFOID: "0",
- SORTID: "0",
- SUBMAN: self.userChineseName,
- SUNMANUSERID: self.userId,
- PREFIX: e.responseJSON.files[0].prefix,
- FILESNAME: e.responseJSON.files[0].name,
- FILESIZE: self.formatFileSize(e.responseJSON.files[0].size),
- FILEURL: e.responseJSON.files[0].url,
- FILESID: e.responseJSON.files[0].fileid
- }
- self.finishUploadArray.push(itemFile);
- }
- },
- beforeSend: function (xhr, data) {
- xhr.setRequestHeader("Authorization", "Bearer " + self.get_AccessToken);
- data.files.forEach(function (file) {
- //console.log("fileid=" + collection[file.name + file.size]);
- xhr.setRequestHeader('X-File-Identifier', fileid);
- //xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
- })
- }
- }).bind('fileuploadadd', function (e, data) {
- data.files.forEach(function (file) {
- chunkSize = 10000000;
- fileid = "";
- frOnload = function (e) {
- fileid = SparkMD5.ArrayBuffer.hash(e.target.result);
- collection[file.name + file.size] = fileid;
- var filetype = file.name.substring(file.name.lastIndexOf('.') + 1, file.name.length).toLowerCase();
- }
- function loadFile() {
- var fileReader = new FileReader();
- fileReader.onload = frOnload;
- var start = 0,
- end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize;
- fileReader.readAsArrayBuffer(blobSlice.call(file, start, end));
- };
- loadFile();
- });
- })
- }
- //格式化文件大小的函数
- self.formatFileSize = function (bytes) {
- if (typeof bytes !== 'number') {
- return '';
- }
- if (bytes >= 1000000000) {
- return (bytes / 1000000000).toFixed(2) + 'GB';
- }
- if (bytes >= 1000000) {
- return (bytes / 1000000).toFixed(2) + 'MB';
- }
- return (bytes / 1000).toFixed(2) + 'KB';
- }
- //格式化文件类型的函数
- self.formatFileExt = function (fileName) {
- var LastIndex = fileName.lastIndexOf(".");
- return fileName.substring(LastIndex + 1, fileName.length);
- }
- //格式化文件名称的函数
- self.formatFileName = function (fileName) {
- var LastIndex = fileName.lastIndexOf(".");
- return fileName.substring(0, LastIndex);
- }
- //加载文件分类
- self.getResourceType = function () {
- self.uploadTypeList = [];
- self.uploadTypeName = "";
- self.uploadTypeCode = "";
- var postData = {
- tablename: "CODESHAREFILESTYPE"
- }
- $http.post(apiurljs.login + "g2app/share/queryCode", { data: s4.encryptData_CBC(JSON.stringify(postData)) }, postCfgJson)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- console.log(res);
- self.uploadTypeList = res.data;
- self.uploadTypeName = res.data[0].CNAME;
- self.uploadTypeCode = res.data[0].CODE;
- })
- }
- //改变文件分类
- self.changeResourceType = function () {
- self.uploadTypeList.forEach(function (item) {
- if (self.uploadTypeCode == item.CODE) {
- self.uploadTypeName = item.CNAME;
- }
- })
- }
- //保存上传文件的记录
- self.saveUploadFile = function () {
- var uploadNum = $(".fileList .template-upload").length;
- var downloadNum = $(".fileList .template-download").length;
- if (downloadNum == 0 && uploadNum == 0) {
- self.addWarning("未选择上传文件");
- } else if (downloadNum == 0 && uploadNum != 0 || downloadNum != 0 && uploadNum != 0) {
- self.addWarning("存在未上传文件");
- } else {
- self.finishUploadArray.forEach(function (item) {
- item.TYPECODE = self.uploadTypeCode;
- item.TYPENAME = self.uploadTypeName;
- item.UPTIMES = sp.dateFtt("yyyy-MM-dd hh:mm:ss", new Date())
- })
- var postData = JSON.stringify(self.finishUploadArray);
- $http.post(apiurljs.login + "g2app/share/shareInsert", { data: s4.encryptData_CBC(postData) }, postCfgJson)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- if (res.success) {
- sp.closeCenter('.sp-layer');
- self.pageno = 1; // 初始化 当前页为 1
- self.getData(self.pageno);
- sp.dialog("保存成功!");
- self.finishUploadArray.forEach(function (item) {
- item.FILENAMES = item.FILESNAME;
- item.FILEEXT = item.PREFIX;
- item.FILESIZE = item.FILESIZE;
- item.FILEURL = item.FILEURL;
- item.FILEID = item.FILESID;
- })
- sp.transmit2("FILEMANAGER_SHENQING", "行政", "", self.finishUploadArray, "0", "KNOWLEDGEATTACHLIST")
- } else {
- self.addWarning("保存失败!");
- }
- })
- }
- }
- //去除警告
- self.removeWarning = function () {
- $(".warninfo").html("").hide();
- }
- //给上传弹出层添加警告
- self.addWarning = function (content) {
- $(".warninfo").html("<i class=\"fa fa-exclamation sp-mr-5\"></i>" + content).show();
- }
- //关闭wps刷新
- $scope.WpsClose = function () {
- self.getData(self.pageno);
- }
- //获取加载数据
- self.getData = function (pageno) {
- self.pageno = pageno;
- $scope.__default__currentPage = self.pageno; //设置页面样式在第几页
- var data = {
- pageSize: self.itemsPerPage,
- pageno: pageno,
- filesname: self.search.FILESNAME,
- typecode: self.search.TYPECODE
- }
- $http.post(apiurljs.login + "g2app/share/queryDataWithPage", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfgJson)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- if (sp.isval(res.data)) {
- res.data.forEach(function (item) {
- item.UPTIMES = item.UPTIMES == null ? "" : sp.dateFtt("yyyy-MM-dd hh:mm", new Date(item.UPTIMES));
- item.FILEURL = apiurljs.login + "g2work" + item.FILEURL;
- item.FILESIZE = item.FILESIZE == "" || item.FILESIZE.indexOf("B") > -1 ? item.FILESIZE : self.formatFileSize(parseFloat(item.FILESIZE));
- })
- self.noDataTip = 1;
- self.rows = res.data;
- self.total_count = res.totalCount;
- } else {
- self.rows = [];
- self.total_count = 0;
- self.noDataTip = 0;
- }
- if (self.CrossPage.type == 0) {
- self.journalRecord(self.CrossPage.ctime, sp.getLocalDate1(), "", "接入日志", window.location.pathname)
- }
- console.log(self.rows);
- }).error(function (err) {
- sp.dialog(JSON.stringify(err));
- });
- }
- self.goUrl = function (obj) {
- if (obj.PREFIX == "wps" || obj.PREFIX == "doc" || obj.PREFIX == "docx" || obj.PREFIX == "") {
- sp.toggleWps(true)
- if (obj.FILESID == "") {
- newDoc(apiurljs.wpspath + "/g2app/abase/saveUploadFileNameshare?Authorization=Bearer " + self.get_AccessToken + "&file-argument=" + encodeURIComponent(s4.encryptData_CBC("tablename=SHAREFILES,id=" + obj.ID + ",routeinfoid=" + obj.ID + ",typename=" + obj.TYPENAME + ",typecode=" + obj.TYPECODE)), obj.FILESNAME)
- } else {
- onlineEditOfficialDocument(apiurljs.wpspath + "/g2work/wpsfiles/" + obj.FILEURL.slice(14), apiurljs.wpspath + "/g2app/abase/saveUploadFileNameshare?Authorization=Bearer " + self.get_AccessToken + "&file-argument=" + encodeURIComponent(s4.encryptData_CBC("tablename=SHAREFILES,id=" + obj.ID + ",routeinfoid=" + obj.ID + ",typename=" + obj.TYPENAME + ",typecode=" + obj.TYPECODE)), "")
- }
- } else if (obj.PREFIX == "ofd" || obj.PREFIX == "pdf") {
- window.open("../../iframeDemo.html?data=" + encodeURIComponent(s4.encryptData_CBC("type=0&file=" + obj.FILEURL.slice(14) + "&tablename=SHAREFILES&routeinfoid=" + obj.ID)))
- } else if (obj.FILEEXT == null || obj.FILEEXT == undefined) {
- return;
- } else {
- window.open(apiurljs.wpspath + "/g2work/files2/inline/" + obj.FILEURL.slice(14))
- }
- }
- //下载
- self.downLoad = function (href) {
- window.location.href = href;
- var time1 = sp.getLocalDate1();
- self.journalRecord(time1, sp.getLocalDate1(), "下载", "接入日志", window.location.pathname)
- }
- //删除
- self.btnDelete = function (item) {
- var time1 = sp.getLocalDate1();
- self.journalRecord(time1, sp.getLocalDate1(), "上传", "修改日志", window.location.pathname)
- var getDelID = item.ID;
- var dialogHead = "<span class=\"sp-dialog-head\"><span class=\"sp-dialog-tip\">温馨提示</span><span class=\"sp-dialog-close sp-closeDialog\" title=\"关闭\">×</span></span>";
- var dialogBody = "<div class=\"sp-dialog-body\">删除后不可恢复,您确认要删除吗?</div>";
- var dialogFoot = "<div class=\"sp-dialog-foot\"><input data-id=" + getDelID + " id='dialog_btnConfirm' type='button' value='确 认' class='sp-dialog-btnTrue' /><input type='button' value='取 消' class='sp-dialog-btnCancle sp-closeDialog' /></div>";
- $('.sp-dialog').html(dialogHead + dialogBody + dialogFoot);
- sp.openCenter(".sp-dialog");
- ///取消按钮
- $('.sp-closeDialog').click(function (event) {
- sp.dialoghide();
- event.preventDefault();
- event.stopPropagation();
- });
- //post消息的id
- $("#dialog_btnConfirm").click(function () {
- var getid = $(this).attr("data-id");
- var data = {
- ID: getid
- }
- $http.post(apiurljs.login + "g2app/share/del", data, postCfgJson)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- sp.dialoghide();
- if (res.success) {
- self.getData(self.pageno);
- sp.deltransmit(item.FILESID)
- } else {
- sp.dialog("删除失败,请联系管理员!");
- }
- })
- });
- }
- //弹出筛选框
- self.openSearchLayer = function () {
- self.search.TYPECODE = self.uploadTypeList[0].code;
- sp.layer("#layer_search");
- var time1 = sp.getLocalDate1();
- self.journalRecord(time1, sp.getLocalDate1(), "查询", "查询日志", "/g2app/share/queryDataWithPage")
- }
- self.doSearch = function () {
- sp.closeCenter('.sp-layer');
- self.pageno = 1; // 初始化 当前页为 1
- self.getData(self.pageno);
- }
- self.closeSeach = function () {
- self.search = {
- FILESNAME: "",
- TYPECODE: sp.getUrlName("CODE") || ""
- };
- sp.layerhide();
- self.getData(1);
- };
- //刷新
- self.btnRefresh = function () {
- self.getData(self.pageno);
- };
- self.openAddFile = function () {
- self.add = {
- FILESNAME: "",
- TYPECODE: "C04",
- TYPENAME: ""
- }
- self.uploadTypeList.forEach(function (item) {
- if (item.CODE == "C04") {
- self.add.TYPENAME = item.CNAME;
- }
- })
- sp.layer("#layer_addwps")
- }
- self.addWpsType = function () {
- self.uploadTypeList.forEach(function (item) {
- if (self.add.TYPECODE == item.CODE) {
- self.add.TYPENAME = item.CNAME;
- }
- })
- }
- self.btnAddWps = function () {
- var data = [{
- ID: "0",
- ROUTEINFOID: "0",
- SORTID: "0",
- SUBMAN: self.userChineseName,
- SUNMANUSERID: self.userId,
- PREFIX: "",
- FILESNAME: self.add.FILESNAME + ".wps",
- FILESIZE: "",
- FILEURL: "",
- FILESID: "",
- UPTIMES: "",
- TYPECODE: self.add.TYPECODE,
- TYPENAME: self.add.TYPENAME
- }]
- $http.post(apiurljs.login + "g2app/share/shareInsert", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfgJson)
- .success(function (obj) {
- var res = strToJson(s4.decryptData_CBC(obj.data));
- sp.layerhide()
- if (res.success == true) {
- self.getData(1)
- } else {
- sp.dialeg(res.message)
- }
- })
- }
- $("#fileupload").attr("data-url", apiurljs.login + "g2work/files/upLoad");
- self.setFileUpload();
- self.getResourceType();
- self.getData(self.pageno);
- //记录日志
- self.journalRecord = function (time1, time2, title, func, url) {
- if (!self.CrossPage.cname) { return; }
- var data = {
- tablename: "SYS_CLICKLOG",
- data: {
- CTIME: time1 == null ? sp.getLocalDate1() : time1,
- TITLE: (title != "" ? self.CrossPage.cname + "/" + title : self.CrossPage.cname),
- REQUESTURL: url,
- REQUESTHEADERURL: window.location.origin,
- LOGTYPE: func,
- USERTYPE: $.cookie("GlWorkPlatform-userType"),
- ADMIN: $.cookie("GlWorkPlatform-userTypeEng"),
- CLIENTIP: sp.myIP(),
- PCNAME: sp.detectOS(),
- BROWSERNAME: sp.browser(),
- RESPONSETIME: time2 == null ? sp.getLocalDate1() : time2,
- USERID: self.userId,
- USERNAME: self.userChineseName
- }
- }
- $http.post(apiurljs.login + "g2app/dataabase/insertFormData", { data: s4.encryptData_CBC(JSON.stringify(data)) }, postCfgJson)
- .success(function (res) {
- self.CrossPage.type = 1;
- })
- }
- }]);
|