map-right.vue 7.0 KB

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