forked from gzzfw/frontEnd/gzDyh

zhangyongtian
2024-09-11 6ffddb4f427176d39bb41df21919d7038e5bf668
gz-customerSystem/src/utils/utility.js
@@ -2,7 +2,7 @@
 * @Company: hugeInfo
 * @Author: ldh
 * @Date: 2022-02-16 11:57:54
 * @LastEditTime: 2024-08-09 14:50:20
 * @LastEditTime: 2024-08-21 16:58:17
 * @LastEditors: dminyi 1301963064@qq.com
 * @Version: 1.0.0
 * @Description: 公共模块方法
@@ -36,7 +36,7 @@
// 下拉框
export { default as options } from './selectOption';
export { default as caseTypeSelect } from './caseTypeSelect';
export { default as caseOptions } from './caseCauseSelect';
// icon 对照表
@@ -102,6 +102,18 @@
   return decodeURI(result[1]);
}
// 逗号隔开数字
export function thousands(num) {
   if (num) {
      var str = num.toString();
      var reg = str.indexOf('.') > -1 ? /(\d)(?=(\d{3})+\.)/g : /(\d)(?=(?:\d{3})+$)/g;
      return str.replace(reg, '$1,');
   } else {
      return 0;
   }
}
//
export function getQueryObj(obj) {
   let strs = '';
@@ -153,6 +165,8 @@
   return info({ type: 'success', content });
}
// 手机号码正则
export const mobileRegExp = new RegExp('^1([0-9][0-9]|[0-9][0-9]|[0-9][0-9]|[0-9][0-9]|[0-9][0-9])\\d{8}$', 'g');
@@ -166,8 +180,8 @@
}
// 时间格式化
export function timeFormat(value, isValue) {
   return !!value ? moment(value).format('YYYY-MM-DD HH:mm:ss') : isValue ? '' : '-';
export function timeFormat(value, isValue, timeFormat) {
   return !!value ? moment(value).format(timeFormat ? timeFormat : 'YYYY-MM-DD HH:mm:ss') : isValue ? '' : '-';
}
export function dateFormat(value) {
@@ -308,3 +322,45 @@
export function verifyEmpty(value) {
   return value?.replace(/\s+/g, '');
}
// 获取元素距离可视区域顶部、左部的距离
export const getOffset = (ele) => {
  var top = ele.offsetTop
  var left = ele.offsetLeft
  while (ele.offsetParent) {
    ele = ele.offsetParent
    if (window.navigator.userAgent.indexOf('MSTE 8') > -1) {
      top += ele.offsetTop
      left += ele.offsetLeft
    } else {
      top += ele.offsetTop + ele.clientTop
      left += ele.offsetLeft + ele.clientLeft
    }
  }
  return {
    left: left,
    top: top,
  }
}
export const getSize = () => {
  let windowW, windowH, contentH, contentW, scrollT;
  windowH = window.innerHeight;
  windowW = window.innerWidth;
  scrollT = document.documentElement.scrollTop || document.body.scrollTop;
  contentH =
    document.documentElement.scrollHeight > document.body.scrollHeight ?
      document.documentElement.scrollHeight :
      document.body.scrollHeight;
  contentW =
    document.documentElement.scrollWidth > document.body.scrollWidth ?
      document.documentElement.scrollWidth :
      document.body.scrollWidth;
  return {
    windowW,
    windowH,
    contentH,
    contentW,
    scrollT
  };
};