优化图标合并相关逻辑

This commit is contained in:
wanglin2 2023-09-22 17:13:09 +08:00
parent 01d7e36990
commit f866abb34c
5 changed files with 21 additions and 37 deletions

View File

@ -1,4 +1,4 @@
import { mergerIconListBy } from '../utils'
import { mergerIconList } from '../utils'
// 超链接图标
const hyperlink =
@ -283,20 +283,18 @@ export const nodeIconList = [
// 获取nodeIconList icon内容
const getNodeIconListIcon = (name, extendIconList = []) => {
let arr = name.split('_')
const iconList = mergerIconListBy(
[...nodeIconList, ...extendIconList],
'type',
'name'
)
const iconList = mergerIconList([...nodeIconList, ...extendIconList])
let typeData = iconList.find(item => {
return item.type === arr[0]
})
if (typeData) {
return typeData.list.find(item => {
let typeName = typeData.list.find(item => {
return item.name === arr[1]
}).icon
})
if (typeName) {
return typeName.icon
}
return ''
} else {
return ''
}

View File

@ -669,29 +669,23 @@ 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 }] },
// { type: 'priority', name: '优先级图标', list: [{ name: '1', icon: 'a' }, { name: 2, icon: 'b' }] },
// { type: 'priority', name: '优先级图标', list: [{ name: '2', icon: 'c' }, { name: 3, icon: 'd' }] },
// ];
// mergeObjArrayBy(data, 'type', 'name') 结果
// mergerIconList(data) 结果
// [
// { type: 'a', list: [ { name: 1, value: 3 }, { name: 2, value: 2 }, { name: 4, value: 4 } ] },
// { type: 'b', list: [ { name: 13, value: 3 } ] }
// { type: 'priority', name: '优先级图标', list: [{ name: '1', icon: 'a' }, { name: 2, icon: 'c' }, { name: 3, icon: 'd' }] },
// ]
export const mergerIconListBy = (arrList, key, name) => {
return arrList.reduce((result, item) => {
const existingItem = result.find(x => x[key] === item[key])
export const mergerIconList = list => {
return list.reduce((result, item) => {
const existingItem = result.find(x => x.type === item.type)
if (existingItem) {
item.list.forEach(newObj => {
const existingObj = existingItem.list.find(
x => x[name] === newObj[name]
)
const existingObj = existingItem.list.find(x => x.name === newObj.name)
if (existingObj) {
existingObj.icon = newObj.icon
} else {

File diff suppressed because one or more lines are too long

View File

@ -300,16 +300,7 @@ export default {
}
},
...(config || {}),
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>`
},
]
}],
iconList: [...icon],
useLeftKeySelectionRightKeyDrag: this.useLeftKeySelectionRightKeyDrag,
customInnerElsAppendTo: null,
enableAutoEnterTextEditWhenKeydown: true,

View File

@ -58,6 +58,7 @@
import Sidebar from './Sidebar'
import { mapState } from 'vuex'
import { nodeIconList } from 'simple-mind-map/src/svg/icons'
import { mergerIconList } from 'simple-mind-map/src/utils/index'
import icon from '@/config/icon'
import image from '@/config/image'
@ -69,7 +70,7 @@ export default {
data() {
return {
activeName: 'icon',
nodeIconList: [...nodeIconList, ...icon],
nodeIconList: mergerIconList([...nodeIconList, ...icon]),
nodeImageList: [...image],
iconList: [],
nodeImage: '',