错误原因
由于每次都在末尾加了逗号,导致最后形成的字符串末尾有逗号。
改进方法
getString(item) {
let parts = [];
const { authScope: { person = [], roles = [], orgScopesWithSub = [], orgScopesWithoutSub = [] } } = item
if (person.length > 0) {
parts.push('指定人员:' + person.map(item => item.name).join('、'));
}
if (orgScopesWithoutSub.length > 0) {
parts.push('指定部门(不含下级部门):' + orgScopesWithoutSub.map(item => item.name).join('、'));
}
if (orgScopesWithSub.length > 0) {
parts.push('指定部门(含下级部门):' + orgScopesWithSub.map(item => item.name).join('、'));
}
if (roles.length > 0) {
parts.push('指定角色:' + roles.map(item => item.name).join('、'));
}
return parts.length === 0 ? '--' : parts.join(',');
},