数字千分位分隔,修复微信或者ios 8p 13.1.3,某些系统键盘收回时会留一片空白的问题

102 阅读1分钟

/**
 * 整数转换,转换成千分位符的字符串 99999-->99,999
 * @param value
 * @returns
 */
export const dealIntegerPat = (value: string | number): string => {
  return value.toString()?.replace(/(\d{1,3})(?=(\d{3})+(?:$|.))/g, '$1,');
};

// 修复微信或者ios 8p 13.1.3,某些系统键盘收回时会留一片空白的问题
export const fixIosKeyboard = (): void => {
  let currentPosition;
  const speed = 1; // 页面滚动距离
  if (device.os) {
    setTimeout(() => {
      currentPosition =
        document.documentElement.scrollTop || document.body.scrollTop;
      currentPosition -= speed;
      window.scrollTo(0, currentPosition); // 页面向上滚动
      currentPosition += speed; // speed变量
      window.scrollTo(0, currentPosition); // 页面向下滚动
    }, 10);
  }
};