test

61 阅读1分钟

// 创建定时器

    createTimer = (count, msg, cb) => {

        // 倒计时

        var timer = setInterval(() => {

            if (count == 0) {

                this.clearTimer(timer);

                cb(msg);

                return;

            } else {

                _log("倒计时", count)

                count--;

            }

        }, 1000);

        _log("创建一个" + count + "s的定时器是", timer)

        return timer

    }

\

    // 闭包 创建定时任务

    createTimerFun = (count, msg) => {

        return (type, timer, cb) => {

            _log("闭包参数", msg)

            if (type == "stop") {

                this.clearTimer(timer);

                cb(msg);

                return;

            } else {

                // 创建定时器 返回定时器

                return this.createTimer(count, msg, cb)

            }

        }

    }

\

    // 清除定时器

    clearTimer = (timer) => {

        _log("停止定时器", timer)

        window.clearInterval(timer);

        this.endingFun = null;

        this.hangUpTimer = null;

    }

\

\

        //     // 开启挂断计时器  // 10s倒计时

        //     this.endingFun = this.createTimerFun(10, "901主坐席满意度挂断");

        //     this.hangUpTimer = this.endingFun("create", null, (msg) => {

        //         $SLMC.emit("slvcr_video_call_status", { type: "ending", msg: "业务办理结束", msg1: msg });

        //     });