refactor: renderHttpMethodTag

This commit is contained in:
dap 2024-10-22 09:36:39 +08:00
parent 0d63b6d9ca
commit 330dcf480e

View File

@ -69,29 +69,23 @@ export function renderIcon(icon: string) {
return <IconifyIcon icon={icon}></IconifyIcon>;
}
// httpMethod
/**
* httpMethod标签
* @param type method类型
* @returns render
*/
export function renderHttpMethodTag(type: string) {
const method = type.toUpperCase();
let color = 'default';
const colors: { [key: string]: string } = {
DELETE: 'red',
GET: 'green',
POST: 'blue',
PUT: 'orange',
};
const color = colors[method] ?? 'default';
const title = `${method}请求`;
switch (method) {
case 'DELETE': {
color = 'red';
break;
}
case 'GET': {
color = 'green';
break;
}
case 'POST': {
color = 'blue';
break;
}
case 'PUT': {
color = 'orange';
break;
}
}
return <Tag color={color}>{title}</Tag>;
}