diff --git a/src/src/mixins/phystonPrompt/groupTagsMixin.js b/src/src/mixins/phystonPrompt/groupTagsMixin.js index cd612d1..b496c56 100644 --- a/src/src/mixins/phystonPrompt/groupTagsMixin.js +++ b/src/src/mixins/phystonPrompt/groupTagsMixin.js @@ -105,17 +105,19 @@ export default { extraNetwork.items.forEach(item => { item.dirnameFormat = item.dirname.replaceAll('\\', '/') }) - let dirs = [] - let splitArrays = extraNetwork.items.map(item => item.dirnameFormat.split('/')) - let minLength = Math.min(...splitArrays.map(item => item.length)) + let prefixPath = common.getSamePrefixPath([...new Set(extraNetwork.items.map(item => item.dirnameFormat))]) + let baseDirs = [] extraNetwork.items.forEach(item => { - item.base_dirname = item.dirnameFormat.split('/').slice(minLength).join('/') - dirs.push(item.base_dirname) + let baseDirname = item.dirnameFormat.replace(prefixPath, '') + if (baseDirname === '') baseDirname = '@root' + baseDirname = baseDirname.replace(/^\//, '') + baseDirs.push(baseDirname) + item.base_dirname = baseDirname }) - dirs = [...new Set(dirs)] - dirs = dirs.filter(item => item !== '') - if (dirs.length > 1) { - dirs.forEach(dir => { + baseDirs = [...new Set(baseDirs)] + + if (baseDirs.length > 1) { + baseDirs.forEach(dir => { let subDirGroup = { color: '', name: dir, diff --git a/src/src/utils/common.js b/src/src/utils/common.js index 3b7fed2..f746b01 100644 --- a/src/src/utils/common.js +++ b/src/src/utils/common.js @@ -632,4 +632,17 @@ export default { getTagsColorKey(groupName, subGroupName) { return groupName + '||' + subGroupName }, + + getSamePrefixPath(arr) { + if (arr.length <= 0) return '' + const arr1 = arr.map(item => item.split("/")); + const arr2 = arr1[0]; + const arr3 = arr1.slice(1); + const result = arr2.filter((item, index) => { + return arr3.every(item2 => { + return item2[index] === item; + }); + }); + return result.join("/"); + } } \ No newline at end of file