polygons.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <div class="right-layout" @click.stop="selectChange(null)">
  3. <div class="right-content">
  4. <div class="tree-layout">
  5. <p class="sub-title">全部数据</p>
  6. <div class="poly-list">
  7. <template v-if="boardData.polygons.length > 0">
  8. <div
  9. v-for="item in boardData.polygons"
  10. class="poly-list-item"
  11. :class="{
  12. active: [
  13. boardStatus.lightPolygonId,
  14. boardStatus.editPolygonId,
  15. selectId,
  16. ].includes(item.id),
  17. }"
  18. @mouseenter="!selectId && (boardStatus.lightPolygonId = item.id)"
  19. @mouseleave="!selectId && (boardStatus.lightPolygonId = null)"
  20. @click.stop="!currentItem && selectChange(item.id)"
  21. >
  22. <div class="left">
  23. <span>{{ item.name ? item.name : "本体边界" + item.id }}</span>
  24. </div>
  25. <div
  26. class="right"
  27. @click.stop
  28. v-if="!boardStatus.editPolygonId && !queryMode"
  29. >
  30. <el-icon class="icon">
  31. <Delete @click="del(item.id)" />
  32. </el-icon>
  33. <el-icon class="icon">
  34. <Edit @click="handleShowEditModel(item)" />
  35. </el-icon>
  36. <el-icon class="icon">
  37. <Download @click="handleDownload(item)" />
  38. </el-icon>
  39. </div>
  40. </div>
  41. </template>
  42. <template v-else>
  43. <div class="empty">暂没数据</div>
  44. </template>
  45. </div>
  46. </div>
  47. </div>
  48. </div>
  49. <Teleport to="body" v-if="!queryMode">
  50. <div class="draw-global-icon" @click="cleanupEdit ? cleanupEdit() : enterEdit()">
  51. <el-icon size="36">
  52. <Check v-if="cleanupEdit" />
  53. <picpenIcon v-else />
  54. </el-icon>
  55. </div>
  56. <SingleInput
  57. v-if="selectItem"
  58. :visible="isShowPolyEditName"
  59. @update:visible="isShowPolyEditName = false"
  60. :value="selectItem.name || ''"
  61. :update-value="(name) => boardDataChange(() => (selectItem.name = name))"
  62. placeholder="请输入"
  63. title="修改边界名称"
  64. />
  65. </Teleport>
  66. </template>
  67. <script setup lang="ts">
  68. import { computed, onBeforeUnmount, ref, shallowRef, watch } from "vue";
  69. import type { PolyDataType } from "@/request/drawing.ts";
  70. import { Delete, Download, Edit, Check } from "@element-plus/icons-vue";
  71. import SingleInput from "@/components/single-input.vue";
  72. import { downloadPointsXLSL1 } from "@/util/pc4xlsl";
  73. import { boardData, scenePoints } from "@/store/scene";
  74. import { getWholeLinePolygonPoints } from "drawing-board";
  75. import { board, boardDataChange, mapManage, queryMode } from "./install";
  76. import { confirm } from "@/helper/message";
  77. import picpenIcon from "@/assets/pic_pen.svg";
  78. const boardStatus = board.polygon.status;
  79. const selectId = ref<string>();
  80. const selectChange = (id: string) => {
  81. if (currentItem.value) return;
  82. if (selectId.value === id) {
  83. boardStatus.lightPolygonId = null;
  84. selectId.value = null;
  85. } else {
  86. selectId.value = id;
  87. if (!selectItem.value) {
  88. selectChange(null);
  89. } else {
  90. boardStatus.lightPolygonId = selectItem.value.id;
  91. const points = getWholeLinePolygonPoints(boardData.value, selectItem.value.id);
  92. if (points.length) {
  93. const total = points.reduce((t, p) => [t[0] + p.x, t[1] + p.y], [0, 0]);
  94. mapManage.map
  95. .getView()
  96. .setCenter([total[0] / points.length, total[1] / points.length]);
  97. }
  98. }
  99. }
  100. };
  101. board.polygon.bus.on("activePolygonId", selectChange);
  102. const selectItem = computed(() =>
  103. boardData.value.polygons.find(({ id }) => id === selectId.value)
  104. );
  105. const currentItem = computed(() =>
  106. boardData.value.polygons.find(({ id }) => id === boardStatus.editPolygonId)
  107. );
  108. const cleanupEdit = shallowRef<() => void>();
  109. const enterEdit = () => {
  110. cleanupEdit.value && cleanupEdit.value();
  111. const quitEdit = board.polygon.editPolygon(selectId.value);
  112. let needUpdate = false;
  113. const stopWatch = watch(
  114. () => currentItem.value,
  115. () => (needUpdate = true),
  116. { deep: true }
  117. );
  118. cleanupEdit.value = () => {
  119. board.polygon.bus.off("penEndHandler", cleanupEdit.value);
  120. quitEdit();
  121. selectChange(null);
  122. stopWatch();
  123. needUpdate && boardDataChange();
  124. cleanupEdit.value = null;
  125. };
  126. board.polygon.bus.on("penEndHandler", cleanupEdit.value);
  127. };
  128. onBeforeUnmount(() => {
  129. cleanupEdit.value && cleanupEdit.value();
  130. board.polygon.status.lightPointId = null;
  131. });
  132. const isShowPolyEditName = ref(false);
  133. const handleShowEditModel = (item: PolyDataType) => {
  134. selectChange(item.id);
  135. isShowPolyEditName.value = true;
  136. };
  137. const del = async (id: string) => {
  138. if ((await confirm("确定要删除吗")) && !currentItem.value) {
  139. boardDataChange(() => board.polygon.removePolygon(id));
  140. }
  141. };
  142. const handleDownload = async (item: any) => {
  143. const polygonPoints: any[] = getWholeLinePolygonPoints(boardData.value, item.id);
  144. const points = polygonPoints.map((p) => {
  145. const pos = [p.x, p.y, 0];
  146. if (p.rtk) {
  147. const sPoint = scenePoints.value.find(({ id }) => id.toString() === p.title);
  148. if (sPoint) {
  149. pos[2] = sPoint.pos[2];
  150. }
  151. }
  152. return pos;
  153. });
  154. const dists = polygonPoints.map((p) => ({
  155. title: p.id,
  156. desc: p.title || p.id,
  157. }));
  158. await downloadPointsXLSL1(
  159. points,
  160. dists,
  161. `${item.name ? item.name : "本体边界" + item.id}`
  162. );
  163. };
  164. </script>
  165. <style lang="scss" scoped>
  166. .tree-item {
  167. display: flex;
  168. width: calc(100% - 50px);
  169. align-items: center;
  170. justify-content: space-between;
  171. .title {
  172. flex: 1;
  173. overflow: hidden;
  174. text-overflow: ellipsis; //文本溢出显示省略号
  175. white-space: nowrap; //文本不会换行
  176. }
  177. .oper {
  178. flex: none;
  179. }
  180. }
  181. .disable {
  182. pointer-events: all;
  183. }
  184. .tree-layout {
  185. p {
  186. color: #303133;
  187. font-size: 14px;
  188. }
  189. .sub-title {
  190. font-size: 14px;
  191. font-weight: bolder;
  192. margin-bottom: 30px;
  193. }
  194. }
  195. .right-layout {
  196. display: flex;
  197. height: 100%;
  198. flex-direction: column;
  199. font-size: 16px;
  200. .right-content {
  201. flex: 1;
  202. overflow-y: auto;
  203. }
  204. }
  205. .tree-layout .tree-scene-name {
  206. font-size: 10px;
  207. margin: 0;
  208. color: #999;
  209. }
  210. .poly-list {
  211. width: 100%;
  212. display: flex;
  213. flex-direction: column;
  214. font-size: 14px;
  215. user-select: none;
  216. .poly-list-item {
  217. cursor: pointer;
  218. width: 100%;
  219. display: flex;
  220. flex-direction: row;
  221. justify-content: space-between;
  222. align-items: center;
  223. margin-bottom: 10px;
  224. &.active {
  225. color: #409eff;
  226. }
  227. .icon {
  228. margin-left: 8px;
  229. font-size: 16px;
  230. color: #409eff;
  231. cursor: pointer;
  232. }
  233. }
  234. .empty {
  235. display: flex;
  236. align-items: center;
  237. justify-content: center;
  238. font-size: 13px;
  239. color: gray;
  240. padding-top: 40px;
  241. }
  242. }
  243. .draw-global-icon {
  244. width: 64px;
  245. height: 64px;
  246. background: #ffffff;
  247. border-radius: 50%;
  248. position: fixed;
  249. z-index: 1000;
  250. transform: translateX(calc(-1 * calc(50% - 300px)));
  251. left: calc(50% - 300px);
  252. top: 90%;
  253. display: flex;
  254. flex-direction: column;
  255. align-items: center;
  256. justify-content: center;
  257. cursor: pointer;
  258. color: #409eff;
  259. }
  260. </style>