jxdnsong
2022-10-25 bf5ba56e8a82f0ef699f2eae413d0dc2c4e4f67d
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
/*
 * @Author: shuishen 1109946754@qq.com
 * @Date: 2022-09-09 17:54:08
 * @LastEditors: shuishen 1109946754@qq.com
 * @LastEditTime: 2022-09-14 16:05:41
 * @FilePath: \smart-campus\src\store\modules\mobilePosition.js
 * @Description:
 *
 * Copyright (c) 2022 by shuishen 1109946754@qq.com, All Rights Reserved.
 */
 
const mobilePosition = {
    state: {
        getSPosition: null
    },
    mutations: {
        GET_NOWPOSITION (state, val) {
            var outData =
                val ||
                function (res) {
                    console.log(res)
                }
 
            console.log(state, 222)
 
            global.Geolocation.getLocation(function success (result) {
                const position = global.DC.CoordTransform.GCJ02ToWGS84(result.lng, result.lat)
 
                if (position[0] > 115.78815057 && position[0] < 115.80346610 && position[1] > 28.63771847 && position[1] < 28.64981682) {
                    outData([position[0], position[1]])
                } else {
                    Message({
                        message: '您当前位置超出学校范围',
                        type: 'warning',
                        duration: 2000
                    })
 
                    outData(['失败'])
                }
            }, function error (result) {
                if (result.code == 1) {
                    confirm('您拒绝了定位功能')
                } else if (result.code == 3 || result.code == 5) {
                    confirm('请求超时')
                }
            }, {
                timeout: 8000, // 默认值为10s;
                failTipFlag: true
            })
        },
        CLOSE_NOWPOSITION (state) {
            // if (state.getSPosition && navigator.geolocation) {
            //   navigator.geolocation.clearWatch(state.getSPosition);
            //   state.getSPosition = null;
            // }
        }
    },
    actions: {}
}
 
export default mobilePosition