123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- // 设置根节点html的字体大小用于移动端适配使用
- export const setHtmlFontSize = () => {
- console.count("setHtmlFontSize");
- (function (doc, win) {
- let resizeEvt = "orientationchange" in win ? "orientationchange" : "resize",
- recalc = function () {
- let htmlDom = doc.getElementsByTagName("html")[0];
- requestAnimationFrame(() => {
- let clientWidth = doc.documentElement.clientWidth || doc.body.clientWidth;
- if (!clientWidth) return;
- htmlDom.style.fontSize =
- clientWidth >= 578.88 ? "144px" : 154.5 * (clientWidth / 578.88) + "px";
- });
- };
- if (!doc.addEventListener) return;
- win.addEventListener(resizeEvt, recalc, false);
- doc.addEventListener("DOMContentLoaded", recalc, false);
- recalc();
- })(document, window);
- };
- // 密码正则 6到12位(字母,数字,下划线,减号)
- export const pwdRegex = (pwd = "") => {
- let regex = /^[a-zA-Z0-9_-]{6,12}$/;
- return regex.test(pwd);
- };
- export const phoneRegex = (pwd = "") => {
- let regex = /^1[3-9]\d{9}$/;
- return regex.test(pwd);
- };
- /**
- * @description 是否是合格http外链
- */
- export const isHttpUrl = (url: string) => {
- const regex = /^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/;
- return regex.test(url);
- };
- export const isHttpsUrl = (url: string) => {
- const regex = /^(?:https?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\*\+,;=.]+$/;
- return regex.test(url);
- };
- /**
- * @description 是否是合格邮箱
- */
- export const emailReg = /^\w+(-+.\w+)*@\w+(-.\w+)*.\w+(-.\w+)*$/;
- export const isEmail = (email: string) => {
- return emailReg.test(email);
- };
- /**
- * @description 只能是数字和英文
- */
- export const neReg = /^[A-Za-z0-9]+$/;
- export const isNE = (value: string) => {
- return neReg.test(value);
- };
- /**
- * @description 是否是pwa
- */
- export const isInStandaloneMode = () =>
- window.matchMedia("(display-mode: standalone)").matches ||
- document.referrer.includes("android-app://");
|