This commit is contained in:
linfso 2025-01-01 23:40:31 +08:00
parent f4b1844d38
commit cf3bed37a3
2 changed files with 30 additions and 10 deletions

View File

@ -76,7 +76,9 @@
<script> <script>
import {Notification} from "element-ui"; import {Notification} from "element-ui";
import Speech from 'speak-tts' import { getToken } from "@/utils/auth";
import { encrypt } from '@/utils/jsencrypt'
// import Speech from 'speak-tts'
import {getTopNoticeListByUserId,addReadTimes,getPublicNoticeList,clearNotice} from "@/api/system/notice"; import {getTopNoticeListByUserId,addReadTimes,getPublicNoticeList,clearNotice} from "@/api/system/notice";
export default { export default {
name: 'TopNotice', name: 'TopNotice',
@ -104,16 +106,16 @@ export default {
mounted() { mounted() {
window.addEventListener("click", this.setCanPlayTone); window.addEventListener("click", this.setCanPlayTone);
this.initXDNoticSdk(); this.initXDNoticSdk();
this.speechInit(); // this.speechInit();
this.initUserNotice(); this.initUserNotice();
}, },
methods: { methods: {
speechInit() { // speechInit() {
this.speech = new Speech(); // this.speech = new Speech();
this.speech.setLanguage("zh-CN"); // this.speech.setLanguage("zh-CN");
this.speech.init().then(() => {}); // this.speech.init().then(() => {});
}, // },
setCanPlayTone() { setCanPlayTone() {
this.isPlay = true; this.isPlay = true;
}, },
@ -127,8 +129,11 @@ export default {
console.log("===>initXDNoticSdk==>") console.log("===>initXDNoticSdk==>")
this.xdNoticSdk = this.$xdNoticeSdk; this.xdNoticSdk = this.$xdNoticeSdk;
const userId=this.$store.getters.userId; const userId=this.$store.getters.userId;
// const token=getToken();
// console.log("===>userId==>",userId); // console.log("===>userId==>",userId);
this.xdNoticSdk.init(userId); // this.xdNoticSdk.init(userId);
this.xdNoticSdk.initWsPlus(userId);
this.xdNoticSdk.setOnOpen(this.onNoticeOpen); this.xdNoticSdk.setOnOpen(this.onNoticeOpen);
this.xdNoticSdk.setOnClose(this.onNoticeClose); this.xdNoticSdk.setOnClose(this.onNoticeClose);

View File

@ -7,8 +7,13 @@ class XDNoticeSdk {
VERSION="1.0.0" VERSION="1.0.0"
MAX_SENT_RETRY_COUNT = 9; MAX_SENT_RETRY_COUNT = 9;
WS_URL = process.env.VUE_APP_WS_HOST+'/ws/'; WS_URL = process.env.VUE_APP_WS_HOST+'/ws/';
WS_PLUS_URL = process.env.VUE_APP_WS_HOST+'/wsplus/';
userId = null; userId = null;
encUserId = null;
token = null;
AUTH_TOKEN=null; AUTH_TOKEN=null;
@ -55,6 +60,13 @@ class XDNoticeSdk {
this.start(); this.start();
} }
initWsPlus(userId){
// 初始化参数建立连接
this.userId=userId;
this.connect();
this.start();
}
setOnOpen(callback){ setOnOpen(callback){
this.onOpenCallback.push(callback); this.onOpenCallback.push(callback);
@ -107,8 +119,11 @@ class XDNoticeSdk {
if (!this.ws || this.getWSReadyState() === this.WS_CLOSING || this.getWSReadyState() === this.WS_CLOSE) { if (!this.ws || this.getWSReadyState() === this.WS_CLOSING || this.getWSReadyState() === this.WS_CLOSE) {
try { try {
// wss://api.emis.tanex56.com/api/bizsvr/ws/123/pc // wss://api.emis.tanex56.com/api/bizsvr/ws/123
this.ws = new WebSocket(this.WS_URL+""+this.userId+"/pc"); // wss://api.emis.tanex56.com/api/bizsvr/wsplus/123
// this.ws = new WebSocket(this.WS_URL+""+this.userId);
this.ws = new WebSocket(this.WS_PLUS_URL+""+this.userId);
this.ws.onerror = () => { this.ws.onerror = () => {
// console.log("ws onerror!"); // console.log("ws onerror!");