index.js 6.8 KB

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