优化图标合并相关逻辑
This commit is contained in:
parent
01d7e36990
commit
f866abb34c
@ -1,4 +1,4 @@
|
|||||||
import { mergerIconListBy } from '../utils'
|
import { mergerIconList } from '../utils'
|
||||||
|
|
||||||
// 超链接图标
|
// 超链接图标
|
||||||
const hyperlink =
|
const hyperlink =
|
||||||
@ -283,20 +283,18 @@ export const nodeIconList = [
|
|||||||
// 获取nodeIconList icon内容
|
// 获取nodeIconList icon内容
|
||||||
const getNodeIconListIcon = (name, extendIconList = []) => {
|
const getNodeIconListIcon = (name, extendIconList = []) => {
|
||||||
let arr = name.split('_')
|
let arr = name.split('_')
|
||||||
const iconList = mergerIconListBy(
|
const iconList = mergerIconList([...nodeIconList, ...extendIconList])
|
||||||
[...nodeIconList, ...extendIconList],
|
|
||||||
'type',
|
|
||||||
'name'
|
|
||||||
)
|
|
||||||
|
|
||||||
let typeData = iconList.find(item => {
|
let typeData = iconList.find(item => {
|
||||||
return item.type === arr[0]
|
return item.type === arr[0]
|
||||||
})
|
})
|
||||||
|
|
||||||
if (typeData) {
|
if (typeData) {
|
||||||
return typeData.list.find(item => {
|
let typeName = typeData.list.find(item => {
|
||||||
return item.name === arr[1]
|
return item.name === arr[1]
|
||||||
}).icon
|
})
|
||||||
|
if (typeName) {
|
||||||
|
return typeName.icon
|
||||||
|
}
|
||||||
|
return ''
|
||||||
} else {
|
} else {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|||||||
@ -669,29 +669,23 @@ export const checkIsNodeStyleDataKey = key => {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 合并数组对象by某个key
|
// 合并图标数组
|
||||||
|
|
||||||
// const data = [
|
// const data = [
|
||||||
// { type: 'a', list: [{ name: 1, value: 1 }, { name: 2, value: 2 }] },
|
// { type: 'priority', name: '优先级图标', list: [{ name: '1', icon: 'a' }, { name: 2, icon: 'b' }] },
|
||||||
// { type: 'b', list: [{ name: 13, value: 3 }] },
|
// { type: 'priority', name: '优先级图标', list: [{ name: '2', icon: 'c' }, { name: 3, icon: 'd' }] },
|
||||||
// { type: 'a', list: [{ name: 1, value: 3 }, { name: 4, value: 4 }] },
|
|
||||||
// ];
|
// ];
|
||||||
|
|
||||||
// mergeObjArrayBy(data, 'type', 'name') 结果
|
// mergerIconList(data) 结果
|
||||||
|
|
||||||
// [
|
// [
|
||||||
// { type: 'a', list: [ { name: 1, value: 3 }, { name: 2, value: 2 }, { name: 4, value: 4 } ] },
|
// { type: 'priority', name: '优先级图标', list: [{ name: '1', icon: 'a' }, { name: 2, icon: 'c' }, { name: 3, icon: 'd' }] },
|
||||||
// { type: 'b', list: [ { name: 13, value: 3 } ] }
|
|
||||||
// ]
|
// ]
|
||||||
|
export const mergerIconList = list => {
|
||||||
export const mergerIconListBy = (arrList, key, name) => {
|
return list.reduce((result, item) => {
|
||||||
return arrList.reduce((result, item) => {
|
const existingItem = result.find(x => x.type === item.type)
|
||||||
const existingItem = result.find(x => x[key] === item[key])
|
|
||||||
if (existingItem) {
|
if (existingItem) {
|
||||||
item.list.forEach(newObj => {
|
item.list.forEach(newObj => {
|
||||||
const existingObj = existingItem.list.find(
|
const existingObj = existingItem.list.find(x => x.name === newObj.name)
|
||||||
x => x[name] === newObj[name]
|
|
||||||
)
|
|
||||||
if (existingObj) {
|
if (existingObj) {
|
||||||
existingObj.icon = newObj.icon
|
existingObj.icon = newObj.icon
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -300,16 +300,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
...(config || {}),
|
...(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,
|
useLeftKeySelectionRightKeyDrag: this.useLeftKeySelectionRightKeyDrag,
|
||||||
customInnerElsAppendTo: null,
|
customInnerElsAppendTo: null,
|
||||||
enableAutoEnterTextEditWhenKeydown: true,
|
enableAutoEnterTextEditWhenKeydown: true,
|
||||||
|
|||||||
@ -58,6 +58,7 @@
|
|||||||
import Sidebar from './Sidebar'
|
import Sidebar from './Sidebar'
|
||||||
import { mapState } from 'vuex'
|
import { mapState } from 'vuex'
|
||||||
import { nodeIconList } from 'simple-mind-map/src/svg/icons'
|
import { nodeIconList } from 'simple-mind-map/src/svg/icons'
|
||||||
|
import { mergerIconList } from 'simple-mind-map/src/utils/index'
|
||||||
import icon from '@/config/icon'
|
import icon from '@/config/icon'
|
||||||
import image from '@/config/image'
|
import image from '@/config/image'
|
||||||
|
|
||||||
@ -69,7 +70,7 @@ export default {
|
|||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
activeName: 'icon',
|
activeName: 'icon',
|
||||||
nodeIconList: [...nodeIconList, ...icon],
|
nodeIconList: mergerIconList([...nodeIconList, ...icon]),
|
||||||
nodeImageList: [...image],
|
nodeImageList: [...image],
|
||||||
iconList: [],
|
iconList: [],
|
||||||
nodeImage: '',
|
nodeImage: '',
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user