消息语音提醒

This commit is contained in:
Vinjor 2024-10-17 15:22:37 +08:00
parent 8e318e6378
commit 63675c5228
10 changed files with 210 additions and 23 deletions

View File

@ -29,9 +29,16 @@
import {
getToken
} from '@/utils/auth'
let innerAudioContext ='';
// #ifdef APP || H5
const jyJPush = uni.requireNativePlugin('JY-JPush');
// #endif
export default {
data() {
return {
msgSocket: this.$msgSocket,
//
ifPlay:false,
aindex: 1,
msgNum: null,
identity: 'user',
@ -64,10 +71,92 @@
// #ifdef APP || H5
this.identity = uni.getStorageSync('identity');
// #endif
if (!this.nowPageInterval) {
this.nowPageInterval = setInterval(() => {
// console.log('this.$msgSocket: ',this.$msgSocket);
this.msgSocket = this.$msgSocket
}, 3000);
}
console.log(this.aindex);
setTimeout(() => {
this.msgInfo()
}, 2000);
this.aindex = this.msg
},
watch: {
msgSocket(newVal, oldVal) {
console.log('msgSocket值发生变化', newVal, oldVal)
this.msgInfo()
},
deep: true,
},
methods: {
dianyidain() {
if(!this.ifPlay){
console.log('执行了dianyidain');
if(innerAudioContext!=""){
try {
console.log('调用前先销毁');
innerAudioContext.stop();
innerAudioContext.destroy();
innerAudioContext="";
}catch (e){
console.log('销毁出错');
}
}
innerAudioContext = uni.createInnerAudioContext();
this.ifPlay=true
// #ifdef APP-PLUS
innerAudioContext.src = '../../static/msgV.mp3';
// #endif
// #ifndef APP-PLUS
innerAudioContext.src = 'https://www.nuoyunr.com/lananRsc/rescue/msgV.mp3';
// #endif
//
const playCount = 3;
let currentCount = 0;
//
innerAudioContext.play();
innerAudioContext.onError((err) => {
console.error('播放错误', err);
this.ifPlay=false
innerAudioContext.stop();
innerAudioContext.destroy(); //
});
//
innerAudioContext.onEnded(() => {
//
currentCount++;
//
if (currentCount < playCount) {
//
innerAudioContext.play();
} else {
//
console.log('播放完成');
this.ifPlay=false
//
innerAudioContext.stop();
innerAudioContext.destroy();
}
});
}else{
console.log('正在播放音频,拒绝播放请求');
}
},
msgInfo() {
console.log(this.msgSocket, 'msgSocket')
if (this.msgSocket) {
console.log('消息回调启动成功')
this.msgSocket.onMessage(res => {
console.log("发出提示音", res);
// this.getbottom();
this.dianyidain()
})
}
},
async getbottom() {
if (!getToken()) {
return

View File

@ -6,7 +6,7 @@ module.exports = {
imagesUrl: 'http://shequ.0315e.com/static/images/pages/',
baseImageUrl: 'https://www.nuoyunr.com/minio/',
shareUrl: 'https://www.lighting-it.cn/share?inviteId=',
wsUrl: 'wss://www.nuoyunr.com',
wsUrl: 'ws://192.168.1.17:48080',
// 应用信息
appInfo: {
// 应用名称

40
main.js
View File

@ -3,10 +3,48 @@ import uView from "uview-ui";
import config from '@/config'
const baseUrl = config.baseUrl
Vue.prototype.$baseUrl = baseUrl;
const baseImageUrl = config.baseImageUrl
Vue.prototype.$baseImageUrl = baseImageUrl;
Vue.use(uView);
// 如此配置即可
import {
tabBarconnect,
closeMsgSocket,
sendMsg
} from '@/utils/tebBarSocket'
import {
getStrData
} from '@/utils/auth'
let msgTimer;
let msgSocket;
export function startMsgSocket(tenantId,userId) {
msgSocket = null
msgSocket = tabBarconnect(tenantId,userId);
if (!msgTimer && getStrData('userId')) {
msgTimer = setInterval(() => {
sendMsg(msgSocket)
}, 10000);
}
Vue.prototype.$msgSocket = msgSocket
}
Vue.prototype.$startMsgSocket = startMsgSocket; //userid
export function tabBarcloseSocket() {
closeMsgSocket;
}
export function getclearInterval() {
console.log('执行关闭请求');
clearInterval(msgTimer);
msgTimer = undefined;
}
Vue.prototype.$getclearInterval = getclearInterval;
// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
import {
request
} from "@/utils/request.js"
Vue.prototype.$request = request
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
@ -23,4 +61,4 @@ export function createApp() {
app
}
}
// #endif
// #endif

View File

@ -47,7 +47,9 @@ import OrderCard from "@/components/orderCard.vue";
import config from '@/config'
import {
getToken,
getUserInfo
getUserInfo,
getStrData,
getTenantId
} from '@/utils/auth'
export default {
@ -109,6 +111,17 @@ export default {
defaultAvatar: require('@/static/icons/avatar.png')
}
},
onLoad(){
if(!getToken()){
uni.reLaunch({
url: '/pages/login/login'
})
}else{
if(!this.$msgSocket){
this.$startMsgSocket(getTenantId(),getStrData("userId"))
}
}
},
onShow() {
if(!getToken()){
uni.reLaunch({

View File

@ -16,9 +16,16 @@
}
},
onLoad() {
uni.reLaunch({
url: '/pages/login/login'
})
if(getToken()){
//
uni.navigateTo({
url: '/pages-home/home/home'
})
}else{
uni.navigateTo({
url: '/pages/login/login'
})
}
},
methods: {
@ -28,4 +35,4 @@
<style>
</style>
</style>

View File

@ -51,7 +51,8 @@
setToken,
setTenantId,
setUserInfo,
setJSONData
setJSONData,
setStrData
} from '@/utils/auth'
import {
login,
@ -155,6 +156,11 @@
})
setToken(res.data.loginResult.accessToken)
setUserInfo(res.data.userinfo)
setStrData("userId",res.data.userinfo.id)
if(res.data.userinfo.roleCodes.indexOf("repair_staff")){
//
this.getIdLeader()
}
this.getStaffInfo(res.data.userinfo.id)
//
uni.navigateTo({
@ -203,6 +209,20 @@
setJSONData("staffInfo",res.data)
}
})
},
/**
* 查是否班组长
*/
getIdLeader(){
request({
url: '/admin-api/repair/worker/getIfLeader',
method: 'get'
}).then((res) => {
console.log(res)
if (res.code == 200) {
setStrData("ifLeader",res.data)
}
})
},
getxz(index) {
this.activeid = index

View File

@ -50,7 +50,8 @@ import {
getToken,
getUserInfo,
getJSONData,
removeToken,removeUserInfo,removeJSONData
removeTenantId,
removeToken,removeUserInfo,removeJSONData,removeStrData
} from '@/utils/auth'
const UQRCode = require('uqrcodejs');
export default {
@ -78,6 +79,10 @@ export default {
//
this.customInfo = getUserInfo()
this.staff = getJSONData("staffInfo")
uni.showToast({
title: this.staff.uniqueCode,
icon: 'none'
})
if(this.staff.uniqueCode){
this.showUniCode =true
this.generateUniCode(this.staff.uniqueCode)
@ -117,6 +122,8 @@ export default {
removeToken()
removeUserInfo()
removeJSONData("staffInfo")
removeStrData("userId")
removeTenantId()
//
uni.navigateTo({
url: '/pages/login/login'

BIN
static/msgV.mp3 Normal file

Binary file not shown.

View File

@ -19,7 +19,9 @@ export function setTenantId(TenantId) {
export function getTenantId(){
return uni.getStorageSync(TenantIdKey)
}
export function removeTenantId() {
return uni.removeStorageSync(TenantIdKey);
}
export function hasRole(roleCode) {
const roleList = uni.getStorageSync('role')
if (roleList && roleList.length > 0) {
@ -63,3 +65,15 @@ export function removeJSONData(keyStr) {
return uni.removeStorageSync(keyStr)
}
export function getStrData(keyStr) {
return uni.getStorageSync(keyStr)
}
export function setStrData(keyStr,dataStr) {
return uni.setStorageSync(keyStr, dataStr)
}
export function removeStrData(keyStr) {
return uni.removeStorageSync(keyStr)
}

View File

@ -1,23 +1,26 @@
import {
startMsgSocket
} from '../main.js'
import {
getTenantId,
getStrData
} from '@/utils/auth'
import config from '@/config'
export function tabBarconnect(userId) {
console.log("通知socket链接", userId);
export function tabBarconnect(tenantId, userId) {
console.log("通知socket链接", tenantId, userId);
var socketTask = uni.connectSocket({
url: config.wsUrl + '/websocket/announcement/' + userId,
url: config.wsUrl + '/websocket/message/'+tenantId+'/' + userId,
success(res) {
},
fail(err) {
}
}
);
return socketTask;
}
export function sendMsg(SocketTask) {
if (SocketTask) {
SocketTask.send({
@ -26,19 +29,15 @@ export function sendMsg(SocketTask) {
console.log('消息链接正常')
},
fail: err => {
console.log('消息链接异常 重新链接' + err, uni.getStorageSync('userId'));
startMsgSocket(uni.getStorageSync('userId'));
console.log('消息链接异常 重新链接' + err, getStrData('userId'));
startMsgSocket(getTenantId(),getStrData('userId'));
}
});
} else {
startMsgSocket(uni.getStorageSync('userId'));
startMsgSocket(getTenantId(),getStrData('userId'));
}
}
export function closeMsgSocket(SocketTask) {
SocketTask.close()
}
}