266 lines
5.4 KiB
Vue
266 lines
5.4 KiB
Vue
![]() |
<template>
|
|||
|
<view class="bottoms">
|
|||
|
|
|||
|
<view class="box" @click="getgogo(1)" v-if="role == 'user' ">
|
|||
|
<view class="imgs">
|
|||
|
<image src="../../static/home.png" v-show="aindex == 1"></image>
|
|||
|
<image src="../../static/homex.png" v-show="aindex != 1"></image>
|
|||
|
</view>
|
|||
|
<view class="">首页</view>
|
|||
|
</view>
|
|||
|
<view class="box" @click="getgogo(8)" v-if="role == 'police' ">
|
|||
|
<view class="imgs">
|
|||
|
<image src="../../static/home.png" v-show="aindex == 8"></image>
|
|||
|
<image src="../../static/homex.png" v-show="aindex != 8"></image>
|
|||
|
</view>
|
|||
|
<view class="">首页</view>
|
|||
|
</view>
|
|||
|
|
|||
|
<view class="box" @click="getgogo(2)">
|
|||
|
<view class="imgs" style="position: relative;">
|
|||
|
<view class="hongdian" v-if=" msgNum && msgNum != 0 ">
|
|||
|
{{msgNum || ""}}
|
|||
|
</view>
|
|||
|
<view class="imgs">
|
|||
|
<image src="../../static/message.png" v-show="aindex == 2"></image>
|
|||
|
<image src="../../static/messagex.png" v-show="aindex != 2"></image>
|
|||
|
</view>
|
|||
|
</view>
|
|||
|
<view class="">消息</view>
|
|||
|
</view>
|
|||
|
<!-- #ifdef APP-PLUS || H5 -->
|
|||
|
<view class="box" @click="getgogo(3)">
|
|||
|
<view class="imgs">
|
|||
|
<image src="../../static/ycar.png" v-show="aindex == 3"></image>
|
|||
|
<image src="../../static/ycarx.png" v-show="aindex != 3"></image>
|
|||
|
</view>
|
|||
|
<view class="">运力</view>
|
|||
|
</view>
|
|||
|
<!-- #endif -->
|
|||
|
|
|||
|
<view class="box" @click="getgogo(4)">
|
|||
|
<view class="imgs">
|
|||
|
<image src="../../static/my.png" v-show="aindex == 4"></image>
|
|||
|
<image src="../../static/myx.png" v-show="aindex != 4"></image>
|
|||
|
</view>
|
|||
|
<view class="">个人中心</view>
|
|||
|
</view>
|
|||
|
</view>
|
|||
|
</template>
|
|||
|
|
|||
|
<script>
|
|||
|
import request from '../../utils/request';
|
|||
|
import {
|
|||
|
getToken
|
|||
|
} from '@/utils/auth'
|
|||
|
const innerAudioContext = uni.createInnerAudioContext();
|
|||
|
const jyJPush = uni.requireNativePlugin('JY-JPush');
|
|||
|
export default {
|
|||
|
data() {
|
|||
|
return {
|
|||
|
msgSocket: this.$msgSocket,
|
|||
|
aindex: 1,
|
|||
|
msgNum: null,
|
|||
|
role: 'user',
|
|||
|
nowPageInterval: null,
|
|||
|
arr: [{
|
|||
|
text: '首页'
|
|||
|
},
|
|||
|
{
|
|||
|
text: '消息'
|
|||
|
},
|
|||
|
{
|
|||
|
text: '运力'
|
|||
|
},
|
|||
|
{
|
|||
|
text: '个人中心'
|
|||
|
},
|
|||
|
]
|
|||
|
}
|
|||
|
},
|
|||
|
props: {
|
|||
|
msg: String
|
|||
|
},
|
|||
|
onLoad() {
|
|||
|
console.log('tabbag', uni.getStorageSync('identity'));
|
|||
|
|
|||
|
},
|
|||
|
onUnload() {
|
|||
|
if (this.nowPageInterval) {
|
|||
|
clearTimeout(this.nowPageInterval);
|
|||
|
}
|
|||
|
},
|
|||
|
mounted() {
|
|||
|
// #ifdef APP || H5
|
|||
|
|
|||
|
console.log('tabbag', uni.getStorageSync('identity'));
|
|||
|
this.role = uni.getStorageSync('identity');
|
|||
|
// #endif
|
|||
|
if (!this.nowPageInterval) {
|
|||
|
this.nowPageInterval = setInterval(() => {
|
|||
|
|
|||
|
this.msgSocket = this.$msgSocket
|
|||
|
}, 3000);
|
|||
|
}
|
|||
|
console.log(this.aindex);
|
|||
|
setTimeout(() => {
|
|||
|
this.msgInfo()
|
|||
|
}, 2000);
|
|||
|
|
|||
|
this.aindex = this.msg
|
|||
|
this.getbottom()
|
|||
|
},
|
|||
|
watch: {
|
|||
|
msgSocket(newVal, oldVal) {
|
|||
|
console.log('msgSocket值发生变化', newVal, oldVal)
|
|||
|
this.msgInfo()
|
|||
|
},
|
|||
|
deep: true,
|
|||
|
},
|
|||
|
methods: {
|
|||
|
|
|||
|
dianyidain() {
|
|||
|
console.log('执行了,dianyidain');
|
|||
|
innerAudioContext.src = 'https://www.nuoyunr.com/lananRsc/rescue/msgV.mp3';
|
|||
|
// 设置播放次数和计数器
|
|||
|
const playCount = 5;
|
|||
|
let currentCount = 0;
|
|||
|
|
|||
|
// 监听音频播放结束事件
|
|||
|
innerAudioContext.onEnded(() => {
|
|||
|
// 播放计数加一
|
|||
|
currentCount++;
|
|||
|
|
|||
|
// 判断是否达到播放次数上限
|
|||
|
if (currentCount < playCount) {
|
|||
|
// 继续播放
|
|||
|
innerAudioContext.play();
|
|||
|
} else {
|
|||
|
// 播放完成,可以在这里添加额外的逻辑
|
|||
|
console.log('播放完成');
|
|||
|
}
|
|||
|
});
|
|||
|
|
|||
|
// 初次播放
|
|||
|
innerAudioContext.play();
|
|||
|
|
|||
|
|
|||
|
},
|
|||
|
msgInfo() {
|
|||
|
console.log(this.msgSocket, 'msgSocket')
|
|||
|
if (this.msgSocket) {
|
|||
|
console.log('消息回调启动成功')
|
|||
|
this.msgSocket.onMessage(res => {
|
|||
|
console.log("发出提示音");
|
|||
|
this.getbottom();
|
|||
|
this.dianyidain()
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
},
|
|||
|
|
|||
|
async getbottom() {
|
|||
|
if (!getToken()) {
|
|||
|
return
|
|||
|
}
|
|||
|
let res = await request({
|
|||
|
url: '/announcement/announcement/getOwnNoRead',
|
|||
|
method: 'get',
|
|||
|
|
|||
|
})
|
|||
|
console.log('jitiao', res);
|
|||
|
if (res.code == 200) {
|
|||
|
this.msgNum = res.data
|
|||
|
}
|
|||
|
},
|
|||
|
getgogo(index) {
|
|||
|
|
|||
|
|
|||
|
if (index == 1) {
|
|||
|
this.aindex = index
|
|||
|
uni.reLaunch({
|
|||
|
url: '/pages/rescue/rescue'
|
|||
|
})
|
|||
|
}
|
|||
|
if (index == 2) {
|
|||
|
this.aindex = index
|
|||
|
uni.reLaunch({
|
|||
|
url: '/pages/message/message'
|
|||
|
})
|
|||
|
}
|
|||
|
if (index == 3) {
|
|||
|
this.aindex = index
|
|||
|
uni.reLaunch({
|
|||
|
url: '/pages/move/move'
|
|||
|
})
|
|||
|
}
|
|||
|
if (index == 4) {
|
|||
|
this.aindex = index
|
|||
|
uni.reLaunch({
|
|||
|
url: '/pages/my/my'
|
|||
|
})
|
|||
|
}
|
|||
|
if (index == 8) {
|
|||
|
this.aindex = index
|
|||
|
uni.reLaunch({
|
|||
|
url: '/pages/rescue/trafficPolice'
|
|||
|
})
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
</script>
|
|||
|
|
|||
|
<style scoped lang="scss">
|
|||
|
.bottoms {
|
|||
|
width: 100%;
|
|||
|
height: 50px;
|
|||
|
position: fixed;
|
|||
|
bottom: 0px;
|
|||
|
background: #242A38;
|
|||
|
display: flex;
|
|||
|
justify-content: space-between;
|
|||
|
font-size: 14px;
|
|||
|
font-weight: 400;
|
|||
|
color: #FFFFFF;
|
|||
|
}
|
|||
|
|
|||
|
.box {
|
|||
|
width: 25%;
|
|||
|
text-align: center;
|
|||
|
font-size: 12px;
|
|||
|
}
|
|||
|
|
|||
|
.imgs {
|
|||
|
margin: 0 auto;
|
|||
|
margin-top: 10px;
|
|||
|
width: 18px;
|
|||
|
height: 16px;
|
|||
|
|
|||
|
image {
|
|||
|
width: 100%;
|
|||
|
height: 100%;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
.hongdian {
|
|||
|
width: 12px;
|
|||
|
height: 12px;
|
|||
|
background-color: crimson;
|
|||
|
border-radius: 50%;
|
|||
|
overflow: hidden;
|
|||
|
position: absolute;
|
|||
|
top: -5px;
|
|||
|
right: -8px;
|
|||
|
z-index: 9999;
|
|||
|
display: flex;
|
|||
|
align-items: center;
|
|||
|
justify-content: center;
|
|||
|
color: white;
|
|||
|
font-size: 2px;
|
|||
|
}
|
|||
|
</style>
|