zengh
2022-05-09 52c39f5e2711e5535b689b66dfa5e100c7882b7f
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
// const { axios } = require("_vue@2.6.12@vue/types/umd");
 
// import myDomMove from './move'
var me = new Vue({
    el: '#mapVue',
    data: {
        map: null, //map
        getdata: null,
        marker: null,
        layuiLayer: null,
        nowIndex: 1,
 
        //基础路径
        // pathUrl: "http://localhost:89",
        pathUrl: this.$store.state.piAPI + "",
 
        layer: null,
 
        snumber: null,
        name: null,
        workDesc: null,
 
        //存放实时坐标
        lat: "",
        lng: "",
        addr: "",
        address: "",
 
 
    },
    created() {},
    mounted() {
        //时钟
        setInterval(() => {
            this.getnow()
        }, 1000);
 
        //获取当前定位
        this.getLocationData();
 
        //初始化数据,地图
        this.getDataList();
 
        //获取个人信息
        this.getOneselfInFo();
 
    },
    methods: {
 
        //初始化数据,地图
        getDataList(tab) {
            var that = this;
            that.beginCome(tab);
        },
 
        //获取个人信息
        getOneselfInFo() {
            var that = this;
            //保安信息查询
            axios({
                method: "POST",
                url: `http://61.131.136.25:2082/api/blade-user/details`,
                params: {
                    id: that.snumber,
                },
            }).then((resdata) => {
                that.name = resdata.data.data.realName;
            });
        },
 
 
        //去打卡
        goClock() {
            var that = this;
            axios({
                method: "POST",
                url: this.pathUrl + `/attendance/AppSave`,
                params: {
                    number: this.snumber,
                    name: this.name,
                    clockTime: this.getNowTime(1),
                    jd: "129.241252",
                    wd: "25.254212",
                    workDesc: this.workDesc,
                    address: this.address
                },
            }).then((resdata) => {
                //不在考勤范围内
                if (resdata.data.code == 400) {
                    layui.use('layer', function() {
                        var layer = layui.layer;
                        layer.msg('打卡失败,不在考勤范围', {
                            icon: 0
                        });
                    });
                }
                //打卡成功
                if (resdata.data.code == 200) {
                    layui.use('layer', function() {
                        var layer = layui.layer;
                        layer.msg('打卡成功!', {
                            icon: 1
                        });
                    });
                }
 
            });
        },
 
        //获取当前位置信息
        getLocationData() {
            var that = this;
            var geolocation = new qq.maps.Geolocation("T7RBZ-62U3X-RSQ4P-ZZVCB-WE7JT-HRBOG", "mapqq");
            var options = {
                timeout: 8000
            };
 
            function showPosition(position) {
                that.lat = position.lat; //
                that.lng = position.lng; //火星坐标 //TODO 实现业务代码逻辑 
                //通过经纬度换算详细地址
                axios({
                    method: "GET",
                    url: `https://fmap.sf-express.com/rgeo/api`,
                    params: {
                        x: position.lng,
                        y: position.lat,
                        ak: '1986afc8a5744263971b7f2482253dfc'
                    },
                }).then((res) => {
                    var address = res.data.result.name.toString();
                    if (address.search("县") != -1) {
                        that.addr = address.substring(address.indexOf("县") + 1, address.length);
                    }
                    if (address.search("区") != -1) {
                        that.addr = address.substring(address.indexOf("区") + 1, address.length);
                    }
                    that.address = address;
                });
 
                if (that.LXdhStart == null) {
                    //点位
                    var position = [that.lat, that.lng];
 
                    //把map定位到点位上,13为地图的级别,也可以直接marker.getLatLng()
                    that.map.setView(position, 15);
                } else {
                    that.map.removeLayer(that.LXdhStart);
                }
 
                //绘制起点和终点
                that.LXdhStart = L.markerClusterGroup();
 
                var transportIcon = L.Icon.extend({ //图标初始化
                    options: {
                        iconSize: [50, 50], // 图标尺寸
                    }
                });
 
                var qd = new transportIcon({
                    iconUrl: './img/dingw.gif'
                });
 
                that.LXdhStart.addLayer(L.marker([that.lat, that.lng], {
                    icon: qd,
                }));
 
                that.map.addLayer(that.LXdhStart);
 
            };
 
            function showErr() {
                //TODO 如果出错了调用此方法 
            };
 
            geolocation.getLocation(showPosition, showErr, options);
        },
 
        //时钟
        getnow() {
            //获得标签对象
            var nowspan = document.getElementById("nowspan");
            nowspan.innerHTML = this.getNowTime(2);
        },
 
 
        //获取当前时间
        getNowTime(type) {
            //1、获得当前时间,格式化时间
            var now = new Date();
            var year = now.getFullYear();
            var month = now.getMonth() + 1;
            if (month < 10) {
                month = "0" + month;
            }
            var date = now.getDate();
            if (date < 10) {
                date = "0" + date;
            }
            var hour = now.getHours();
            if (hour < 10) {
                hour = "0" + hour;
            }
            var minute = now.getMinutes();
            if (minute < 10) {
                minute = "0" + minute;
            }
            var second = now.getSeconds();
            if (second < 10) {
                second = "0" + second;
            }
            var nowstr = null;
            if (type == 1) {
                nowstr = year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
            }
            if (type == 2) {
                nowstr = year + "年" + month + "月" + date + "日  " + hour + ":" + minute + ":" + second;
            }
            return nowstr;
        },
 
        beginCome() {
            //url解码
            this.snumber = this.getQueryVariable('snumber');
            //创建并接受map
            this.map = this.beginMap(this.map);
            //应用地图高度
            this.map.invalidateSize(true);
        },
 
        //获取参数
        getQueryVariable(variable) {
            var query = window.location.search.substring(1);
            var vars = query.split("&");
            for (var i = 0; i < vars.length; i++) {
                var pair = vars[i].split("=");
                //解码url 和 JSON
                if (pair[0] == variable) {
                    return JSON.parse(decodeURI(pair[1]));
                }
            }
            return (false);
        },
 
        //开始
        beginMap(map) {
            var createMap = () => {
                //初始化地图
                map = L.map('map', {
                    zoom: 12,
                    minZoom: 2,
                    maxZoom: 17,
                    attributionControl: false, //去掉右下角
                    zoomControl: false, //去掉缩放
                });
                //添加切片图层
                L.tileLayer(
                    //顺丰地图
                    // "https://webmap-tile.sf-express.com/MapTileService/rt?x={x}&y={y}&z={z}", {
                    "https://webmap-tile.sf-express.com/MapTileService/rt?fetchtype=static&x={x}&y={y}&z={z}&project=sfmap&pic_size=256&pic_type=png8&data_name=361100&data_format=merged-dat&data_type=normal", {}
                ).addTo(map);
            }
            createMap();
            return map;
        },
    }
})