polygons.vue 8.1 KB

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