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
// import $store from '../index.js'
// import vueconfig from '../../vue.config.js'
import $getPositions from './lid/getPosition.js'
import WxStorage from "../static/lib/wxStorage.js" //微信Storage
import $store from './index.js'
 
let positions = {
    state: {
        isBeginTask: {},
        isOnTask: {},
        isOnTaskValue: {},
        changes: true,
        i: 0
    },
    actions: {
        // connectws({
        //     state,
        //     commit
        // }) {
        //     console.log("开启websocket")
        // },
    },
    mutations: {
        addTask(state, value) {
            let id = value;
            state.isOnTask[id] = {
                id: id,
                position: new $getPositions({
                    id: id,
                    fn: function(res) {
                        // console.log(res);
                        state.isOnTaskValue = {
                            id: id,
                            intlat: res.intlat,
                            i: state.i++
                        }
                        state.changes = !state.changes;
                        // console.log(state.isOnTaskValue)
                        $store.commit("setMsg", {
                            id: id,
                            intlat: res.intlat,
                        })
                    }
                })
            }
            setTimeout(() => {
                $store.commit("startTask", id)
            }, 1000)
        },
        startTask(state, value) {
            if (!state.isOnTask[value]) {
                console.log("未创建该任务:", value)
                return
            }
            if (!state.isOnTask[value].position.isContinued) {
                state.isOnTask[value].position.continuedTime();
            }
        },
        stopTask(state, value) {
            if (!state.isOnTask[value]) {
                console.log("未创建该任务:", value)
                return
            }
            if (state.isOnTask[value].position.isContinued) {
                state.isOnTask[value].position.overContinued();
            }
        },
        setMsg(state, value) {
            //发送任务位置
            //uid ;自己id,rid: 任务id,jd,wd经度纬度
            console.log(value, 123)
            let d = {
                uid: WxStorage.get("ids") || $store.state.puserID,
                rid: value.id,
                jd: value.intlatold[0],
                wd: value.intlatold[1],
            }
            uni.request({
                url: $store.state.piAPI + "trar/submit",
                method: "POST",
                data: d,
                success(res) {
                    // console.log(res.data.msg);
                },
            });
        },
        useWebScoketApi(state, val) {
            let rid = val.rid,
                serid = val.serid,
                type = val.type,
                that = val.that,
                goto1 = val.goto,
                // data = val.data,
                tips = (type, title) => {
                    if (that.$refs.uTips) {
                        that.$refs.uTips.show({
                            title: title,
                            type: type,
                            duration: '2300'
                        })
                    }
                    // that.getGrabOrders(that.current); //重获取数据
                }
            if (type == "start") {
                type = goto1 + ',' + type
            }
            uni.request({
                url: $store.state.piAPI + "taskqd/startTask?" +
                    `rid=${rid}&serid=${serid}&type=${type}`,
                method: "GET",
                success(res) {
                    let type = res.data.data.type;
                    if (val.fn) {
                        val.fn();
                    }
                    if (type == 'start') { //开启成功
                        tips('success', '开启任务成功')
                        return;
                    }
                    if (type == 'stop') { //开启成功
                        tips('success', '反馈任务成功')
                        return;
                    }
                },
            });
        },
    }
}
 
export default positions