/** appendbase 追加内容到基本元素中 * **/ UE.plugins["appendbase"] = function() { let me = this; me.commands["appendbase"] = { execCommand: function(cmd,text) { let range = me.selection.getRange(); //判断是否在基本元素中 let startNode = range.startContainer; let endNode = range.endContainer; let startA = UE.dom.domUtils.findParentByTagName(startNode, "a", true); let endA = UE.dom.domUtils.findParentByTagName(endNode, "a", true); if(!startA || startA.getAttribute("class").indexOf("input") == -1){ return false; } if(!endA || endA.getAttribute("class").indexOf("input") == -1){ return false; } //在同一个元素内才插入 if(startA == endA){ let dataType = startA.getAttribute("dataType"); //文本02 多行文本03 数字04 if(dataType == "02"){ // startA.innerHTML = startA.innerHTML+text; // insertAfterText(startA, text) let value = startA.innerHTML; let newValue = value.substring(0, range.startOffset) + text + value.substring(range.endOffset, value.length); startA.innerHTML = newValue; } else if(dataType == "03"){ let textarea = $(startA).find("textarea"); textarea.insertAtCaret(text); } } } } }; //end UE.plugins["appendbase"] /** amendment 修订 * **/ UE.plugins["amendment"] = function() { let me = this; // emrRemark.init(me); function getValue(ele){ let value = ""; if(ele){ if(ele.nodeName == "TEXTAREA"){ value = ele.textContent; } else if(ele.nodeName == "INPUT"){ value = ele.value; } else { value = ele.textContent; } } return value; } function beforeInputEvent(e){ // console.log("beforeInputEvent") // console.log(e) let ele = e.target; // console.log(ele) // console.log(util) if(ele){ // 获取到a标签 let inputA = emrRemark.getParentA(ele); if(inputA){ let value = getValue(ele); emrRemark.setData(inputA,value); } } } function inputEvent(e){ // console.log("amendment.inputEvent") let ele = e.target; // console.log(ele) // showEleRemark(ele); if(ele){ let inputA = emrRemark.getParentA(ele); if(inputA){ emrRemark.showAllRemark(); } } } me.commands["amendment"] = { execCommand: function(cmd,ui) { me.options.amendment = !me.options.amendment; // console.log(me.options.amendment) if(ui.target){ if(me.options.amendment){ me.document.addEventListener("beforeinput", beforeInputEvent), me.document.addEventListener("input", inputEvent); ui.target.classList.add("edui-active"); } else { me.document.removeEventListener("beforeinput", beforeInputEvent), me.document.removeEventListener("input", inputEvent); ui.target.classList.remove("edui-active"); } emrRemark.showAllRemark(); } } } }; //end UE.plugins["amendment"] /** annotations 批注 * **/ UE.plugins["annotations"] = function() { let me = this; me.commands["annotations"] = { execCommand: function(cmd,ui) { me.options.annotations = !me.options.annotations; // console.log(me.options.annotations) if(ui.target){ if(me.options.annotations){ ui.target.classList.add("edui-active"); me.document.addEventListener("input", emrRemark.annotationsInput); } else { ui.target.classList.remove("edui-active"); me.document.removeEventListener("input", emrRemark.annotationsInput); } emrRemark.showAllRemark(); } } } }; //end UE.plugins["annotations"] /** addannotations 添加批注 * **/ UE.plugins["addannotations"] = function() { let me = this; function createSpan(){ let span = me.document.createElement("label"); span.classList.add("note"); span.setAttribute("note","true"); span.setAttribute("data-original",""); span.setAttribute("data-create-time", util.formatDate(new Date())); span.setAttribute("data-creator", me.options.userName); // span.setAttribute("data-id", dataId); return span; } function setAndShowRemark(){ if(!me.options.annotations){ me.options.annotations = !me.options.annotations; me.document.addEventListener("input", emrRemark.annotationsInput); // 设置批注为选中状态 let toolbar = document.querySelector(".edui-for-annotations"); if(toolbar && toolbar.firstChild){ toolbar.firstChild.classList.add("edui-active"); } } emrRemark.showAllRemark(); } me.commands["addannotations"] = { execCommand: function(cmd,ui) { // console.log("addannotations") let range = me.selection.getRange().adjustmentBoundary(); // console.log(range.startContainer) // 处理牙位 let startA = emrRemark.getParentA(range.startContainer); let endA = emrRemark.getParentA(range.endContainer); // console.log(startA); // console.log(endA); // 同一个牙位 if(startA && endA && startA == endA && startA.getAttribute("datatype") == "tooth"){ let tooth = startA.querySelector(".tooth-all"); tooth.innerHTML = ''; setAndShowRemark(); return false; } // 处理牙位 end // 处理图片 if(startA && endA && startA == endA && startA.getAttribute("datatype") == "imgUpload"){ let note = me.document.createElement("label"); note.className = "note"; note.style.position="absolute"; // 是否可以单独remove而不需要其他处理 note.setAttribute("remove","true"); note.setAttribute("note","true"); note.setAttribute("data-create-time", util.formatDate(new Date())); note.setAttribute("data-creator", me.options.userName); note.setAttribute("data-original", ""); let cupload = startA.querySelector(".Cupload") cupload.prepend(note); setAndShowRemark(); // startA.innerHTML = ''; return false; } // 处理图片 end //若是未选择,就在当前位置插入节点 if(range.endOffset == range.startOffset){ range.insertNode(createSpan()); setAndShowRemark(); return; } //若是已经选择,走以下流程 // let endOffset = range.endOffset; // console.log(range); // 起始节点若是空的,跳过 let rangeNode = null; range.traversal(function(node){ let content = node.textContent; if(content && content.trim() && !rangeNode){ rangeNode = node; return false; } }); range.setStart(rangeNode,0); // console.log(rangeNode); // console.log(range); range.applyInlineStyle("label",{ "class":"note", "note":"true", "data-original":"", "data-create-time": util.formatDate(new Date()), "data-creator": me.options.userName }, null, true); // let text = startNode.textContent; // let selectText = ""; // let preText = text.substring(0,range.startOffset); // let suffText = ""; // // 若是选择同一个元素,则按位移量获取文本,若不是同一个元素,则以起始元素为准,结束位移量就是起始元素的结束位置 // if(range.startContainer == range.endContainer){ // selectText = text.substring(range.startOffset,endOffset); // suffText = text.substring(endOffset,text.length); // } else { // selectText = text.substring(range.startOffset,text.length); // } // let resultText = ''+selectText+''; // console.log("preText=="+preText); // console.log("selectText=="+selectText); // console.log("suffText=="+suffText); // console.log("resultText=="+resultText); // startNode.parentNode.innerHTML = startNode.parentNode.innerHTML.replace(selectText,resultText); // console.log(me.selection) me.selection.clearRange(); // debugger setAndShowRemark(); } } }; //end UE.plugins["addannotations"] /** 签名 * **/ UE.plugins["sign"] = function() { let me = this; me.commands["sign"] = { execCommand: function(cmd) { sign(me); } } };