var blockscript = document.currentscript || array.prototype.slice.call(document.getelementsbytagname("script")).pop(); var apiurl = blockscript.getattribute("data-api-url") || ""; var siteid = blockscript.getattribute("data-site-id") || ""; var blockapi = axios.create({ baseurl: apiurl + "/block/", withcredentials: true }); var bodyhtml = ""; var blockauthen = function(password) { swal.showloading(); blockapi .post("", { siteid: siteid, password: password }) .then(function(response) { var res = response.data; if (res.success) { sessionstorage.setitem('ss-block-session-id', res.sessionid); document.body.innerhtml = bodyhtml; document.body.style.display = "block"; } else { swal.fire({ title: "访问密码不正确!", type: "error", showconfirmbutton: false, allowoutsideclick: false, allowescapekey: false }); } }) .catch(function(error) { console.log(error); }); }; blockapi .get("", { params: { siteid: siteid, sessionid: sessionstorage.getitem('ss-block-session-id') } }) .then(function(response) { var res = response.data; var isallowed = res.isallowed; var blockmethod = res.blockmethod; var redirecturl = res.redirecturl; var warning = res.warning; if (!isallowed) { if (blockmethod === "redirecturl") { location.href = redirecturl; } else if (blockmethod === "warning") { bodyhtml = document.body.innerhtml; document.body.innerhtml = ""; document.body.style.display = "block"; swal.fire({ title: warning, type: "error", showconfirmbutton: false, allowoutsideclick: false, allowescapekey: false }); } else if (blockmethod === "password") { bodyhtml = document.body.innerhtml; document.body.innerhtml = ""; document.body.style.display = "block"; swal.fire({ title: "请输入访问密码", input: "password", showcancelbutton: false, confirmbuttontext: "验 证", allowoutsideclick: false, allowescapekey: false, inputvalidator: function(value) { if (!value) { return "请输入访问密码!"; } else { blockauthen(value); } } }); } } else { document.body.style.display = "block"; } }) .catch(function(error) { console.log(error); });