export const getQueryString = (t: string, e: any) => { var n = new RegExp(`[&,?]${t}=([^\\&]*)`, "i"), o = n.exec(e || window.location.search), oHash = n.exec(e || window.location.hash); // 兼容hash传递的参数 return (o ? o[1] : "") || (oHash ? oHash[1] : ""); }; /* 字符串转成数组 */ export const strToArr = (str: string, arrLen: number) => { let arr = str.split(""); for (let i = arr.length; i < arrLen; i++) { arr[i] = " "; } return arr; }; /** * toast 原生组件 */ export const Toast = (text: string, time: number) => { const content = document.createElement("div"); const ele = document.createElement("span"); content.appendChild(ele); content.style.opacity = "0"; content.style.transition = "all 0.2s"; content.style.position = "fixed"; content.style.top = "0"; content.style.left = "0"; content.style.zIndex = "9999"; content.style.width = "100%"; content.style.height = "100%"; content.style.display = "flex"; content.style.justifyContent = "center"; content.style.alignItems = "center"; content.style.padding = "50px"; ele.innerHTML = text; ele.style.background = "rgba(0, 0, 0, 0.7)"; ele.style.borderRadius = "15px"; ele.style.padding = "15px 15px"; ele.style.fontSize = "26px"; ele.style.color = "#fff"; ele.style.textAlign = "center"; setTimeout(() => { content.style.opacity = "1"; }, 10); document.body.appendChild(content); setTimeout(() => { content.style.opacity = "0"; removeToast(content); }, time * 1000); const removeToast = (container: any) => { setTimeout(() => { container.parentNode.removeChild(container); }, 500); }; }; export const getSources = () => { let sources = getQueryString("sources", location.href) sources = sources === "1000000000" ? "1100110101" : sources; return sources; }; export const getSaleChannelId = () => { let sources = getQueryString("saleChannelId", location.href); return sources; }; export const getSkuCode = () => { let sources = getQueryString("skuCode", location.href); return sources; }; export const phoneNumberCheck = (phone: string) => { return /^1\d{10}$/.test(phone); }; export const numberCodeCheck = (numberCode: string) => { return /\d{6}$/.test(numberCode); }; export const isweixin = () => { return /MicroMessenger/i.test(navigator.userAgent); }; export const getMessage = (code: string) => { switch (code) { case "10001": return "登录失败,请重新登录"; case "10002": return "请输入防刷验证码"; case "10003": return "防刷验证码输入错误,请重新输入"; case "10004": return "验证码已过期,请重新发送"; case "10005": return "验证码输入有误,请重新输入"; case "10006": return "用户不存在,请重新输入"; case "10007": return "手机号输入有误"; case "10008": return "验证码类型输入有误"; case "10009": return "验证码发送失败"; case "10010": return "用户Id获取失败"; case "10011": return "验证码输入错误次数过多,请重新发送"; case "10012": return "微信openid获取失败"; case "10013": return "请填写手机号"; case "10014": return "获取第三方平台用户信息失败"; case "10015": return "资源组不存在"; case "10016": return "防刷验证码刷新过于频繁,请稍后重试"; case "10022": return "该账号已经在企业端注册"; default: return ""; } };