index.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. // 设置根节点html的字体大小用于移动端适配使用
  2. export const setHtmlFontSize = () => {
  3. console.count("setHtmlFontSize");
  4. (function (doc, win) {
  5. let resizeEvt = "orientationchange" in win ? "orientationchange" : "resize",
  6. recalc = function () {
  7. let htmlDom = doc.getElementsByTagName("html")[0];
  8. requestAnimationFrame(() => {
  9. let clientWidth = doc.documentElement.clientWidth || doc.body.clientWidth;
  10. if (!clientWidth) return;
  11. htmlDom.style.fontSize =
  12. clientWidth >= 578.88 ? "144px" : 154.5 * (clientWidth / 578.88) + "px";
  13. });
  14. };
  15. if (!doc.addEventListener) return;
  16. win.addEventListener(resizeEvt, recalc, false);
  17. doc.addEventListener("DOMContentLoaded", recalc, false);
  18. recalc();
  19. })(document, window);
  20. };
  21. // 密码正则 6到12位(字母,数字,下划线,减号)
  22. export const pwdRegex = (pwd = '') => {
  23. let regex = /^[a-zA-Z0-9_-]{6,12}$/;
  24. return regex.test(pwd)
  25. }
  26. // 手机号正则
  27. export const phoneRegex = (pwd = '') => {
  28. let regex = /^1[3-9]\d{9}$/;
  29. return regex.test(pwd)
  30. }