2024-10-09 13:34:36 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<view class="content">
|
|
|
|
|
|
|
|
|
|
|
|
</view>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2025-09-03 13:22:16 +08:00
|
|
|
|
import {
|
|
|
|
|
|
getToken,
|
|
|
|
|
|
getUserInfo
|
|
|
|
|
|
} from "@/utils/auth";
|
|
|
|
|
|
import request from '@/utils/request';
|
|
|
|
|
|
let innerAudioContext = '';
|
|
|
|
|
|
const keepAlivePlugin = uni.requireNativePlugin('Ba-KeepAlive')
|
2024-10-09 13:34:36 +08:00
|
|
|
|
export default {
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
2025-09-03 13:22:16 +08:00
|
|
|
|
// 是否正在播放
|
|
|
|
|
|
ifPlay: false,
|
2024-10-30 18:14:19 +08:00
|
|
|
|
keepLive: {
|
|
|
|
|
|
channelId: 'Ba-KeepAlive',
|
|
|
|
|
|
channelName: "Ba-KeepAlive",
|
|
|
|
|
|
title: "汽修小助手正在运行",
|
|
|
|
|
|
content: "汽修小助手正在运行",
|
|
|
|
|
|
dataResult: "",
|
|
|
|
|
|
type: undefined
|
|
|
|
|
|
}
|
2024-10-09 13:34:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
},
|
2025-09-03 13:22:16 +08:00
|
|
|
|
onLoad() {
|
|
|
|
|
|
// #ifdef APP
|
|
|
|
|
|
//保活技术
|
|
|
|
|
|
this.register()
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
if (getToken()) {
|
|
|
|
|
|
this.getNoReadNum()
|
|
|
|
|
|
//跳转首页
|
|
|
|
|
|
//判断是否是仓管,仓管需要跳单独的首页
|
|
|
|
|
|
let userInfo = getUserInfo()
|
|
|
|
|
|
if (userInfo.roleCodes.includes('repair_warehouse')) {
|
|
|
|
|
|
//仓管
|
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
|
url: '/pages-warehouse/home/home'
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
|
url: '/pages-home/home/home'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
|
url: '/pages/login/login'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
onShow() {
|
|
|
|
|
|
if (getToken()) {
|
|
|
|
|
|
//判断是否是仓管,仓管需要跳单独的首页
|
|
|
|
|
|
let userInfo = getUserInfo()
|
|
|
|
|
|
if (userInfo.roleCodes.includes('repair_warehouse')) {
|
|
|
|
|
|
//仓管
|
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
|
url: '/pages-warehouse/home/home'
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
|
url: '/pages-home/home/home'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
uni.navigateTo({
|
|
|
|
|
|
url: '/pages/login/login'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2024-10-09 13:34:36 +08:00
|
|
|
|
methods: {
|
2024-10-30 18:14:19 +08:00
|
|
|
|
register() { //注册
|
|
|
|
|
|
console.log(keepAlivePlugin, 'keepAlive');
|
|
|
|
|
|
keepAlivePlugin.register({
|
|
|
|
|
|
channelId: this.keepLive.channelId,
|
|
|
|
|
|
channelName: this.keepLive.channelName,
|
|
|
|
|
|
title: this.keepLive.title,
|
|
|
|
|
|
content: this.keepLive.content,
|
|
|
|
|
|
},
|
|
|
|
|
|
(res) => {
|
|
|
|
|
|
console.log('保活注册', res);
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
2025-09-03 13:22:16 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 获取未读消息数量
|
|
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
|
|
*/
|
|
|
|
|
|
async getNoReadNum() {
|
|
|
|
|
|
await request({
|
|
|
|
|
|
url: "/admin-api/system/notify-message/get-unread-count?systemCode=weixiu",
|
|
|
|
|
|
method: "GET"
|
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
|
if (res.code == 200 && res.data > 0) {
|
|
|
|
|
|
this.dianyidain()
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
dianyidain() {
|
|
|
|
|
|
if (!this.ifPlay) {
|
|
|
|
|
|
console.log('执行了,dianyidain');
|
|
|
|
|
|
const ifHint = uni.getStorageSync("ifHint")
|
|
|
|
|
|
console.log('当前提示开关', ifHint);
|
|
|
|
|
|
if (ifHint == false) {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
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 = 4;
|
|
|
|
|
|
let currentCount = 0;
|
|
|
|
|
|
// 初次播放
|
|
|
|
|
|
innerAudioContext.play();
|
|
|
|
|
|
// 震动
|
|
|
|
|
|
uni.vibrateLong({
|
|
|
|
|
|
success: function() {
|
|
|
|
|
|
console.log('success');
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
innerAudioContext.onError((err) => {
|
|
|
|
|
|
console.error('播放错误', err);
|
|
|
|
|
|
this.ifPlay = false
|
|
|
|
|
|
innerAudioContext.stop();
|
|
|
|
|
|
innerAudioContext.destroy(); // 播放错误后释放实例
|
|
|
|
|
|
});
|
|
|
|
|
|
// 监听音频播放结束事件
|
|
|
|
|
|
innerAudioContext.onEnded(() => {
|
|
|
|
|
|
// 播放计数加一
|
|
|
|
|
|
currentCount++;
|
|
|
|
|
|
// 判断是否达到播放次数上限
|
|
|
|
|
|
if (currentCount < playCount) {
|
|
|
|
|
|
// 继续播放
|
|
|
|
|
|
innerAudioContext.play();
|
|
|
|
|
|
// 震动
|
|
|
|
|
|
uni.vibrateLong({
|
|
|
|
|
|
success: function() {
|
|
|
|
|
|
console.log('success');
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
// 播放完成,可以在这里添加额外的逻辑
|
|
|
|
|
|
console.log('播放完成');
|
|
|
|
|
|
this.ifPlay = false
|
|
|
|
|
|
//及时释放资源
|
|
|
|
|
|
innerAudioContext.stop();
|
|
|
|
|
|
innerAudioContext.destroy();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
} else {
|
|
|
|
|
|
console.log('正在播放音频,拒绝播放请求');
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
2024-10-09 13:34:36 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
|
|
2025-09-03 13:22:16 +08:00
|
|
|
|
</style>
|