Improve getTags()

This commit is contained in:
Yang Luo 2023-04-09 14:47:08 +08:00
parent b7d78d1e27
commit 30ea3a1335
3 changed files with 20 additions and 10 deletions

View File

@ -139,7 +139,7 @@ class PermissionListPage extends BaseListPage {
sorter: true, sorter: true,
...this.getColumnSearchProps("users"), ...this.getColumnSearchProps("users"),
render: (text, record, index) => { render: (text, record, index) => {
return Setting.getTags(text); return Setting.getTags(text, "users");
}, },
}, },
{ {
@ -150,7 +150,7 @@ class PermissionListPage extends BaseListPage {
sorter: true, sorter: true,
...this.getColumnSearchProps("roles"), ...this.getColumnSearchProps("roles"),
render: (text, record, index) => { render: (text, record, index) => {
return Setting.getTags(text); return Setting.getTags(text, "roles");
}, },
}, },
{ {

View File

@ -130,7 +130,7 @@ class RoleListPage extends BaseListPage {
sorter: true, sorter: true,
...this.getColumnSearchProps("users"), ...this.getColumnSearchProps("users"),
render: (text, record, index) => { render: (text, record, index) => {
return Setting.getTags(text); return Setting.getTags(text, "users");
}, },
}, },
{ {
@ -141,7 +141,7 @@ class RoleListPage extends BaseListPage {
sorter: true, sorter: true,
...this.getColumnSearchProps("roles"), ...this.getColumnSearchProps("roles"),
render: (text, record, index) => { render: (text, record, index) => {
return Setting.getTags(text); return Setting.getTags(text, "roles");
}, },
}, },
{ {

View File

@ -1070,18 +1070,28 @@ export function getTagColor(s) {
return "processing"; return "processing";
} }
export function getTags(tags) { export function getTags(tags, urlPrefix = null) {
const res = []; const res = [];
if (!tags) { if (!tags) {
return res; return res;
} }
tags.forEach((tag, i) => { tags.forEach((tag, i) => {
res.push( if (urlPrefix === null) {
<Tag color={getTagColor(tag)}> res.push(
{tag} <Tag color={getTagColor(tag)}>
</Tag> {tag}
); </Tag>
);
} else {
res.push(
<Link to={`/${urlPrefix}/${tag}`}>
<Tag color={getTagColor(tag)}>
{tag}
</Tag>
</Link>
);
}
}); });
return res; return res;
} }