common.ts 28 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
import md5 from 'md5';
import { ref } from 'vue'
import { ElLoading, ElMessageBox } from 'element-plus'

const KEY = 'csbr#pwd'//密钥 后端给的加入签名中

// 加载遮罩
const loading = ref()
export const openFullLoading = (flag: boolean = true) => {
  if (flag) {
    loading.value = ElLoading.service({
      lock: true,
      text: '加载中...',
      background: 'rgba(0, 0, 0, 0)',
    })
  } else {
    loading.value.close()
  }
}

/**
 * 将组件ContentWrap滚动到可视范围内
 * @param name
 */
export const handleContentWrapView = (name) => {
  let dom = document.getElementById(`id-${name}`);
  dom && dom.scrollIntoView({
    behavior: "smooth", // 平滑过渡
    block: "start", // 上边框与视窗顶部平齐。默认值
  });
}

/** 添加表格最后一行滚动到可视范围内 */
export const scrollLastRowToView = (tableRef, dataLen) => {
  if (!tableRef) {
    return;
  }
  let bodyWrapper = tableRef.$el.querySelector('.el-table__body');
  let domScroll = bodyWrapper.parentElement.parentElement;
  let rect = domScroll.getBoundingClientRect();
  let maxNum = dataLen + 1;
  if (maxNum * 36 > rect.height + domScroll.scrollTop) {
    tableRef.setScrollTop(maxNum * 36 - rect.height + 2)
  }
}

/** 消息类型 */
declare type MessageType = '' | 'success' | 'warning' | 'info' | 'error';

/**
 *
 * @param msg 提示内容
 * @param type 提示类型
 * @param callBack 确认的回调
 * @param cancelCallBack 取消的回调
 */
export const openMessageBox = (msg, callBack?:Function,cancelCallBack?:Function, type: MessageType = 'warning') => {
  ElMessageBox.confirm(msg, "提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: type
  }).then(() => {
    if (callBack) {
      callBack()
    }
  }).catch(()=>{
    if (cancelCallBack) {
      cancelCallBack()
    }
  })
}

//加密的封装
export const autoSalt = (val: string = '', isKey: boolean = true, isStamp: boolean = false) => {
  const stamp = () => Math.round(new Date().getTime() / 1000)//时间戳
  const ctx = isKey ? `${val}${KEY}` : val
  const date = isStamp ? stamp() : ''
  return md5(`${ctx}${date}`)
}

// 防抖函数
export const debounce = (callback, delay) => {
  let timer: any = null;
  return function (query) {
    timer && clearTimeout(timer);
    timer = setTimeout(() => {
      callback(query)
    }, delay);
  }
}

/**
 * 公用函数
 * **/
//设置级联
export const filterCascaderData = (data, field, val, type = 'disabled') => {
  if (type == 'disabled') {
    data.map((item: any) => {
      if (item[field] != val) {
        delete item.disabled
        if (item.children) {
          item.children = filterCascaderData(item.children, field, val, type)
        }
      } else {
        item.disabled = true
      }
    })
    return data
  } else {
    let dataArr = data.filter((item: any) => {
      if (item[field] != val) {
        if (item.children) {
          item.children = filterCascaderData(item.children, field, val, type)
        }
        return true
      }
    })
    return dataArr
  }
}
// 数字千分位 保留两位小数
export const changeNum = (num, fixed = 0, round = false) => {
  num = parseFloat(num);
  if (round) {
    let parts = num.toFixed(fixed).split(".")
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g,",")
    return parts.join(".")
  }
  var str = num.toFixed(fixed);
  var reg = str.indexOf(".") > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g
  return str.replace(reg, "$1,")
}
// 获取当前时间
export const getCurrentTime = () => {
  const date = new Date();
  const year = date.getFullYear() // 年
  const month = date.getMonth() + 1; // 月
  const day = date.getDate(); // 日
  const hour = date.getHours(); // 时
  const minutes = date.getMinutes(); // 分
  const seconds = date.getSeconds() //秒
  const weekArr = ['星期一', '星期二', '星期三', '星期四', '星期五', '星期六', '星期天'];
  const week = weekArr[date.getDay()];
  // 给一位数的数据前面加 “0”
  let YY = year,
    MM = month >= 1 && month <= 9 ? '0' + month : month,
    DD = day >= 0 && day <= 9 ? '0' + day : day,
    hh = hour >= 0 && hour <= 9 ? '0' + hour : hour,
    mm = minutes >= 0 && minutes <= 9 ? '0' + minutes : minutes,
    ss = seconds >= 0 && seconds <= 9 ? '0' + seconds : seconds;
  return `${YY}-${MM}-${DD} ${hh}:${mm}:${ss}`;
}
// 获取当前时间一年后的日期
export const getFutureDate = (today) => {
  //判断是否为闰年  若为闰年,返回1,反之则返回0
  const isLeap = (year) => {
    if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
      return 1;
    }
    return 0;
  }
  const saliDate = today.split("-");
  let riNum = '0';
  let yueNum = '0';
  let nianNum = saliDate[0];
  //判断月 同时判断年
  if (saliDate[1] - 1 <= 0 && saliDate[2] == "01") {
    yueNum = '12';
    riNum = '31';
    nianNum = nianNum;
  } else {
    yueNum = saliDate[1];
    nianNum = nianNum - 0 + 1;
    //当 日 是01 的时候要判断当前下一个月是否为31 还是30天  在判断一个是否为闰年  2月份是29 还是28
    if (saliDate[2] == "01") {
      switch (saliDate[1] - 1) {
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 0://0就是12月  因为是只有点击的是2019-01-01  才会是2018-12-31
          riNum = '31';
          yueNum = "0" + (saliDate[1] - 1);
          break;
        case 4:
        case 6:
        case 9:
        case 11:
          riNum = '30';
          yueNum = "0" + (saliDate[1] - 1);
          break;
      }
      if (saliDate[1] - 1 == 2) {
        yueNum = "0" + (saliDate[1] - 1);
        //判断是否为闰年
        if (isLeap(saliDate[0]) == 1) {
          riNum = '29';
        } else {
          riNum = '28';
        }
      }
    } else {
      if (saliDate[2] - 1 <= 9) {
        riNum = "0" + (saliDate[2] - 1);
      } else {
        riNum = '' + (saliDate[2] - 1);
      }
    }
  }
  return nianNum + "-" + yueNum + "-" + riNum;
}
// 获取当前时间之前的间隔duration的时间
export const getPastTime = (duration, type) => {
  // 获取当前时间
  const currentDate = new Date();
  const unitTime = 60 * 60 * 1000
  let pastTime = new Date()
  if (type == 'H') {
    pastTime = new Date(currentDate.getTime() - (duration * unitTime))
  } else if (type == 'D') {
    pastTime = new Date(currentDate.getTime() - (duration * 24 * unitTime))
  }
  return pastTime
}

/** 根据流获取url地址,用于文件查看。 */
export const getDownloadUrl = (data, fileName, type: any = null,flag=true) => {
  let mineType = 'application/octet-stream'
  if (type == 'excel') {
    mineType = 'application/vnd.ms-excel'
  } else if (type == 'word') {
    mineType = 'application/msword'
  } else if (type == 'zip') {
    mineType = 'application/zip'
  } else if (type == 'html') {
    mineType = 'text/html'
  } else if (type == 'markdown') {
    mineType = 'text/markdown'
  } else if (type == 'pdf') {
    mineType = 'application/pdf'
  } else if (type == 'png') {
    mineType = 'image/png'
  } else if (type == 'jpeg') {
    mineType = 'image/jpeg'
  } else if (type == 'jpg') {
    mineType = 'image/jpg'
  } else if (type == 'rar') {
    mineType = 'application/x-rar-compressed';
  } else if(type == 'svg') {
    mineType = 'image/svg+xml'
  } else if (type == 'zip') {
    mineType = 'application/zip'
  }

  // 创建 blob对象
  let blob = new Blob([data], { type: mineType })
  if(!flag) {
    return blob
  }
  // 浏览器api 有的不支持-二种都写
  window.URL = window.URL || window.webkitURL
  // 获取链接地址-(内容赋值到临时链接)
  return URL.createObjectURL(blob)
}

// 文件下载
export const download = (data, fileName, type: any = null) => {
  // 获取链接地址-(内容赋值到临时链接)
  let href = <string>getDownloadUrl(data, fileName, type);
  // 创建a标签
  let downA = document.createElement('a')
  // 把链接赋值给a标签
  downA.href = href
  // 赋值文件名称
  downA.download = fileName
  // 点击下载
  downA.click()
  // 销毁超连接
  window.URL.revokeObjectURL(href)
}

//本地文件下载  下载的模板文件放在public下的file文件夹中
export const downFile = (fileUrl, fileName) => {
  const anchor = document.createElement('a')
  anchor.href = fileUrl
  anchor.setAttribute('download', fileName)
  anchor.innerHTML = 'downloading...'
  anchor.style.display = 'none'
  document.body.appendChild(anchor)
  setTimeout(() => {
    anchor.click()
    anchor.remove()
    setTimeout(() => {
      self.URL.revokeObjectURL(anchor.href)
    }, 250)
  }, 66)
}

// 表单提交参数
export const setFormFields = (list) => {
  let obj = {};
  list.map((item) => {
    if (item.field && item.visible !== false) {
      obj[item.field] = item.default ?? "";
    }
    if (item.inputOptions && item.visible !== false) {
      if (item.inputOptions.visible !== false) {
        obj[item.inputOptions.field] = item.inputOptions.default ?? "";
      }
    }
    if (item.children && item.visible !== false) {
      obj = { ...obj, ...setFormFields(item.children) };
    }
  });
  return obj;
};

// 设置表单选项disabled属性
export const setItemsDisabled = (list, isDisabled) => {
  if (Array.isArray(list)) {
    let arr: any = []
    if (list.length) {
      arr = list.map(item => {
        item.disabled = item.disabled ?? isDisabled
        item.children?.map(child => child.disabled = child.disabled ?? isDisabled)
        return item
      })
    }
    return arr
  } else {
    let obj = {}
    if (Object.keys(list).length) {
      for (var l in list) {
        const item = list[l]
        obj[l] = { ...item }
        obj[l].disabled = obj[l].disabled ?? isDisabled
        if (item.children) {
          obj = { ...obj, ...setItemsDisabled(item.children, isDisabled) };
        }
      }
    }
    return obj
  }
}

// 将数据以任意大于0的整数分组
export const chunk = (arr, size) => {
  //获取数组的长度,如果你传入的不是数组,那么获取到的就是undefined
  const length = arr.length;
  //判断不是数组,或者size没有设置,size小于1,就返回空数组
  if (!length || !size || size < 1) {
    return [];
  }
  //核心部分
  var index = 0; //用来表示切割元素的范围start
  var resIndex = 0; //用来递增表示输出数组的下标

  //根据length和size算出输出数组的长度,并且创建它。
  var result = new Array(Math.ceil(length / size));
  //进行循环
  while (index < length) {
    //循环过程中设置result[0]和result[1]的值。该值根据arr.slice切割得到。
    result[resIndex++] = arr.slice(index, (index += size));
  }
  //输出新数组
  return result;
}

// 设置tag样式
export const tagType = (row, type) => {
  let state = 'info'
  if (type == 'connectStatus') {
    switch (row[type]) {
      case "1":
        state = 'success'
        break;
      case "2":
        state = 'info'
        break;
      default:
        state = 'info'
        break;
    }
  } else if (type == 'bizState') {
    switch (row[type]) {
      case "Y":
        state = 'success'
        break;
      case "S":
        state = 'info'
        break;
    }
  } else if (type == 'tableCheckResult') {
    switch (row[type]) {
      case 1:
        state = 'success'
        break;
      case 3:
        state = 'warning'
        break;
      case 2:
        state = 'danger'
        break;
    }
  } else if (type == 'fieldCheckResult') {
    switch (row[type]) {
      case 1:
        state = 'success'
        break;
      case 2:
        state = 'danger'
        break;
    }
  } else if (type == 'isOpenStandard') {
    if (row[type] === 'Y') {
      state = 'success'
    } else {
      state = 'info';
    }
  } else if (type == 'approvalState') {//纠纷处理状态。
    switch (row[type]) {
      case "Y":
        state = 'success'
        break;
      case "R":
        state = 'danger'
        break;
      default:
        state = 'warning';
        break;
    }
  } else if (type == 'approveState') {
    switch (row[type]) {
      case "N":
        state = 'info';
        break;
      case "A":
        state = 'warning'
        break;
      case "Y":
        state = 'success'
        break;
      case "R":
        state = 'danger'
        break;
      case "C":
        state = 'info';
        break;
      default:
        state = row['dataState'] === 1 ? 'success' : 'info';
        break;
    }
  } else if (type == 'importState') {
    if (row[type] === 0) {
      state = 'success'
    } else if (row[type] === 1) {
      state = 'info'
    } else {
      state = 'danger';
    }
  } else if (type == 'executeState' || type == 'execResult') {
    if (row[type] == 'Y') {
      state = 'success'
    } else if (row[type] == 'N') {
      state = 'danger';
    } else if (row[type] == 'P') { //部分通过
      state = 'warning';
    } else if (row[type] == 'R') { //部分通过
      state = 'warning';
    }
  } else if (type == 'execState') {
    if (row[type] == 0 || row[type] == null) {
      state = 'info';
    } else if (row[type] == 1) {
      state = 'warning';
    } else if (row[type] == 2) {
      state = 'success'
    } else if (row[type] == 3) {
      state = 'danger';
    } else {
      state = 'info';
    }
  } else if (type == 'state') {
    switch (row[type]) {
      case 'N': 
        state = 'warning';
        break;
      case "Y":
        state = 'success'
        break;
      case "R":
        state = 'danger'
        break;
      case 1:
      case 2:
        state = 'info';
        break;
      case 3:
        state = 'warning'
        break;
      case 4:
        state = 'success'
        break;
    }
  } else if(type=="runingState") {
    switch (row[type]) {
      case "Y":
        state = 'success';
        break;
      case "N":
        state = 'danger'
        break;
      case "R":
        state = 'warning'
        break;
      case "NR":
        state = "info"
        break
      case "S":
        state = "info"
        break
      case "SN":
        state = "warning"
        break
      case "RN":
        state = "warning"
        break
      default:state = "info"
    }
  }else if(type=="releaseStatus") {
    switch (row[type]) {
      case 1:
        state = 'info'; //待发布
        break;
      case 2:
        state = 'info'//发布中
        break;
      case 3:
        state = 'success' // 发布成功
        break;
        default:  state = 'info'
    }
  }
  else if(type=="success") {
    switch (row[type]) {
      case true:
        state = 'success'; //待发布
        break;
      case false:
        state = 'danger'//发布中
        break;
    }
  }
  return state;
}

// 设置filter值
export const tagMethod = (row, type) => {
  let tag: any = null
  if (type == 'menuType') {
    switch (row[type]) {
      case "M":
        tag = '目录'
        break;
      case "C":
        tag = '菜单'
        break;
      case "P":
        tag = '页面'
        break;
      case "F":
        tag = '按钮'
        break;
      default:
        tag = '--'
        break;
    }
  } else if (type == 'bizState') {
    switch (row[type]) {
      case "Y":
        tag = '有效'
        break;
      case "S":
        tag = '停用'
        break;
      default:
        tag = '--'
        break;
    }
  } else if (type == 'connectStatus') {
    switch (row[type]) {
      case "1":
        tag = '已连通'
        break;
      case "2":
        tag = '未连通'
        break;
      default:
        tag = '未连通'
        break;
    }
  } else if (type == 'visible' || type == 'isPartition' || type == 'isDgCapacity' || type == 'isUnique' || type == 'isFk' || type == 'notNull' || type == 'isPrimary') {
    switch (row[type]) {
      case "Y":
        tag = '是'
        break;
      case "N":
        tag = '否'
        break;
      default:
        tag = '--'
        break;
    }
  } else if (type == 'expireDate') {
    tag = `${row.startDate}${row.expireDate}`
  } else if (type == 'tableCheckResult') {
    switch (row[type]) {
      case 1:
        tag = '全部通过'
        break;
      case 3:
        tag = '部分通过'
        break;
      case 2:
        tag = '不通过'
        break;
      default:
        tag = '--'
        break;
    }
  } else if (type == 'fieldCheckResult') {
    switch (row[type]) {
      case 1:
        tag = '通过'
        break;
      case 2:
        tag = '不通过'
        break;
      default:
        tag = '--'
        break;
    }
  } else if (type == 'isOpenStandard') {
    switch (row[type]) {
      case 'Y':
        tag = '开启'
        break;
      default:
        tag = '关闭'
        break;
    }
  } else if (type == 'state') { //纠纷处理状态
    switch (row[type]) {
      case 3:
        tag = '发证中'
        break;
      case 4:
        tag = '已发证'
        break;
      case 2:
        tag = '待发证'
        break;
      case 1:
        tag = '待制证'
        break;
      case 0:
        tag = '已过期'
        break;
      case "Y":
        tag = '已通过'
        break;
      case "R":
        tag = '已驳回'
        break;
      case 'N':
        tag = '待受理'
        break;
    }
  } else if (type == 'approveState') {
    switch (row[type]) {
      case "N":
        tag = '草稿中'
        break;
      case "A":
        tag = '审批中'
        break;
      case "Y":
        tag = '已通过'
        break;
      case "R":
        tag = '已驳回'
        break;
      case "C":
        tag = '已撤销'
        break;
      default:
        tag = row['dataState'] === 1 ? '已提交' : '草稿中'
        break;
    }
  } else if (type == 'standardType') {
    switch (row[type]) {
      case "1":
        tag = '前缀标准'
        break;
      case "2":
        tag = '前缀标准'
        break;
      default:
        tag = '--'
        break;
    }
  } else if (type == 'dictionaryType') {
    switch (row[type]) {
      case 1:
        tag = '列表结构'
        break;
      case 2:
        tag = '层级结构'
        break;
      case 3:
        tag = '螺旋结构'
        break;
      case 4:
        tag = '通用结构'
        break;
      default:
        tag = '--'
        break;
    }
  } else if (type == 'collectType') {
    switch (row[type]) {
      case 1:
        tag = '离线'
        break;
      case 2:
        tag = '实时'
        break;
      default:
        tag = '--'
        break;
    }
  } else if (type == 'collectMode') {
    switch (row[type]) {
      case 1:
        tag = '增量'
        break;
      case 2:
        tag = '全量'
        break;
      default:
        tag = '--'
        break;
    }
  } else if (type == 'importState') {
    if (row[type] === 0) {
      tag = '导入成功'
    } else if (row[type] === 1) {
      tag = '导入处理中'
    } else {
      tag = '导入异常';
    }
  } else if (type == 'executeState' || type == 'execResult') {
    if (row[type] == 'Y') {
      tag = '成功'
    } else if (row[type] == 'N') {
      tag = '失败';
    } else if (row[type] == 'P') { //部分通过
      tag = '部分通过';
    }else if (row[type] == 'R') { //部分通过
      tag = '执行中';
    }
  } else if (type == 'execState') {
    if (row[type] == 0 || row[type] == null) {
      tag = '未执行'
    } else if (row[type] == 1) {
      tag = '执行中';
    } else if (row[type] == 2) {
      tag = '成功';
    } else if (row[type] == 3) {
      tag = '失败';
    }
  } else if (type == 'runingState') {
    switch (row[type]) {
      case "R":
        tag = '运行中'
        break;
      case "Y":
        tag = '成功'
        break;
      case "N":
        tag = '失败'
        break;
      case "NR":
      tag = "未运行"
      break
      case "S":
      tag = "停止"
      break;
      case "SN":
      tag = "停止中"
      break;
      case "RN":
      tag = " 启动中"
      break;
      default:tag = "未运行"
    }
  } else if (type == 'releaseStatus') {
    switch (row[type]) {
      case 1:
        tag = '待发布'
        break;
      case 2:
        tag = '发布中'
        break;
      case 3:
        tag = '成功'
        break;
      default: tag = "待发布"
    }
  }else if (type == 'success') {
    switch (row[type]) {
      case true:
        tag = '成功'
        break;
      case false:
        tag = '失败'
        break;
    }
  }
   else {
    tag = row[type];
  }
  return tag
}

/** 翻译cron表达式为中文 */
export const transferCronexPressionToText = (a, isLog) => {
  let findall = (arr, x) => {
    let results: any = [];
    arr.forEach((el, i) => el.indexOf(x) != -1 && results.push(i));
    return results;
  };
  let statistics = (a, time: any) => {
    let results: any = [];
    if (a.length) {
      a.forEach((j, jndex) => {
        results.push(time[j]);
      });
    }
    return results;
  }
  if (!a) {
    return a;
  }
  if (a.split(' ').length === 6) {
    a = '00 ' + a;
  }
  let finalTitle: any = [];
  let lable = ['秒', '分', '时', '日', '月', '星期', '年'];
  let time = ['s', 'm', 'h', 'd', 'month', 'week', 'year'];
  let weekNum = { '1': '日', '2': '一', '3': '二', '4': '三', '5': '四', '6': '五', '7': '六' };
  // 每出现次数
  let everyCount = 0;
  // 周期出现次数
  let periodCount = 0;
  // 循环出现次数
  let loopCount = 0;
  let arr = a.split(' ');
  //多次出现*号将不为第一次出现的项变为未指定
  let mapArr = arr.map((item, index) => {
    if (item == '*' && index != arr.indexOf('*')) {
      return (item = '?');
    } else {
      return item;
    }
  });
  let loopLastindex = null;
  mapArr.forEach((item, index) => {
    if (item.indexOf('/') != -1) {
      loopLastindex = index;
    }
  });
  mapArr.forEach((item, index) => {
    let str = '';
    if (item.indexOf('-') != -1) {
      if (index == 5) {
        str = `${[lable[index]]}${weekNum[item.split('-')[0]]}${[lable[index]]}${weekNum[item.split('-')[1]]}`;
      } else {
        str = `${item.split('-')[0]}${item.split('-')[1]}${[lable[index]]}`;
      }
      periodCount++;
    } else if (item.indexOf('/') != -1) {
      if (index == 5) {
        if (index == loopLastindex) {
          str = `从${[lable[index]]}${weekNum[item.split('/')[0]]}开始,每${item.split('/')[1]}天`;
        } else {
          str = `${[lable[index]]}${weekNum[item.split('/')[0]]},每${item.split('/')[1]}天`;
        }
      } else if (index == 2) {
        if (index == loopLastindex) {
          str = `从${item.split('/')[0]}${[lable[index]]}开始,每${item.split('/')[1]}小时`;
        } else {
          str = `${item.split('/')[0]}${[lable[index]]},每${item.split('/')[1]}小时`;
        }
      } else if (index == 4) {
        if (index == loopLastindex) {
          str = `从${item.split('/')[0]}${[lable[index]]}开始,每${item.split('/')[1]}个月`;
        } else {
          str = `${item.split('/')[0]}${[lable[index]]},每${item.split('/')[1]}个月`;
        }
      } else {
        if (index == loopLastindex) {
          str = `从${item.split('/')[0]}${[lable[index]]}开始,每${item.split('/')[1]}${[lable[index]]}`;
        } else {
          str = `${item.split('/')[0]}${[lable[index]]},每${item.split('/')[1]}${[lable[index]]}`;
        }
      }
      loopCount++;
    } else if (item.indexOf('W') != -1) {
      str = `本月${item.split('W')[0]}${[lable[index]]},最近的工作日`;
    } else if (item.indexOf('L') != -1) {
      if (index == 5) {
        str = `本月最后一个${[lable[index]]}${weekNum[item.split('L')[0]]}`;
      } else {
        str = `本月最后一天`;
      }
    } else if (item.indexOf('#') != -1) {
      str = `本月第${item.split('#')[0]}周,星期${weekNum[item.split('#')[1]]}`;
    } else if (item.indexOf('*') != -1) {
      // str = `每${[lable[index]]}`;
      if (everyCount) {
        str = '';
      } else {
        str = `每${[lable[index]]}`;
        everyCount++;
      }
    } else if (item.indexOf(',') != -1) {
      if (index == 5) {
        str = `${[lable[index]]}${item.split(',').map(i => weekNum[i]).join(',')}`;
      } else {
        str = `${item}${[lable[index]]}`;
      }
    } else if (item.indexOf('?') != -1 || index == 0) {
      str = ` `;
    } else if (typeof Number(item) === 'number' && !isNaN(Number(item))) {
      if (index == 5) {
        str = `${[lable[index]]}${weekNum[item]}`;
      } else {
        if (item == "") {
          str = "";
        } else {
          str = `${Number(item)}${[lable[index]]}`;
        }
      }
    } else {
      str = '';
    }
    time[index] = str;
  });
  let newArr = arr;
  time.reverse()
  newArr.reverse();
  //周期
  let periodArr = findall(newArr, '-');
  // 循环
  let loopArr = findall(newArr, '/');
  // 指定周
  let specifyArr = findall(newArr, '#');
  // 工作日
  let workArr = findall(newArr, 'W');
  // 最后一个
  let lastArr = findall(newArr, 'L');
  // 每
  let everyArr = findall(newArr, '*');
  // 指定
  let appointArr: any = [];
  newArr.forEach((item, index) => {
    if ((typeof Number(item) === 'number' && !isNaN(Number(item)) && index !== newArr.length - 1) || item.indexOf(',') != -1) {
      appointArr.push(index);
    }
  });
  let periodStr = statistics(periodArr, time);
  let loopStr = statistics(loopArr, time);
  let specifyStr = statistics(specifyArr, time);
  let workStr = statistics(workArr, time);
  let lastStr = statistics(lastArr, time);
  let everyStr = statistics(everyArr, time);
  let appointStr = statistics(appointArr, time);
  if (everyStr.length) {
    finalTitle.push(isLog ? `${everyStr[everyStr.length - 1]}` : `触发频次:${everyStr[everyStr.length - 1]}执行一次`);
  }
  if (periodStr.length) {
    finalTitle.push(isLog ? `${periodStr.join('的')}` : `触发周期:${periodStr.join('的')}`);
  }
  if (loopStr.length) {
    finalTitle.push(isLog ? `${loopStr.join('的')}` : `触发循环:${loopStr.join('的')}执行一次`);
  }
  if (specifyStr.length) {
    finalTitle.push(isLog ? `${specifyStr.join('的')}` : `指定周:${specifyStr.join('的')}`);
  }
  if (workStr.length) {
    finalTitle.push(`${workStr.join('')}`);
  }
  if (lastStr.length) {
    finalTitle.push(`${lastStr[lastStr.length - 1]}`);
  }
  if (appointStr.length) {
    if (appointStr[0] == "") {
      appointStr = appointStr.slice(1);
    }
    finalTitle.push(isLog ? `${appointStr.join('的')}` : `指定时间:${appointStr.join('的')}`);
  }
  return isLog ? finalTitle.join('') : finalTitle;
};

// 创建SVG标签
export const createSVG = (blob)=>{
return new Promise((resolve)=>{
  let reader = new FileReader();
  reader.onload = function(event:any,) {
    let svgString = event.target.result;
    let parser = new DOMParser();
    let svgElement = parser.parseFromString(svgString, "image/svg+xml").documentElement
     resolve(svgElement.outerHTML)
  };
  reader.readAsText(blob);
})

}


// base64图片压缩
//压缩方法
export const dealImage = (base64, w, callback) => {
  var newImage = new Image();
  var quality = 0.6;    //压缩系数0-1之间
  newImage.src = base64;
  newImage.setAttribute("crossOrigin", 'Anonymous');	//url为外域时需要
  var imgWidth, imgHeight;
  newImage.onload = function () {
      imgWidth = newImage.width;
      imgHeight = newImage.height;
      var canvas = document.createElement("canvas");
      var ctx :any= canvas.getContext("2d");
      if (Math.max(imgWidth, imgHeight) > w) {
          if (imgWidth > imgHeight) {
              canvas.width = w;
              canvas.height = w * imgHeight / imgWidth;
          } else {
              canvas.height = w;
              canvas.width = w * imgWidth / imgHeight;
          }
      } else {
          canvas.width = imgWidth;
          canvas.height = imgHeight;
          quality = 0.6;
      }
      ctx.clearRect(0, 0, canvas.width, canvas.height);
      ctx.drawImage(this, 0, 0, canvas.width, canvas.height);
      var base64 = canvas.toDataURL("image/jpeg", quality); //压缩语句
      callback(base64);//必须通过回调函数返回,否则无法及时拿到该值
  }
}

/** 将应用或api流量限制单位统一为分 */
export const transferFlowLimit = (v, unit) => { //将时间统一转化为分钟为单位。
  if (unit == 'm') {
    return v;
  }
  if (unit == 'd') {
    return v / 24 / 60;
  }
  if (unit == 'h') {
    return v / 60
  }
  if (unit == 's') {
    return v * 60;
  }
}