xieb
2023-09-13 3667807a7b7418efc090ee3fa6a6b734bc3080bf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const layerTreeTypes = ['layer', 'resource'] as const
type LayerTreeType = (typeof layerTreeTypes)[number]
const Spliter = '__'
 
export function getLayerTreeKey (type: LayerTreeType, id: number | string) {
  return `${type}${Spliter}${id}`
}
 
export function isLayerTreeKey (key: string, type?: LayerTreeType) {
  if (type) {
    return key.startsWith(`${type}${Spliter}`)
  } else {
    return layerTreeTypes.some(t => key.startsWith(`${t}${Spliter}`))
  }
}
 
export function getIdFromLayerTreeKey (key: string) {
  return key.split(Spliter)[1]
}