添加语音识别 及管控功能

This commit is contained in:
haozq 2024-06-04 16:52:12 +08:00
parent 645fa020a0
commit 37344df2ad
5 changed files with 186 additions and 11 deletions

View File

@ -1,6 +1,6 @@
let aqEnnable = true // 参数加密开关
//后端路径
const commonUrl = "http://10.138.225.233:18080/zhgd/";
const commonUrl = "http://127.0.0.1:18080/zhgd/";
//前端路径
const URL_IP="http://10.138.225.233:21624/zhgd-web"
/* 登录相关 */

View File

@ -363,7 +363,6 @@ function detectionRecord(button,construction){
if(button !== ''){
let buttons = document.getElementsByClassName('button-style');
let isSelected = button.style.color === "rgb(81, 170, 209)";
for (let i = 0; i < buttons.length; i++) {
buttons[i].style.border = '';
buttons[i].style.color = '';
@ -377,9 +376,6 @@ function detectionRecord(button,construction){
detectionRecord('','');
}
}
const url = commonUrl + "screen/largeScreen/constructionQuality/detectionRecord";
const params = {
"roleCode": roleCode,
"orgId": orgId,
@ -387,6 +383,66 @@ function detectionRecord(button,construction){
"bidCode": bidCode,
"construction": construction
}
console.log(construction)
console.log(construction=='table')
if(construction=='table'){
$(".echarts-div").css("display","none");
$("#data-table-div").css("display","block");
getDataTable();
}else{
$(".echarts-div").css("display","block");
$("#data-table-div").css("display","none");
getDetectionRecord(params);
}
}
//施工质量列表
function getDataTable(){
const url = commonUrl + "screen/largeScreen/constructionQuality/getDevDataList";
table.render({
elem: '#data-table',
url: url,
skin: 'line',
headers:{
decrypt:"decrypt",
"Authorization":token
},
where: {
roleCode: roleCode,
orgId: orgId,
userId: userId,
bidCode: bidCode,
},
cols: [[
{field: 'number', width:80,title: '序号', align: 'center', type: 'numbers', fixed: 'left'},
{field: 'name', align: 'center', title: '区域名称'},
{field: 'bidName', align: 'center', title: '工程名称'},
{field: 'val', align: 'center', title: '本次沉降'},
{field: 'hisVal', align: 'center', title: '累计沉降'},
{field: 'createTime', align: 'center', title: '检测时间'},
{field: 'jcUser', align: 'center', title: '检测人'},
{field: 'jhUser', align: 'center', title: '校核人'},
{field: 'devCode', align: 'center', title: '仪器型号计量编号'}
]],
initComplete: function () {
// 在表格渲染完成后,重新渲染序号列
var that = this.elem.next();
var tool = that.children('.layui-table-box').children('.layui-table-fixed').children('.layui-table-body').children('.layui-table');
tool.find("tr").each(function (index, item) {
$(this).find('td[data-field="LAY_TABLE_INDEX"]').text(index + 1);
});
},
page: true, //开启分页
loading: true, //数据加载中。。。
limits: [5, 10, 20, 100],
limit: 7
})
}
//查询echars
function getDetectionRecord(params){
const url = commonUrl + "screen/largeScreen/constructionQuality/detectionRecord";
let encryptStr = encryptCBC(JSON.stringify(params));
ajaxRequest(url, "POST", encryptStr, true, function () {
}, function (result) {
@ -416,6 +472,8 @@ function detectionRecord(button,construction){
}, "application/json",aqEnnable);
}
//检测记录对比echarts图表
function detectionRecordEcharts(extractedData){
var myChart = echarts.init(document.getElementById('dome'));

View File

@ -1,4 +1,6 @@
let element, layer, form, bidCode;
let talkAbout=false;
layui.use(['layer', 'element'], function () {
element = layui.element;
layer = layui.layer;
@ -43,6 +45,121 @@ layui.use(['layer', 'element'], function () {
}
})
});
let loading;
// 检查浏览器是否支持语音识别 API
if ('webkitSpeechRecognition' in window) {
const recognition = new webkitSpeechRecognition(); // 创建一个 SpeechRecognition 对象
recognition.continuous = false; // 是否持续识别,这里设置为 false
recognition.lang = 'zh-CN'; // 设置识别的语言,这里设置为中文
recognition.interimResults = false; // 是否返回临时识别结果
// 当语音识别开始时触发
recognition.onstart = function() {
loading = layer.load(2, {
shade: false ,//0.1透明度的白色背景
content:'<div style="color:#fff;">语音识别中......</div>',
success: function (layerContentStyle) { // 设置loading样式
layerContentStyle.find('.layui-layer-content').css({
'padding-left': '45px',
'text-align': 'left',
'width': '175px',
'line-height':'30px'
});
}
});
};
// 当语音识别结束时触发
recognition.onend = function() {
talkAbout=false;
layer.close(loading);
loading = layer.load(2, {
shade: false ,//0.1透明度的白色背景
time: 1000,
content:'<div style="color:#fff;">正在检测中......</div>',
success: function (layerContentStyle) { // 设置loading样式
layerContentStyle.find('.layui-layer-content').css({
'padding-left': '45px',
'text-align': 'left',
'width': '175px',
'line-height':'30px'
});
}
});
};
// 当识别到一个结果时触发
recognition.onresult = function(event) {
layer.close(loading);
const transcript = event.results[0][0].transcript; // 获取识别的文本
if(transcript){
let openUrl=''
if(transcript.indexOf("首页")!=-1){
openUrl ='../index/index.html'
}else if(transcript.indexOf("视频监控")!=-1){
openUrl ='../video/video.html'
}else if(transcript.indexOf("组塔检测")!=-1){
openUrl ='../towerAssInspect/towerAssInspect.html'
}else if(transcript.indexOf("作业环境")!=-1){
openUrl ='../operEnvironment/operEnvironment.html'
}else if(transcript.indexOf("施工质量")!=-1){
openUrl ='../consQuality/consQuality.html'
}else if(transcript.indexOf("人员管控")!=-1){
openUrl ='../personnelControl/personnelControl.html'
}else if(transcript.indexOf("出入管理")!=-1){
openUrl ='../accessMge/accessMge.html'
}else if(transcript.indexOf("告警管理")!=-1){
openUrl ='../alarmMge/alarmMge.html'
}else {
console.log("识别结果异常");
layer.msg('指令不正确', {
icon: 6,
time: 1000
});
return ;
}
console.log(openUrl)
if(openUrl){
const li= $('#nav-right ul li');
for (let i = 0; i <li.length ; i++) {
console.log($(li[i]).attr('hrefvalue'));
if($(li[i]).attr('hrefvalue')==openUrl){
$(li[i]).removeClass('nocheck').addClass('checked');
}else{
$(li[i]).removeClass('checked').addClass('nocheck');
}
}
$('#indexIframe').attr('src', openUrl);
console.log("跳转页面中");
console.log(openUrl)
}
}else{
layer.msg('未能正确识别语音', {
icon: 6,
time: 1000
});
}
console.log('你说了:' + transcript);
};
// 当语音识别服务错误时触发
recognition.onerror = function(error) {
layer.close(loading);
// console.error('语音识别服务错误:', error);
layer.msg('浏览器不支持语音识别服务', {
icon: 6,
time: 1000
});
};
// 开始语音识别
document.querySelector('#start-button').addEventListener('click', function() {
if(!talkAbout){
recognition.start();
talkAbout=true;
}
});
} else {
console.error('浏览器不支持语音识别服务。');
}
});
@ -134,7 +251,3 @@ function goBackground() {
const newWindow = window.open(hrefUrl, 'newwindow');
}
/* 对讲 */
function talk() {
return layer.msg('网络异常', { icon: 2 });
}

View File

@ -98,11 +98,15 @@
<div class="left-under layout">
<div class="background-img" style="background-image: url('../../img/consQuality/DetectionRecord.png');">
<div class="layout" style="width: 100%;height: 10%">
<div class="button-style" onclick="detectionRecord(this,'table')">沉降点记录</div>
<div class="button-style" onclick="detectionRecord(this,thePileFoundationIsMadeIntoHoles)">桩基成孔</div>
<div class="button-style" onclick="detectionRecord(this,groundAcceptance)">地面压实</div>
<div class="button-style" onclick="detectionRecord(this,concretePouring)">大体积混凝土温控检测</div>
</div>
<div id="dome" style="height: 90%;width: 100%;"></div>
<div id="dome" class="echarts-div" style="height: 90%;width: 100%;"></div>
<div style="width: 100%;height: 85%; overflow: auto; " id="data-table-div" >
<table class="layui-hide" id="data-table" lay-filter="data-table"></table>
</div>
</div>
</div>
</div>

View File

@ -20,7 +20,7 @@
<body>
<div id="nav-box" class="layout">
<div id="nav-icon">
<img src="../../img/navigation/talk.png" alt="对讲" onclick="talk()" data-mtpis="对讲">
<img src="../../img/navigation/talk.png" alt="对讲" id="start-button" data-mtpis="对讲">
<img src="../../img/navigation/logout.png" onclick="loginout()" alt="退出" data-mtpis="退出">
</div>
<div id="nav-left" class="layout">