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
86
87
88
89
90
91
92
93
94
95
96
97
<template>
  <mars-pannel :visible="true" right="10" top="10" width="300">
    <mars-table :pagination="false" :customRow="rowClick" :columns="columns" :dataSource="dataSource" :row-selection="rowSelection" />
  </mars-pannel>
  <mars-pannel customClass="message-list" :visible="true" right="10" top="310" width="300">
    <div v-for="(msgList, index) in msg" :key="index">
      <p>{{ msgList }}</p>
    </div>
  </mars-pannel>
</template>
 
<script setup lang="ts">
import { ref } from "vue"
import * as mapWork from "./map.js"
 
interface DataItem {
  key: string | number
  num: number
  carNumber: number
  type: string
}
 
const dataSource = ref<DataItem[]>([])
// 默认的选项
const rowKeys = ref<string[]>([]) // Check here to configure the default column
 
const msg = ref<string[]>([])
 
const arr: DataItem[] = []
const arrKey: string[] = []
 
mapWork.eventTarget.on("carList", function (event: any) {
  event.tableData.forEach((item: any, index: number) => {
    arr.push({
      key: item.id,
      num: index + 1,
      carNumber: item.name,
      type: item.type === "1" ? "土方车" : "挖掘机"
    })
    arrKey.push(item.id)
  })
  dataSource.value = arr
  rowKeys.value = arrKey
})
 
mapWork.eventTarget.on("showPath", function (event: any) {
  msg.value.push(event.path)
})
 
const columns: any[] = [
  {
    title: "序号",
    dataIndex: "num",
    key: "num"
  },
  {
    title: "车牌号",
    dataIndex: "carNumber",
    key: "carNumber"
  },
  {
    title: "类型",
    dataIndex: "type",
    key: "type"
  }
]
 
const rowSelection = ref({
  hideSelectAll: true,
  hideDefaultSelections: true,
  selectedRowKeys: rowKeys,
  onChange: (selectedRowKeys: string[]) => {
    // 使得点击之后选项改变
    rowKeys.value = selectedRowKeys
  },
  onSelect: (record: DataItem, selected: boolean) => {
    // 对车子进行的操作
    mapWork.onSelect(record.key, selected)
  }
})
 
// 点击行事件
const rowClick = (recode: any) => {
  return {
    onClick: () => {
      mapWork.flyToModel(recode.key)
    }
  }
}
</script>
 
<style lang="less">
.message-list {
  max-height: 300px;
  overflow: auto;
}
</style>