guoshilong
2023-09-13 79f8ad79d4aebbc26037cda5d5a9a1ed295b6e4b
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]
}