123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- import config from '@config/index.js';
- //函数类工具,对函数进行操作 返回函数
- //延时操作
- export function debounce(func, delay) {
- let timer = null;
- return function (...args) {
- if (timer) {
- clearTimeout(timer);
- }
- timer = setTimeout(() => {
- func.apply(this, args);
- }, delay);
- }
- }
- // 时间戳转换日期
- export function dateParser(timestamp,link = '-'){
- let time = new Date(timestamp);
- let year = time.getFullYear();
- let month = time.getMonth()+1;
- let date = time.getDate();
- let hour = time.getHours().toString().padStart(2,'0');
- let minute = time.getMinutes().toString().padStart(2,'0');
- // let result = year+link+month+link+date;
- let result = year+link+month+link+date+' '+hour+':'+minute;
- return result;
- }
- //时间搓转换年龄
- export const getAge = (time) => {
- const birthday = new Date(time),
- year = birthday.getFullYear(),
- month = birthday.getMonth() + 1,
- day = birthday.getDate(),
- now = new Date(),
- now_year = now.getFullYear(),
- now_month = now.getMonth() + 1,
- now_day = now.getDate();
- let age= now_year - year;
- if (now_month > month) {
- age += 1;
- } else if (now_month === month) {
- if (now_day >= day) {
- age += 1;
- }
- }
- return age;
- };
- //获取URL参数-返回json对象
- export const parseUrl = (url) => {
- const r = url.substr(1).split("&"),
- obj = {};
- r.forEach((v) => {
- const index = v.indexOf('=');
- if (index > -1) {
- obj[v.substring(0, index)] = v.substring(index + 1);
- }
- });
- return obj;
- }
- //字符串去空格
- export const strTrim = (str) =>{
- return str.replace(/ |<div>|<\/div>|<br>|\s/g,'');
- };
- //获取组合组件已填文字填入saveText
- function getSaveText(data){//console.log(data)
- const arr = data.questionMapping.map((it)=>{
- return it.value?(it.labelPrefix||'')+(it.value||'')+(it.labelSuffix||''):'';
- });
- return arr.join('');
- }
- //添加自由文本标签
- function notTextLabel(label){
- return +label.tagType!==8;
- }
- /*
- * 给标签组添加自由文本标签
- * 入参:arr源数组,
- * noPre是否不添加前置文本标签,默认false即添加
- * noEnd是否不添加后置文本标签,默认false即添加
- * ifEmpty是否添加空标签,默认true即添加,传false添加逗号,如查体
- * */
- export const fullfillText = (arr,noPre=false,noEnd=false,ifEmpty=true)=>{
- let newArr =[],
- pre={},
- textLabel={},
- _textLabel={},
- notText = true,
- saveText=[],
- tempText = '',
- value = '';
- arr.map((it,i)=>{
- notText = notTextLabel(it);
- value = it.value||'';
- textLabel = JSON.parse(config.textLabel);
- _textLabel = JSON.parse(config._textLabel);
- if(i===0){
- //第一个标签不是文本标签时在前面添加文本标签
- if(!noPre&¬Text){
- newArr.push(textLabel);
- saveText.push('');
- }
- newArr.push(it);
- if(it.tagType != 3){
- tempText = value?it.labelPrefix+value+it.labelSuffix:'';
- tempText = notText?tempText:it.value||it.name;
- }else{
- tempText = getSaveText(it);
- }
- saveText.push(tempText);
- }else{
- pre = arr[i-1];
- //如果本身不是文本标签且前面一个也不是文本标签,该标签前面添加文本标签
- if(notTextLabel(pre)&¬Text){
- // newArr.push(textLabel,it);
- ifEmpty?newArr.push(textLabel,it):newArr.push(_textLabel,it);
- if(it.tagType != 3) {
- tempText = value ? it.labelPrefix + value + it.labelSuffix : '';
- }else{
- tempText = getSaveText(it);
- }
- saveText.push("",tempText);
- //最后一个非文本标签,后面添加一个文本标签
- /*if(!noEnd&&i===arr.length-1){
- newArr.push(textLabel);
- saveText.push("");
- }*/
- }else{ //本身是或者前面是文本标签时,前面不添加文本标签
- newArr.push(it);
- if(it.tagType != 3) {
- tempText = value ? it.labelPrefix + value + it.labelSuffix : '';
- // tempText = notText?tempText:it.value||it.name;
- tempText = notText ? tempText : (it.value || it.value == "" ? it.value : it.name);
- }else{
- tempText = getSaveText(it);
- }
- saveText.push(tempText);
- }
- if(notText&&!noEnd&&i===arr.length-1){//最后一个非文本标签,后面添加一个文本标签
- //不能用上面的变量textLabel,因为上一个if可能也进了,这样就是同一个对象,值改变时会同步
- newArr.push(JSON.parse(config.textLabel));
- saveText.push("");
- }
- }
- });
- return {newArr,saveText};
- };
- //获取标签index,入参:病例项index+标签index+标签内index
- export const getLabelIndex = (index)=>{
- let ikey = '';
- if(index.length == 3){
- ikey = index.substr(1,1);
- }else if(index.length == 4){
- ikey = index.substr(1,2);
- }else if(index.length == 5){
- ikey = index.substr(1,3);
- }
- return ikey;
- };
- export const getWindowInnerHeight = ()=>{
- if(window.innerHeight!=undefined){
- return window.innerHeight;
- }else{
- let by = document.body, ele = document.documentElement;
- return Math.min(by.clientHeight,ele.clientHeight);
- }
- };
- export const getWindowInnerWidth = ()=>{
- let width = window.innerWidth || document.body.clientWidth || document.documentElement.clientWidth
- return width
- };
- export const getIds = (data)=>{
- let ids = [];
- data&&data.forEach((it,i)=>{
- ids.push(it.id);
- })
- return ids;
- }
|