fuchengshen
2022-07-09 3a25c05b5ab837714f30469cdcb1e2a77d8d7f6c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<template>
  <mars-dialog title="模型构件" width="320" :min-width="320" top="70" bottom="50" left="10">
    <mars-tree checkable :tree-data="LayerTreeData" @select="flytoModelNode" @check="onModelChecked" />
  </mars-dialog>
</template>
<script lang="ts" setup>
import { toRaw, onMounted, ref } from "vue"
import * as mapWork from "./map"
import axios from "axios"
import { $message } from "@mars/components/mars-ui/index"
import { useWidget } from "@mars/widgets/common/store/widget"
 
const { currentWidget } = useWidget()
 
// 加载拥有关联图层的树控件
const LayerTreeData = ref<any[]>([])
 
let keyVal = 0
 
onMounted(async () => {
  const url = currentWidget.data.url
 
  const scenetree = url.substring(0, url.lastIndexOf("/") + 1) + "scenetree.json"
 
  const scene: any = await axios.get(scenetree)
 
  if (scene.data) {
    let item = scene.data
    if (scene.data.scenes) {
      item = scene.data.scenes[0]
    }
    const childeren = isHaveChildren(item.children)
    LayerTreeData.value.push({
      title: item.name,
      key: keyVal,
      id: item.id,
      sphere: item.sphere ? item.sphere : null,
      children: childeren
    })
  } else {
    LayerTreeData.value = []
  }
})
 
function isHaveChildren(arr: any) {
  if (!arr) {
    return []
  }
  keyVal++
  const childeren: any[] = []
  arr.forEach((item: any) => {
    const childrenObject: any = {}
    childrenObject.title = item.name ? item.name : "element"
    childrenObject.key = keyVal + "-" + Math.random()
    childrenObject.id = item.id
    childrenObject.sphere = item.sphere
 
    const childOne: any = isHaveChildren(item.children)
    if (childOne.length !== 0) {
      childrenObject.children = childOne
    }
    return childeren.push(childrenObject)
  })
  return childeren
}
 
// 点击节点 定位
const flytoModelNode = (selectedKeys: any, selected: any) => {
  const id = toRaw(currentWidget.data.id)
  mapWork.flytoModelNode(id, selected.node.sphere)
}
 
// 选中节点 修改样式
const onModelChecked = (keys: string[], e: any) => {
  const id = toRaw(currentWidget.data.id)
  // 判断
  if (keys.length > 2000) {
    $message(`勾选数据${keys.length}大于2000,请减少勾选数量。`)
    return
  }
  mapWork.checkModelStyle(id, e.checkedNodes)
}
</script>
 
<style scoped lang="less"></style>