vue2 全局定时器语音推送 min.js

vue2 全局定时器语音推送 min.js_第1张图片

import {
    getOrderPage,
    getOrderSvPage,
} from "@/api/system/order";


const speechSynthesis = window.speechSynthesis;
const speechText = new SpeechSynthesisUtterance();
new Vue({
    // ...
    beforeCreate() {

        this.timer = setInterval(() => {
            let queryParams = {
                pageNo: 1,
                pageSize: 1,
                merchantClientStatus: 0,
            }
            if (localStorage.getItem("ACCESS_TOKEN")) {
                if (store.getters.roles[0] == 'agent') {
                    getOrderSvPage(queryParams).then(response => {
                        if (response.data.list && response.data.list.length > 0) {
                            this.$notify({
                                title: response.data.list[0].merchantName +
                                    '有未接订单,请尽快处理!',
                                type: 'warning'
                            });
                            speechText.text = response.data.list[
                                    0].merchantName +
                                '有未接订单,请尽快处理!'
                            console.log(speechSynthesis.speak(speechText))
                            speechSynthesis.speak(speechText);
                        } else {
                            speechSynthesis.cancel(speechText)
                        }
                    });
                } else {
                    getOrderPage(queryParams).then(response => {
                        if (response.data.list && response.data.list.length > 0) {
                            this.$notify({
                                title: response.data.list[0].merchantName +
                                    '有未接订单,请尽快处理!',
                                type: 'warning'
                            });

                            speechText.text = response.data.list[
                                    0].merchantName +
                                '有未接订单,请尽快处理!'
                            console.log(speechSynthesis.speak(speechText))
                            speechSynthesis.speak(speechText);

                        } else {
                            speechSynthesis.cancel(speechText)
                        }
                    });
                }
            }
        }, 5000); // 每隔1秒执行一次
    },
    beforeDestroy() {
        clearInterval(this.timer); // 清除定时器
    },
    // ...
})

需要浏览器开启权限才可以正常播放   已edge举例

vue2 全局定时器语音推送 min.js_第2张图片

你可能感兴趣的:(前端)