page.js
2.37 KB
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
/* eslint-disable no-param-reassign */
export const state = () => ({
pageData: [],
pageParams: {
scheduleId: null,
latitude: null,
longitude: null,
minVerticalSpeed: null,
maxVerticalSpeed: null,
minHorizontalSpeed: null,
maxHorizontalSpeed: null,
minAboveSeaLevel: null,
maxAboveSeaLevel: null,
minAboveGroundLevel: null,
maxAboveGroundLevel: null,
pageNo: 1,
pageSize: 10,
total: 0,
},
});
export const getters = {
getPageData: (state) => state.pageData,
getPageParams: (state) => state.pageParams,
getPagination: (state) => {
const {total, pageSize} = state.pageParams;
const page = state.pageParams.pageNo;
return {total, pageSize, page};
},
};
export const actions = {
fetchPageData(context, params) {
return new Promise((resolve, reject) => {
context.commit('DEL_PAGE_DATA');
this.$axios
.get('/api/log/page', {
params,
})
.then((r) => {
const result = r.data;
result.droneLogs.forEach((elem, idx) => {
elem.no =
result.totalElement - (result.pageNo * result.pageSize + idx);
});
context.commit('SET_PAGE_DATA', result);
resolve(result);
})
.catch((e) => {
reject(e);
});
});
},
setPageParams(context, data) {
context.commit('SET_PAGE_PARAMS', data);
},
clearPageParams(context) {
context.commit('DEL_PAGE_PARAMS');
},
setPagination(context, params) {
context.commit('SET_PAGINATION', params);
},
};
export const mutations = {
SET_PAGE_DATA(state, payload) {
state.pageData = payload.droneLogs;
state.pageParams.total = Number(payload.totalElement);
state.pageParams.pageNo = Number(payload.pageNo);
state.pageParams.pageSize = Number(payload.pageSize);
},
DEL_PAGE_DATA(state) {
state.pageData = [];
},
SET_PAGE_PARAMS(state, params) {
state.pageParams = JSON.parse(JSON.stringify(params));
},
SET_PAGINATION: (state, data) => {
state.pageParams.pageNo = data.page;
state.pageParams.pageSize = data.size;
},
DEL_PAGE_PARAMS(state) {
state.pageParams = {
scheduleId: null,
minSpeed: null,
maxSpeed: null,
minAltitude: null,
maxAltitude: null,
latitude: null,
longitude: null,
pageNo: 1,
pageSize: 10,
total: 0,
};
},
};