Files
2026-01-16 14:13:44 +08:00

412 lines
15 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var theobject = null; //This gets a value as soon as a resize start
var resizeWidth = "";
var resizeHeight = "";
var resizeLeft = "";
var resizeTop = "";
var resizeId = "";
var firstLeft = "";
var firstTop = "";
function resizeObject() {
this.el = null; //pointer to the object
this.dir = ""; //type of current resize (n, s, e, w, ne, nw, se, sw)
this.grabx = null; //Some useful values
this.graby = null;
this.width = null;
this.height = null;
this.left = null;
this.top = null;
}
//Find out what kind of resize! Return a string inlcluding the directions
function getDirection(el) {
var xPos, yPos, offset, dir;
dir = "";
xPos = window.event.offsetX;
yPos = window.event.offsetY;
offset = 8; //The distance from the edge in pixels
if (yPos < offset) dir += "n";
else if (yPos > el.offsetHeight - offset) dir += "s";
if (xPos < offset) dir += "w";
else if (xPos > el.offsetWidth - offset) dir += "e";
return dir;
}
function doDown() {
var el = getReal(event.srcElement, "className", "reSize");
if (el == null) {
theobject = null;
return;
}
resizeId = el.id;
firstLeft = $('#' + resizeId).position().left;
firstTop = $('#' + resizeId).position().top;
dir = getDirection(el);
if (dir == "") return;
theobject = new resizeObject();
theobject.el = el;
theobject.dir = dir;
theobject.grabx = window.event.clientX;
theobject.graby = window.event.clientY;
theobject.width = el.offsetWidth;
theobject.height = el.offsetHeight;
theobject.left = el.offsetLeft;
theobject.top = el.offsetTop;
window.event.returnValue = false;
window.event.cancelBubble = true;
}
function doUp3() {
if (theobject != null) {
theobject = null;
}
if (resizeId != '') {
var reSizeDiv = $('#' + resizeId);
resizeWidth = reSizeDiv.css("width");
resizeHeight = reSizeDiv.css("height");
$.ajax({
type: "GET",
url: ext.contextPath + "/process/dataVisualContent/updateReSize.do?id=" + resizeId + "&width=" + resizeWidth + "&height=" + resizeHeight,
async: false,
globle: false,
success: function (data) {
}
});
}
resizeWidth = "";
resizeHeight = "";
resizeLeft = "";
resizeTop = "";
resizeId = "";
firstLeft = "";
firstTop = "";
}
function doUp0() {
if (theobject != null) {
theobject = null;
}
}
function doUp() {
if (theobject != null) {
theobject = null;
}
if (resizeId != '') {
var reSizeDiv = $('#' + resizeId);
resizeWidth = reSizeDiv.css("width");
resizeHeight = reSizeDiv.css("height");
resizeLeft = reSizeDiv.css("left").replace("px", "");
resizeTop = reSizeDiv.css("top").replace("px", "");
// if(firstLeft==resizeLeft&&firstTop==resizeTop){
// stopMove(resizeId,"noMove");
// }else{
// stopMove(resizeId,"move");
// }
$.ajax({
type: "GET",
url: ext.contextPath + "/process/dataVisualContent/updateReSize.do?id=" + resizeId + "&width=" + resizeWidth + "&height=" + resizeHeight,
async: false,
globle: false,
success: function (data) {
}
});
$.ajax({
type: "GET",
url: ext.contextPath + "/process/dataVisualContent/updateLayout.do?id=" + resizeId + "&postx=" + resizeLeft + "&posty=" + resizeTop,
async: false,
globle: false,
success: function (data) {
}
});
// $('#'+resizeId).draggable({
// cursor:'move'
// });
}
resizeWidth = "";
resizeHeight = "";
resizeLeft = "";
resizeTop = "";
resizeId = "";
firstLeft = "";
firstTop = "";
}
function doMove() {
var el, xPos, yPos, str, xMin, yMin;
xMin = 8; //The smallest width possible
yMin = 8; // height
el = getReal(event.srcElement, "className", "reSize");
if (el == null) {
return;
}
if (el.className.indexOf("reSize") >= 0) {
str = getDirection(el);
//Fix the cursor
if (str == "") str = "default";
else str += "-resize";
el.style.cursor = str;
}
//Dragging starts here
if (theobject != null) {
if (dir.indexOf("e") != -1)
theobject.el.style.width = Math.max(xMin, theobject.width +
window.event.clientX - theobject.grabx) + "px";
if (dir.indexOf("s") != -1)
theobject.el.style.height = Math.max(yMin, theobject.height +
window.event.clientY - theobject.graby) + "px";
if (dir.indexOf("w") != -1) {
theobject.el.style.left = Math.min(theobject.left +
window.event.clientX - theobject.grabx, theobject.left + theobject.width - xMin) + "px";
theobject.el.style.width = Math.max(xMin, theobject.width -
window.event.clientX + theobject.grabx) + "px";
}
if (dir.indexOf("n") != -1) {
theobject.el.style.top = Math.min(theobject.top +
window.event.clientY - theobject.graby, theobject.top + theobject.height - yMin) + "px";
theobject.el.style.height = Math.max(yMin, theobject.height -
window.event.clientY + theobject.graby) + "px";
}
window.event.returnValue = false;
window.event.cancelBubble = true;
}
}
function getReal(el, type, value) {
temp = el;
while ((temp != null) && (temp.tagName != "BODY")) {
if (temp.className.indexOf("reSize") >= 0) {
el = temp;
return el;
} else {
return;
}
temp = temp.parentElement;
}
return el;
}
function doUp2(resizeId2) {
var reSizeDiv = $('#' + resizeId2);
// resizeWidth=reSizeDiv.css("width");
// resizeHeight=reSizeDiv.css("height");
resizeLeft = reSizeDiv.css("left");
resizeTop = reSizeDiv.css("top");
// $.ajax({
// type : "GET",
// url : ext.contextPath+"/process/dataVisualContent/updateReSize.do?id="+resizeId+"&width="+resizeWidth+"&height="+resizeHeight,
// async: false,
// globle:false,
// success : function(data){
// }
// });
$.ajax({
type: "GET",
url: ext.contextPath + "/process/dataVisualContent/getOneJson.do?id=" + resizeId2,
async: false,
globle: false,
dataType: 'json',
success: function (data) {
data = data[0];
if (data.postx.indexOf('%') < 0 && data.posty.indexOf('%') < 0) {
$.ajax({
type: "GET",
url: ext.contextPath + "/process/dataVisualContent/updateLayout.do?id=" + resizeId2 + "&postx=" + resizeLeft + "&posty=" + resizeTop,
async: false,
globle: false,
success: function (data) {
}
});
}
}
});
resizeWidth = "";
resizeHeight = "";
resizeLeft = "";
resizeTop = "";
resizeId = "";
firstLeft = "";
firstTop = "";
}
var rec;
var flag = 0;
function voiceClick(voicetext,voicemethod,paths,contentId){
paths=paths.split(",");
let path1="";let path2="";
if(paths.length>2){
path1=paths[1];
path2=paths[0];
}else{
path1=paths[0];
path2=paths[0];
}
flag += 1;
if (flag % 2 == 1) {
rec = Recorder({ type: "mp3", sampleRate: 16000, bitRate: 16, numChannels: 1 });//使用默认配置mp3格式
//打开麦克风授权获得相关资源
rec.open(function () {
//开始录音
rec.start();
}, function (msg, isUserNotAllow) {
//用户拒绝了权限或浏览器不支持
alert((isUserNotAllow ? "用户拒绝了权限," : "") + "无法录音:" + msg);
});
document.getElementById(contentId+"Img").src=path2;
}
if (flag % 2 == 0) {
//停止录音得到了录音文件blob二进制对象想干嘛就干嘛
rec.stop(function (blob, duration) {
var api=ext.contextPath +"/data/baiDuAipSpeech/save.do";
var reader=new FileReader();
let to_speak = window.speechSynthesis;
reader.onloadend=function(){
$.ajax({
url:api, //上传接口地址
type:"POST",
data:{
type:blob.type, //告诉后端这个录音是什么格式的可能前后端都固定的mp3可以不用写
upfile_b64:(/.+;\s*base64\s*,\s*(.+)$/i.exec(reader.result)||[])[1] //录音文件内容后端进行base64解码成二进制
},
success:function(data){
console.log(data);
data = eval('(' + data + ')');
let result=data.result[0];
if(result.indexOf("请对取水一号凤凰进行巡检")>=0){
result="请对取水一号泵房进行巡检";
}
console.log(result);
if(result.indexOf(voicetext)>=0){
eval(voicemethod);
}else if(result.indexOf("请对取水一号泵房进行巡检")>=0||
result.indexOf("一号反冲洗泵情况")>=0||
result.indexOf("二号反冲洗泵情况")>=0||
result.indexOf("三号反冲洗泵情况")>=0||
result.indexOf("一号送水泵情况")>=0||
result.indexOf("二号送水泵情况")>=0||
result.indexOf("三号送水泵情况")>=0||
result.indexOf("四号送水泵情况")>=0||
result.indexOf("五号送水泵情况")>=0||
result.indexOf("六号送水泵情况")>=0||
result.indexOf("七号送水泵情况")>=0||
result.indexOf("八号送水泵情况")>=0){
$.ajax({
type: "GET",
url: ext.contextPath + "/data/baiDuAipSpeech/sendBim.do?text=" + result,
async: false,
globle: false,
success: function (data) {
console.log("in bim");
if(result.indexOf("请对取水一号泵房进行巡检")>=0||result.indexOf("请对取水一号凤凰进行巡检")>=0){
to_speak = new SpeechSynthesisUtterance("好的,现在开始执行取水一号泵房自动巡检");
window.speechSynthesis.speak(to_speak);
}else if(result.indexOf("一号反冲洗泵情况")>=0){
to_speak = new SpeechSynthesisUtterance("正在为您定位一号反冲洗泵");
window.speechSynthesis.speak(to_speak);
}else if(result.indexOf("二号反冲洗泵情况")>=0){
to_speak = new SpeechSynthesisUtterance("正在为您定位二号反冲洗泵");
window.speechSynthesis.speak(to_speak);
}else if(result.indexOf("三号反冲洗泵情况")>=0){
to_speak = new SpeechSynthesisUtterance("正在为您定位三号反冲洗泵");
window.speechSynthesis.speak(to_speak);
}else if(result.indexOf("一号送水泵情况")>=0){
to_speak = new SpeechSynthesisUtterance("正在为您定位一号送水泵");
window.speechSynthesis.speak(to_speak);
}else if(result.indexOf("二号送水泵情况")>=0){
to_speak = new SpeechSynthesisUtterance("正在为您定位二号送水泵");
window.speechSynthesis.speak(to_speak);
}else if(result.indexOf("三号送水泵情况")>=0){
to_speak = new SpeechSynthesisUtterance("正在为您定位三号送水泵");
window.speechSynthesis.speak(to_speak);
}else if(result.indexOf("四号送水泵情况")>=0){
to_speak = new SpeechSynthesisUtterance("正在为您定位四号送水泵");
window.speechSynthesis.speak(to_speak);
}else if(result.indexOf("五号送水泵情况")>=0){
to_speak = new SpeechSynthesisUtterance("正在为您定位五号送水泵");
window.speechSynthesis.speak(to_speak);
}else if(result.indexOf("六号送水泵情况")>=0){
to_speak = new SpeechSynthesisUtterance("正在为您定位六号送水泵");
window.speechSynthesis.speak(to_speak);
}else if(result.indexOf("七号送水泵情况")>=0){
to_speak = new SpeechSynthesisUtterance("正在为您定位七号送水泵");
window.speechSynthesis.speak(to_speak);
}else if(result.indexOf("八号送水泵情况")>=0){
to_speak = new SpeechSynthesisUtterance("正在为您定位八号送水泵");
window.speechSynthesis.speak(to_speak);
}
}
});
}else{
to_speak = new SpeechSynthesisUtterance("暂时没法识别你的语音呢");
window.speechSynthesis.speak(to_speak);
}
// console.log("上传成功",v);
rec.close();
},
error:function(s){
console.error("上传失败",s);
rec.close();
}
});
};
reader.readAsDataURL(blob);
}, function (msg) {
alert("录音失败:" + msg);
rec.close();
});
flag=0;
document.getElementById(contentId+"Img").src=path1;
}
}
// document.onmousedown = doDown;
// document.onmouseup = doUp;
// document.onmousemove = doMove;