ue.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. /** appendbase 追加内容到基本元素中
  2. * **/
  3. UE.plugins["appendbase"] = function() {
  4. let me = this;
  5. me.commands["appendbase"] = {
  6. execCommand: function(cmd,text) {
  7. let range = me.selection.getRange();
  8. //判断是否在基本元素中
  9. let startNode = range.startContainer;
  10. let endNode = range.endContainer;
  11. let startA = UE.dom.domUtils.findParentByTagName(startNode, "a", true);
  12. let endA = UE.dom.domUtils.findParentByTagName(endNode, "a", true);
  13. if(!startA || startA.getAttribute("class").indexOf("input") == -1){
  14. return false;
  15. }
  16. if(!endA || endA.getAttribute("class").indexOf("input") == -1){
  17. return false;
  18. }
  19. //在同一个元素内才插入
  20. if(startA == endA){
  21. let dataType = startA.getAttribute("dataType");
  22. //文本02 多行文本03 数字04
  23. if(dataType == "02"){
  24. // startA.innerHTML = startA.innerHTML+text;
  25. // insertAfterText(startA, text)
  26. let value = startA.innerHTML;
  27. let newValue = value.substring(0, range.startOffset) + text + value.substring(range.endOffset, value.length);
  28. startA.innerHTML = newValue;
  29. } else if(dataType == "03"){
  30. let textarea = $(startA).find("textarea");
  31. textarea.insertAtCaret(text);
  32. }
  33. }
  34. }
  35. }
  36. };
  37. //end UE.plugins["appendbase"]
  38. /** amendment 修订
  39. * **/
  40. UE.plugins["amendment"] = function() {
  41. let me = this;
  42. // emrRemark.init(me);
  43. function getValue(ele){
  44. let value = "";
  45. if(ele){
  46. if(ele.nodeName == "TEXTAREA"){
  47. value = ele.textContent;
  48. } else if(ele.nodeName == "INPUT"){
  49. value = ele.value;
  50. } else {
  51. value = ele.textContent;
  52. }
  53. }
  54. return value;
  55. }
  56. function beforeInputEvent(e){
  57. // console.log("beforeInputEvent")
  58. // console.log(e)
  59. let ele = e.target;
  60. // console.log(ele)
  61. // console.log(util)
  62. if(ele){
  63. // 获取到a标签
  64. let inputA = emrRemark.getParentA(ele);
  65. if(inputA){
  66. let value = getValue(ele);
  67. emrRemark.setData(inputA,value);
  68. }
  69. }
  70. }
  71. function inputEvent(e){
  72. // console.log("amendment.inputEvent")
  73. let ele = e.target;
  74. // console.log(ele)
  75. // showEleRemark(ele);
  76. if(ele){
  77. let inputA = emrRemark.getParentA(ele);
  78. if(inputA){
  79. emrRemark.showAllRemark();
  80. }
  81. }
  82. }
  83. me.commands["amendment"] = {
  84. execCommand: function(cmd,ui) {
  85. me.options.amendment = !me.options.amendment;
  86. // console.log(me.options.amendment)
  87. if(ui.target){
  88. if(me.options.amendment){
  89. me.document.addEventListener("beforeinput", beforeInputEvent),
  90. me.document.addEventListener("input", inputEvent);
  91. ui.target.classList.add("edui-active");
  92. } else {
  93. me.document.removeEventListener("beforeinput", beforeInputEvent),
  94. me.document.removeEventListener("input", inputEvent);
  95. ui.target.classList.remove("edui-active");
  96. }
  97. emrRemark.showAllRemark();
  98. }
  99. }
  100. }
  101. };
  102. //end UE.plugins["amendment"]
  103. /** annotations 批注
  104. * **/
  105. UE.plugins["annotations"] = function() {
  106. let me = this;
  107. me.commands["annotations"] = {
  108. execCommand: function(cmd,ui) {
  109. me.options.annotations = !me.options.annotations;
  110. // console.log(me.options.annotations)
  111. if(ui.target){
  112. if(me.options.annotations){
  113. ui.target.classList.add("edui-active");
  114. me.document.addEventListener("input", emrRemark.annotationsInput);
  115. } else {
  116. ui.target.classList.remove("edui-active");
  117. me.document.removeEventListener("input", emrRemark.annotationsInput);
  118. }
  119. emrRemark.showAllRemark();
  120. }
  121. }
  122. }
  123. };
  124. //end UE.plugins["annotations"]
  125. /** addannotations 添加批注
  126. * **/
  127. UE.plugins["addannotations"] = function() {
  128. let me = this;
  129. function createSpan(){
  130. let span = me.document.createElement("label");
  131. span.classList.add("note");
  132. span.setAttribute("note","true");
  133. span.setAttribute("data-original","");
  134. span.setAttribute("data-create-time", util.formatDate(new Date()));
  135. span.setAttribute("data-creator", me.options.userName);
  136. // span.setAttribute("data-id", dataId);
  137. return span;
  138. }
  139. function setAndShowRemark(){
  140. if(!me.options.annotations){
  141. me.options.annotations = !me.options.annotations;
  142. me.document.addEventListener("input", emrRemark.annotationsInput);
  143. // 设置批注为选中状态
  144. let toolbar = document.querySelector(".edui-for-annotations");
  145. if(toolbar && toolbar.firstChild){
  146. toolbar.firstChild.classList.add("edui-active");
  147. }
  148. }
  149. emrRemark.showAllRemark();
  150. }
  151. me.commands["addannotations"] = {
  152. execCommand: function(cmd,ui) {
  153. // console.log("addannotations")
  154. let range = me.selection.getRange().adjustmentBoundary();
  155. // console.log(range.startContainer)
  156. // 处理牙位
  157. let startA = emrRemark.getParentA(range.startContainer);
  158. let endA = emrRemark.getParentA(range.endContainer);
  159. // console.log(startA);
  160. // console.log(endA);
  161. // 同一个牙位
  162. if(startA && endA && startA == endA && startA.getAttribute("datatype") == "tooth"){
  163. let tooth = startA.querySelector(".tooth-all");
  164. tooth.innerHTML = '<label class="note" note="true" data-create-time="'+util.formatDate(new Date())
  165. +'" data-creator="'+me.options.userName+'" data-original="">'+tooth.innerHTML+'</label>';
  166. setAndShowRemark();
  167. return false;
  168. }
  169. // 处理牙位 end
  170. // 处理图片
  171. if(startA && endA && startA == endA && startA.getAttribute("datatype") == "imgUpload"){
  172. let note = me.document.createElement("label");
  173. note.className = "note";
  174. note.style.position="absolute";
  175. // 是否可以单独remove而不需要其他处理
  176. note.setAttribute("remove","true");
  177. note.setAttribute("note","true");
  178. note.setAttribute("data-create-time", util.formatDate(new Date()));
  179. note.setAttribute("data-creator", me.options.userName);
  180. note.setAttribute("data-original", "");
  181. let cupload = startA.querySelector(".Cupload")
  182. cupload.prepend(note);
  183. setAndShowRemark();
  184. // startA.innerHTML = '<label class="note" note="true" data-create-time="'+util.formatDate(new Date())
  185. // +'" data-creator="'+me.options.userName+'" data-original="">'+startA.innerHTML+'</label>';
  186. return false;
  187. }
  188. // 处理图片 end
  189. //若是未选择,就在当前位置插入节点
  190. if(range.endOffset == range.startOffset){
  191. range.insertNode(createSpan());
  192. setAndShowRemark();
  193. return;
  194. }
  195. //若是已经选择,走以下流程
  196. // let endOffset = range.endOffset;
  197. // console.log(range);
  198. // 起始节点若是空的,跳过
  199. let rangeNode = null;
  200. range.traversal(function(node){
  201. let content = node.textContent;
  202. if(content && content.trim() && !rangeNode){
  203. rangeNode = node;
  204. return false;
  205. }
  206. });
  207. range.setStart(rangeNode,0);
  208. // console.log(rangeNode);
  209. // console.log(range);
  210. range.applyInlineStyle("label",{
  211. "class":"note",
  212. "note":"true",
  213. "data-original":"",
  214. "data-create-time": util.formatDate(new Date()),
  215. "data-creator": me.options.userName
  216. }, null, true);
  217. // let text = startNode.textContent;
  218. // let selectText = "";
  219. // let preText = text.substring(0,range.startOffset);
  220. // let suffText = "";
  221. // // 若是选择同一个元素,则按位移量获取文本,若不是同一个元素,则以起始元素为准,结束位移量就是起始元素的结束位置
  222. // if(range.startContainer == range.endContainer){
  223. // selectText = text.substring(range.startOffset,endOffset);
  224. // suffText = text.substring(endOffset,text.length);
  225. // } else {
  226. // selectText = text.substring(range.startOffset,text.length);
  227. // }
  228. // let resultText = '<span class="note" note="true" data-create-time="'+datetime
  229. // +'" data-creator="'+me.options.userName+'" data-id="'+remarkId+'">'+selectText+'</span>';
  230. // console.log("preText=="+preText);
  231. // console.log("selectText=="+selectText);
  232. // console.log("suffText=="+suffText);
  233. // console.log("resultText=="+resultText);
  234. // startNode.parentNode.innerHTML = startNode.parentNode.innerHTML.replace(selectText,resultText);
  235. // console.log(me.selection)
  236. me.selection.clearRange();
  237. // debugger
  238. setAndShowRemark();
  239. }
  240. }
  241. };
  242. //end UE.plugins["addannotations"]
  243. /** 签名
  244. * **/
  245. UE.plugins["sign"] = function() {
  246. let me = this;
  247. me.commands["sign"] = {
  248. execCommand: function(cmd) {
  249. sign(me);
  250. }
  251. }
  252. };