mixins.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. import { patentKeywordsHighlight } from '../../components/mixins'
  2. const colourBlend = (c1, c2, ratio) => {
  3. ratio = Math.max(Math.min(Number(ratio), 1), 0)
  4. let r1 = parseInt(c1.substring(1, 3), 16)
  5. let g1 = parseInt(c1.substring(3, 5), 16)
  6. let b1 = parseInt(c1.substring(5, 7), 16)
  7. let r2 = parseInt(c2.substring(1, 3), 16)
  8. let g2 = parseInt(c2.substring(3, 5), 16)
  9. let b2 = parseInt(c2.substring(5, 7), 16)
  10. let r = Math.round(r1 * (1 - ratio) + r2 * ratio)
  11. let g = Math.round(g1 * (1 - ratio) + g2 * ratio)
  12. let b = Math.round(b1 * (1 - ratio) + b2 * ratio)
  13. r = ('0' + (r || 0).toString(16)).slice(-2)
  14. g = ('0' + (g || 0).toString(16)).slice(-2)
  15. b = ('0' + (b || 0).toString(16)).slice(-2)
  16. return '#' + r + g + b
  17. }
  18. export const commonMixins = {
  19. props: ['patent', 'reportId', 'patentId','projectId','patentNo'],
  20. mixins: [patentKeywordsHighlight],
  21. data() {
  22. return {
  23. style:{
  24. height:'100%',
  25. width:'100%'
  26. },
  27. size:{}
  28. }
  29. },
  30. mounted() {
  31. window.addEventListener('resize', this.changeWidth)
  32. },
  33. methods: {
  34. changeWidth() {
  35. var dom = document.querySelector('.picture')
  36. var maxWidth = null
  37. var maxHeight = null
  38. if(dom){
  39. maxWidth = dom.clientWidth - 30
  40. maxHeight = 200
  41. }else{
  42. maxWidth = 120
  43. maxHeight = 150
  44. }
  45. var size = JSON.parse(JSON.stringify(this.size))
  46. const scale = Math.min(maxWidth / size.width, maxHeight / size.height);
  47. size.width=scale * size.width
  48. size.height=scale * size.height
  49. this.$set(this.style,'width',size.width+'px')
  50. this.$set(this.style, 'height', size.height + 'px')
  51. if (this.patent) {
  52. this.$set(this.patent,'imgWidth',size.width+'px')
  53. this.$set(this.patent,'imgHeight',size.height+'px')
  54. }
  55. },
  56. getImagePath(url) {
  57. if (!url) {
  58. return ''
  59. }
  60. if(this.reportId){
  61. var url1 = this.$p2 + url
  62. }else{
  63. var url1 = url
  64. }
  65. return url1
  66. },
  67. getImagePath1(patent) {
  68. if(Object.keys(patent).length==0){
  69. return ''
  70. }
  71. if(!patent.abstractPath){
  72. return this.getErrorImage(patent)
  73. }
  74. var url = this.$p2 + patent.abstractPath
  75. this.$set(patent,'abstractPath2',url)
  76. this.getHeight(url, patent)
  77. return url
  78. },
  79. async getHeight(url,patent){
  80. let size = await this.getImageSize(url);
  81. var dom = document.querySelector('.picture')
  82. var maxWidth = null
  83. var maxHeight = null
  84. if (dom) {
  85. maxWidth = dom.clientWidth -5
  86. maxHeight = dom.clientHeight -5
  87. }else{
  88. maxWidth = 120
  89. maxHeight = 150
  90. }
  91. const scale = Math.min(maxWidth / size.width, maxHeight / size.height);
  92. this.size = size
  93. size.width=scale * size.width
  94. size.height=scale * size.height
  95. this.$set(this.style,'width',size.width+'px')
  96. this.$set(this.style, 'height', size.height + 'px')
  97. this.$set(patent,'imgWidth',size.width+'px')
  98. this.$set(patent,'imgHeight',size.height+'px')
  99. return size
  100. },
  101. getImageSize(url) {
  102. return new Promise(function (resolve, reject) {
  103. let image = new Image();
  104. image.onload = function () {
  105. resolve({
  106. width: image.width,
  107. height: image.height
  108. });
  109. };
  110. image.onerror = function () {
  111. // reject(new Error('error'));
  112. };
  113. image.src = url;
  114. });
  115. },
  116. getErrorImage(patent){
  117. if(Object.keys(patent).length==0){
  118. return ''
  119. }
  120. if(!patent.publicNo){
  121. return ''
  122. }
  123. var cc = patent.publicNo.substring(0,2)
  124. if(patent.publicAccreditDate){
  125. var date = patent.publicAccreditDate.replace(/-/g,'')
  126. }else{
  127. var date = patent.publicDate.replace(/-/g,'')
  128. }
  129. var NR = patent.publicNo.substring(2,patent.publicNo.length)
  130. var KD = patent.publicNo.substring(patent.publicNo.length-2,patent.publicNo.length)
  131. var a = 'http://worldwide.espacenet.com/espacenetImage.jpg?flavour=firstPageClipping&locale=en_EP&FT=D&date='+ date +'&CC='+ cc +'&NR='+ NR +'&KD='+ KD +'&bg='
  132. return a
  133. }
  134. }
  135. }
  136. export const addContrast = {
  137. props:['reportId','activeName','evidenceFlieId','signPatentNo','reportType','taskId','type','projectId'],
  138. data() {
  139. return {
  140. mX: 0,
  141. mY: 0,
  142. isSelecting: false,
  143. anchorOffset: 0,
  144. currentSelectObj:{},
  145. contrast: {},
  146. currentColor:null,
  147. duiBiCurrentSelectObj: {},
  148. name:this.activeName,
  149. }
  150. },
  151. computed: {
  152. index() {
  153. return JSON.stringify(this.$store.state.patent.index)
  154. },
  155. contrastList() {
  156. return this.$store.state.report.contrastList
  157. },
  158. opinionContrastList() {
  159. return this.$store.state.report.opinionContrastList
  160. },
  161. },
  162. watch: {
  163. index(val) {
  164. var index1 = JSON.parse(val)
  165. this.currentColor = index1.color
  166. },
  167. activeName(val) {
  168. this.name = val
  169. },
  170. },
  171. mounted() {
  172. window.pizhu = this.pizhu
  173. window.hiddenPizhu = this.hiddenPizhu
  174. window.selectMark = this.selectMark
  175. window.addDuiBi = this.addDuiBi
  176. },
  177. methods: {
  178. // 点击对比按钮
  179. addDuiBi() {
  180. this.duiBiCurrentSelectObj=this.$store.state.patent.index
  181. // open打开弹窗
  182. if (this.duiBiCurrentSelectObj.Id) {
  183. this.duiBiCurrentSelectObj.patentNo = this.duiBiCurrentSelectObj.pno
  184. this.$emit('openContrast',this.duiBiCurrentSelectObj)
  185. }
  186. },
  187. //点击图标回显数据
  188. selectMark(id, selectType) {
  189. if(!this.$reportPermission(this.reportId,[0,1])){
  190. return false
  191. }
  192. var Id = id.substring(1,id.length)
  193. if (selectType=='p') {
  194. var index = this.piZhuContrastList.findIndex(item => {
  195. if (item.id == Id) {
  196. // 清空currentSelectObj,否则Id与id同时存在
  197. this.currentSelectObj = {}
  198. this.$store.commit("SET_PATENT_INDEX", this.currentSelectObj)
  199. this.contrast = item
  200. this.$store.commit('SET_PATENT_INDEX', this.contrast)
  201. }
  202. return item.id == Id
  203. })
  204. if (index != -1) {
  205. this.showPizhu()
  206. }
  207. } else if (selectType == 'c') {
  208. let a=this.contrastList.find(item => {
  209. return item.id==Id
  210. })
  211. this.$emit('openContrast', a)
  212. } else if (selectType == 'o') {
  213. let a=this.opinionContrastList.find(item => {
  214. return item.id==Id
  215. })
  216. this.$emit('openOpinioncontrast', a)
  217. }
  218. },
  219. mousemove(e) {
  220. this.mX = e.pageX;
  221. this.mY = e.pageY;
  222. },
  223. mouseup(e) {
  224. sessionStorage.mY = this.mY
  225. sessionStorage.mX = this.mX
  226. this.isSelecting = true;
  227. if (this.isSelecting) {
  228. this.isSelecting = false;
  229. let selectObj = document.getSelection();
  230. this.anchorOffset = 0;
  231. let temSelectObj = this.getSelectobj(selectObj);
  232. var tempdt = this.getColumnName(selectObj.anchorNode);
  233. if (tempdt != undefined && selectObj.toString() != '') {
  234. this.currentSelectObj = temSelectObj;
  235. this.currentSelectObj.color = this.currentColor;
  236. this.currentSelectObj.Type = 0;
  237. this.currentSelectObj.patentNo = this.patent.patentNo
  238. // rangeId(专题库id/报告id)
  239. this.currentSelectObj.rangeId = this.reportId
  240. // 创建来源(默认0/专题库1/报告2)
  241. this.currentSelectObj.createFrom = 2
  242. // this.showPizhu();
  243. this.currentSelectObj.remark = ''
  244. }
  245. else {
  246. this.currentSelectObj = {};
  247. this.$store.commit("SET_CONTEXT_MENU",
  248. {
  249. displayContextMenu: false,
  250. }
  251. )
  252. }
  253. if (this.currentSelectObj.Id) {
  254. var a = JSON.parse(this.index)
  255. a.Id = this.currentSelectObj.Id
  256. a.patentNo = this.currentSelectObj.patentNo
  257. a.pno = this.patent.patentNo
  258. a.text = this.currentSelectObj.text
  259. a.rangeId = this.reportId
  260. a.scratchField = this.currentSelectObj.column
  261. a.position = this.currentSelectObj.index
  262. a.id = null
  263. a.remark = null
  264. // a.color = this.currentSelectObj.color
  265. a.createFrom = this.reportId?2:0
  266. a.Type = 0
  267. a.rightSort=this.currentSelectObj.rightSort
  268. a.evidenceFlieId = this.evidenceFlieId
  269. a.signPatentNo = this.signPatentNo
  270. a.reportType = this.reportType ?this.reportType:this.type
  271. a.taskId = this.taskId
  272. a.rightPosition = this.currentSelectObj.rightPosition
  273. this.$store.commit("SET_PATENT_INDEX", a)
  274. this.showPizhu()
  275. // this.$store.commit("SET_CONTEXT_MENU",
  276. // {
  277. // clientX: e.clientX, // left
  278. // clientY: e.clientY,
  279. // displayContextMenu: true,
  280. // menuContent:[
  281. // {
  282. // name:'对比',
  283. // methods:'contrast'
  284. // }
  285. // ]
  286. // })
  287. }
  288. }
  289. },
  290. // 打开批注框
  291. pizhu() {
  292. if (this.contrast.id == undefined) {
  293. this.currentSelectObj = JSON.parse(this.index)
  294. }
  295. if (this.currentSelectObj.Id != undefined || this.contrast.id != undefined) {
  296. // 划词进入
  297. // if (this.currentSelectObj.Id != undefined) {
  298. // console.log(2,this.currentSelectObj);
  299. // this.$store.commit('SET_PATENT_INDEX', this.currentSelectObj)
  300. // }
  301. this.currentSelectObj.Type = 2;
  302. this.hiddenPizhu();
  303. this.showPizhu2()
  304. this.contrast = {}
  305. }
  306. },
  307. showPizhu2() {//展示批注
  308. let dl = document.getElementsByClassName("pizhu");
  309. let mX = sessionStorage.mX
  310. let mY = sessionStorage.mY
  311. if ((document.body.clientWidth - mX - 380) < 0) {
  312. mX = document.body.clientWidth - 390;
  313. }
  314. if ((document.body.clientHeight - mY - 40) < 0) {
  315. mY = document.body.clientHeight - 40;
  316. }
  317. if ((document.body.clientHeight - mY) < 420) {
  318. mY = mY - 410
  319. }
  320. if ((document.body.clientWidth - mX) < 330) {
  321. mX = mX - 330
  322. }
  323. dl[0].setAttribute("style", "user-select:none;box-shadow: 10px 10px 5px #888888;display:block;position:absolute;left:" + mX.toString() + "px;top:" + mY.toString() + "px;background-color: #F7EED6;border-radius: 15px 15px;padding: 10px;width:380px;z-index: 2;");
  324. },
  325. showPizhu() {//展示菜单
  326. let mX = sessionStorage.mX
  327. let mY = sessionStorage.mY
  328. let dl = document.getElementsByClassName("caidan");
  329. if ((document.body.clientWidth - mX - 420) < 0) {
  330. mX = document.body.clientWidth - 420;
  331. }
  332. if ((document.body.clientHeight - mY - 40) < 0) {
  333. mY = document.body.clientHeight - 40;
  334. }
  335. dl[0].setAttribute("style", "opacity:0.95;box-shadow: 10px 10px 5px #888888;display:block;position:absolute;left:" + mX.toString() + "px;top:" + mY.toString() + "px;background-color: white;border-radius: 15px 15px;height:30px;display: flex;align-items: center;padding: 10px;user-select:none");
  336. },
  337. // 关闭菜单
  338. hiddenPizhu() {
  339. let dl = document.getElementsByClassName("caidan");
  340. dl[0].setAttribute("style", "display:none;");
  341. },
  342. getSelectobj(selectObj) {
  343. var temNode = selectObj.anchorNode;
  344. var a = temNode.parentElement
  345. NotIncludeDataType(a)
  346. function NotIncludeDataType(node) {
  347. if (node.getAttribute("data-type") != null) {
  348. temNode = node
  349. } else {
  350. if(node.parentElement){
  351. NotIncludeDataType(node.parentElement);
  352. }else{
  353. temNode = temNode.parentElement
  354. }
  355. }
  356. }
  357. var rightSort = null
  358. if(temNode.getAttribute("data-type") == null){
  359. return false
  360. }
  361. if (this.reportType == 7 && temNode.getAttribute("data-type").includes('权利要求')) {
  362. var node1 = null
  363. getRightSort(a)
  364. function getRightSort(node) {
  365. if (node.getAttribute("right-sort") != null) {
  366. rightSort = node.getAttribute("right-sort")
  367. node1 = node
  368. } else {
  369. getAttribute(node.parentElement);
  370. }
  371. }
  372. var rightPosition = this.getColumn(node1, selectObj)
  373. }
  374. this.getColumn(temNode, selectObj);
  375. this.isFirst = true
  376. return { "Id": this.uuid(), "column": temNode.getAttribute("data-type"), "index": this.anchorOffset, "text": selectObj.toString(), 'temNode': temNode.innerHTML,'rightSort':rightSort,'rightPosition':rightPosition };
  377. },
  378. getColumn(node, selectObj) {
  379. var baseNode = this.getColumnNode(node);
  380. var anchorNodePosition = this.getPosition(baseNode, selectObj.anchorNode, selectObj.anchorOffset);
  381. var focusNodePosition = this.getPosition(baseNode, selectObj.focusNode, selectObj.focusOffset);
  382. var num = Math.min(anchorNodePosition, focusNodePosition)
  383. this.anchorOffset = num
  384. return num;
  385. },
  386. getColumnNode(node) {
  387. //获取节点所在的栏位节点
  388. if (node != null) {
  389. if (node.nodeType != 3 && node.getAttribute("data-type") != null) {
  390. return node;
  391. } else {
  392. if (node == document.root) {
  393. return node;
  394. } else {
  395. return this.getColumnNode(node.parentNode);
  396. }
  397. }
  398. }
  399. },
  400. getNodes(baseNode, path) {
  401. // 拿到所有类型的节点
  402. var temPath = path;
  403. if (baseNode != null) {
  404. temPath.push(baseNode);
  405. if (baseNode.childNodes.length > 0) {
  406. for (let i = 0; i < baseNode.childNodes.length; i++) {
  407. this.getNodes(baseNode.childNodes[i], temPath);
  408. }
  409. }
  410. }
  411. },
  412. getPosition(baseNode, node, offset) {
  413. //根据节点获取给定node中offset位置在栏位中的实际位置
  414. let path = [];
  415. this.getNodes(baseNode, path);
  416. let retIdx = 0;
  417. for (let i = 0; i < path.length; i++) {
  418. if (path[i] == node) {
  419. retIdx += offset;
  420. return retIdx;
  421. } else {
  422. if (path[i].nodeType == 3) {
  423. retIdx += path[i].nodeValue.length;
  424. }
  425. }
  426. }
  427. },
  428. uuid() {
  429. var s = [];
  430. var hexDigits = "0123456789abcdef";
  431. for (var i = 0; i < 36; i++) {
  432. s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
  433. }
  434. s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
  435. s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
  436. s[8] = s[13] = s[18] = s[23] = "-";
  437. var uuid = s.join("");
  438. return uuid;
  439. },
  440. getColumnName(el) {
  441. let root = el;
  442. if (el == undefined) {
  443. return undefined;
  444. }
  445. if (!(el instanceof HTMLElement)) {
  446. root = el.parentElement;
  447. }
  448. let dt = root.getAttribute("data-Type");
  449. if (dt != undefined) {
  450. return root;
  451. }
  452. return dt = this.getColumnName(root.parentElement);
  453. },
  454. },
  455. }