fix: icon 合并错误

This commit is contained in:
wanghao1993 2023-09-20 00:00:48 +08:00
parent 977799a3ac
commit ba44f69f9f
4 changed files with 64 additions and 5 deletions

View File

@ -13,6 +13,7 @@
}
],
"types": "./types/index.d.ts",
"typings": "./types/index.d.ts",
"license": "MIT",
"repository": {
"type": "git",

View File

@ -1,3 +1,5 @@
import { mergerIconListBy } from '../utils'
// 超链接图标
const hyperlink =
'<svg t="1624174958075" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7982" ><path d="M435.484444 251.733333v68.892445L295.822222 320.682667a168.504889 168.504889 0 0 0-2.844444 336.952889h142.506666v68.892444H295.822222a237.397333 237.397333 0 0 1 0-474.794667h139.662222z m248.945778 0a237.397333 237.397333 0 0 1 0 474.851556H544.654222v-69.006222l139.776 0.056889a168.504889 168.504889 0 0 0 2.844445-336.952889H544.597333V251.676444h139.776z m-25.827555 203.946667a34.474667 34.474667 0 0 1 0 68.892444H321.649778a34.474667 34.474667 0 0 1 0-68.892444h336.952889z" p-id="7983"></path></svg>'
@ -281,12 +283,23 @@ export const nodeIconList = [
// 获取nodeIconList icon内容
const getNodeIconListIcon = (name, extendIconList = []) => {
let arr = name.split('_')
let typeData = [...nodeIconList, ...extendIconList].find(item => {
const iconList = mergerIconListBy(
[...nodeIconList, ...extendIconList],
'type',
'name'
)
let typeData = iconList.find(item => {
return item.type === arr[0]
})
return typeData.list.find(item => {
return item.name === arr[1]
}).icon
if (typeData) {
return typeData.list.find(item => {
return item.name === arr[1]
}).icon
} else {
return ''
}
}
export default {

View File

@ -669,3 +669,39 @@ export const checkIsNodeStyleDataKey = key => {
}
return false
}
// 合并数组对象by某个key
// const data = [
// { type: 'a', list: [{ name: 1, value: 1 }, { name: 2, value: 2 }] },
// { type: 'b', list: [{ name: 13, value: 3 }] },
// { type: 'a', list: [{ name: 1, value: 3 }, { name: 4, value: 4 }] },
// ];
// mergeObjArrayBy(data, 'type', 'name') 结果
// [
// { type: 'a', list: [ { name: 1, value: 3 }, { name: 2, value: 2 }, { name: 4, value: 4 } ] },
// { type: 'b', list: [ { name: 13, value: 3 } ] }
// ]
export const mergerIconListBy = (arrList, key, name) => {
return arrList.reduce((result, item) => {
const existingItem = result.find(x => x[key] === item[key])
if (existingItem) {
item.list.forEach(newObj => {
const existingObj = existingItem.list.find(
x => x[name] === newObj[name]
)
if (existingObj) {
existingObj.icon = newObj.icon
} else {
existingItem.list.push(newObj)
}
})
} else {
result.push({ ...item })
}
return result
}, [])
}

View File

@ -292,7 +292,16 @@ export default {
}
},
...(config || {}),
iconList: icon,
iconList: [...icon, {
name: '优先级图标',
type: 'priority',
list: [
{
name: '0',
icon: `<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 256 256"><path fill="currentColor" d="M156 128c0 14.86-5.9 40-28 40s-28-25.14-28-40s5.9-40 28-40s28 25.14 28 40Zm76 0A104 104 0 1 1 128 24a104.11 104.11 0 0 1 104 104Zm-60 0c0-14.25-3.56-27.53-10-37.39C154 78.44 142.23 72 128 72s-26 6.44-34 18.61c-6.47 9.86-10 23.14-10 37.39s3.56 27.53 10 37.39c8 12.18 19.74 18.61 34 18.61s26-6.43 34-18.61c6.44-9.86 10-23.14 10-37.39Z"/></svg>`
},
]
}],
useLeftKeySelectionRightKeyDrag: this.useLeftKeySelectionRightKeyDrag,
customInnerElsAppendTo: null,
enableAutoEnterTextEditWhenKeydown: true,