forked from yunsii/ant-design-pro-plus
/
model.tsx
69 lines (62 loc) · 1.65 KB
/
model.tsx
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
import React from 'react';
import { Badge } from 'antd';
import _find from 'lodash/find';
import _isArray from 'lodash/isArray';
import isNumber from 'lodash/isNumber';
import isString from 'lodash/isString';
import _partial from 'lodash/partial';
export function getData(response) {
const { data } = response;
return data || {};
}
export function getList(response) {
// 本地化更新数据,直接传入数组
if (_isArray(response)) {
return { list: response };
}
// 请求接口响应数据处理
const { data } = response;
return data.data
? {
list: _isArray(data.data) ? data.data : [],
pagination: {
current: data.current_page,
pageSize: data.per_page,
total: data.total,
},
}
: { list: _isArray(data) ? data : [] };
}
function isValidCode(code) {
return isNumber(code) || isString(code);
}
export function renderBadge(node) {
const color = node.status ? { status: node.status } : { color: node.color };
return <Badge {...color} text={node.text} />;
}
export function renderStatus(status, code) {
if (isValidCode(code)) {
const target = _find(status, { value: code });
if (!target) {
return `未编码:${code}`;
}
return renderBadge(target);
}
return '无状态';
}
export function renderCode(list, code) {
if (isValidCode(code)) {
const type = _find(list, { value: code });
if (type && type.color) {
return renderBadge(type);
}
if (type) {
return type.text;
}
return `未编码:${code}`;
}
return `无类型`;
}
export function isResponseOk(response) {
return response && response.status_code === 200;
}