zengh
2022-09-14 8ea19a6bb34daab1410f6186992a4c1e90299c92
leafletMapOur/grabOrdersMap/js/vueMain.js
@@ -37,86 +37,146 @@
      mapPositionLoding: false, //定位loding
      oncePosition: null, //一次定位实例
      onPosition: false, //持续定位指示
      setPositionTime: null, //发送定位节流
      setPositionUseTime: 30000, //节流时间
   },
   methods: {
      unis(data) {
         //向uniapp传值
         uni.postMessage({
            data: {
               action: data
            }
         });
      },
      setUniAppMsg(state, data) {
         let that = this;
         if (window.parent) {
            console.log("有window.parent")
            if (state == "hBackMsg") {
               window.parent.hBackMsg(data);
            }
            if (state == "setIntLat") {
               window.parent.setIntLat({
                  rid: that.data.id,
                  fn: (out) => {
                     // console.log(out,"1111");
                     // that.addIcon(out);
                     that.addIcon([out[1], out[0]]);
                  }
               });
            }
            if (state == "showTip") {
               that.parent.showTip("获取定位失败");
            }
         } else {
            console.log("没window.parent")
            if (state == "hBackMsg") {
               // window.parent.hBackMsg(data);
               that.unis("hBackMsg")
            }
            if (state == "setIntLat") {
               // window.parent.setIntLat({
               //    rid: that.data.id,
               //    fn: (out) => {
               //       // console.log(out,"1111");
               //       // that.addIcon(out);
               //       that.addIcon([out[1], out[0]]);
               //    }
               // });
               that.unis("setIntLat")
            }
            if (state == "showTip") {
               // that.parent.showTip("获取定位失败");
               that.unis("showTip")
            }
      // unis(data) {
      //    //向uniapp传值
      //    uni.postMessage({
      //       data: {
      //          action: data
      //       }
      //    });
      // },
      // setUniAppMsg(state, data) {
      //    let that = this;
      //    if (window.parent) {
      //       console.log("有window.parent")
      //       if (state == "hBackMsg") {
      //          window.parent.hBackMsg(data);
      //       }
      //       if (state == "setIntLat") {
      //          window.parent.setIntLat({
      //             rid: that.data.id,
      //             fn: (out) => {
      //                // console.log(out,"1111");
      //                // that.addIcon(out);
      //                that.addIcon([out[1], out[0]]);
      //             }
      //          });
      //       }
      //       if (state == "showTip") {
      //          that.parent.showTip("获取定位失败");
      //       }
      //    } else {
      //       console.log("没window.parent")
      //       if (state == "hBackMsg") {
      //          // window.parent.hBackMsg(data);
      //          that.unis("hBackMsg")
      //       }
      //       if (state == "setIntLat") {
      //          // window.parent.setIntLat({
      //          //    rid: that.data.id,
      //          //    fn: (out) => {
      //          //       // console.log(out,"1111");
      //          //       // that.addIcon(out);
      //          //       that.addIcon([out[1], out[0]]);
      //          //    }
      //          // });
      //          that.unis("setIntLat")
      //       }
      //       if (state == "showTip") {
      //          // that.parent.showTip("获取定位失败");
      //          that.unis("showTip")
      //       }
         }
      },
      //    }
      // },
      openAPP(type) {
         // console.log(type)
         let that = this;
         if (type != 1) {
            if (that.data.butCT == "beginUp") {
               // 反馈
               uni.navigateTo({
               if (that.onPosition) {
                  that.onPosition.overContinued();
               }
               uni.redirectTo({
                  url: '/pages/grabOrders/feedback?data=' + JSON.stringify(this.data) +
                     '&other="11111"'
               });
            } else if (that.data.butCT == "begin") {
               // 开始任务
               that.setUniAppMsg("hBackMsg", {
                  type: "start",
                  data: {
                     id: that.data.id,
                     serid: that.data.serid
                  },
                  fn: function(val) {
                     if (val == "success") {
                        // console.log("成功开启任务")
                        that.data.butCT = "beginUp";
                        that.data.rtype = '0';
                        that.data.type = "0";
               // that.setUniAppMsg("hBackMsg", {
               //    type: "start",
               //    data: {
               //       id: that.data.id,
               //       serid: that.data.serid
               //    },
               //    fn: function(val) {
               //       if (val == "success") {
               //          // console.log("成功开启任务")
               //          that.data.butCT = "beginUp";
               //          that.data.rtype = '0';
               //          that.data.type = "0";
               //       }
               //    }
               // })
               let rid = that.data.id,
                  serid = that.data.serid,
                  type = 'start',
                  url = that.data.appenUrl + "taskqd/startTask?" +
                  `rid=${rid}&serid=${serid}&type=${type}`;
               axios.get(url).then((res) => {
                  // console.log(res);
                  that.onPosition = new $getPositions({
                     id: rid,
                     fn: function(res) {
                        // console.log(res);
                        // state.isOnTaskValue[id] = {
                        //    id: id,
                        //    intlat: res.intlat
                        // }
                        // state.changes = !state.changes;
                        // console.log(state.isOnTaskValue)
                        // $store.commit("setMsg", {
                        //    id: id,
                        //    intlat: res.intlat
                        // })
                        let out = res.intlat;
                        if (typeof out != "string") {
                           that.addIcon([out[1], out[0]]);
                           //坐标输出
                           let d = {
                              uid: that.data.myid,
                              rid: rid,
                              jd: out[0],
                              wd: out[1],
                           }
                           if (that.setPositionTime) {
                              return;
                           } else {
                              that.setPositionTime = setTimeout(() => {
                                 axios.post(that.data.appenUrl +
                                       "trar/submit", d)
                                    .then(res => {
                                       // console.log('res=>', res);
                                    })
                                 clearTimeout(that.setPositionTime);
                                 that.setPositionTime = null;
                              }, that.setPositionUseTime)
                           }
                        } else {
                           console.log("获取定位失败")
                        }
                     }
                  }
                  })
                  that.onPosition.continuedTime();
                  that.data.butCT = "beginUp";
                  that.data.rtype = '0';
                  that.data.type = "0";
               })
            }
         } else {
@@ -159,34 +219,91 @@
      },
      beginCome() {
         var data = {
            appenUrl: "http://192.168.0.108:83/",
            butCT: "begin",
            buttype: 0,
            captain: "我",
            city: "南昌市",
            content: "测试",
            district: "西湖区",
            id: 37,
            integral: "222",
            iscation: "1",
            jnum: 3,
            line: "LINESTRING(115.8995839881188 28.687205773173343,115.89391916267935 28.678966027079593,115.90404718391959 28.673644524394046,115.91211526863638 28.681369286356936)",
            num: 1,
            nums: 0,
            province: "江西省",
            publisher: "管理",
            raddress: null,
            rname: "测试1",
            rtype: "0",
            serid: "1123598821738675201,",
            team: "你,他,它",
            time: "2022-02-18 14:15:52",
            type: "2",
            url: "http://223.82.109.183:2081/zhba/upload/20220218/67f0c8bf3e7b5024c64133691f265072.ico",
         }
               appenUrl: "http://192.168.0.108:83/",
               butCT: "begin",
               buttype: 0,
               captain: "我",
               city: "南昌市",
               content: "测试",
               district: "西湖区",
               id: 37,
               integral: "222",
               iscation: "1",
               jnum: 3,
               line: "LINESTRING(115.8995839881188 28.687205773173343,115.89391916267935 28.678966027079593,115.90404718391959 28.673644524394046,115.91211526863638 28.681369286356936)",
               num: 1,
               nums: 0,
               province: "江西省",
               publisher: "管理",
               raddress: null,
               rname: "测试1",
               rtype: "0",
               serid: "1123598821738675201,",
               team: "你,他,它",
               time: "2022-02-18 14:15:52",
               type: "0",
               url: "http://61.131.136.25:2081/zhba/upload/20220218/67f0c8bf3e7b5024c64133691f265072.ico",
               fname:"管理员"
            },
            that = this;
         //url解码
         this.data = this.getQueryVariable('data') || data;
         // console.log(this.data)
         if (typeof this.data == "string") {
            this.data = JSON.parse(this.data)
         }
         console.log(this.data)
         if (this.data.isOn || this.data.butCT == "beginUp") {
            //队长开启任务
            let rid = that.data.id;
            that.onPosition = new $getPositions({
               id: rid,
               fn: function(res) {
                  // console.log(res);
                  // state.isOnTaskValue[id] = {
                  //    id: id,
                  //    intlat: res.intlat
                  // }
                  // state.changes = !state.changes;
                  // console.log(state.isOnTaskValue)
                  // $store.commit("setMsg", {
                  //    id: id,
                  //    intlat: res.intlat
                  // })
                  let out = res.intlat;
                  if (typeof out != "string") {
                     that.addIcon([out[1], out[0]]);
                     console.log(out)
                     //坐标输出
                     let d = {
                        uid: that.data.myid,
                        rid: rid,
                        jd: out[0],
                        wd: out[1],
                     }
                     // console.log(d)
                     if (that.setPositionTime) {
                        return;
                     } else {
                        that.setPositionTime = setTimeout(() => {
                           axios.post(that.data.appenUrl + "trar/submit", d)
                              .then(res => {
                                 // console.log('res=>', res);
                              })
                           clearTimeout(that.setPositionTime);
                           that.setPositionTime = null;
                        }, that.setPositionUseTime)
                     }
                  } else {
                     console.log("获取定位失败")
                  }
               }
            })
            that.onPosition.continuedTime();
            that.data.butCT = "beginUp";
            that.data.rtype = '0';
            that.data.type = "0";
         }
         if (typeof this.data.team === "string") {
            this.data.team = this.data.team.split(',');
         }
@@ -196,6 +313,7 @@
         // return
         this.map = this.beginMap(this.map, position); //创建并接受map
         this.map.invalidateSize(true); //应用地图高度
         console.log("完成数据")
      },
      changeDom(data) {
         // console.log(data, 'changeDom');
@@ -242,7 +360,7 @@
         // desc = "+proj=longlat +datum=WGS84 +no_defs ",
         // crs = new L.CRS("EPSG:4326", desc, {});
         // center = [data[0].wd, data[0].jd],
         // url = `http://223.82.109.183:2082/api/alarm/alarm/APP-getAlarm?id=${data[0].id}`;
         // url = `http://106.225.193.35:83/api/alarm/alarm/APP-getAlarm?id=${data[0].id}`;
         // url = `http://localhost:89/alarm/alarm/APP-getAlarm?id=${data[0].id}`;
         // this.nowPosition = center;
         // axios.post(url).then((res) => {
@@ -409,8 +527,6 @@
                     console.log(res)
                     if (typeof res.intlat === "string") {
                        // that.parent.showTip("获取定位失败")
                        //向uniapp传值
                        that.setUniAppMsg("showTip")
                     } else {
                        that.addIcon([res.intlat[1], res.intlat[0]]);
@@ -675,7 +791,11 @@
      //map适应任务详情高度
      // console.log(document.getElementById("map"))
      //因为按钮使用v-if所以在识别高度时候,but还没渲染所以手动添加 56px 不会变
      let UmainHeight = document.getElementById("Umain").clientHeight + 56;
      console.log("应用数据")
      let UmainHeight = document.getElementById("Umain").clientHeight;
      if (this.data.iscation == "1") {
         UmainHeight += 56;
      }
      let h = document.getElementById("mapVue").clientHeight;
      this.checkDomHeight({
         domName: "getElementById",
@@ -716,7 +836,7 @@
      });
      this.domMove.init();
      // console.log(window.parent.setIntLat)
      that.setUniAppMsg("setIntLat")
      // that.setUniAppMsg("setIntLat")
      // window.parent.setIntLat({
      //    rid: this.data.id,
      //    fn: (out) => {
@@ -725,18 +845,25 @@
      //       that.addIcon([out[1], out[0]]);
      //    }
      // })
      window.addEventListener('message', e => {
         console.log(e, 'HTML 接受APP发送过来的消息 (H5端)');
         app.dataList = JSON.parse(e.data.data).navigation
         console.log(app.dataList, '+++++++++');
      }, false)
      // window.addEventListener('message', e => {
      //    console.log(e, 'HTML 接受APP发送过来的消息 (H5端)');
      //    app.dataList = JSON.parse(e.data.data).navigation
      //    console.log(app.dataList, '+++++++++');
      // }, false)
      // HTML 接受APP发送过来的消息 (APP端)
      function requestData(data) {
         console.log(JSON.stringify(data), 'HTML 接受APP发送过来的消息 (APP端)');
         app.dataList = data.navigation // 赋值
      }
      // // HTML 接受APP发送过来的消息 (APP端)
      // function requestData(data) {
      //    console.log(JSON.stringify(data), 'HTML 接受APP发送过来的消息 (APP端)');
      //    app.dataList = data.navigation // 赋值
      // }
   },
   wacth: {}
   wacth: {},
   beforeDestroy() {
      let that = this;
      if (that.onPosition) {
         that.onPosition.overContinued();
         console.log("关闭地图")
      }
   }
})