import mapData from "../../../static/mapData"; import rpc from "./rpc"; import vueEvents from '@/utils/vueEvent.js' window.mapMsg = { setTimeInterval: null, testMsg(res) { // console.log(res); this.setMsgMatching({ message: res, baidu_keys: { results: [{ word: res }] } }); }, init() { var that = this; window.addEventListener("message", res => { // if (res.data.status === "ok") { // that.setMsgMatching(res.data.params); // } if (res.data.type === "command") { let info = res.data.params if (info.includes("定位到")) { info.search("。") != -1 ? mapMsg.testMsg(info.slice(3, -1)) : mapMsg.testMsg(info.slice(3)) } else if (info.includes("定位")) { info.search("。") != -1 ? mapMsg.testMsg(info.slice(2, -1)) : mapMsg.testMsg(info.slice(2)) } else { info.search("。") != -1 ? mapMsg.testMsg(info.slice(0, -1)) : mapMsg.testMsg(info.slice(0)) // mapMsg.testMsg(info.slice(0, -1))//有句号 // mapMsg.testMsg(info.slice(0))//没句号 } } }); }, // clearTime() { // if (this.setTimeInterval) { // clearInterval(this.setTimeInterval); // this.setTimeInterval = null; // } // // this.setTime(); // }, // setTime() { // if (this.setTimeInterval) { // clearInterval(this.setTimeInterval); // this.setTimeInterval = null; // } // this.setTimeInterval = setTimeout((res) => { // vueEvents.$emit("queryData", false); // rpc.setClearAllMsg(); // rpc.setLineRoaming() // clearInterval(this.setTimeInterval); // this.setTimeInterval = null; // }, 90000) // }, //消息匹配 setMsgMatching(result) { // 收到的消息 var param = result.message; // 默认的匹配词 var rest = mapData.msgMach.rest; //'复位', '还原', '初始化', '初始位置' var rom = mapData.msgMach.lineRoam;//'漫游', '导航' var closeRomData = mapData.msgMach.closeRoam;//'停止漫游', '停止导航' // var acceptData = mapData.msgMach.acceptMsg; // 地图复位 var valRest = rest.filter((rs) => { if (param.indexOf(rs) > -1) { return rs; } }) if (valRest.length > 0) { // this.clearTime(); vueEvents.$emit("queryData", false); rpc.setClearAllMsg(); rpc.setMapRest(); return } // 停止漫游 var closeRom = closeRomData.filter((rs) => { if (param.indexOf(rs) > -1) { return rs } }); if (closeRom.length > 0) { // this.clearTime(); rpc.setCloseLineRomaing(); return } //漫游 var valRom = rom.filter((rs) => { if (param.indexOf(rs) > -1) { return rs; } }) if (valRom.length > 0) { vueEvents.$emit("queryData", false); // this.clearTime(); rpc.setClearAllMsg(); rpc.setLineRoaming() return } // this.clearTime(); rpc.getFuzzyQuery(result) // var accept = acceptData.filter(res => { // if (param.indexOf(res) > -1) { // return res; // } // }) // if (accept.length > 0) { // this.clearTime(); // rpc.getFuzzyQuery(result) // } // else{ // vueEvents.$emit("queryData", false); // rpc.setClearAllMsg(); // rpc.setMapRest(); // } }, }; export default mapMsg