diff --git a/src/utils/index.js b/src/utils/index.js index bdbe792..5fa1ed9 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -264,12 +264,11 @@ export function addingPrefixToFile(list, options = {}) { return []; const { pathKey = "filePath", nameKey = "fileName", idKey = "id" } = options; const FILE_URL = getFileUrl(); - for (let i = 0; i < list.length; i++) { - list[i].url = FILE_URL + list[i][pathKey]; - list[i].name = list[i][nameKey] || getFileName(list[i][pathKey]); - list[i].id = list[i][idKey]; - } - return list; + return list.filter(item => item[pathKey]).map(item => ({ + url: FILE_URL + item[pathKey], + name: item[nameKey] || getFileName(item[pathKey]), + id: item[idKey], + })); } /** @@ -277,10 +276,8 @@ export function addingPrefixToFile(list, options = {}) { */ export function getLabelName(options) { const { status, list, idKey = "bianma", nameKey = "name" } = options; - for (let i = 0; i < list.length; i++) { - if (status?.toString() === list[i][idKey]?.toString()) - return list[i][nameKey]; - } + const item = list.find(item => item[idKey]?.toString() === status?.toString()) || { [nameKey]: "" }; + return item[nameKey]; } /**