优化语音播报
parent
2a9b05b489
commit
93049cf453
62
App.vue
62
App.vue
|
@ -1,24 +1,13 @@
|
|||
<script>
|
||||
// import io from '@/jsFile/socket.io.js';
|
||||
// const socket = io("ws://7and5.cn:2120",{
|
||||
// query: {},
|
||||
// transports: [ 'websocket', 'polling' ],
|
||||
// timeout: 5000,
|
||||
// });
|
||||
export default {
|
||||
globalData:{
|
||||
projectname:'', // 项目名称
|
||||
lat:'', // 公司地址维度
|
||||
lng:'' ,// 公司地址经度
|
||||
hostapi:'https://7and5.cn' ,// 域名配置
|
||||
// uid:1,
|
||||
// socketInit:false,
|
||||
// bgmMusic:null,
|
||||
// ifPlayIng:false,
|
||||
},
|
||||
// 优先于show方法
|
||||
onLaunch: function() {
|
||||
// this.connect();
|
||||
// 配置全局域名
|
||||
// #ifdef H5 || APP-PLUS
|
||||
this.globalData.bgmMusic = uni.createInnerAudioContext();
|
||||
|
@ -42,57 +31,6 @@
|
|||
|
||||
},
|
||||
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设置消息提醒(调用手机系统静音或铃声)
|
||||
openSettings() {
|
||||
uni.getSystemInfo({
|
||||
|
|
|
@ -62,13 +62,13 @@
|
|||
return {
|
||||
windowHeight: uni.getSystemInfoSync().windowHeight,
|
||||
ifPhone:false,
|
||||
login_phone:'17366921088',//登录手机号
|
||||
login_phone:'',//登录手机号
|
||||
ifCode:false,
|
||||
login_code:'',//登录验证码
|
||||
ifunitName:false,
|
||||
login_unitName:'湖南争鸣光电科技有限公司',//登录单位名称
|
||||
login_unitName:'',//登录单位名称
|
||||
ifPassword:false,
|
||||
login_password:'123456',//登录密码
|
||||
login_password:'',//登录密码
|
||||
codeText:'获取验证码' ,// 获取验证码按钮文字
|
||||
flagCode:true ,// 允许点击获取验证码
|
||||
countDown:null,
|
||||
|
|
|
@ -340,6 +340,12 @@
|
|||
},
|
||||
ifConnect(){
|
||||
return this.$store.state.ifConnect
|
||||
},
|
||||
ifVoice(){
|
||||
return this.$store.state.ifVoice
|
||||
},
|
||||
ifMessage(){
|
||||
return this.$store.state.ifMessage
|
||||
}
|
||||
},
|
||||
onShow() {
|
||||
|
@ -362,11 +368,26 @@
|
|||
this.getIncrementServiceType();
|
||||
// 调用获取常见故障列表事件
|
||||
this.getFaultsList();
|
||||
// 获取设置信息
|
||||
this.getSettings();
|
||||
if(!this.ifConnect && this.uid){
|
||||
this.connect();
|
||||
}
|
||||
},
|
||||
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(){
|
||||
socket.io.reconnect();
|
||||
},
|
||||
|
@ -398,18 +419,21 @@
|
|||
// 接收消息
|
||||
socket.on('new_msg', (msg)=> {
|
||||
console.log(msg);
|
||||
console.log(uni.getStorageSync('ifVoice'),uni.getStorageSync('ifMessage'),55555);
|
||||
// this.offMusic();
|
||||
uni.showToast({
|
||||
title:msg
|
||||
})
|
||||
this.bofang();
|
||||
|
||||
if(uni.getStorageSync('ifVoice') || uni.getStorageSync('ifMessage')){
|
||||
console.log('进入接收消息');
|
||||
uni.showToast({
|
||||
title:msg
|
||||
})
|
||||
this.bofang();
|
||||
}
|
||||
});
|
||||
},
|
||||
bofang(){
|
||||
this.bgmMusic.autoplay = 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.play(()=>{
|
||||
console.log('背景音乐播放中');
|
||||
|
@ -485,6 +509,11 @@
|
|||
this.settlementList[0].num = homeObj.pending_payment_count; //待收款数量
|
||||
this.settlementList[1].num = homeObj.paid_for_count; //已收款数量
|
||||
break;
|
||||
case 5:
|
||||
// 待办事件
|
||||
this.stayEventList[0].num = homeObj.approval_count;
|
||||
this.stayEventList[1].num = homeObj.pending_payment_count;
|
||||
break;
|
||||
}
|
||||
// 重构公告列表
|
||||
// if(homeObj.notice.length) {
|
||||
|
|
|
@ -109,6 +109,7 @@
|
|||
this.$requst.post('/universal/api.settings/settings',params).then(res=>{
|
||||
if(res.code){
|
||||
// uni.navigateBack({delta:1})
|
||||
this.getSettings();
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -128,6 +129,8 @@
|
|||
if(res.code){
|
||||
this.voiceStatus = [false,true][res.data.voice_reminder];
|
||||
this.newsStatus = [false,true][res.data.receive_message];
|
||||
uni.setStorageSync('ifVoice',this.voiceStatus);
|
||||
uni.setStorageSync('ifMessage',this.newsStatus);
|
||||
for (let key in res.data) {
|
||||
if(res.data[key]!=1&&res.data[key]!=0){
|
||||
let obj = {
|
||||
|
|
|
@ -8,9 +8,7 @@ Vue.use(Vuex);//vue的插件机制
|
|||
const store = new Vuex.Store({
|
||||
state:{//存放状态
|
||||
uid:'',
|
||||
ifConnect:false,
|
||||
ifVoice:false,
|
||||
ifMessage:false
|
||||
ifConnect:false
|
||||
},
|
||||
mutations: {
|
||||
setUid(state, str) {
|
||||
|
@ -18,14 +16,6 @@ const store = new Vuex.Store({
|
|||
},
|
||||
setConnect(state, str) {
|
||||
state.ifConnect = str;
|
||||
},
|
||||
// 语音开关设置
|
||||
setVoice(state, str) {
|
||||
state.ifVoice = str;
|
||||
},
|
||||
// 新消息通知设置
|
||||
setMessage(state, str) {
|
||||
state.ifMessage = str;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue