orcrist-wechat
Version:
for Orcrist Wechat sdk
78 lines (65 loc) • 1.86 kB
JavaScript
/**
* 获取url?后参数
*/
export const getQueryString = (t, e) => {
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] : "");
};
//获取url后面所有的search
export const getQueryMap = (t) => {
var e,
n,
o = {},
a = /[\?\&][^\?\&]+=[^\?\&#]+/g,
i = /[\?\&]([^=\?]+)=([^\?\&#]+)/;
if (((t = t || window.location.href), (e = t.match(a)), !e)) {
return o;
}
for (var r = 0, l = e.length; r < l; r++) {
n = e[r].match(i);
null !== n && (o[n[1]] = n[2]);
}
return o;
};
/**
* toast 原生组件
*/
export const Toast = (text, time) => {
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) => {
setTimeout(() => {
container.parentNode.removeChild(container);
}, 500);
};
};