This repository has been archived by the owner on Oct 31, 2019. It is now read-only.
/
ProjectTypeStore.js
131 lines (119 loc) · 3.18 KB
/
ProjectTypeStore.js
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
import { action, computed, observable } from 'mobx';
import { axios, store } from 'choerodon-boot-combine';
import queryString from 'query-string';
import { handleFiltersParams } from '../../../common/util';
@store('ProjectTypeStore')
class ProjectTypeStore {
@observable projectTypeData = [];
@observable loading = false;
@observable pagination = {
current: 1,
pageSize: 10,
total: 0,
};
@observable filters = {};
@observable sort = {};
@observable params = [];
@observable editData = {};
@observable sidebarVisible = false;
@observable sidebarType = 'create';
@action
setSidebarType(type) {
this.sidebarType = type;
}
refresh() {
this.loadData({ current: 1, pageSize: 10 }, {}, {}, []);
}
@action
setEditData(data) {
this.editData = data;
}
@action
showSideBar() {
this.sidebarVisible = true;
}
@action
hideSideBar() {
this.sidebarVisible = false;
}
@action
updateData(values) {
this.loading = true;
return axios.post(`/iam/v1/projects/types/${this.editData.id}`, JSON.stringify({
...values,
id: this.editData.id,
objectVersionNumber: this.editData.objectVersionNumber,
}))
.then(action((data) => {
this.loading = false;
this.sidebarVisible = false;
return data;
}))
.catch(action((error) => {
Choerodon.handleResponseError(error);
this.loading = false;
}));
}
@action
createType(values) {
this.loading = true;
return axios.post('/iam/v1/projects/types', values).then(action((data) => {
this.loading = false;
this.sidebarVisible = false;
return data;
})).catch(action((error) => {
Choerodon.handleResponseError(error);
this.loading = false;
}));
}
@action
loadData(pagination = this.pagination, filters = this.filters, sort = this.sort, params = this.params) {
const { columnKey, order } = sort;
const sorter = [];
if (columnKey) {
sorter.push(columnKey);
if (order === 'descend') {
sorter.push('desc');
}
}
this.loading = true;
this.filters = filters;
this.sort = sort;
this.params = params;
// 若params或filters含特殊字符表格数据置空
const isIncludeSpecialCode = handleFiltersParams(params, filters);
if (isIncludeSpecialCode) {
this.projectTypeData.length = 0;
this.pagination = {
current: 1,
pageSize: 10,
total: 0,
};
this.loading = false;
return;
}
return axios.get(`/iam/v1/projects/types/paging_query?${queryString.stringify({
name: filters.name,
code: filters.code,
description: filters.description,
params: params.join(','),
sort: sorter.join(','),
})}`)
.then(action(({ failed, list, total }) => {
if (!failed) {
this.projectTypeData = list;
this.pagination = {
...pagination,
total,
};
}
this.loading = false;
}))
.catch(action((error) => {
Choerodon.handleResponseError(error);
this.loading = false;
}));
}
}
const projectTypeStore = new ProjectTypeStore();
export default projectTypeStore;