define(function(require, exports, module) { require("./addpicture.css") let Window = require("system/views/pages/window"); let tpl = require("./addpicture.tpl"); let uploadpictureWindow = require("system/views/pages/uploadwindow/uploadpictureWindow"); let bizService = require("system/service/bizservice"); let Service = require('apps/rht/etp/etp0603/etp0603service'); let rhtComm = require('apps/rht/comm/rhtComm'); let navigatorSort = []; let currentCheckedNode = ""; //已选中树节点 let rootPath = "upload_picture"; //根目录 let upIns; let deleteType = "1"; // 0 1 代表软删除与硬删除 let treeNodes = ""; //所有的节点信息 let checkedPicture = []; //当前已经选择的图片 let rtnetp0603info = []; function UploadPicture(args) { let self = (upIns = this); this.options = { title: "图片空间", content: tpl, width: 800, height: 536, modal: true, closed: true, closable: true, minimizable: false, maximizable: false, collapsible: false, resizable: false, data: null, onBeforeClose: function() {} }; this.args = args; this.imgSrc = this.args.imgSrc rootPath = this.args.rootPath; this.selectItem = false; this.imageServer = rhtComm.getRhtOptionValue('*','SYS','SYS_IMAGE_SERVER',''); Window.call(this, this.options); } inherits(UploadPicture, Window); UploadPicture.prototype.init = function() { let self = this; // let tree = { // data: [], // actions: { // onClick: function(event, treeNode) { // upIns.showPicture(treeNode.imgsrc || ""); // currentCheckedNode = treeNode; // upIns.pictureClick(); // upIns.createNavigator(treeNodes, treeNode.id); // } // } // }; // this.register("tree", "tree_upload", tree); setTimeout(function() { let eventsOpts = [ { elements: $(".upload"), eventsType: "click", eventFn: upIns.uploadingFile }, // { // elements: $(".createFolder"), // eventsType: "click", // eventFn: upIns.createFolder // }, // { // elements: $(".deletefile"), // eventsType: "click", // eventFn: upIns.deleteFile // }, { elements: $("#window_confirm"), eventsType: "click", eventFn: upIns.windowConfirm }, { elements: $("#window_cancel"), eventsType: "click", eventFn: upIns.windowCancel } ]; // upIns.refreshZtree(); eventsOpts.forEach(function(val) { upIns.bindingEvents(val); }); // upIns.bindingSearch(); // upIns.bindCreateTpl(); upIns.showPicture(upIns.imgSrc) }, 500); }; // function getLowerCaseData(dataRow) { // let data = {}; // for (let key in dataRow) { // data[key.toLowerCase()] = dataRow[key]; // } // return data; // } // //导航查找排列 // function findTreeNavigation(dataSource, treeId) { // dataSource.forEach(function(val) { // if (val.id === treeId) { // navigatorSort.push(val); // if (val.pId) { // findTreeNavigation(dataSource, val.pId); // } // } // }); // return navigatorSort; // } // //刷新ztree数据 // UploadPicture.prototype.refreshZtree = function() { // let param = { rootpath: rootPath }; // /* // bizService.fileQuery(param, function(type, res) { // checkedPicture = []; // res.forEach(function(val, index) { // val.pId = val.pid; // }); // treeNodes = res; // upIns.vm["tree_upload"].reset(res); // //定位到查找的文件夹地方 // let domNode = upIns.vm["tree_upload"].getNodesByFilter(function(node) { // return node.name.indexOf(currentCheckedNode.name) > -1; // }, true); // upIns.vm["tree_upload"].setSelect(domNode); // res.forEach(function(val) { // if (val.id === currentCheckedNode.id) { // //刷新视图层 // upIns.showPicture(val.imgsrc); // } // }); // upIns.pictureClick(); // }); // */ // Service.queryPicture(param, function(type, res) { // checkedPicture = []; // res.forEach(function(val, index) { // val.pId = val.pid; // }); // treeNodes = res; // upIns.vm["tree_upload"].reset(res); // //定位到查找的文件夹地方 // let domNode = upIns.vm["tree_upload"].getNodesByFilter(function(node) { // return node.name.indexOf(currentCheckedNode.name) > -1; // }, true); // upIns.vm["tree_upload"].setSelect(domNode); // res.forEach(function(val) { // if (val.id === currentCheckedNode.id) { // //刷新视图层 // upIns.showPicture(val.imgsrc); // } // }); // upIns.pictureClick(); // }); // }; //navigator 导航 // UploadPicture.prototype.createNavigator = function(dataSource, treeId) { // navigatorSort = []; // let sList = findTreeNavigation(dataSource, treeId).reverse(); // let navp = $(".file_path"); // let cSpan = []; // navp.children().remove(); // sList.forEach(function(val, index) { // let str = "" + val.name + " > "; // if (index === sList.length - 1) { // str = "" + val.name + ""; // } // cSpan.push(str); // }); // navp.append(cSpan.join("")); // //计算总长度是否超出 // let allSpan = navp.find("span"); // let allSpanWidth = 50; // let navWidth = navp.width(); // let z = 0; // for (let i = allSpan.length - 1; i > -1; i--) { // let spanWidth = allSpan.eq(i).width(); // allSpanWidth += spanWidth; // if (allSpanWidth > navWidth) { // z = i + 1; // break; // } // } // if (navp.width() < allSpanWidth) { // navp // .find("span:first") // .before( // ' << ' // ); // for (let t = 0; t < z; t++) { // allSpan.eq(t).remove(); // $(".navmode").append(cSpan[t]); // } // } // upIns.bindingEvents({ // elements: navp.find("span"), // eventsType: "click", // eventFn: function(e) { // let id = $(e.currentTarget).attr("data-id"); // //定位到查找的文件夹地方 // let domNode = upIns.vm["tree_upload"].getNodesByFilter(function(node) { // return node.id.indexOf(id) > -1; // }, true); // upIns.vm["tree_upload"].setSelect(domNode); // upIns.showPicture(domNode ? domNode.imgsrc : ""); // upIns.createNavigator(treeNodes, id); // } // }); // upIns.bindingEvents({ // elements: navp.find("stronge"), // eventsType: "click", // eventFn: function(e) { // if (navp.find(".navmode").css("display") === "none") { // navp.find(".navmode").css("display", "flex"); // return; // } // navp.find(".navmode").css("display", "none"); // } // }); // }; //选择图片逻辑 // UploadPicture.prototype.pictureClick = function() { // let upIns = this; // if ($(".picture_view").length > 0) { // upIns.bindingEvents({ // elements: $(".picture_view"), // eventsType: "click", // eventFn: function(ev) { // let targetElement = $(ev.currentTarget); // let currentImageMsg = { // fileid: targetElement.find("img").attr("data-id"), // imgsrc: targetElement.find("img").attr("src") // }; // if (targetElement.attr("data-type") === "checked") { // targetElement.css("boxShadow", "").attr("data-type", ""); // } else { // targetElement // .css("boxShadow", "0px 0px 0px 2px #4886cd") // .attr("data-type", "checked"); // } // for (let i = checkedPicture.length - 1; i > -1; i--) { // if (checkedPicture[i].fileid === currentImageMsg.fileid) { // checkedPicture.splice(i, 1); // return; // } // if (i === 0) { // checkedPicture.push(currentImageMsg); // } // } // if (checkedPicture.length < 1) { // checkedPicture.push(currentImageMsg); // } // console.log(checkedPicture); // } // }); // } // }; //绑定事件 UploadPicture.prototype.bindingEvents = function(options) { if (options.eventsType === "click") { if (options && typeof options === "object" && !Array.isArray(options)) { options.elements.on(options.eventsType, function(ev) { options.eventFn(ev); }); } else { throw "options is not defined"; } } else if (options.eventsType === "keyup") { options.elements[options.eventsType](function(ev) { options.eventFn(ev); }); } }; //获取图片数据展示图片 UploadPicture.prototype.showPicture = function(imgSrc) { let pictureEle = $(".picture_panel"); pictureEle.children().remove(); if(imgSrc !== '') { let str = '
' + "
" + "
" + "
"; pictureEle.append(str); }else { let str = '
' + "暂无图片" + "
"; pictureEle.append(str); } }; //点击上传方法 UploadPicture.prototype.uploadingFile = function(ev) { let option = { customUrl:upIns.imageServer + 'api/storage/file', data: { dir: currentCheckedNode.filepath || rootPath, hasFileId: "0", maxSize: 1024, multiple: true, onBeforeUpload: function(data, file) { upIns.args.onBeforeUpload ? upIns.args.onBeforeUpload(data, file) : ""; } } }; let uploadInstance = new uploadpictureWindow(option, function(response) { rtnetp0603info = response; //成功上传之后的回调 //upIns.refreshZtree(); upIns.showPicture(upIns.imageServer + 'api/storage/file/' + eval("(" + response + ")").data[0]) }); uploadInstance.open(); }; //搜索框搜索 // UploadPicture.prototype.bindingSearch = function() { // this.bindingEvents({ // elements: $(".search_input input"), // eventsType: "keyup", // eventFn: function(ev) { // let inputVal = $(ev.currentTarget).val(); // //回车键 // if (ev.keyCode === 13) { // //定位到查找的文件夹地方 // let domNode = upIns.vm["tree_upload"].getNodesByFilter(function( // node // ) { // return node.name.indexOf(ev.currentTarget.value) > -1; // }, // true); // upIns.vm["tree_upload"].setSelect(domNode); // } // } // }); // }; //创建新文件夹的弹窗 // UploadPicture.prototype.bindCreateTpl = function() { // this.bindingEvents({ // elements: $(".folder_cofirm span"), // eventsType: "click", // eventFn: function(e) { // //点击确定 // if ($(e.currentTarget).attr("data-set") == "confirm") { // let folderName = $("#folderName").val(); // upIns.createFolder(folderName); // $("#folderName").val(""); // } else { // upIns.createFolder(); // } // } // }); // }; //打开窗体 UploadPicture.prototype.open = function() { let self = this; Window.prototype.open.call(self); }; //确定后关闭窗体 UploadPicture.prototype.windowConfirm = function() { upIns.close(); //upIns.args && upIns.args.confirm ? upIns.args.confirm(checkedPicture) : ""; upIns.args && upIns.args.confirm ? upIns.args.confirm(rtnetp0603info) : ""; }; //取消后关闭窗体 UploadPicture.prototype.windowCancel = function() { upIns.close(); //upIns.args && upIns.args.cancel ? upIns.args.cancel() : ""; upIns.args && upIns.args.confirm ? upIns.args.cancel(rtnetp0603info) : ""; }; return UploadPicture; });