whyczyk
2022-02-09 3d8a4eb4995756b02d31417cafb882de0678cba0
src/assets/units/function/Timeout.js
@@ -4,49 +4,49 @@
    this.time = '';
    this.callback = '';
    this.workState = false;
    this.name = name?name:-33;
    this.name = name ? name : -33;
}
// 开启计时器并添加
Timeout.prototype.start = function(callback, time, exe) {
Timeout.prototype.start = function (callback, time, exe) {
    // 配置执行函数
    if(typeof callback == 'function' && typeof time == 'number') {
    if (typeof callback == 'function' && typeof time == 'number') {
        this.callback = callback;
        this.time = time;
        // 获取缓存的session
        let name = sessionStorage.getItem('acTabs');
        if(exe != 'exe') {
        if (exe != 'exe') {
            this.workState = true;
            callback();
        }else {
        } else {
            // 已经停止了
            if(!this.workState) {
            if (!this.workState) {
                return;
            }
            // 清除计时器
            clearTimeout(this.timer);
            if(this.name == -33 || this.name == name) {
            if (this.name == -33 || this.name == name) {
                this.timer = setTimeout(callback, time);
            }else {
                setTimeout(()=>{
            } else {
                setTimeout(() => {
                    this.open();
                }, 300);
            }
        }
    }else {
    } else {
        console.warn('未完整配置参数!');
    }
};
// 开启计时器
Timeout.prototype.open = function() {
Timeout.prototype.open = function () {
    var callback = this.callback;
    var time = this.time;
    this.start(callback, time, 'exe');
};
// 关闭计时器
Timeout.prototype.stop = function() {
Timeout.prototype.stop = function () {
    clearTimeout(this.timer);
    this.workState = false;
};
@@ -59,7 +59,7 @@
};
// 关闭后重启计时器
Timeout.prototype.restart = function() {
Timeout.prototype.restart = function () {
    this.workState = true;
    this.open();
};