|

楼主 |
发表于 2025-3-13 12:26:14
|
显示全部楼层
河北省石家庄市
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.VerifyPlugin = factory());
})(this, (function () { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments;
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
// @ts-nocheck
var VerifyCodePlugin = /** @class */ (function () {
function VerifyCodePlugin(options) {
var _this_1 = this;
this.countDown = function () {
var _a, _b, _c, _d;
var _this = _this_1;
var second = _this.flag.countDown - 1;
_this.flag.countDown = second;
if (!((_a = _this.options.params) === null || _a === void 0 ? void 0 : _a.uid)) {
clearTimeout(_this.flag.countDownTimer);
_this.flag.countDownTimer = null;
return;
}
if (second > 0 && localStorage.getItem("verify_count_down_info".concat((_b = _this.options.params) === null || _b === void 0 ? void 0 : _b.uid))) {
_this.$count_down_num.innerHTML = second;
localStorage.setItem("verify_count_down_info".concat((_c = _this.options.params) === null || _c === void 0 ? void 0 : _c.uid), JSON.stringify({
time: new Date().getTime(),
seconds: second,
}));
_this.flag.countDownTimer = setTimeout(function () {
_this.countDown();
}, 1000);
}
else {
clearTimeout(_this.flag.countDownTimer);
_this.flag.countDownTimer = null;
_this.flag.countDown = 60;
_this.resetState(0);
localStorage.removeItem("verify_count_down_info".concat((_d = _this.options.params) === null || _d === void 0 ? void 0 : _d.uid));
}
};
this.flag = {
isMouseDown: false,
startX: 0,
endX: 0,
parentOffset: 0,
timerHandler: null,
// canDrag: true,
isSuccess: false,
originx: '',
originy: '',
token: '',
requestTimer: null,
loading: false,
ele: null,
countDown: 60,
countDownTimer: null
};
// 存放鼠标轨迹以及时间戳
this.publicTimer = null;
this.trajectory = ''; // 鼠标轨迹
this.startStamp = '';
this.puzzleImgLeft = 0; // 小图距离左侧的距离
this.puzzleInfo = null;
}
VerifyCodePlugin.prototype.init = function (options) {
this.flag.countDown = 60;
clearTimeout(this.flag.countDownTimer);
this.flag.countDownTimer = null;
this.trajectory = '';
this.setOption(options);
this.render();
this.getDom();
this.getClass();
if (this.options.type !== 'popup') {
this.getCaptcha();
}
this.bind();
};
VerifyCodePlugin.prototype.setOption = function (options) {
var _default = {
type: '',
target: '',
w: '290px',
riskRequestId: '',
projectToken: '',
projectTeamToken: '',
zIndex: 9999,
env: '',
loadingText: options.loadingText ? options.loadingText : '加载中',
btnText: options.btnText ? options.btnText : '向右滑动完成验证',
headerText: options.headerText ? options.headerText : '请完成安全验证',
resetDuration: options.resetDuration || 1000,
maskClosable: true,
countDownText: '验证过于频繁,请{s}秒后重试',
genUrl: '',
checkUrl: '',
params: {},
dragCircle: true,
init: function () { },
callback: function () { }
};
this.options = this.extend(_default, options);
};
VerifyCodePlugin.prototype.extend = function (target, options) {
for (var item in options) {
target[item] = options[item];
}
return target;
};
VerifyCodePlugin.prototype.render = function () {
this.destory();
var html = '<div class="ptlogin-slider-verify ' + (this.options.type || '') + '" id="ptlogin_slider" style="width: ' + this.options.w + '">' +
'<div class="verify_panel" id="verify_panel">' +
'<div class="verify_panel-placeholder" id="verify_panel-placeholder">' +
'<div class="verify_bgimg">' +
'<img class="big-img" id="puzzle_big" alt="" src="" />' +
'<img class="puzzle-img" id="puzzle_small" src="" style="left: 0px;" />' +
'</div>' +
'<div class="offline" id="offline">' +
'<div class="offline-text" id="offline-text">图片加载失败,请稍后重试</div>' +
'</div>' +
'<div class="verify-loadbox" id="loadbox">' +
'<div class="loadbox-inner">' +
'<i class="verify-loading-icon"></i>' +
'<span class="loading_text" id="verify_loading_text">' + this.options.loadingText + '</span>' +
'</div>' +
'</div>' +
'<div class="count-down">' +
'<div class="count-down-text">' +
this.options.countDownText.replace('{s}', '<span class="count-down-num" id="count-down-num">60</span>') +
'</div>' +
'</div>' +
'<span class="refresh-btn" id="refresh_btn"></span>' +
'</div>' +
'</div>' +
'<div class="verify-bar-area" id="verify-bar">' +
'<span class="verify-multi-error-msg" id="multi-error-retry">失败过多,点此重试</span>' +
'<span class="verify-msg" id="verify_msg">' +
this.options.btnText +
'</span>' +
'<div class="verify_slide_indicator" id="slide_indicator" style="width: 0px"></div>' +
'<div class="verify_slide_drag" id="drag" style="left: 0px">' +
'<div class="verify_slide_icon"><i></i><i></i><i></i></div>' + '</div>' + '</div>' + '</div>';
if (this.options.type === 'popup') {
var popup = '<div class="popup-verify-mask verify-hide" id="popup-verify-mask" style="z-index: ' + this.options.zIndex + '">' +
'<div class="popup-verify-wrapper" id="verify-wrapper">' +
'<div class="popup-verify-header">' + '<div id="popup-verify-header-text">' + this.options.headerText + '</div>' +
'<span id="popup-verify-close"></span>' +
'</div>' +
'<div class="popup-verify-body">' + html + '</div>' +
'</div>' + '</div>';
if (document.getElementById(this.options.target)) {
document.getElementById(this.options.target).innerHTML = popup;
}
else {
if (this.flag.ele) {
this.flag.ele.innerHTML = '';
// document.body.removeChild(this.flag.ele);
}
var ele = document.createElement('div');
ele.innerHTML = popup;
document.body.appendChild(ele);
this.flag.ele = ele;
document.getElementById('popup-verify-mask').style.position = 'fixed';
}
}
else {
if (document.getElementById(this.options.target)) {
document.getElementById(this.options.target).innerHTML = html;
}
}
};
VerifyCodePlugin.prototype.getCaptcha = function (callback) {
var _this = this;
this.$loadbox.style.display = 'block';
this.$ptlogin_slider.className =
this.ptlogin_slider_Class + ' vloading';
this.flag.loading = true;
this.$ptlogin_slider.style.width = _this.options.w;
this.setDataSource(callback);
};
VerifyCodePlugin.prototype.postAsync = function (url, parms, success, error) {
if (window.XMLHttpRequest) {
var xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
var xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
xhr.open('post', url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(parms);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
success(xhr);
}
else {
error(xhr);
}
}
};
};
// 设置图片地址
VerifyCodePlugin.prototype.setDataSource = function (callback) {
var _this_1 = this;
var _a, _b, _c;
var _this = this;
if (!window.navigator.onLine) {
_this.setOffline();
return;
}
if ((_a = _this.options.params) === null || _a === void 0 ? void 0 : _a.uid) {
var count_down_info = localStorage.getItem("verify_count_down_info".concat((_b = _this.options.params) === null || _b === void 0 ? void 0 : _b.uid));
if (count_down_info) {
var now = new Date();
var info = JSON.parse(count_down_info);
var count = Math.floor((now.getTime() - info.time) / 1000);
if (count < info.seconds) {
this.$loadbox.style.display = 'none';
this.setMultiError(info.seconds - count);
return;
}
else {
localStorage.removeItem("verify_count_down_info".concat((_c = _this.options.params) === null || _c === void 0 ? void 0 : _c.uid));
}
}
}
this.$loadbox.style.display = 'block';
this.$ptlogin_slider.className =
this.ptlogin_slider_Class + ' vloading';
this.$verify_msg.innerHTML = this.options.loadingText;
this.flag.loading = true;
var env = this.options.env === '' ? '' : "".concat(this.options.env, ".");
this.postAsync(_this.options.genUrl && _this.options.genUrl !== '' ? _this.options.genUrl : "//".concat(env, "api.4399dev.com/risk/captcha/gen"), JSON.stringify(__assign({ "riskRequestId": this.options.riskRequestId, "captchaType": 1, "projectToken": this.options.projectToken, "projectTeamToken": this.options.projectTeamToken }, this.options.params)), function (res) {
var data = JSON.parse(res.response);
var _this = _this_1;
if (!data.id && data.code !== 9403) {
_this.setOffline('出现未知错误,请重新验证');
}
else if (data.code === 9403) {
_this_1.setMultiError();
_this.$loadbox.style.display = 'none';
// _this.$ptlogin_slider.className =
// _this.ptlogin_slider_Class;
_this.$verify_msg.innerHTML = _this.options.btnText;
_this.flag.loading = false;
return;
}
_this_1.flag.canDrag = true;
_this.puzzleInfo = data;
_this.$puzzle_big.setAttribute('src', data.backgroundImage);
_this.$puzzle_small.setAttribute('src', data.sliderImage);
_this.$puzzle_small.style.top = '0px';
if (callback) {
callback();
}
}, function (err) {
if (err.status == 429) {
var _this = _this_1;
if (_this.flag.requestTimer) {
clearTimeout(_this.flag.requestTimer);
}
_this.flag.requestTimer = setTimeout(function (e) {
this.setDataSource(callback);
}, 500);
}
else {
_this.setOffline('出现未知错误,请重新验证');
}
});
};
VerifyCodePlugin.prototype.getDom = function () {
this.$ptlogin_slider = document.getElementById('ptlogin_slider');
this.$drag = document.getElementById('drag');
this.$puzzle_big = document.getElementById('puzzle_big');
this.$puzzle_small = document.getElementById('puzzle_small');
this.$verify_msg = document.getElementById('verify_msg');
this.$verifyBar = document.getElementById('verify-bar');
this.$slide_indicator = document.getElementById('slide_indicator');
this.$tips = document.getElementById('tips');
this.$loadbox = document.getElementById('loadbox');
this.$resultJson = document.getElementById('result_json');
this.$refresh_btn = document.getElementById('refresh_btn');
this.$verify_panel = document.getElementById('verify_panel');
this.$loading_text = document.getElementById('verify_loading_text');
this.$multi_error_retry = document.getElementById('multi-error-retry');
this.$count_down_num = document.getElementById('count-down-num');
this.$offline_text = document.getElementById('offline-text');
this.$verify_panel_placeholder = document.getElementById('verify_panel-placeholder');
if (this.options.type === 'popup') {
this.$verify_close = document.getElementById('popup-verify-close');
this.$verify_mask = document.getElementById('popup-verify-mask');
this.$verify_wrapper = document.getElementById('verify-wrapper');
this.$verify_header_text = document.getElementById('popup-verify-header-text');
}
};
VerifyCodePlugin.prototype.getClass = function () {
this.verifyBar_Class = this.$verifyBar.className;
this.ptlogin_slider_Class = this.$ptlogin_slider.className;
this.slide_indicator_Class = this.$slide_indicator.className;
if (this.options.type === 'popup') {
this.verify_mask_Class = 'popup-verify-mask';
}
};
VerifyCodePlugin.prototype.bind = function () {
var _this = this;
this.addEvent(this.$drag, 'mousedown', function (event) {
_this.mousedownHandler(event);
});
this.addEvent(this.$drag, 'touchstart', function (event) {
_this.mousedownHandler(event);
_this.onmouseoverHandler(event);
});
this.addEvent(document, 'mousemove', function (event) {
_this.mousemoveHandler(event);
});
this.addEvent(window, 'touchmove', function (event) {
_this.mousemoveHandler(event);
});
this.addEvent(document, 'mouseup', function (event) {
_this.mouseupHandler(event);
});
this.addEvent(window, 'touchend', function (event) {
_this.mouseupHandler(event);
});
this.addEvent(_this.$refresh_btn, 'click', function (event) {
console.log(event);
if (event.stopPropagation) {
event.stopPropagation(); // 针对非IE浏览器
}
else {
event.cancelBubble = true; // 针对IE浏览器
}
if (_this.flag.canDrag || _this.$ptlogin_slider.className.indexOf('network-error') !== -1) {
_this.$loadbox.style.display = 'block';
_this.$ptlogin_slider.className =
_this.ptlogin_slider_Class + ' vloading';
_this.$verify_msg.innerHTML = _this.options.loadingText;
_this.flag.loading = true;
_this.resetState(0);
}
});
this.addEvent(this.$multi_error_retry, 'click', function () {
_this.$loadbox.style.display = 'block';
_this.$ptlogin_slider.className =
_this.ptlogin_slider_Class + ' vloading';
_this.$verify_msg.innerHTML = _this.options.loadingText;
_this.flag.loading = true;
_this.resetState(0);
});
this.addEvent(this.$verifyBar, 'mouseover', function () {
_this.onmouseoverHandler(event);
});
this.addEvent(this.$puzzle_big, 'load', function (e) {
_this.$loadbox.style.display = 'none';
_this.$ptlogin_slider.className =
_this.ptlogin_slider_Class;
_this.$verify_msg.innerHTML = _this.options.btnText;
_this.flag.loading = false;
});
// this.addEvent(this.$puzzle_small, 'load', function(){
// _this.$loadbox.style.display = 'none';
// })
if (this.options.type === 'popup') {
_this.addEvent(_this.$verify_close, 'click', function () {
_this.hideVerify();
});
_this.addEvent(_this.$verify_mask, 'click', function (event) {
if (_this.isElementOrDescendant(event.target, _this.$verify_wrapper))
return;
var ele = document.getElementById('ptlogin_slider');
if (ele.className.indexOf('moving') !== -1 || !_this.options.maskClosable)
return;
_this.hideVerify();
});
}
};
VerifyCodePlugin.prototype.isElementOrDescendant = function (a, b) {
var node = a;
while (node !== null && node !== b) {
node = node.parentNode;
}
return node === b;
};
VerifyCodePlugin.prototype.hideVerify = function () {
if (this.options.type !== 'popup')
return;
var _this = this;
_this.$verify_mask.className =
_this.verify_mask_Class + ' verify-hide ';
};
VerifyCodePlugin.prototype.showVerify = function () {
var _a, _b, _c;
if (this.options.type !== 'popup')
return;
var _this = this;
if (!window.navigator.onLine) {
_this.setOffline();
_this.$verify_mask.className =
_this.verify_mask_Class;
return;
}
if ((_a = _this.options.params) === null || _a === void 0 ? void 0 : _a.uid) {
var count_down_info = localStorage.getItem("verify_count_down_info".concat((_b = _this.options.params) === null || _b === void 0 ? void 0 : _b.uid));
if (count_down_info) {
var now = new Date();
var info = JSON.parse(count_down_info);
var count = Math.floor((now.getTime() - info.time) / 1000);
if (count < info.seconds) {
this.$loadbox.style.display = 'none';
this.setMultiError(info.seconds - count);
_this.$verify_mask.className =
_this.verify_mask_Class;
return;
}
else {
localStorage.removeItem("verify_count_down_info".concat((_c = _this.options.params) === null || _c === void 0 ? void 0 : _c.uid));
}
}
}
_this.resetState(0);
_this.$loadbox.style.display = 'block';
_this.$ptlogin_slider.className =
_this.ptlogin_slider_Class + ' vloading';
_this.$verify_msg.innerHTML = _this.options.loadingText;
_this.flag.loading = true;
_this.$verify_mask.className =
_this.verify_mask_Class;
};
VerifyCodePlugin.prototype.onmouseoverHandler = function (event) {
if (this.flag.loading)
return;
this.$verify_panel.style.display = 'block';
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
this.flag.originy = this.$ptlogin_slider.offsetTop - scrollTop;
this.flag.originx = this.$ptlogin_slider.offsetLeft;
};
VerifyCodePlugin.prototype.mousedownHandler = function (event) {
if (this.flag.loading)
return;
if (this.flag.canDrag) {
if (!event.touches) {
var clientX = event.clientX;
var clientY = event.clientY;
}
else {
var clientX = event.touches[0].pageX;
var clientY = event.touches[0].pageY;
}
this.startStamp = new Date().getTime();
this.trajectory =
this.trajectory +
clientX +
',' +
clientY +
',' +
this.startStamp +
'|';
this.flag.isMouseDown = true;
// 防止 ie 拖动时元素被选中
this.$ptlogin_slider.onselectstart = function () {
return false;
};
this.flag.startX = clientX;
this.flag.parentOffset = this.$verifyBar.offsetLeft;
}
};
VerifyCodePlugin.prototype.mousemoveHandler = function (event) {
if (this.flag.loading)
return;
if (this.flag.isMouseDown) {
event.preventDefault();
if (!event.touches) {
var clientX = event.clientX;
var clientY = event.clientY;
}
else {
var clientX = event.touches[0].pageX;
var clientY = event.touches[0].pageY;
}
var diff = new Date().getTime() - this.startStamp;
this.trajectory =
this.trajectory +
clientX +
',' +
clientY +
',' +
diff +
'|';
this.flag.endX =
clientX - this.flag.startX + this.flag.parentOffset;
this.limitDragArea();
this.$drag.style.left = this.flag.endX + 'px';
this.puzzleImgLeft = this.flag.endX;
this.$puzzle_small.style.left = this.flag.endX * ((this.$ptlogin_slider.clientWidth - this.$puzzle_small.clientWidth) / (this.$verifyBar.clientWidth - this.$drag.clientWidth)) + 'px';
this.$slide_indicator.style.width = Number(this.flag.endX) > 0 ?
(Number(this.flag.endX) +
(this.options.dragCircle ? this.$drag.clientWidth / 2 : 0) +
'px') : '0px';
this.$verify_msg.innerHTML = '';
this.$verifyBar.className =
this.verifyBar_Class + ' slider-moving';
this.$ptlogin_slider.className =
this.ptlogin_slider_Class + ' moving';
}
return;
};
VerifyCodePlugin.prototype.mouseupHandler = function (event) {
if (this.flag.loading)
return;
var _this = this;
if (_this.flag.isMouseDown) {
// _this.flag.isMouseDown = false;
// _this.flag.canDrag = false;
if (this.flag.endX > -1) {
_this.flag.isMouseDown = false;
_this.flag.canDrag = false;
}
this.validate();
}
};
VerifyCodePlugin.prototype.validate = function () {
var _this_1 = this;
var _this = this;
if (!window.navigator.onLine) {
_this.setOffline();
return;
}
var env = this.options.env === '' ? '' : "".concat(this.options.env, ".");
this.postAsync(_this.options.checkUrl && _this.options.checkUrl !== '' ? _this.options.checkUrl : "//".concat(env, "api.4399dev.com/risk/captcha/check"), JSON.stringify(__assign({ "riskRequestId": this.options.riskRequestId, "captchaType": 1, "id": this.puzzleInfo.id, "percentage": (this.$puzzle_small.offsetLeft / this.$puzzle_big.clientWidth).toFixed(2), "projectToken": this.options.projectToken, "projectTeamToken": this.options.projectTeamToken }, this.options.params)), function (res) {
var data = JSON.parse(res.response);
if (data.success) {
_this_1.setSuccess();
}
else {
_this_1.setError();
}
if (_this_1.options.callback) {
_this_1.options.callback(data);
}
}, function (err) {
_this.setOffline('出现未知错误,请重新验证');
});
};
VerifyCodePlugin.prototype.setOffline = function (text) {
if (text === void 0) { text = '图片加载失败,请稍后重试'; }
var _this = this;
_this.flag.canDrag = false;
_this.$offline_text.innerHTML = text;
_this.$ptlogin_slider.className =
_this.ptlogin_slider_Class + ' network-error';
_this.$verifyBar.className = _this.verifyBar_Class;
_this.$drag.style.left = 0;
_this.$puzzle_small.style.left = 0;
_this.$slide_indicator.style.width = 0;
_this.$loading_text.innerHTML = _this.options.loadingText;
_this.$verify_msg.innerHTML = _this.options.btnText;
if (_this.options.type === 'popup') {
_this.$verify_header_text.innerHTML = _this.options.headerText;
}
};
VerifyCodePlugin.prototype.setSuccess = function () {
var _this_1 = this;
var _this = this;
_this.$verifyBar.className =
_this.verifyBar_Class + ' verify-success';
this.$ptlogin_slider.className =
_this.ptlogin_slider_Class + ' success';
_this.flag.canDrag = false;
_this.flag.verifySuccess = true;
if (this.options.type === 'popup') {
_this.publicTimer = setTimeout(function () {
_this_1.hideVerify();
clearTimeout(_this.publicTimer);
_this.publicTimer = null;
}, 500);
}
};
VerifyCodePlugin.prototype.setError = function () {
var _this = this;
_this.$verifyBar.className =
_this.verifyBar_Class + ' verify-error ';
_this.trajectory = '';
_this.resetState();
};
VerifyCodePlugin.prototype.setMultiError = function (seconds) {
var _a;
if (seconds === void 0) { seconds = 60; }
var _this = this;
_this.flag.countDown = seconds;
_this.$count_down_num.innerHTML = seconds;
_this.$verifyBar.className =
_this.verifyBar_Class + ' verify-multi-error';
_this.$ptlogin_slider.className =
_this.ptlogin_slider_Class + ' multi-error';
_this.flag.canDrag = false;
_this.$drag.style.left = 0;
_this.$puzzle_small.style.left = 0;
_this.$slide_indicator.style.width = 0;
_this.$verify_msg.innerHTML = _this.options.btnText;
if (_this.flag.countDownTimer) {
clearTimeout(_this.flag.countDownTimer);
_this.flag.countDownTimer = null;
}
localStorage.setItem("verify_count_down_info".concat((_a = _this.options.params) === null || _a === void 0 ? void 0 : _a.uid), JSON.stringify({
time: new Date().getTime(),
seconds: seconds,
}));
_this.flag.countDownTimer = setTimeout(function () {
_this.countDown();
}, 1000);
};
VerifyCodePlugin.prototype.resetState = function (duration, callback) {
var _this = this;
if (_this.flag.timerHandler) {
clearTimeout(_this.flag.timerHandler);
}
this.flag.canDrag = true;
if (duration === 0) {
_this.$verifyBar.className = _this.verifyBar_Class;
_this.$ptlogin_slider.className = _this.ptlogin_slider_Class;
_this.$drag.style.left = 0;
_this.$puzzle_small.style.left = 0;
_this.$slide_indicator.style.width = 0;
_this.$count_down_num.innerHTML = 60;
_this.getCaptcha(function () {
_this.$loading_text.innerHTML = _this.options.loadingText;
if (_this.options.type === 'popup') {
_this.$verify_header_text.innerHTML = _this.options.headerText;
}
if (callback) {
callback();
}
});
return;
}
_this.flag.timerHandler = setTimeout(function (e) {
_this.$verifyBar.className = _this.verifyBar_Class;
_this.$ptlogin_slider.className = _this.ptlogin_slider_Class;
_this.$drag.style.left = 0;
_this.$puzzle_small.style.left = 0;
_this.$slide_indicator.style.width = 0;
_this.$count_down_num.innerHTML = 60;
_this.getCaptcha(function () {
_this.$loading_text.innerHTML = _this.options.loadingText;
if (_this.options.type === 'popup') {
_this.$verify_header_text.innerHTML = _this.options.headerText;
}
if (callback) {
callback();
}
});
}, duration || _this.options.resetDuration);
};
VerifyCodePlugin.prototype.countDragLeft = function (e, diff) {
if (e) {
var n;
var i;
var dragLeft = parseInt(this.$drag.offsetLeft, 10);
var ptlogin_slider_Width = this.$ptlogin_slider.clientWidth - diff;
var f = 40;
var a = dragLeft;
var c = diff < 0 ? -diff : diff / 2;
return dragLeft <= c
? ((n = dragLeft), (i = diff < 0 ? -n / 2 : n), (a += i))
: ptlogin_slider_Width - dragLeft - f <= c
? ((n = dragLeft - (ptlogin_slider_Width - f - c)),
(i = diff < 0 ? -n / 2 : n),
(a += diff / 2 + i))
: (a += diff / 2);
}
};
VerifyCodePlugin.prototype.addEvent = function (ele, type, handler) {
if (ele.addEventListener) {
ele.addEventListener(type, handler, { passive: false });
}
else if (ele.attachEvent) {
ele.attachEvent('on' + type, handler);
}
else {
ele['on' + type] = handler;
}
};
VerifyCodePlugin.prototype.removeEvent = function (ele, type, handler) {
if (ele.removeEventListener) {
ele.removeEventListener(type.handler, { passive: false });
}
else if (ele.detachEvent) {
ele.detachEvent('on' + type, handler);
}
else {
ele['on' + type] = null;
}
};
VerifyCodePlugin.prototype.limitDragArea = function () {
var ptlogin_slider_Width = this.$verifyBar.clientWidth;
var sliderWidth = this.$drag.clientWidth;
if (this.flag.endX <= 0) {
this.flag.endX = 0;
}
if (this.flag.endX >= ptlogin_slider_Width - sliderWidth) {
this.flag.endX = ptlogin_slider_Width - sliderWidth;
}
};
VerifyCodePlugin.prototype.nowTime = function () {
return new Date().getTime();
};
VerifyCodePlugin.prototype.rand = function () {
return Math.random()
.toString()
.substr(2);
};
VerifyCodePlugin.prototype.destory = function () {
if (this.options.type === 'popup') {
if (document.getElementById(this.options.target)) {
document.getElementById(this.options.target).innerHTML = '';
}
else {
if (this.flag.ele) {
this.flag.ele.innerHTML = '';
// document.body.removeChild(this.flag.ele);
}
}
}
else {
if (document.getElementById(this.options.target)) {
document.getElementById(this.options.target).innerHTML = '';
}
}
};
return VerifyCodePlugin;
}());
// @ts-nocheck
var VerifyMessagePlugin = /** @class */ (function () {
function VerifyMessagePlugin() {
this.timer = null;
this.status = 0; // 0 - 未获取 1 - 倒计时 2 - 验证失败 3 - 验证成功
this.seconds = 60;
this.code = '';
this.code_id = '';
this.phoneError = {
9101: '无权限',
1902: '参数不合法',
500: '未知错误'
},
this.codeError = {
9403: '限制访问',
9101: '无权限',
9404: '验证码生成错误',
9102: '账号体系不存在',
9405: '验证手机号失效',
500: '未知错误'
};
}
VerifyMessagePlugin.prototype.init = function (options) {
var _a, _b;
var _this = this;
this.setOption(options);
if (localStorage.getItem("mes_verfiy_code_".concat((_a = options.params) === null || _a === void 0 ? void 0 : _a.uid))) {
_this.code_id = localStorage.getItem("mes_verfiy_code_".concat((_b = options.params) === null || _b === void 0 ? void 0 : _b.uid));
}
if (options.target && options.target !== '') {
this.render();
this.getDom();
this.getClass();
this.bind();
this.getUserPhone();
}
};
VerifyMessagePlugin.prototype.setOption = function (options) {
var _default = {
target: '',
style: 'wap',
riskRequestId: '',
projectToken: '',
projectTeamToken: '',
params: {},
env: '',
bindCallback: null,
genUrl: '',
checkUrl: '',
phoneUrl: '',
callback: function () {
}
};
this.options = this.extend(_default, options);
};
VerifyMessagePlugin.prototype.extend = function (target, options) {
for (var item in options) {
target[item] = options[item];
}
return target;
};
VerifyMessagePlugin.prototype.getDom = function () {
var _a, _b, _c, _d;
var _this = this;
this.$mes_verify = document.getElementById('mes-verify');
this.$phone_input = document.getElementById('mes-verify-row-phone-input');
this.$code_input = document.getElementById('mes-verify-row-code-input');
this.$code_btn = document.getElementById('mes-verify-get-btn');
this.$confirm_btn = document.getElementById('mes-verify-confirm-btn');
this.$help_btn = document.getElementById('mes-verify-help-btn');
var count_down_info = localStorage.getItem("mes_verify_seconds_".concat((_a = _this.options.params) === null || _a === void 0 ? void 0 : _a.uid));
if (count_down_info) {
var now = new Date();
var info = JSON.parse(count_down_info);
var count = Math.floor((now.getTime() - info.time) / 1000);
if (count < info.seconds) {
_this.status = 1;
_this.seconds = info.seconds - count;
localStorage.setItem("mes_verify_seconds_".concat((_b = _this.options.params) === null || _b === void 0 ? void 0 : _b.uid), JSON.stringify({
time: new Date().getTime(),
seconds: _this.seconds,
}));
_this.$code_btn.classList.add('disabled');
_this.$code_btn.innerHTML = "".concat(_this.seconds, "s\u540E\u91CD\u65B0\u83B7\u53D6");
_this.timer = setTimeout(function () {
_this.countDown();
}, 1000);
}
else {
_this.$code_btn.classList.remove('disabled');
localStorage.removeItem("mes_verify_seconds_".concat((_c = _this.options.params) === null || _c === void 0 ? void 0 : _c.uid));
localStorage.removeItem("mes_verfiy_code_".concat((_d = _this.options.params) === null || _d === void 0 ? void 0 : _d.uid));
}
}
};
VerifyMessagePlugin.prototype.getClass = function () {
this.$mes_verify_class = this.$mes_verify.className;
this.$code_input_class = this.$code_input.className;
this.$code_btn_class = this.$code_btn.className;
this.$confirm_btn_class = this.$confirm_btn.className;
};
VerifyMessagePlugin.prototype.getUserPhone = function () {
var _this = this;
if (!window.navigator.onLine) {
_this.unKnownErrorModal();
return;
}
var env = this.options.env === '' ? '' : "".concat(this.options.env, ".");
this.postAsync(_this.options.phoneUrl && _this.options.phoneUrl !== '' ? _this.options.phoneUrl : "//".concat(env, "api.4399dev.com/risk/user/queryPhone"), JSON.stringify(__assign({ "riskRequestId": this.options.riskRequestId, "captchaType": 2, "projectToken": this.options.projectToken, "projectTeamToken": this.options.projectTeamToken }, this.options.params)), function (res) {
var data = JSON.parse(res.response);
if (data.data) {
if (data.data.phone) {
_this.$phone_input.value = data.data.phone;
}
}
else {
if (data.code === 4123) {
_this.noPhoneModal();
}
else {
_this.unKnownErrorModal();
}
}
}, function (err) {
_this.unKnownErrorModal();
});
};
VerifyMessagePlugin.prototype.getCode = function () {
var _this = this;
if (!window.navigator.onLine) {
_this.unKnownErrorModal();
return;
}
var env = this.options.env === '' ? '' : "".concat(this.options.env, ".");
if (_this.status == 1)
return;
this.postAsync(_this.options.genUrl && _this.options.genUrl !== '' ? _this.options.genUrl : "//".concat(env, "api.4399dev.com/risk/captcha/gen"), JSON.stringify(__assign({ "riskRequestId": this.options.riskRequestId, "captchaType": 2, "projectToken": this.options.projectToken, "projectTeamToken": this.options.projectTeamToken }, this.options.params)), function (res) {
var _a, _b;
var data = JSON.parse(res.response);
if (data.id) {
_this.code_id = data.id;
localStorage.setItem("mes_verfiy_code_".concat((_a = _this.options.params) === null || _a === void 0 ? void 0 : _a.uid), data.id);
_this.status = 1;
_this.seconds = 60;
localStorage.setItem("mes_verify_seconds_".concat((_b = _this.options.params) === null || _b === void 0 ? void 0 : _b.uid), JSON.stringify({
time: new Date().getTime(),
seconds: _this.seconds,
}));
_this.$code_btn.innerHTML = "".concat(_this.seconds, "s\u540E\u91CD\u65B0\u83B7\u53D6");
_this.$code_btn.classList.add('disabled');
_this.timer = setTimeout(function () {
_this.countDown();
}, 1000);
}
else {
_this.unKnownErrorModal();
}
}, (function (err) {
_this.unKnownErrorModal();
}));
};
VerifyMessagePlugin.prototype.postAsync = function (url, parms, success, error) {
if (window.XMLHttpRequest) {
var xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
var xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
xhr.open('post', url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(parms);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
success(xhr);
}
else {
error(xhr);
}
}
};
};
VerifyMessagePlugin.prototype.validateCode = function () {
var _this = this;
if (!window.navigator.onLine) {
_this.unKnownErrorModal();
return;
}
var env = this.options.env === '' ? '' : "".concat(this.options.env, ".");
this.postAsync(_this.options.checkUrl && _this.options.checkUrl !== '' ? _this.options.checkUrl : "//".concat(env, "api.4399dev.com/risk/captcha/check"), JSON.stringify(__assign({ "riskRequestId": _this.options.riskRequestId, "captchaType": 2, "id": _this.code_id, "data": _this.code, "projectToken": _this.options.projectToken, "projectTeamToken": _this.options.projectTeamToken }, _this.options.params)), function (res) {
var _a;
var data = JSON.parse(res.response);
if (data.code != 0) {
_this.unKnownErrorModal();
}
localStorage.removeItem("mes_verfiy_code_".concat((_a = _this.options.params) === null || _a === void 0 ? void 0 : _a.uid));
if (_this.options.callback) {
_this.options.callback(data);
}
}, function (err) {
_this.unKnownErrorModal();
});
};
VerifyMessagePlugin.prototype.setError = function () {
this.$mes_verify.className = this.$mes_verify_class + ' error';
};
VerifyMessagePlugin.prototype.removeError = function () {
this.$mes_verify.className = this.$mes_verify_class;
};
VerifyMessagePlugin.prototype.countDown = function () {
var _a, _b, _c;
var _this = this;
var seconds = _this.seconds - 1;
_this.seconds = seconds;
if (seconds > 0 && localStorage.getItem("mes_verify_seconds_".concat((_a = _this.options.params) === null || _a === void 0 ? void 0 : _a.uid))) {
_this.$code_btn.innerHTML = "".concat(_this.seconds, "s\u540E\u91CD\u65B0\u83B7\u53D6");
localStorage.setItem("mes_verify_seconds_".concat((_b = _this.options.params) === null || _b === void 0 ? void 0 : _b.uid), JSON.stringify({
time: new Date().getTime(),
seconds: _this.seconds,
}));
_this.timer = setTimeout(function () {
_this.countDown();
}, 1000);
}
else {
clearTimeout(_this.timer);
_this.timer = null;
_this.seconds = 60;
_this.status = 0;
_this.$code_btn.innerHTML = '获取验证码';
localStorage.removeItem("mes_verify_seconds_".concat((_c = _this.options.params) === null || _c === void 0 ? void 0 : _c.uid));
_this.$code_btn.classList.remove('disabled');
}
};
VerifyMessagePlugin.prototype.addEvent = function (ele, type, handler) {
if (ele.addEventListener) {
ele.addEventListener(type, handler, { passive: false });
}
else if (ele.attachEvent) {
ele.attachEvent('on' + type, handler);
}
else {
ele['on' + type] = handler;
}
};
VerifyMessagePlugin.prototype.removeEvent = function (ele, type, handler) {
if (ele.removeEventListener) {
ele.removeEventListener(type.handler, { passive: false });
}
else if (ele.detachEvent) {
ele.detachEvent('on' + type, handler);
}
else {
ele['on' + type] = null;
}
};
VerifyMessagePlugin.prototype.bind = function () {
var _this = this;
this.addEvent(this.$code_input, 'keyup', function (e) {
_this.code = e.target.value;
if (_this.code.length < 6) {
_this.$confirm_btn.className = _this.$confirm_btn_class;
}
else {
_this.$confirm_btn.classList.remove('disabled');
}
});
this.addEvent(this.$code_btn, 'click', function () {
_this.getCode();
});
this.addEvent(this.$confirm_btn, 'click', function () {
if (_this.code === '' || _this.code_id === '')
return;
_this.validateCode();
});
this.addEvent(this.$help_btn, 'click', function () {
var content = '<div>如果没有收到手机验证码,建议您进行以下操作:</div>' +
'<div>1.检查您的手机是否停机或无网络;</div>' +
'<div>2.检查您的手机号是否正确;</div>' +
'<div>3.检查您的验证码短信是否被屏蔽。</div>';
var footer = '<button class="verify-modal-primary-btn close-btn">确定</button>';
_this.modal({
content: content,
footer: footer
});
});
};
VerifyMessagePlugin.prototype.noPhoneModal = function () {
var _this = this;
var content = '<div>当前账号未绑定手机号,请先绑定手机验证后再进行操作</div>';
var footer = '<button class="verify-modal-primary-btn close-btn">知道了</button>';
if (_this.options.bindCallback) {
footer =
'<button class="verify-modal-primary-btn ok-btn">去绑定</button>' +
'<button class="verify-modal-default-btn close-btn">取消</button>';
}
_this.modal({
content: content,
footer: footer,
onOk: function (callback) {
callback();
_this.options.bindCallback();
}
});
};
VerifyMessagePlugin.prototype.noGetPhoneModal = function (content) {
var _this = this;
var content = content;
var footer = '<button class="verify-modal-primary-btn close-btn">知道了</button>';
_this.modal({
content: content,
footer: footer,
});
};
VerifyMessagePlugin.prototype.unKnownErrorModal = function () {
var _this = this;
var content = '<div>出现未知错误,请重新验证</div>';
var footer = '<button class="verify-modal-primary-btn ok-btn">重新验证</button>' +
'<button class="verify-modal-default-btn close-btn">取消</button>';
_this.modal({
content: content,
footer: footer,
onOk: function (callback) {
callback();
if (_this.options.target && _this.options.target !== '') {
_this.getUserPhone();
}
}
});
};
VerifyMessagePlugin.prototype.modal = function (_a) {
var _b = _a.title, title = _b === void 0 ? '提示' : _b, _c = _a.content, content = _c === void 0 ? '' : _c, _d = _a.footer, footer = _d === void 0 ? '' : _d, _e = _a.onOk, onOk = _e === void 0 ? function () { } : _e;
var _this = this;
var modal_html = '<div class="mes-verify-modal-mask">' +
'<div class="mes-verify-modal">' +
'<div class="mes-verify-modal-header">' +
title +
'<span class="mes-verify-modal-close-x"></span>' +
'</div>' +
'<div class="mes-verify-modal-body">' +
content +
'</div>' +
'<div class="mes-verify-modal-footer">' +
footer +
'</div>' +
'</div>' +
'</div>';
var ele = document.createElement('div');
ele.innerHTML = modal_html;
var close = ele.getElementsByClassName('mes-verify-modal-close-x')[0];
var cancel = ele.getElementsByClassName('close-btn')[0];
var oks = ele.getElementsByClassName('ok-btn');
if (oks.length !== 0) {
var ok = oks[0];
_this.addEvent(ok, 'click', function () {
onOk(function () {
document.body.removeChild(ele);
});
});
}
this.addEvent(close, 'click', function () {
document.body.removeChild(ele);
});
this.addEvent(cancel, 'click', function () {
document.body.removeChild(ele);
});
document.body.appendChild(ele);
};
VerifyMessagePlugin.prototype.render = function () {
var html_mes = '<div id="mes-verify" class="mes-verify-' + this.options.style + '">' +
'<div class="mes-verify-title">' +
'请先进行短信验证' +
'</div>' +
'<div class="mes-verify-row">' +
'<span class="mes-verify-row-label">' +
'手机号' +
'</span>' +
'<input class="mes-verify-row-input phone" disabled="true" id="mes-verify-row-phone-input"/>' +
'</div>' +
'<div class="mes-verify-row">' +
'<span class="mes-verify-row-label">' +
'验证码' +
'</span>' +
'<input class="mes-verify-row-input code" maxlength="6" autocomplete="off" placeholder="请输入验证码" id="mes-verify-row-code-input"/>' +
'<button class="mes-verify-get-btn" id="mes-verify-get-btn">' +
'获取验证码' +
'</button>' +
'<div class="mes-verify-error-tip">验证码错误</div>' +
'</div>' +
'<button class="mes-verify-confirm-btn disabled" id="mes-verify-confirm-btn">' +
'确定' +
'</button>' +
'<div class="mes-verify-help">' +
'无法接收验证码?' +
'<a class="mes-verify-help-btn" id="mes-verify-help-btn">查看帮助</a>' +
'</div>' +
'</div>';
if (document.getElementById(this.options.target)) {
document.getElementById(this.options.target).innerHTML = html_mes;
}
};
return VerifyMessagePlugin;
}());
// @ts-nocheck
var VerifyTextPlugin = /** @class */ (function () {
function VerifyTextPlugin(options) {
var _this_1 = this;
this.formatRes = function () {
var ratio = 614 / _this_1.$bgimg_box.clientWidth;
return _this_1.res.map(function (v) {
return {
"x": v.x * ratio,
"y": v.y * ratio
};
});
};
this.countDown = function () {
var _a, _b, _c, _d;
var _this = _this_1;
var second = _this.flag.countDown - 1;
_this.flag.countDown = second;
if (!((_a = _this.options.params) === null || _a === void 0 ? void 0 : _a.uid)) {
clearTimeout(_this.flag.countDownTimer);
_this.flag.countDownTimer = null;
return;
}
if (second > 0 && localStorage.getItem("verify_text_count_down_info".concat((_b = _this.options.params) === null || _b === void 0 ? void 0 : _b.uid))) {
_this.$count_down_num.innerHTML = second;
localStorage.setItem("verify_text_count_down_info".concat((_c = _this.options.params) === null || _c === void 0 ? void 0 : _c.uid), JSON.stringify({
time: new Date().getTime(),
seconds: second,
}));
_this.flag.countDownTimer = setTimeout(function () {
_this.countDown();
}, 1000);
}
else {
clearTimeout(_this.flag.countDownTimer);
_this.flag.countDownTimer = null;
_this.flag.countDown = 60;
_this.resetState(0);
localStorage.removeItem("verify_text_count_down_info".concat((_d = _this.options.params) === null || _d === void 0 ? void 0 : _d.uid));
}
};
this.flag = {
isMouseDown: false,
startX: 0,
endX: 0,
parentOffset: 0,
timerHandler: null,
// canDrag: true,
isSuccess: false,
originx: '',
originy: '',
token: '',
requestTimer: null,
loading: false,
ele: null,
countDown: 60,
countDownTimer: null
};
this.res = [];
this.publicTimer = null;
// 存放鼠标轨迹以及时间戳
this.trajectory = ''; // 鼠标轨迹
this.startStamp = '';
this.puzzleImgLeft = 0; // 小图距离左侧的距离
this.puzzleInfo = null;
}
VerifyTextPlugin.prototype.init = function (options) {
this.flag.countDown = 60;
clearTimeout(this.flag.countDownTimer);
this.flag.countDownTimer = null;
this.trajectory = '';
this.setOption(options);
this.render();
this.getDom();
this.getClass();
if (this.options.type !== 'popup') {
this.getCaptcha();
}
this.bind();
};
VerifyTextPlugin.prototype.setOption = function (options) {
var _default = {
type: '',
target: '',
w: '290px',
riskRequestId: '',
projectToken: '',
projectTeamToken: '',
zIndex: 9999,
env: '',
loadingText: options.loadingText ? options.loadingText : '加载中',
resetDuration: options.resetDuration || 1000,
maskClosable: true,
countDownText: '验证过于频繁,请{s}秒后重试',
params: {},
genUrl: '',
checkUrl: '',
dragCircle: true,
init: function () { },
callback: function () { }
};
this.options = this.extend(_default, options);
};
VerifyTextPlugin.prototype.extend = function (target, options) {
for (var item in options) {
target[item] = options[item];
}
return target;
};
VerifyTextPlugin.prototype.render = function () {
this.destory();
var html = '<div class="text-select-verify-wrapper ' + (this.options.type || '') + '">' +
'<div class="text-select-verify-tip">' + '请依次点击' + '<img class="tip-img" id="tip-img" alt="" src="" />' + '</div>' +
'<div class="ptlogin-slider-verify text-select-verify ' + (this.options.type || '') + '" id="ptlogin_slider-text" style="width: ' + this.options.w + '">' +
'<div class="verify_panel" id="verify_panel-text">' +
'<div class="text-select-verify-tip trigger">' + '请依次点击' + '<img class="tip-img" id="tip-img-trigger" alt="" src="" />' + '</div>' +
'<div class="verify_panel-placeholder" id="verify_panel-placeholder-text">' +
'<div class="verify_bgimg" id="bgimg_box-text">' +
'<img class="big-img" id="puzzle_big-text" alt="" src="" />' +
'</div>' +
'<div class="offline" id="offline">' +
'<div class="offline-text" id="offline-text-text">图片加载失败,请稍后<span class="text-retry-btn">重试</span></div>' +
'</div>' +
'<div class="verify-loadbox" id="loadbox-text">' +
'<div class="loadbox-inner">' +
'<i class="verify-loading-icon"></i>' +
'<span class="loading_text" id="verify_loading_text-text">' + this.options.loadingText + '</span>' +
'</div>' +
'</div>' +
'<div class="count-down">' +
'<div class="count-down-text">' +
this.options.countDownText.replace('{s}', '<span class="count-down-num" id="count-down-num-text">60</span>') +
'</div>' +
'</div>' +
'<div class="text-select-success">' +
'<div class="text-select-res-content">' +
'<div class="text-select-success-icon"></div>' +
'<div>验证通过</div>' +
'</div>' +
'</div>' +
'<div class="text-select-error">' +
'<div class="text-select-res-content">' +
'<div class="text-select-error-icon"></div>' +
'<div>验证失败,请重试</div>' +
'</div>' +
'</div>' +
'<i class="refresh-btn" id="refresh_btn-text"></i>' +
'</div>' +
'</div>' +
'<div class="verify-bar-area" id="verify-bar">' +
'<div class="normal">请完成安全验证</div>' +
'<div class="success"><span class="bar-icon"></span>验证成功</div>' +
'<div class="error"><span class="bar-icon"></span>验证失败</div>' +
'</div>' +
'</div>' +
'</div>';
if (this.options.type === 'popup') {
var popup = '<div class="popup-verify-mask verify-hide" id="popup-verify-mask-text" style="z-index: ' + this.options.zIndex + '">' +
'<div class="popup-verify-wrapper text-select" id="verify-wrapper-text">' +
'<div class="popup-verify-header">' + '<div id="popup-verify-header-text-text">' + '请依次点击' + '<img class="tip-img" id="tip-img-popup" alt="" src="" />' + '</div>' +
'<span id="popup-verify-close-text"></span>' +
'</div>' +
'<div class="popup-verify-body">' + html + '</div>' +
'</div>' + '</div>';
if (document.getElementById(this.options.target)) {
document.getElementById(this.options.target).innerHTML = popup;
}
else {
if (this.flag.ele) {
this.flag.ele.innerHTML = '';
this.flag.ele.remove();
}
var ele = document.createElement('div');
ele.innerHTML = popup;
document.body.appendChild(ele);
this.flag.ele = ele;
document.getElementById('popup-verify-mask-text').style.position = 'fixed';
}
}
else {
if (document.getElementById(this.options.target)) {
document.getElementById(this.options.target).innerHTML = html;
}
}
};
VerifyTextPlugin.prototype.getCaptcha = function (callback) {
var _this = this;
this.$loadbox.style.display = 'block';
this.$ptlogin_slider.className =
this.ptlogin_slider_Class + ' loading';
this.flag.loading = true;
this.$ptlogin_slider.style.width = _this.options.w;
this.clearMark();
this.setDataSource(callback);
};
VerifyTextPlugin.prototype.postAsync = function (url, parms, success, error) {
if (window.XMLHttpRequest) {
var xhr = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
var xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
xhr.open('post', url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(parms);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
success(xhr);
}
else {
error(xhr);
}
}
};
};
// 设置图片地址
VerifyTextPlugin.prototype.setDataSource = function (callback) {
var _this_1 = this;
var _a, _b, _c;
var _this = this;
if (!window.navigator.onLine) {
_this.setOffline();
return;
}
if ((_a = _this.options.params) === null || _a === void 0 ? void 0 : _a.uid) {
var count_down_info = localStorage.getItem("verify_text_count_down_info".concat((_b = _this.options.params) === null || _b === void 0 ? void 0 : _b.uid));
if (count_down_info) {
var now = new Date();
var info = JSON.parse(count_down_info);
var count = Math.floor((now.getTime() - info.time) / 1000);
if (count < info.seconds) {
this.$loadbox.style.display = 'none';
this.setMultiError(info.seconds - count);
return;
}
else {
localStorage.removeItem("verify_text_count_down_info".concat((_c = _this.options.params) === null || _c === void 0 ? void 0 : _c.uid));
}
}
}
this.$loadbox.style.display = 'block';
this.$ptlogin_slider.className =
this.ptlogin_slider_Class + ' loading';
this.flag.loading = true;
var env = this.options.env === '' ? '' : "".concat(this.options.env, ".");
this.postAsync(_this.options.genUrl && _this.options.genUrl !== '' ? _this.options.genUrl : "//".concat(env, "api.4399dev.com/risk/captcha/gen"), JSON.stringify(__assign({ "riskRequestId": this.options.riskRequestId, "captchaType": 3, "projectToken": this.options.projectToken, "projectTeamToken": this.options.projectTeamToken }, this.options.params)), function (res) {
var data = JSON.parse(res.response);
var _this = _this_1;
if (!data.id && data.code !== 9403) {
_this.setOffline('出现未知错误,请重新验证');
}
else if (data.code === 9403) {
_this_1.setMultiError();
_this.$loadbox.style.display = 'none';
// _this.$ptlogin_slider.className =
// _this.ptlogin_slider_Class;
_this.flag.loading = false;
return;
}
_this_1.flag.canDrag = true;
_this.puzzleInfo = data;
_this.$puzzle_big.setAttribute('src', data.backgroundImage);
_this.$puzzle_small.setAttribute('src', data.sliderImage);
if (callback) {
callback();
}
}, function (err) {
if (err.status == 429) {
var _this = _this_1;
if (_this.flag.requestTimer) {
clearTimeout(_this.flag.requestTimer);
}
_this.flag.requestTimer = setTimeout(function (e) {
this.setDataSource(callback);
}, 500);
}
else {
_this.setOffline('出现未知错误,请重新验证');
}
});
};
VerifyTextPlugin.prototype.getDom = function () {
this.$ptlogin_slider = document.getElementById('ptlogin_slider-text');
this.$bgimg_box = document.getElementById('bgimg_box-text');
this.$puzzle_big = document.getElementById('puzzle_big-text');
this.$puzzle_small = document.getElementById('tip-img');
if (this.options.type === 'trigger') {
this.$puzzle_small = document.getElementById('tip-img-trigger');
}
if (this.options.type === 'popup') {
this.$puzzle_small = document.getElementById('tip-img-popup');
}
this.$loadbox = document.getElementById('loadbox-text');
this.$refresh_btn = document.getElementById('refresh_btn-text');
this.$verify_panel = document.getElementById('verify_panel-text');
this.$loading_text = document.getElementById('verify_loading_text-text');
this.$count_down_num = document.getElementById('count-down-num-text');
this.$offline_text = document.getElementById('offline-text-text');
this.$verify_panel_placeholder = document.getElementById('verify_panel-placeholder-text');
if (this.options.type === 'popup') {
this.$verify_close = document.getElementById('popup-verify-close-text');
this.$verify_mask = document.getElementById('popup-verify-mask-text');
this.$verify_wrapper = document.getElementById('verify-wrapper-text');
this.$verify_header_text = document.getElementById('popup-verify-header-text-text');
}
};
VerifyTextPlugin.prototype.getClass = function () {
this.ptlogin_slider_Class = this.$ptlogin_slider.className;
if (this.options.type === 'popup') {
this.verify_mask_Class = 'popup-verify-mask';
}
};
VerifyTextPlugin.prototype.clearMark = function () {
this.res = [];
var marks = this.$bgimg_box.getElementsByClassName('verify-marker');
for (var i = 0; i < marks.length; i++) {
this.$bgimg_box.removeChild(marks);
}
};
VerifyTextPlugin.prototype.bind = function () {
var _this = this;
this.addEvent(this.$bgimg_box, 'mousedown', function (e) {
if (_this.res.length >= 3 || !_this.flag.canDrag) {
return;
}
var x = e.clientX - _this.$bgimg_box.getBoundingClientRect().left;
var y = e.clientY - _this.$bgimg_box.getBoundingClientRect().top;
var ele = document.createElement('span');
ele.innerHTML = _this.res.length + 1;
ele.classList.add('verify-marker');
ele.style.left = x + 'px';
ele.style.top = y + 'px';
_this.addEvent(ele, 'mousedown', function (e) {
if (ele.innerHTML == _this.res.length + '') {
e.stopPropagation();
_this.$bgimg_box.removeChild(ele);
_this.res.shift();
}
});
_this.$bgimg_box.appendChild(ele);
_this.res.push({ x: x, y: y });
if (_this.res.length === 3) {
_this.validate();
}
});
this.addEvent(this.$refresh_btn, 'click', function () {
if (_this.flag.canDrag || _this.$ptlogin_slider.className.indexOf('network-error') !== -1) {
_this.$loadbox.style.display = 'block';
_this.$ptlogin_slider.className =
_this.ptlogin_slider_Class + ' loading';
_this.flag.loading = true;
_this.resetState(0);
}
});
this.addEvent(this.$puzzle_big, 'load', function (e) {
_this.$loadbox.style.display = 'none';
_this.$ptlogin_slider.className =
_this.ptlogin_slider_Class;
_this.flag.loading = false;
});
// this.addEvent(this.$puzzle_small, 'load', function(){
// _this.$loadbox.style.display = 'none';
// })
if (this.options.type === 'popup') {
this.addEvent(this.$verify_mask, 'click', function () {
var ele = document.getElementById('ptlogin_slider');
if (ele.classList.contains('moving') || !_this.options.maskClosable)
return;
_this.hideVerify();
});
this.addEvent(this.$verify_close, 'click', function () {
_this.hideVerify();
});
this.addEvent(this.$verify_wrapper, 'click', function (event) {
event.stopPropagation();
});
}
};
VerifyTextPlugin.prototype.hideVerify = function () {
if (this.options.type !== 'popup')
return;
var _this = this;
_this.$verify_mask.className =
_this.verify_mask_Class + ' verify-hide ';
};
VerifyTextPlugin.prototype.showVerify = function () {
var _a, _b, _c;
if (this.options.type !== 'popup')
return;
var _this = this;
if (!window.navigator.onLine) {
_this.setOffline();
_this.$verify_mask.className =
_this.verify_mask_Class;
return;
}
if ((_a = _this.options.params) === null || _a === void 0 ? void 0 : _a.uid) {
var count_down_info = localStorage.getItem("verify_text_count_down_info".concat((_b = _this.options.params) === null || _b === void 0 ? void 0 : _b.uid));
if (count_down_info) {
var now = new Date();
var info = JSON.parse(count_down_info);
var count = Math.floor((now.getTime() - info.time) / 1000);
if (count < info.seconds) {
this.$loadbox.style.display = 'none';
this.setMultiError(info.seconds - count);
_this.$verify_mask.className =
_this.verify_mask_Class;
return;
}
else {
localStorage.removeItem("verify_text_count_down_info".concat((_c = _this.options.params) === null || _c === void 0 ? void 0 : _c.uid));
}
}
}
_this.resetState(0);
_this.$loadbox.style.display = 'block';
_this.$ptlogin_slider.className =
_this.ptlogin_slider_Class + ' loading';
_this.flag.loading = true;
_this.$verify_mask.className =
_this.verify_mask_Class;
};
VerifyTextPlugin.prototype.validate = function () {
var _this_1 = this;
var _this = this;
if (!window.navigator.onLine) {
_this.setOffline();
return;
}
var env = this.options.env === '' ? '' : "".concat(this.options.env, ".");
this.postAsync(_this.options.checkUrl && _this.options.checkUrl !== '' ? _this.options.checkUrl : "//".concat(env, "api.4399dev.com/risk/captcha/check"), JSON.stringify(__assign({ "riskRequestId": this.options.riskRequestId, "captchaType": 3, "id": this.puzzleInfo.id, "data": this.formatRes(), "projectToken": this.options.projectToken, "projectTeamToken": this.options.projectTeamToken }, this.options.params)), function (res) {
var data = JSON.parse(res.response);
if (data.success) {
_this_1.setSuccess();
}
else {
_this_1.setError();
}
if (_this_1.options.callback) {
_this_1.options.callback(data);
}
}, function (err) {
_this.setOffline('出现未知错误,请重新验证');
});
};
VerifyTextPlugin.prototype.setOffline = function (text) {
if (text === void 0) { text = '图片加载失败,请稍后重试'; }
var _this = this;
_this.flag.canDrag = false;
_this.$offline_text.innerHTML = text;
_this.$ptlogin_slider.className =
_this.ptlogin_slider_Class + ' network-error';
_this.$loading_text.innerHTML = _this.options.loadingText;
};
VerifyTextPlugin.prototype.setSuccess = function () {
var _this_1 = this;
var _this = this;
this.$ptlogin_slider.className =
_this.ptlogin_slider_Class + ' success';
_this.flag.canDrag = false;
_this.flag.verifySuccess = true;
if (this.options.type === 'popup') {
_this.publicTimer = setTimeout(function () {
_this_1.hideVerify();
clearTimeout(_this.publicTimer);
_this.publicTimer = null;
}, 500);
}
};
VerifyTextPlugin.prototype.setError = function () {
var _this = this;
_this.trajectory = '';
this.$ptlogin_slider.className =
_this.ptlogin_slider_Class + ' error';
_this.resetState();
};
VerifyTextPlugin.prototype.setMultiError = function (seconds) {
var _a;
if (seconds === void 0) { seconds = 60; }
var _this = this;
_this.flag.countDown = seconds;
_this.$count_down_num.innerHTML = seconds;
_this.$ptlogin_slider.className =
_this.ptlogin_slider_Class + ' multi-error';
_this.flag.canDrag = false;
if (_this.flag.countDownTimer) {
clearTimeout(_this.flag.countDownTimer);
_this.flag.countDownTimer = null;
}
localStorage.setItem("verify_text_count_down_info".concat((_a = _this.options.params) === null || _a === void 0 ? void 0 : _a.uid), JSON.stringify({
time: new Date().getTime(),
seconds: seconds,
}));
_this.flag.countDownTimer = setTimeout(function () {
_this.countDown();
}, 1000);
};
VerifyTextPlugin.prototype.resetState = function (duration, callback) {
var _this = this;
if (_this.flag.timerHandler) {
clearTimeout(_this.flag.timerHandler);
}
this.flag.canDrag = true;
if (duration === 0) {
_this.$ptlogin_slider.className = _this.ptlogin_slider_Class;
_this.$count_down_num.innerHTML = 60;
_this.clearMark();
_this.getCaptcha(function () {
_this.$loading_text.innerHTML = _this.options.loadingText;
if (callback) {
callback();
}
});
return;
}
_this.flag.timerHandler = setTimeout(function (e) {
_this.$ptlogin_slider.className = _this.ptlogin_slider_Class;
_this.$count_down_num.innerHTML = 60;
_this.clearMark();
_this.getCaptcha(function () {
_this.$loading_text.innerHTML = _this.options.loadingText;
if (callback) {
callback();
}
});
}, duration || _this.options.resetDuration);
};
VerifyTextPlugin.prototype.countDragLeft = function (e, diff) {
if (e) {
var n;
var i;
var ptlogin_slider_Width = this.$ptlogin_slider.clientWidth - diff;
var f = 40;
var a = dragLeft;
var c = diff < 0 ? -diff : diff / 2;
return dragLeft <= c
? ((n = dragLeft), (i = diff < 0 ? -n / 2 : n), (a += i))
: ptlogin_slider_Width - dragLeft - f <= c
? ((n = dragLeft - (ptlogin_slider_Width - f - c)),
(i = diff < 0 ? -n / 2 : n),
(a += diff / 2 + i))
: (a += diff / 2);
}
};
VerifyTextPlugin.prototype.addEvent = function (ele, type, handler) {
if (ele.addEventListener) {
ele.addEventListener(type, handler, { passive: false });
}
else if (ele.attachEvent) {
ele.attachEvent('on' + type, handler);
}
else {
ele['on' + type] = handler;
}
};
VerifyTextPlugin.prototype.removeEvent = function (ele, type, handler) {
if (ele.removeEventListener) {
ele.removeEventListener(type.handler, { passive: false });
}
else if (ele.detachEvent) {
ele.detachEvent('on' + type, handler);
}
else {
ele['on' + type] = null;
}
};
VerifyTextPlugin.prototype.nowTime = function () {
return new Date().getTime();
};
VerifyTextPlugin.prototype.rand = function () {
return Math.random()
.toString()
.substr(2);
};
VerifyTextPlugin.prototype.destory = function () {
if (this.options.type === 'popup') {
if (document.getElementById(this.options.target)) {
document.getElementById(this.options.target).innerHTML = '';
}
else {
if (this.flag.ele) {
this.flag.ele.innerHTML = '';
this.flag.ele.remove();
}
}
}
else {
if (document.getElementById(this.options.target)) {
document.getElementById(this.options.target).innerHTML = '';
}
}
};
return VerifyTextPlugin;
}());
var VerifyPlugin = {
code: VerifyCodePlugin,
message: VerifyMessagePlugin,
text: VerifyTextPlugin
};
return VerifyPlugin;
}));
|
|