北京经济技术开发区经开区虚拟城市项目-【前端】-Web
lixuliang
2024-09-14 c7187e038c284acc051a439c5eda16582bdb9b7a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
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.type === "command") {
                let info = res.data.params;
                let resIndex = '';
                if (info.includes("定位到")) {
                    resIndex = info.search('定位到') + 3;
                } else if (info.includes("定位")) {
                    resIndex = info.search('定位') + 2;
                } else {
                    resIndex = info.search('') + 0;
                }
                info.search("。") != -1 ? mapMsg.testMsg(info.slice(resIndex, -1)) : mapMsg.testMsg(info.slice(resIndex));
            }
            // // 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