index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <RightFillPano>
  3. <ui-group borderBottom>
  4. <template #header>
  5. <ui-button @click="editTagging = createTagging()">
  6. <ui-icon type="add" />
  7. 新增
  8. </ui-button>
  9. </template>
  10. </ui-group>
  11. <ui-group title="标注">
  12. <template #icon>
  13. <ui-icon
  14. ctrl
  15. :type="custom.showTaggings ? 'eye-s' : 'eye-n'"
  16. @click="custom.showTaggings = !custom.showTaggings"
  17. />
  18. </template>
  19. <ui-group-option>
  20. <ui-input type="text" width="100%" placeholder="搜索">
  21. <template #preIcon>
  22. <ui-icon type="search" />
  23. </template>
  24. </ui-input>
  25. </ui-group-option>
  26. <TagingSign
  27. v-for="tagging in taggings"
  28. :key="tagging.id"
  29. :tagging="tagging"
  30. :selected="selectTagging === tagging"
  31. @edit="editTagging = tagging"
  32. @delete="deleteTagging(tagging)"
  33. @select="selectTagging = tagging"
  34. @flyPositions="flyTaggingPositions(tagging)"
  35. />
  36. </ui-group>
  37. </RightFillPano>
  38. <Edit
  39. v-if="editTagging"
  40. :data="editTagging"
  41. @quit="editTagging = null"
  42. @save="saveHandler"
  43. />
  44. </template>
  45. <script lang="ts" setup>
  46. import Edit from './edit.vue'
  47. import TagingSign from './sign.vue'
  48. import { Message } from 'bill/index'
  49. import { RightFillPano } from '@/layout'
  50. import { togetherCallback } from '@/utils'
  51. import { useViewStack } from '@/hook'
  52. import { ref, watch } from 'vue';
  53. import { sdk } from '@/sdk'
  54. import {
  55. taggings,
  56. isTemploraryID,
  57. Tagging,
  58. autoSaveTaggings,
  59. createTagging,
  60. enterEdit,
  61. Model,
  62. getModel,
  63. getModelShowVariable,
  64. getTaggingPositions,
  65. taggingPositions,
  66. createTaggingPosition
  67. } from '@/store'
  68. import {
  69. custom,
  70. showTaggingPositionsStack,
  71. showLeftCtrlPanoStack,
  72. showLeftPanoStack,
  73. currentModelStack,
  74. showRightCtrlPanoStack,
  75. showRightPanoStack
  76. } from '@/env'
  77. const editTagging = ref<Tagging | null>(null)
  78. const saveHandler = (tagging: Tagging) => {
  79. if (!editTagging.value) return;
  80. if (isTemploraryID(editTagging.value.id)) {
  81. taggings.value.push(tagging)
  82. } else {
  83. Object.assign(editTagging.value, tagging)
  84. }
  85. editTagging.value = null
  86. }
  87. const deleteTagging = (tagging: Tagging) => {
  88. const index = taggings.value.indexOf(tagging)
  89. taggings.value.splice(index, 1)
  90. }
  91. let stopFlyTaggingPositions: () => void
  92. const flyTaggingPositions = (tagging: Tagging) => {
  93. const positions = getTaggingPositions(tagging)
  94. stopFlyTaggingPositions && stopFlyTaggingPositions()
  95. let isStop = false
  96. const flyIndex = (i: number) => {
  97. if (isStop || i >= positions.length) {
  98. return;
  99. }
  100. const position = positions[i]
  101. const model = getModel(position.modelId)
  102. if (!model || !getModelShowVariable(model).value) {
  103. flyIndex(i + 1)
  104. return;
  105. }
  106. const pop = showTaggingPositionsStack.push(ref(new WeakSet([position])))
  107. sdk.comeTo({
  108. position: position.localPos,
  109. modelId: position.modelId,
  110. dur: 300,
  111. distance: 3
  112. })
  113. console.log('改变了', custom.showTaggingPositions.has(position))
  114. setTimeout(() => {
  115. pop()
  116. flyIndex(i + 1)
  117. }, 2000)
  118. }
  119. flyIndex(0)
  120. stopFlyTaggingPositions = () => isStop = true
  121. }
  122. const stopFlyKeyupHandler = (ev: KeyboardEvent) => {
  123. ev.code === 'Escape' && stopFlyTaggingPositions && stopFlyTaggingPositions()
  124. }
  125. useViewStack(() => {
  126. document.documentElement.addEventListener('keyup', stopFlyKeyupHandler, false)
  127. return () => document.documentElement.removeEventListener('keydown', stopFlyKeyupHandler, false)
  128. })
  129. const selectTagging = ref<Tagging | null>(null)
  130. watch(selectTagging, (a, b, onCleanup) => {
  131. if (selectTagging.value) {
  132. const leave = () => selectTagging.value = null
  133. let currentModel: Model | null = custom.currentModel
  134. if (!currentModel) {
  135. for (const [model, show] of custom.showModelsMap.entries()) {
  136. show && (currentModel = model)
  137. }
  138. if (!currentModel) {
  139. Message.error('请显示要添加热点的模型')
  140. leave()
  141. return
  142. }
  143. }
  144. const pop = togetherCallback([
  145. showLeftCtrlPanoStack.push(ref(true)),
  146. showLeftPanoStack.push(ref(true)),
  147. currentModelStack.push(ref(currentModel)),
  148. showRightCtrlPanoStack.push(ref(false)),
  149. showRightPanoStack.push(ref(false))
  150. ])
  151. const clickHandler = (ev: MouseEvent) => {
  152. const position = sdk.getPositionByScreen({
  153. x: ev.clientX,
  154. y: ev.clientY
  155. }, custom.currentModel?.id)
  156. if (!position) {
  157. Message.error('当前位置无法添加')
  158. } else if (selectTagging.value) {
  159. const storePosition = createTaggingPosition({
  160. ...position,
  161. taggingId: selectTagging.value.id
  162. })
  163. taggingPositions.value.push(storePosition)
  164. leave()
  165. }
  166. }
  167. const keyupHandler = (ev: KeyboardEvent) => ev.code === 'Escape' && leave()
  168. document.documentElement.addEventListener('keyup', keyupHandler, false);
  169. sdk.layout.addEventListener('click', clickHandler, false)
  170. enterEdit(leave)
  171. onCleanup(() => {
  172. document.documentElement.removeEventListener('keyup', keyupHandler, false);
  173. sdk.layout.removeEventListener('click', clickHandler, false);
  174. pop()
  175. })
  176. }
  177. })
  178. useViewStack(autoSaveTaggings)
  179. </script>