智慧保安互联网APP
zengh
2022-06-21 4efeb31d5b4921d7e851c256009486ad86bc70e2
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
import md5 from 'js-md5'
import axios from 'axios'
const actions = {
    loging(store, data) {
        var user = [{
                    name: '1',
                    password: '111111'
                },
                {
                    name: '2',
                    password: '222222'
                },
                {
                    name: '3',
                    password: '333333'
                },
            ],
            pasw = md5(data.pass),
            // url = this.$store.state.piAPI + '/blade-auth/oauth/token?tenantId=000000&username=' + data.name +
            url = store.state.piAPI + '/blade-auth/oauth/token?tenantId=000000&username=' + data.name +
            ' &password=' + pasw + '&grant_type=password&scope=all&type=account';
        // url ='http://192.168.0.109:82/blade-auth/oauth/token';
        // url ='http://192.168.0.109:82/blade-auth/oauth/token?tenantId=000000&username=admin&password=93369e86dc5fa854a0eaf75558c4039d&grant_type=password';
        // url ='http://web.byisf.com/api/blade-auth/oauth/token?tenantId=000000&username=admin&password=93369e86dc5fa854a0eaf75558c4039d&grant_type=password&scope=all';
        console.log(store.state.piAPI);
        wx.request({ //uniapp 自带axios
            url: url, //仅为示例,并非真实接口地址。
            // data: d,
            // data: {
            //     tenantId: '000000',
            //     username: data.name,
            //     password: pasw,
            //     grant_type: 'password',
            //     scope: 'all',
            //     type: "account"
            // },
            header: {
                // "Content-Type":"",
                "Authorization": "Basic c2FiZXI6c2FiZXJfc2VjcmV0",
                "Tenant-Id": "963841"
 
                // "Cookie": "JSESSIONID=maOJY05vT2jj4nHwsQGSPgWWVFH1mY-TGWOLYCSh"
            },
            method: "post",
            //     // dataType: 'JSON',
            success: (res) => {
 
                if (res.statusCode == 200) {
                    if (res.data.error_code == "400") {
                        uni.showToast({
                            title: '密码错误,请重试',
                            icon: 'none',
                            duration: 2000
                        });
                        return;
                    }
                    store.commit('getUserData', res.data)
                    // console.log(res.data,123542);
                    data.isit = true;
                    data.userName = res.data.nick_name; //警袁姓名
                    data.userID = res.data.user_id; //警袁id
                    data.avatar = res.data.avatar; //头像
                    data.accounts = data.name;
                    data.pass = data.pass;
                    // data.userPhon = res.user_id;
 
 
 
 
                    // 实时定位获取得方法
 
                    uni.getLocation({
                        type: 'gcj02',
                        geocode: true,
                        success: function(wzres) {
                            uni.request({
                                url: "http://61.131.136.25:2080/api/liveLocation/saveLiveLocationAndLocus",
                                method: "post",
                                data: {
                                    type: 1,
                                    workerId: res.data.user_id,
                                    longitude: wzres.longitude,
                                    latitude: wzres.latitude,
                                    location: wzres.address.country +
                                        wzres.address.province + wzres
                                        .address.city + wzres.address
                                        .district + wzres.address
                                        .street + wzres.address
                                        .streetNum
                                }
                            })
                        }
                    });
 
                    setInterval(function() {
 
                        uni.getLocation({
                            type: 'gcj02',
                            geocode: true,
                            success: function(wzres) {
                                uni.request({
                                    url: "http://61.131.136.25:2080/api/liveLocation/saveLiveLocationAndLocus",
                                    method: "post",
                                    data: {
                                        type: 1,
                                        workerId: res.data.user_id,
                                        longitude: wzres.longitude,
                                        latitude: wzres.latitude,
                                        location: wzres.address.country +
                                            wzres.address.province + wzres
                                            .address.city + wzres.address
                                            .district + wzres.address
                                            .street + wzres.address
                                            .streetNum
                                    }
                                })
                            }
                        });
 
                    }, 30000)
 
                    uni.request({
                        url: store.state.piAPI + "/blade-system/dept/detail?id=" + res
                            .data.dept_id,
                        method: "get",
                        data: {
 
                        },
                        success: (result) => {
                            data.deptName = result.data.data.deptName
                            res.data.deptName = result.data.data.deptName
                            store.commit('login', data);
                            uni.$u.func.login(res.data)
                        }
                    });
 
 
                }
            },
            fail: (res) => {
                console.log('失去连接 请稍等');
                // console.log(res);
            }
        });
        // var time = setTimeout(() => { //模拟请求时间
        //     var ud = user,
        //         isit = false;
        //     for (var key in ud) {
        //         if (ud[key].name == data.name && ud[key].password == data.pass) {
        //             isit = true;
        //             break;
        //         } else {
        //             isit = false;
        //         }
        //     }
        //     data.isit = isit;
        //     store.commit('login', data);
        // }, 2000)
 
    }
}
 
export default actions