edit-path.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. <template>
  2. <Teleport to="#layout-app">
  3. <RightFillPano class="edit-path-point">
  4. <div v-show="!~activePointNdx" :class="{ disabled: !data.points.length }">
  5. <ui-group
  6. :title="`${isTemploraryID(data.id) ? '创建' : '编辑'}路线`"
  7. borderBottom
  8. >
  9. <ui-group-option class="item">
  10. <span class="label">路径名称</span>
  11. <span class="oper"> <Switch v-model:checked="data.showName" /> </span>
  12. </ui-group-option>
  13. <ui-group-option class="item">
  14. <ui-input
  15. width="100%"
  16. type="text"
  17. ref="nameInput"
  18. class="nameInput"
  19. placeholder="路径名称"
  20. @keydown="keydownHandler"
  21. v-model="data.name"
  22. :maxlength="100"
  23. />
  24. </ui-group-option>
  25. <ui-group-option class="item">
  26. <span class="label">路径粗细</span>
  27. <span class="oper">
  28. <InputNumber
  29. style="width: 120px"
  30. v-model:value="data.lineWidth"
  31. :max="1"
  32. :min="0.1"
  33. :step="0.1"
  34. :controls="false"
  35. >
  36. <template #addonBefore>
  37. <span
  38. class="fun-ctrl"
  39. @click="
  40. data.lineWidth = round(Math.max(0.1, data.lineWidth - 0.1), 1)
  41. "
  42. >-</span
  43. >
  44. </template>
  45. <template #addonAfter>
  46. <span
  47. class="fun-ctrl"
  48. @click="data.lineWidth = round(Math.min(1, data.lineWidth + 0.1), 1)"
  49. >+</span
  50. >
  51. </template>
  52. </InputNumber>
  53. </span>
  54. </ui-group-option>
  55. <ui-group-option class="item">
  56. <span class="label">路径颜色</span>
  57. <span class="oper">
  58. <ui-input
  59. type="color"
  60. width="24px"
  61. height="24px"
  62. v-model="data.lineColor"
  63. />
  64. </span>
  65. </ui-group-option>
  66. <ui-group-option class="item">
  67. <span class="label">路径箭头</span>
  68. <span class="oper">
  69. <Switch v-model:checked="data.showDirection" />
  70. </span>
  71. </ui-group-option>
  72. <ui-group-option class="item" v-if="data.showDirection">
  73. <span class="label">箭头反向</span>
  74. <span class="oper"> <Switch v-model:checked="data.reverseDirection" /> </span>
  75. </ui-group-option>
  76. </ui-group>
  77. <ui-group borderBottom>
  78. <ui-group-option>
  79. <span>文字大小</span>
  80. <Slider v-model:value="data.fontSize" :min="12" :max="60" :step="0.1" />
  81. </ui-group-option>
  82. </ui-group>
  83. <ui-group borderBottom>
  84. <ui-group-option>
  85. <SignItem
  86. label="可见范围"
  87. v-if="!data.globalVisibility"
  88. @apply-global="$emit('applyGlobal', 'visibilityRange')"
  89. >
  90. <Slider
  91. v-model:value="data.visibilityRange"
  92. :min="1"
  93. :max="1000"
  94. :step="0.1"
  95. />
  96. </SignItem>
  97. </ui-group-option>
  98. <ui-group-option>
  99. <SignItem @apply-global="$emit('applyGlobal', 'globalVisibility')">
  100. <template v-slot:label>
  101. <ui-input
  102. type="checkbox"
  103. label="全部范围可视"
  104. :modelValue="!!data.globalVisibility"
  105. @update:modelValue="(v: boolean) => data.globalVisibility = v"
  106. />
  107. </template>
  108. </SignItem>
  109. </ui-group-option>
  110. </ui-group>
  111. <Button
  112. block
  113. type="primary"
  114. ghost
  115. size="large"
  116. @click="switchPlay"
  117. v-if="data.points.length"
  118. >
  119. {{ isScenePathPlayIng ? "停止" : "" }}预览路径
  120. </Button>
  121. </div>
  122. <div v-if="~activePointNdx">
  123. <ui-group title="编辑点" borderBottom>
  124. <ui-group-option>描述:</ui-group-option>
  125. <ui-group-option>
  126. <ui-input
  127. class="input"
  128. width="100%"
  129. height="158px"
  130. v-model="data.points[activePointNdx].name"
  131. placeholder="特征描述:"
  132. type="textarea"
  133. :maxlength="200"
  134. />
  135. </ui-group-option>
  136. </ui-group>
  137. <Button block danger type="primary" ghost size="large" @click="deletePoint">
  138. 删除
  139. </Button>
  140. </div>
  141. </RightFillPano>
  142. <span
  143. @click="unKeepAdding ? unKeepAdding() : keepAdding()"
  144. class="pin-position strengthen fun-ctrl"
  145. :class="{ disabled: !data.points.length }"
  146. v-if="node"
  147. >
  148. <ui-icon
  149. :style="{ color: unKeepAdding ? 'var(--color-main-normal)' : 'currentColor' }"
  150. type="pen"
  151. size="30px"
  152. />
  153. </span>
  154. </Teleport>
  155. </template>
  156. <script setup lang="ts">
  157. import {
  158. showLeftCtrlPanoStack,
  159. showLeftPanoStack,
  160. showRightCtrlPanoStack,
  161. showRightPanoStack,
  162. } from "@/env";
  163. import { computed, onUnmounted, ref, shallowRef, watch, watchEffect } from "vue";
  164. import { isTemploraryID, Path } from "@/store";
  165. import { RightFillPano } from "@/layout";
  166. import { useViewStack } from "@/hook";
  167. import { round, togetherCallback } from "@/utils";
  168. import { Switch, Slider, Button, InputNumber } from "ant-design-vue";
  169. import SignItem from "@/views/tagging-position/sign-item.vue";
  170. import { Message } from "bill/expose-common";
  171. import {
  172. getPathNode,
  173. isScenePathPlayIng,
  174. pauseScenePath,
  175. playScenePath,
  176. } from "@/sdk/association/path";
  177. const props = defineProps<{ data: Path }>();
  178. defineEmits<{
  179. (e: "applyGlobal", k: string | string[]): void;
  180. }>();
  181. onUnmounted(() => {
  182. console.error("unmounte");
  183. unKeepAdding.value && unKeepAdding.value();
  184. });
  185. const nameInput = ref();
  186. const keydownHandler = (event: KeyboardEvent) => {
  187. if (event.key === "z" && (event.ctrlKey || event.composed)) {
  188. console.log("组织");
  189. // 阻止默认的撤销行为
  190. event.preventDefault();
  191. }
  192. };
  193. watchEffect((onCleanup) => {
  194. document.documentElement.addEventListener("keydown", keydownHandler);
  195. onCleanup(() =>
  196. document.documentElement.removeEventListener("keydown", keydownHandler)
  197. );
  198. });
  199. const node = computed(() => getPathNode(props.data.id));
  200. watch(
  201. node,
  202. () => {
  203. if (props.data.points.length) {
  204. node.value?.fly();
  205. }
  206. },
  207. { immediate: true }
  208. );
  209. const activePointNdx = ref(-1);
  210. watchEffect((onCleanup) => {
  211. if (!node.value) return;
  212. const $node = node.value;
  213. const handler = (ndx: number) => {
  214. activePointNdx.value = ndx;
  215. console.error("change ndx", ndx);
  216. };
  217. $node.changeEditMode(true);
  218. $node.bus.on("activePoint", handler);
  219. console.log("监听");
  220. onCleanup(() => {
  221. console.log("取消监听");
  222. $node.bus.off("activePoint", handler);
  223. $node.changeEditMode(false);
  224. });
  225. });
  226. const deletePoint = () => {
  227. node.value?.deletePoint(activePointNdx.value);
  228. activePointNdx.value = -1;
  229. };
  230. let unKeepAdding = shallowRef<() => void>();
  231. const keepAdding = () => {
  232. unKeepAdding.value && unKeepAdding.value();
  233. node.value?.changeCanEdit(true);
  234. // const hide = Message.show({ msg: "请在模型上单击选择路径点位置", type: "warning" });
  235. unKeepAdding.value = () => {
  236. node.value?.changeCanEdit(false);
  237. // hide();
  238. unKeepAdding.value = void 0;
  239. };
  240. };
  241. if (!props.data.points.length) {
  242. keepAdding();
  243. }
  244. useViewStack(() => {
  245. return togetherCallback([
  246. showRightPanoStack.push(ref(false)),
  247. showLeftCtrlPanoStack.push(ref(false)),
  248. showLeftPanoStack.push(ref(false)),
  249. showRightCtrlPanoStack.push(ref(false)),
  250. ]);
  251. });
  252. const switchPlay = () => {
  253. if (isScenePathPlayIng.value) {
  254. pauseScenePath();
  255. } else {
  256. playScenePath(props.data);
  257. }
  258. };
  259. </script>
  260. <style lang="scss" scoped>
  261. .edit-path-point {
  262. position: absolute;
  263. right: 0;
  264. height: 100%;
  265. top: 0;
  266. --editor-menu-right: 0px;
  267. }
  268. .item {
  269. display: flex;
  270. align-items: center;
  271. justify-content: space-between;
  272. }
  273. .pin-position {
  274. position: absolute;
  275. left: 50%;
  276. transform: translate(-50%);
  277. width: 64px;
  278. height: 64px;
  279. background: rgba(27, 27, 28, 0.8);
  280. border-radius: 50%;
  281. bottom: 20px;
  282. z-index: 9;
  283. display: flex;
  284. align-items: center;
  285. justify-content: center;
  286. }
  287. </style>
  288. <style>
  289. .nameInput.ui-input .text.suffix input {
  290. padding-right: 70px;
  291. }
  292. </style>