优化语音播报

master
chen 2022-08-16 14:35:07 +08:00
parent 2a9b05b489
commit 93049cf453
5 changed files with 42 additions and 82 deletions

62
App.vue
View File

@ -1,24 +1,13 @@
<script> <script>
// import io from '@/jsFile/socket.io.js';
// const socket = io("ws://7and5.cn:2120",{
// query: {},
// transports: [ 'websocket', 'polling' ],
// timeout: 5000,
// });
export default { export default {
globalData:{ globalData:{
projectname:'', // projectname:'', //
lat:'', // lat:'', //
lng:'' ,// lng:'' ,//
hostapi:'https://7and5.cn' ,// hostapi:'https://7and5.cn' ,//
// uid:1,
// socketInit:false,
// bgmMusic:null,
// ifPlayIng:false,
}, },
// show // show
onLaunch: function() { onLaunch: function() {
// this.connect();
// //
// #ifdef H5 || APP-PLUS // #ifdef H5 || APP-PLUS
this.globalData.bgmMusic = uni.createInnerAudioContext(); this.globalData.bgmMusic = uni.createInnerAudioContext();
@ -42,57 +31,6 @@
}, },
methods:{ methods:{
connect() {
socket.io.reconnect();
console.log(this.uid,1234);
socket.on('connect', ()=> {
socket.emit('login', this.uid);
console.log('连接成功');
});
//线
socket.on('disconnect', ()=> {
socket.connect();//
console.log('关闭链接后重新链接');
// this.openSettings();
});
//线广
socket.on('loginout', (data)=> {
console.log("会员下线",data);
});
//线广
socket.on('login_msg', (msg)=> {
console.log("会员上线",msg);
});
//
socket.on('new_msg', (msg)=> {
console.log(msg);
this.offMusic();
uni.showToast({
title:msg
})
this.bofang();
});
},
bofang(){
this.globalData.bgmMusic.autoplay = true;//
// this.bgmMusic.loop = true;//
this.globalData.bgmMusic.src = 'http://m801.music.126.net/20220728102722/4a7c3c7692a5f0b808f03f8ab7d02bfb/jdymusic/obj/wo3DlMOGwrbDjj7DisKw/4800358085/4a32/22b6/02f5/d96abc3bed5758b0e7172ea66aec841d.mp3';//
this.globalData.bgmMusic.volume = 1;//
this.globalData.bgmMusic.onPlay(()=>{
console.log('背景音乐播放中');
this.globalData.ifPlayIng = true;
});
},
//
offMusic(){
if(this.globalData.ifPlayIng){
this.globalData.bgmMusic.stop();
this.globalData.bgmMusic.onStop(()=>{
console.log('背景音乐停止了');
});
this.globalData.ifPlayIng = false;
}
},
// uniapp // uniapp
openSettings() { openSettings() {
uni.getSystemInfo({ uni.getSystemInfo({

View File

@ -62,13 +62,13 @@
return { return {
windowHeight: uni.getSystemInfoSync().windowHeight, windowHeight: uni.getSystemInfoSync().windowHeight,
ifPhone:false, ifPhone:false,
login_phone:'17366921088',// login_phone:'',//
ifCode:false, ifCode:false,
login_code:'',// login_code:'',//
ifunitName:false, ifunitName:false,
login_unitName:'湖南争鸣光电科技有限公司',// login_unitName:'',//
ifPassword:false, ifPassword:false,
login_password:'123456',// login_password:'',//
codeText:'获取验证码' ,// codeText:'获取验证码' ,//
flagCode:true ,// flagCode:true ,//
countDown:null, countDown:null,

View File

@ -340,6 +340,12 @@
}, },
ifConnect(){ ifConnect(){
return this.$store.state.ifConnect return this.$store.state.ifConnect
},
ifVoice(){
return this.$store.state.ifVoice
},
ifMessage(){
return this.$store.state.ifMessage
} }
}, },
onShow() { onShow() {
@ -362,11 +368,26 @@
this.getIncrementServiceType(); this.getIncrementServiceType();
// //
this.getFaultsList(); this.getFaultsList();
//
this.getSettings();
if(!this.ifConnect && this.uid){ if(!this.ifConnect && this.uid){
this.connect(); this.connect();
} }
}, },
methods: { methods: {
//
getSettings(){
let params = {
voice_reminder:'',
receive_message:''
}
this.$requst.get('/universal/api.settings/settings',params).then(res=>{
if(res.code){
uni.setStorageSync('ifVoice',[false,true][res.data.voice_reminder]);
uni.setStorageSync('ifMessage',[false,true][res.data.receive_message]);
}
})
},
connectEv(){ connectEv(){
socket.io.reconnect(); socket.io.reconnect();
}, },
@ -398,18 +419,21 @@
// //
socket.on('new_msg', (msg)=> { socket.on('new_msg', (msg)=> {
console.log(msg); console.log(msg);
console.log(uni.getStorageSync('ifVoice'),uni.getStorageSync('ifMessage'),55555);
// this.offMusic(); // this.offMusic();
if(uni.getStorageSync('ifVoice') || uni.getStorageSync('ifMessage')){
console.log('进入接收消息');
uni.showToast({ uni.showToast({
title:msg title:msg
}) })
this.bofang(); this.bofang();
}
}); });
}, },
bofang(){ bofang(){
this.bgmMusic.autoplay = true;// this.bgmMusic.autoplay = true;//
// this.bgmMusic.loop = true;// // this.bgmMusic.loop = true;//
this.bgmMusic.src = 'http://m801.music.126.net/20220728102722/4a7c3c7692a5f0b808f03f8ab7d02bfb/jdymusic/obj/wo3DlMOGwrbDjj7DisKw/4800358085/4a32/22b6/02f5/d96abc3bed5758b0e7172ea66aec841d.mp3';// this.bgmMusic.src = 'https://img-cdn2.yespik.com/sound/00/29/33/70/293370_548da270e343f070330174bd880d2e83.mp3';//
this.bgmMusic.volume = 1;// this.bgmMusic.volume = 1;//
this.bgmMusic.play(()=>{ this.bgmMusic.play(()=>{
console.log('背景音乐播放中'); console.log('背景音乐播放中');
@ -485,6 +509,11 @@
this.settlementList[0].num = homeObj.pending_payment_count; // this.settlementList[0].num = homeObj.pending_payment_count; //
this.settlementList[1].num = homeObj.paid_for_count; // this.settlementList[1].num = homeObj.paid_for_count; //
break; break;
case 5:
//
this.stayEventList[0].num = homeObj.approval_count;
this.stayEventList[1].num = homeObj.pending_payment_count;
break;
} }
// //
// if(homeObj.notice.length) { // if(homeObj.notice.length) {

View File

@ -109,6 +109,7 @@
this.$requst.post('/universal/api.settings/settings',params).then(res=>{ this.$requst.post('/universal/api.settings/settings',params).then(res=>{
if(res.code){ if(res.code){
// uni.navigateBack({delta:1}) // uni.navigateBack({delta:1})
this.getSettings();
} }
}) })
}, },
@ -128,6 +129,8 @@
if(res.code){ if(res.code){
this.voiceStatus = [false,true][res.data.voice_reminder]; this.voiceStatus = [false,true][res.data.voice_reminder];
this.newsStatus = [false,true][res.data.receive_message]; this.newsStatus = [false,true][res.data.receive_message];
uni.setStorageSync('ifVoice',this.voiceStatus);
uni.setStorageSync('ifMessage',this.newsStatus);
for (let key in res.data) { for (let key in res.data) {
if(res.data[key]!=1&&res.data[key]!=0){ if(res.data[key]!=1&&res.data[key]!=0){
let obj = { let obj = {

View File

@ -8,9 +8,7 @@ Vue.use(Vuex);//vue的插件机制
const store = new Vuex.Store({ const store = new Vuex.Store({
state:{//存放状态 state:{//存放状态
uid:'', uid:'',
ifConnect:false, ifConnect:false
ifVoice:false,
ifMessage:false
}, },
mutations: { mutations: {
setUid(state, str) { setUid(state, str) {
@ -18,14 +16,6 @@ const store = new Vuex.Store({
}, },
setConnect(state, str) { setConnect(state, str) {
state.ifConnect = str; state.ifConnect = str;
},
// 语音开关设置
setVoice(state, str) {
state.ifVoice = str;
},
// 新消息通知设置
setMessage(state, str) {
state.ifMessage = str;
} }
} }
}) })