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
import { message } from 'antd';
// import { useIntl } from 'umi';
// const { formatMessage } = useIntl();
export const dispatchHandle = (dispatch, type, payload = {}, callback, errCallback) => {
dispatch({
type,
payload,
callback: (data, res) => {
if (callback) {
if (typeof callback === 'function') callback(data, res);
if (callback === 'success') message.success('操作成功!');
}
},
errCallback: () => {
if (errCallback) {
if (typeof errCallback === 'function') errCallback();
}
},
});
};
// dispatchHandle
export const FormReset = (that, callback) => {
const { form } = that.props;
form.resetFields();
if (callback && typeof callback === 'function') {
callback();
}
};
export const HandleSearch = (that, opts = {}) => {
const { form } = that.props;
const { formValues } = that.state;
const { handle, callback } = opts;
form.validateFields((err, fieldsValue) => {
if (err) return;
const myValues = {};
if (handle && typeof handle === 'function') {
handle(fieldsValue);
}
for (let x in fieldsValue) {
if (fieldsValue[x] === null) delete fieldsValue[x]
}
const values = {
// ...formValues,
...fieldsValue,
};
that.setState({
formValues: { ...myValues, ...values },
});
that.getListItems(values);
});
};
export const HandleTableChange = (that, pagination) => {
const { formValues } = that.state;
const params = {
...formValues,
pageNumber: pagination.current,
pageSize: pagination.pageSize,
};
that.setState({
formValues: params,
});
that.getListItems(params);
};
// 编辑页面方法
export const SetIsEditState = (that, param = {}) => {
const { isEdit, type, payload } = param;
that.setState({
isEdit: isEdit || false,
});
type && dispatchHandle(that, type, payload);
}
export const HandleSubmit = (that, type, opts = {}) => {
const { form } = that.props;
const { handle, callback } = opts;
form.validateFields((err, fieldsValue) => {
if (err) return;
if (handle && typeof handle === 'function') {
handle(fieldsValue);
}
dispatchHandle(that, type, fieldsValue, () => {
// message.success(formatMessage({ id: 'app.msg.message.success' }));
if (callback && typeof callback === 'function') {
callback();
}
});
});
};
/* 表格数据格式处理 new add by peter */
export const HandleResultList = (result = []) => {
let dataSource = [];
if (Array.isArray(result) && result.length > 0) {
//数组列表
dataSource = [...result];
dataSource.map((item, index) => {
item.key = item.id;
})
} else if (Array.isArray(result) && result.length == 0) {
//空数组
dataSource = [];
} else if (result && (Object.keys(result).length > 0)) {
//单一object,通过keyword查询出来的
dataSource.push(result);
dataSource.map((item, index) => {
item.key = item.id;
})
}
return dataSource;
// console.log(dataSource);
}