index.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import {projectData,handleData,highlight} from '@/views/project/patentCollection/components/mixins'
  2. import { mapGetters } from "vuex";
  3. export const patentDetails={
  4. mixins:[projectData,handleData,highlight],
  5. props:{
  6. patent:{
  7. default:()=>{
  8. return {}
  9. }
  10. },
  11. evidence:{},
  12. signPatentNo:{},
  13. reportType:{}
  14. },
  15. data() {
  16. return {
  17. name:'0',
  18. anchorOffset:null
  19. }
  20. },
  21. computed:{
  22. ...mapGetters(["contextMenu"]),
  23. textStyle(){
  24. return this.$store.state.patent.style
  25. },
  26. },
  27. methods: {
  28. setStyle(){
  29. if(!this.textStyle){
  30. return false
  31. }
  32. return 'font-size:'+this.textStyle.size+'px;line-height:'+this.textStyle.lineHeight+';padding:'+this.textStyle.padding[0]+'px '+this.textStyle.padding[1]+'px '+this.textStyle.padding[2]+'px '+this.textStyle.padding[3]+'px'
  33. },
  34. //鼠标弹起
  35. mouseup(e){
  36. let selectObj = document.getSelection();
  37. this.anchorOffset = 0;
  38. let temSelectObj = this.getSelectobj(selectObj);
  39. var tempdt = this.getColumnName(selectObj.anchorNode);
  40. var currentSelectObj = {}
  41. if (tempdt != undefined && selectObj.toString() != '') {
  42. currentSelectObj = temSelectObj;
  43. currentSelectObj.color = this.contextMenu.mark.color;
  44. currentSelectObj.Type = 0;
  45. currentSelectObj.patentNo = this.patent.patentNo
  46. // rangeId(专题库id/报告id)
  47. currentSelectObj.projectId = this.projectId
  48. // 创建来源(默认0/专题库1/报告2)
  49. currentSelectObj.createFrom = 1
  50. currentSelectObj.remark = ''
  51. }
  52. if (currentSelectObj.Id) {
  53. var a = {}
  54. a.Id = currentSelectObj.Id//划词生成的ID
  55. a.patentNo = currentSelectObj.patentNo//专利号
  56. a.signPatentNo = this.signPatentNo//标的专利号
  57. a.text = currentSelectObj.text//选中的文本
  58. a.projectId = currentSelectObj.projectId//项目Id
  59. a.column = currentSelectObj.column//选中文本所在栏位
  60. a.position = currentSelectObj.index//选中文本开始位置
  61. a.id = null//对比记录Id
  62. a.remark=null//备注
  63. a.markType = 1//高亮类型
  64. a.markColor = ''//高亮类型
  65. // a.color = this.currentSelectObj.color
  66. a.createFrom =this.projectId? 1:0//来源
  67. a.literatureId = this.evidence?this.evidence.id:null
  68. this.showMenu(e)
  69. this.$store.commit("SET_PATENT_INDEX", a)
  70. }
  71. },
  72. //打开弹窗
  73. showMenu(e){
  74. var menuContent = null
  75. if(this.reportType == 1 || this.reportType == 2){
  76. menuContent=[
  77. {
  78. name: "对比",
  79. method: "contrast",
  80. }
  81. ]
  82. }
  83. this.$store.commit("SET_CONTEXT_MENU", {
  84. clientX:e.pageX,
  85. clientY:e.pageY,
  86. displayContextMenu:true,
  87. menuContent:menuContent
  88. })
  89. },
  90. //获取选中的文本信息
  91. getSelectobj(selectObj) {
  92. var temNode = selectObj.anchorNode;
  93. var a = temNode.parentElement
  94. NotIncludeDataType(a)
  95. function NotIncludeDataType(node) {
  96. if(!node){
  97. return false
  98. }
  99. if (node.getAttribute("data-type") != null) {
  100. temNode = node
  101. } else {
  102. NotIncludeDataType(node.parentElement);
  103. }
  104. }
  105. this.getColumn(temNode, selectObj);
  106. if(temNode.nodeType == 3){
  107. return false
  108. }
  109. this.isFirst = true
  110. return { "Id": this.uuid(), "column": temNode.getAttribute("data-type"), "index": this.anchorOffset, "text": selectObj.toString(), 'temNode': temNode.innerHTML };
  111. },
  112. //获取ID
  113. uuid() {
  114. var s = [];
  115. var hexDigits = "0123456789abcdef";
  116. for (var i = 0; i < 36; i++) {
  117. s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  118. }
  119. s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
  120. s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
  121. s[8] = s[13] = s[18] = s[23] = "-";
  122. var uuid = s.join("");
  123. return uuid;
  124. },
  125. //获取开始位置
  126. getColumn(node, selectObj) {
  127. var baseNode = this.getColumnNode(node);
  128. var anchorNodePosition = this.getPosition(baseNode, selectObj.anchorNode, selectObj.anchorOffset);
  129. var focusNodePosition = this.getPosition(baseNode, selectObj.focusNode, selectObj.focusOffset);
  130. var num = Math.min(anchorNodePosition, focusNodePosition)
  131. this.anchorOffset = num
  132. return true;
  133. },
  134. //获取节点所在的栏位节点
  135. getColumnNode(node) {
  136. if (node != null) {
  137. if(node.nodeType == 9){
  138. return false
  139. }
  140. if (node.nodeType != 3 && node.getAttribute("data-type") != null) {
  141. return node;
  142. }else {
  143. if (node == document.root) {
  144. return node;
  145. } else {
  146. return this.getColumnNode(node.parentNode);
  147. }
  148. }
  149. }
  150. },
  151. //根据节点获取给定node中offset位置在栏位中的实际位置
  152. getPosition(baseNode, node, offset) {
  153. let path = [];
  154. this.getNodes(baseNode, path);
  155. let retIdx = 0;
  156. for (let i = 0; i < path.length; i++){
  157. if (path[i] == node) {
  158. retIdx += offset;
  159. return retIdx;
  160. } else {
  161. if (path[i].nodeType == 3) {
  162. retIdx += path[i].nodeValue.length;
  163. }
  164. }
  165. }
  166. },
  167. // 拿到所有类型的节点
  168. getNodes(baseNode, path) {
  169. var temPath = path;
  170. if(baseNode != null){
  171. temPath.push(baseNode);
  172. if(baseNode.childNodes && baseNode.childNodes.length >0){
  173. for(let i=0;i<baseNode.childNodes.length;i++){
  174. this.getNodes(baseNode.childNodes[i],temPath);
  175. }
  176. }
  177. }
  178. },
  179. //获取所选文本所在节点
  180. getColumnName(el) {
  181. let root = el;
  182. if (el == undefined) {
  183. return undefined;
  184. }
  185. if (!(el instanceof HTMLElement)) {
  186. root = el.parentElement;
  187. }
  188. let dt = root.getAttribute("data-Type");
  189. if (dt != undefined) {
  190. return root;
  191. }
  192. return dt = this.getColumnName(root.parentElement);
  193. },
  194. },
  195. }