diff --git a/common/enum.js b/common/enum.js index 20063c6..e71b2d5 100644 --- a/common/enum.js +++ b/common/enum.js @@ -98,6 +98,7 @@ const audioTypeEnum = { printFail: getCdnRoot('tone/print-fail.mp3'), printSuccess: getCdnRoot('tone/print-success.mp3'), repetitive: getCdnRoot('tone/repetitive.mp3'), + notifyTone: getCdnRoot('tone/notifyTone.mp3'), } export { diff --git a/common/env.js b/common/env.js index 5c0fc1c..bce90a7 100644 --- a/common/env.js +++ b/common/env.js @@ -1,9 +1,11 @@ let envMap = { development: { apiHost: 'http://47.102.220.189:58089/api/bizsvr', + socketHost: 'ws://47.102.220.189:58089/api/bizsvr', }, production: { apiHost: 'http://api.emis.tanex56.com/api/bizsvr', + socketHost: 'ws://api.emis.tanex56.com/api/bizsvr', } } let curEnvConf diff --git a/common/messageNotice/socket.js b/common/messageNotice/socket.js new file mode 100644 index 0000000..c58aa9f --- /dev/null +++ b/common/messageNotice/socket.js @@ -0,0 +1,64 @@ +import { curEnvConf } from "@/common/env" +import { getCommonReqData } from "@/common/manageServer" +import { showToast, playAudio } from "@/common/untool" +import { audioTypeEnum } from "@/common/enum" + +export const createSocketMessage = ({ userInfo })=> { + const url = curEnvConf.socketHost + let comReqData = getCommonReqData() + const socketTask = uni.connectSocket({ + url: `${url}/ws/${userInfo?.userId}`, + // method: 'GET', + header: { + ...comReqData.header, + }, + success(res){ + }, + fail(err) { + } + }) + socketTask.onError((err)=> { + console.log('socketTask.onError: ', err); + }) + socketTask.onClose((res)=> { + console.log('socketTask.onClose: ', res); + }) + socketTask.onOpen((res)=> { + console.log('socketTask.onOpen: ', res); + }) + socketTask.onMessage(function (res) { + debugger + console.log('onSocketMessage 收到服务器内容:', res?.data); + playAudio(audioTypeEnum.notifyTone) + // let that=this; + // if(evtStr==null||evtStr==undefined){ + // return; + // } + + // let evt= JSON.parse(evtStr); + // if(evt==null||evt==undefined){ + // return; + // } + + // 播放声音通知 + // this.playTone(); + + // var messageBody = evt.title; + // let noticeId= evt.noticeId; + + // 弹出通知提示 + // Notification.info({ + // title: "系统通知", + // dangerouslyUseHTMLString: true, + // message: messageBody, + // position: 'top-right', + // customClass:'notify-success', + // duration: 0, + // onClick: function () { + // // 提示消息 + // //that.setAddReadTimes(noticeId); + // }, + // }); + debugger + }); +} \ No newline at end of file diff --git a/static/tone/notifyTone.mp3 b/static/tone/notifyTone.mp3 new file mode 100644 index 0000000..7673713 Binary files /dev/null and b/static/tone/notifyTone.mp3 differ diff --git a/store/modules/user.js b/store/modules/user.js index 3f5bfff..72a812f 100644 --- a/store/modules/user.js +++ b/store/modules/user.js @@ -7,6 +7,7 @@ import { } from "@/session" import * as apiService from "@/common/api" import { goto } from "@/common/untool" +import { createSocketMessage } from "@/common/messageNotice/socket" export default { state: { @@ -83,6 +84,8 @@ export default { let resQr = await apiService.getStaffQRCodePng() info.qrCodeImgUrl = resQr?.data?.fileUrl + // 链接socket + createSocketMessage({ userInfo: info }) commit(USERKEY.GETUSERINFO, info) },