func.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import config from '@config/index.js';
  2. //函数类工具,对函数进行操作 返回函数
  3. //延时操作
  4. export function debounce(func, delay) {
  5. let timer = null;
  6. return function (...args) {
  7. if (timer) {
  8. clearTimeout(timer);
  9. }
  10. timer = setTimeout(() => {
  11. func.apply(this, args);
  12. }, delay);
  13. }
  14. }
  15. // 时间戳转换日期
  16. export function dateParser(timestamp,link = '-'){
  17. let time = new Date(timestamp);
  18. let year = time.getFullYear();
  19. let month = time.getMonth()+1;
  20. let date = time.getDate();
  21. let hour = time.getHours().toString().padStart(2,'0');
  22. let minute = time.getMinutes().toString().padStart(2,'0');
  23. // let result = year+link+month+link+date;
  24. let result = year+link+month+link+date+' '+hour+':'+minute;
  25. return result;
  26. }
  27. //时间搓转换年龄
  28. export const getAge = (time) => {
  29. const birthday = new Date(time),
  30. year = birthday.getFullYear(),
  31. month = birthday.getMonth() + 1,
  32. day = birthday.getDate(),
  33. now = new Date(),
  34. now_year = now.getFullYear(),
  35. now_month = now.getMonth() + 1,
  36. now_day = now.getDate();
  37. let age= now_year - year;
  38. if (now_month > month) {
  39. age += 1;
  40. } else if (now_month === month) {
  41. if (now_day >= day) {
  42. age += 1;
  43. }
  44. }
  45. return age;
  46. };
  47. //获取URL参数-返回json对象
  48. export const parseUrl = (url) => {
  49. const r = url.substr(1).split("&"),
  50. obj = {};
  51. r.forEach((v) => {
  52. const index = v.indexOf('=');
  53. if (index > -1) {
  54. obj[v.substring(0, index)] = v.substring(index + 1);
  55. }
  56. });
  57. return obj;
  58. }
  59. //字符串去空格
  60. export const strTrim = (str) =>{
  61. return str.replace(/&nbsp;|<div>|<\/div>|<br>|\s/g,'');
  62. };
  63. //获取已填文字填入saveText
  64. function getSaveText(arr){
  65. }
  66. //添加自由文本标签
  67. function notTextLabel(label){
  68. return +label.tagType!==8;
  69. }
  70. /*
  71. * 给标签组添加自由文本标签
  72. * 入参:arr源数组,
  73. * noPre是否不添加前置文本标签,默认false即添加
  74. * noEnd是否不添加后置文本标签,默认false即添加
  75. * ifEmpty是否添加空标签,默认true即添加,传false添加逗号,如查体
  76. * */
  77. export const fullfillText = (arr,noPre=false,noEnd=false,ifEmpty=true)=>{
  78. let newArr =[],
  79. pre={},
  80. textLabel={},
  81. _textLabel={},
  82. notText = true,
  83. saveText=[],
  84. tempText = '',
  85. value = '';
  86. arr.map((it,i)=>{
  87. notText = notTextLabel(it);
  88. value = it.value||'';
  89. textLabel = JSON.parse(config.textLabel);
  90. _textLabel = JSON.parse(config._textLabel);
  91. if(i===0){
  92. //第一个标签不是文本标签时在前面添加文本标签
  93. if(!noPre&&notText){
  94. newArr.push(textLabel);
  95. saveText.push('');
  96. }
  97. newArr.push(it);
  98. tempText = value?it.labelPrefix+value+it.labelSuffix:'';
  99. tempText = notText?tempText:it.value||it.name;
  100. saveText.push(tempText);
  101. }else{
  102. pre = arr[i-1];
  103. //如果本身不是文本标签且前面一个也不是文本标签,该标签前面添加文本标签
  104. if(notTextLabel(pre)&&notText){
  105. // newArr.push(textLabel,it);
  106. ifEmpty?newArr.push(textLabel,it):newArr.push(_textLabel,it);
  107. tempText = value?it.labelPrefix+value+it.labelSuffix:'';
  108. saveText.push("",tempText);
  109. //最后一个非文本标签,后面添加一个文本标签
  110. /*if(!noEnd&&i===arr.length-1){
  111. newArr.push(textLabel);
  112. saveText.push("");
  113. }*/
  114. }else{ //本身是或者前面是文本标签时,前面不添加文本标签
  115. newArr.push(it);
  116. tempText = value?it.labelPrefix+value+it.labelSuffix:'';
  117. tempText = notText?tempText:it.value||it.name;
  118. saveText.push(tempText);
  119. }
  120. if(notText&&!noEnd&&i===arr.length-1){//最后一个非文本标签,后面添加一个文本标签
  121. //不能用上面的变量textLabel,因为上一个if可能也进了,这样就是同一个对象,值改变时会同步
  122. newArr.push(JSON.parse(config.textLabel));
  123. saveText.push("");
  124. }
  125. }
  126. });
  127. return {newArr,saveText};
  128. };
  129. //获取标签index,入参:病例项index+标签index+标签内index
  130. export const getLabelIndex = (index)=>{
  131. let ikey = '';
  132. if(index.length == 3){
  133. ikey = index.substr(1,1);
  134. }else if(index.length == 4){
  135. ikey = index.substr(1,2);
  136. }else if(index.length == 5){
  137. ikey = index.substr(1,3);
  138. }
  139. return ikey;
  140. };
  141. export const getWindowInnerHeight = ()=>{
  142. if(window.innerHeight!=undefined){
  143. return window.innerHeight;
  144. }else{
  145. let by = document.body, ele = document.documentElement;
  146. return Math.min(by.clientHeight,ele.clientHeight);
  147. }
  148. };
  149. export const getIds = (data)=>{
  150. let ids = [];
  151. data&&data.forEach((it,i)=>{
  152. ids.push(it.id);
  153. })
  154. return ids;
  155. }