SViewer.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. <template>
  2. <main v-if="source">
  3. <iframe ref="sourceFrame" :src="sourceURL" frameborder="0" @load="onLoadSource"></iframe>
  4. <div class="model" v-show="!showAdjust">
  5. <div class="bim" :class="{ active: bimChecked, disable: project && !project.bimData }">
  6. <div @click="onBimChecked">
  7. <i class="iconfont icon-BIM"></i>
  8. </div>
  9. <span v-show="showBimTips">BIM</span>
  10. </div>
  11. </div>
  12. <div class="tools" v-show="!bimChecked">
  13. <div class="item-date">
  14. <Calendar :value="sourceDate" :highlighted="sourceDays" @selected="onSelected" @prev="onPrevDate" @next="onNextDate" />
  15. </div>
  16. <div class="item-mode" v-if="source.type == 2">
  17. <div class="iconfont icon-show_roaming" :class="{ active: mode == 0 }" @click="onModeChange(0)"></div>
  18. <div class="iconfont icon-show_plane" :class="{ active: mode == 1 }" @click="onModeChange(1)"></div>
  19. </div>
  20. </div>
  21. </main>
  22. <Toast v-if="showTips" type="warn" :content="showTips" :close="() => (showTips = null)" />
  23. </template>
  24. <script setup>
  25. import { ref, onMounted, computed, nextTick } from 'vue'
  26. import { http } from '@/utils/request'
  27. import Toast from '@/components/dialog/Toast'
  28. import browser from '@/utils/browser'
  29. import Calendar from '@/components/calendar/mobile.vue'
  30. import sync, { loadSourceScene, loadTargetScene } from '@/utils/sync'
  31. const showBimTips = ref(false)
  32. const showTips = ref(null)
  33. const bimChecked = ref(null)
  34. const sourceFrame = ref(null)
  35. const mode = ref(0)
  36. const source = ref(null)
  37. const target = ref(null)
  38. const project = ref(null)
  39. const scenes = computed(() => {
  40. if (!project.value) {
  41. return []
  42. }
  43. return project.value.sceneList.map(item => {
  44. return {
  45. num: item.num,
  46. type: item.type,
  47. createTime: item.createTime,
  48. }
  49. })
  50. })
  51. const sourceURL = computed(() => {
  52. if (bimChecked.value) {
  53. return `smart-bim.html?m=${project.value.bimData.bimOssFilePath}`
  54. }
  55. if (source.value.type < 2) {
  56. let pose = ''
  57. if (sourceFrame.value && sourceFrame.value.contentWindow.app && sourceFrame.value.contentWindow.app.Camera) {
  58. let sdk = sourceFrame.value.contentWindow.app
  59. pose = '&' + sdk.Camera.getPoseUrlParams()
  60. }
  61. // 看看、看见场景
  62. return `smart-kankan.html?m=${source.value.num}${pose}`
  63. } else {
  64. // 深时场景
  65. return `smart-laser.html?m=${source.value.num}&dev`
  66. }
  67. })
  68. const sourceDate = computed(() => {
  69. if (source.value) {
  70. return source.value.createTime.toDate()
  71. }
  72. })
  73. const sourceDays = computed(() => {
  74. const outDays = { year: [], month: [], day: [] }
  75. if (!scenes.value) {
  76. return outDays
  77. }
  78. const inDays = scenes.value.map(item => item.createTime.split(' ')[0].split('-'))
  79. inDays.forEach(item => {
  80. const [year, month, day] = item
  81. if (outDays.year.indexOf(year) == -1) {
  82. outDays.year.push(year)
  83. }
  84. if (outDays.month.indexOf(month) == -1) {
  85. outDays.month.push(month)
  86. }
  87. if (outDays.day.indexOf(day) == -1) {
  88. outDays.day.push(day)
  89. }
  90. })
  91. return outDays
  92. })
  93. const onModeChange = targetMode => {
  94. if (sourceFrame.value && sourceFrame.value.contentWindow.loaded) {
  95. sourceFrame.value.contentWindow.loaded.then(sdk => sdk.scene.changeMode(targetMode))
  96. mode.value = targetMode
  97. }
  98. }
  99. const onSelected = data => {
  100. if (!data.payload) {
  101. return
  102. }
  103. let { payload } = data
  104. let time = payload.format('YYYY-mm-dd')
  105. let find = scenes.value.find(c => c.createTime.indexOf(time) != -1)
  106. if (find) {
  107. if (find.num != source.value.num) {
  108. source.value = find
  109. }
  110. }
  111. }
  112. const onPrevDate = name => {
  113. let index = scenes.value.findIndex(item => item.num == source.value.num)
  114. if (index == -1) {
  115. return
  116. }
  117. if (--index == -1) {
  118. index = scenes.value.length - 1
  119. }
  120. source.value = scenes.value[index]
  121. }
  122. const onNextDate = name => {
  123. let index = scenes.value.findIndex(item => item.num == source.value.num)
  124. if (index == -1) {
  125. return
  126. }
  127. if (++index > scenes.value.length - 1) {
  128. index = 0
  129. }
  130. source.value = scenes.value[index]
  131. }
  132. // bim点击
  133. const onBimChecked = () => {
  134. showBimTips.value = true;
  135. setTimeout(() => {
  136. showBimTips.value = false
  137. }, 2000);
  138. if (!project.value || !project.value.bimData) {
  139. showTips.value = '未发现BIM文件'
  140. return
  141. }
  142. if (bimChecked.value) {
  143. bimChecked.value = false
  144. showBimTips.value = false
  145. } else {
  146. bimChecked.value = true
  147. }
  148. }
  149. onMounted(() => {
  150. const projectId = browser.valueFromUrl('projectId') || 1
  151. http.get(`smart-site/project/info?projectId=${projectId}`)
  152. .then(response => {
  153. if (response.success) {
  154. project.value = response.data
  155. if (project.value.sceneList.length) {
  156. source.value = project.value.sceneList[0]
  157. }
  158. } else {
  159. showTips.value = response.message
  160. }
  161. })
  162. .catch(err => {
  163. showTips.value = '服务器连接失败'
  164. })
  165. })
  166. </script>
  167. <style lang="scss" scoped>
  168. main {
  169. width: 100%;
  170. height: 100%;
  171. iframe {
  172. width: 100%;
  173. height: 100%;
  174. }
  175. .tools {
  176. position: absolute;
  177. width: 100%;
  178. bottom: 40px;
  179. z-index: 2000;
  180. display: flex;
  181. justify-content: center;
  182. align-items: center;
  183. color: #fff;
  184. pointer-events: none;
  185. > div {
  186. pointer-events: all;
  187. }
  188. .item-mode {
  189. height: 50px;
  190. background: rgba(27, 27, 28, 0.8);
  191. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
  192. border-radius: 47px 47px 47px 47px;
  193. border: 1px solid #000000;
  194. display: flex;
  195. justify-content: center;
  196. align-items: center;
  197. margin-left: 10px;
  198. margin-right: 10px;
  199. font-size: 16px;
  200. padding: 0 16px;
  201. div {
  202. cursor: pointer;
  203. font-size: 18px;
  204. }
  205. div:last-child {
  206. margin-left: 20px;
  207. }
  208. div.active {
  209. color: #0076f6;
  210. }
  211. }
  212. }
  213. .model {
  214. position: absolute;
  215. left: 15px;
  216. top: 20px;
  217. z-index: 1000;
  218. display: flex;
  219. flex-direction: column;
  220. span {
  221. position: absolute;
  222. left: 130%;
  223. top: 48%;
  224. background: rgba(27, 27, 28, 0.8);
  225. padding: 4px;
  226. border-radius: 4px;
  227. color:#fff;
  228. &::before {
  229. content: '';
  230. position: absolute;
  231. right: 100%;
  232. top: 50%;
  233. margin-top:-7px;
  234. width: 0;
  235. height: 0;
  236. border-top: 7px solid transparent;
  237. border-right: 14px solid rgba(27, 27, 28, 0.8);
  238. border-bottom: 7px solid transparent;
  239. }
  240. }
  241. > div {
  242. cursor: pointer;
  243. width: 50px;
  244. height: 50px;
  245. margin-top: 16px;
  246. background: rgba(27, 27, 28, 0.8);
  247. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
  248. border-radius: 47px 47px 47px 47px;
  249. border: 1px solid #000000;
  250. display: flex;
  251. flex-direction: column;
  252. align-items: center;
  253. justify-content: center;
  254. > div {
  255. width: 100%;
  256. height: 100%;
  257. display: flex;
  258. flex-direction: column;
  259. align-items: center;
  260. justify-content: center;
  261. }
  262. &.active {
  263. color: #0076f6;
  264. }
  265. &.disable {
  266. opacity: 0.5;
  267. }
  268. i {
  269. font-size: 20px;
  270. }
  271. }
  272. }
  273. }
  274. </style>
  275. <style lang="scss">
  276. #app {
  277. background-color: rgba(0, 0, 0, 0.8);
  278. display: flex;
  279. flex-direction: column;
  280. }
  281. </style>