map-right.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <template>
  2. <div class="right-layout">
  3. <div class="right-content">
  4. <el-form :inline="false" v-if="router.currentRoute.value.name === 'map'">
  5. <el-form-item v-if="relics">
  6. <el-input v-model="relicsName" :maxlength="50" placeholder="不可移动文物名称">
  7. <template #append>
  8. <el-button type="primary" @click="updateRelics">修改</el-button>
  9. </template>
  10. </el-input>
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" :icon="Plus" style="width: 100%" @click="addHandler">
  14. 添加场景
  15. </el-button>
  16. </el-form-item>
  17. </el-form>
  18. <div class="tree-layout">
  19. <p>全部数据</p>
  20. <el-tree
  21. style="max-width: 600px"
  22. :data="treeNode"
  23. node-key="id"
  24. ref="treeRef"
  25. show-checkbox
  26. default-expand-all
  27. :expand-on-click-node="false"
  28. >
  29. <template #default="{ node, data }">
  30. <div
  31. class="tree-item"
  32. @click="!data.disable && emit((data.type === 'scene' ? 'flyScene' : 'flyPoint') as any, data.raw)"
  33. >
  34. <el-tooltip
  35. v-if="data.type === 'scene'"
  36. class="box-item"
  37. effect="dark"
  38. :content="data.raw.sceneName + ' ' + node.label"
  39. placement="top"
  40. >
  41. <span :class="{ disable: data.disable }" class="title">
  42. <el-icon> <Grid /> </el-icon>
  43. {{ data.raw.sceneName }}
  44. <span class="tree-scene-name">{{ node.label }}</span>
  45. </span>
  46. </el-tooltip>
  47. <span :class="{ disable: data.disable }" class="title" v-else>
  48. <el-icon>
  49. <LocationInformation />
  50. </el-icon>
  51. {{ node.label }}
  52. </span>
  53. <span class="oper">
  54. <template v-if="router.currentRoute.value.name === 'map'">
  55. <el-icon color="#409efc" v-if="data.type === 'scene'">
  56. <Delete @click.stop="delRelicsScene(data.raw)" />
  57. </el-icon>
  58. <el-icon v-else color="#409efc">
  59. <Edit @click.stop="inputPoint = data.raw" />
  60. </el-icon>
  61. </template>
  62. <el-icon color="#409efc" style="margin-left: 8px">
  63. <Link
  64. @click.stop="
  65. data.type === 'scene'
  66. ? gotoScene(data.raw)
  67. : emit('gotoPoint', data.raw)
  68. "
  69. />
  70. </el-icon>
  71. </span>
  72. </div>
  73. </template>
  74. </el-tree>
  75. </div>
  76. </div>
  77. <el-button
  78. type="primary"
  79. :icon="Document"
  80. style="width: 100%"
  81. @click="exportFile(getSelectPoints())"
  82. >
  83. 导出四普数据
  84. </el-button>
  85. <el-button
  86. type="primary"
  87. :icon="Document"
  88. style="width: 100%; margin-top: 20px; margin-left: 0"
  89. @click="exportImage(getSelectPoints())"
  90. >
  91. 下载全景图
  92. </el-button>
  93. </div>
  94. <SingleInput
  95. :visible="!!inputPoint"
  96. @update:visible="inputPoint = null"
  97. :value="inputPoint?.name || ''"
  98. :update-value="updatePointName"
  99. title="修改点位名称"
  100. />
  101. </template>
  102. <script setup lang="ts">
  103. import {
  104. Plus,
  105. Delete,
  106. Document,
  107. Grid,
  108. LocationInformation,
  109. Edit,
  110. Link,
  111. } from "@element-plus/icons-vue";
  112. import { computed, ref, watchEffect } from "vue";
  113. import {
  114. Scene,
  115. scenes,
  116. ScenePoint,
  117. delRelicsScene,
  118. updateScenePointName,
  119. gotoScene,
  120. relicsId,
  121. refreshScenes,
  122. } from "@/store/scene";
  123. import { relics, updateRelicsName } from "@/store/relics";
  124. import SingleInput from "@/components/single-input.vue";
  125. import { ElMessage } from "element-plus";
  126. import { router } from "@/router";
  127. import { selectScenes } from "../quisk";
  128. import { addRelicsSceneFetch, delRelicsSceneFetch } from "@/request";
  129. import { exportFile, exportImage } from "./pc4Helper";
  130. const emit = defineEmits<{
  131. (e: "flyScene", data: Scene): void;
  132. (e: "flyPoint", data: ScenePoint): void;
  133. (e: "gotoPoint", data: ScenePoint): void;
  134. }>();
  135. const inputPoint = ref<ScenePoint | null>(null);
  136. const updatePointName = async (title: string) => {
  137. await updateScenePointName(inputPoint.value!, title);
  138. };
  139. const relicsName = ref("");
  140. watchEffect(() => (relicsName.value = relics.value?.name || ""));
  141. const updateRelics = async () => {
  142. await updateRelicsName(relicsName.value);
  143. ElMessage.success("修改成功");
  144. };
  145. const treeRef = ref<any>();
  146. const treeNode = computed(() =>
  147. scenes.value.map((scene) => ({
  148. label: scene.sceneCode,
  149. id: scene.id,
  150. type: "scene",
  151. disable: scene.scenePos.every((pos) => !pos.pos || pos.pos.length === 0),
  152. raw: scene,
  153. children: scene.scenePos.map((pos) => ({
  154. label: pos.name,
  155. disable: !pos.pos || pos.pos.length === 0,
  156. id: pos.id,
  157. type: "point",
  158. raw: pos,
  159. })),
  160. }))
  161. );
  162. const getSelectPoints = () =>
  163. treeRef
  164. .value!.getCheckedNodes(false, false)
  165. .filter((option: any) => option.type === "point")
  166. .map((option: any) => option.raw) as ScenePoint[];
  167. const addHandler = async () => {
  168. const sceneCodes = scenes.value.map((scene) => scene.sceneCode);
  169. await selectScenes({
  170. sceneCodes: sceneCodes,
  171. submit: async (nSceneCodes) => {
  172. const requests: Promise<any>[] = [];
  173. for (let i = 0; i < sceneCodes.length; i++) {
  174. if (!nSceneCodes.includes(sceneCodes[i])) {
  175. requests.push(delRelicsSceneFetch(relicsId.value, scenes.value[i].id));
  176. }
  177. }
  178. for (let i = 0; i < nSceneCodes.length; i++) {
  179. if (!sceneCodes.includes(nSceneCodes[i])) {
  180. requests.push(addSceneHandler(nSceneCodes[i]));
  181. }
  182. }
  183. await Promise.all(requests);
  184. },
  185. });
  186. await refreshScenes();
  187. };
  188. const addSceneHandler = async (sceneCode: string) => {
  189. const sceneTypes = ["SS", "KJ", "SG"];
  190. if (sceneTypes.every((type) => !sceneCode.startsWith(type))) {
  191. ElMessage.error("场景码不正确");
  192. throw "场景码不正确";
  193. } else {
  194. await addRelicsSceneFetch(relicsId.value!, sceneCode);
  195. }
  196. };
  197. </script>
  198. <style lang="scss" scoped>
  199. .tree-item {
  200. display: flex;
  201. width: calc(100% - 50px);
  202. align-items: center;
  203. justify-content: space-between;
  204. .title {
  205. flex: 1;
  206. overflow: hidden;
  207. text-overflow: ellipsis; //文本溢出显示省略号
  208. white-space: nowrap; //文本不会换行
  209. }
  210. .oper {
  211. flex: none;
  212. }
  213. }
  214. .tree-layout {
  215. p {
  216. color: #303133;
  217. font-size: 14px;
  218. }
  219. }
  220. .right-layout {
  221. display: flex;
  222. height: 100%;
  223. flex-direction: column;
  224. .right-content {
  225. flex: 1;
  226. overflow-y: auto;
  227. }
  228. }
  229. .tree-layout .tree-scene-name {
  230. font-size: 10px;
  231. margin: 0;
  232. color: #999;
  233. }
  234. </style>