LaserBim.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. <template>
  2. <header>
  3. <div v-if="project">项目 - {{ project.name }}</div>
  4. </header>
  5. <article>
  6. <main>
  7. <div class="split" v-if="source">
  8. <iframe ref="sourceFrame" :src="`smart-laser.html?m=${source.num}&dev`" frameborder="0" @load="onLoadSource"></iframe>
  9. <div class="tools">
  10. <div class="item-mode">
  11. <div class="iconfont icon-show_roaming_normal" :class="{ active: mode == 0 }" @click="onModeChange(0)"></div>
  12. <div class="iconfont icon-show_more" :class="{ active: mode == 1 }" @click="onModeChange(1)"></div>
  13. </div>
  14. <div class="item-date" v-if="target">
  15. <span class="prev" @click="onPrevDate('source')"><i class="iconfont icon-show_back"></i></span>
  16. <span @click="onPickDate('source')">{{ source.date }}</span>
  17. <span class="next" @click="onNextDate('source')"><i class="iconfont icon-show_back"></i></span>
  18. </div>
  19. </div>
  20. </div>
  21. <div class="split" v-if="target">
  22. <iframe ref="targetFrame" :src="`smart-bim.html?m=${target.num}`" frameborder="0" @load="onLoadTarget"></iframe>
  23. </div>
  24. <div class="tools" v-if="source">
  25. <div class="item-date" v-if="!target">
  26. <span class="prev" @click="onPrevDate()"><i class="iconfont icon-show_back"></i></span>
  27. <span @click="onPickDate('all')">{{ source.date }}</span>
  28. <span class="next" @click="onNextDate()"><i class="iconfont icon-show_back"></i></span>
  29. </div>
  30. <div class="item-split" @click="onCompare">
  31. <i class="iconfont icon-size-o"></i>
  32. </div>
  33. </div>
  34. <div class="popup" v-if="source && datepickName">
  35. <div>
  36. <span @click="onPickClose"><i class="iconfont icon-close"></i></span>
  37. <datepicker :inline="true" :value="datepickValue" :highlighted="highlighted" @selected="onSelected"></datepicker>
  38. </div>
  39. </div>
  40. </main>
  41. </article>
  42. </template>
  43. <script setup>
  44. import Datepicker from 'vuejs3-datepicker'
  45. import { ref, onActivated, onDeactivated, reactive, onMounted, computed } from 'vue'
  46. import ConvertViews from '@/utils/ConvertViews'
  47. let sourceApp = null, sourceSceneName
  48. let targetApp = null
  49. const views = new ConvertViews()
  50. const datepickName = ref(null)
  51. const datepickValue = ref(null)
  52. const sourceFrame = ref(null)
  53. const targetFrame = ref(null)
  54. const mode = ref(0)
  55. const source = ref(null)
  56. const target = ref(null)
  57. const project = ref(null)
  58. const projects = reactive([{ pid: '001', name: '五楼办公区', num: 'SS-t-bFMqa1dqUU', date: '2022-09-01' }])
  59. const scenes = reactive([
  60. { pid: '001', num: 'SS-t-bFMqa1dqUU', date: '2022-09-01' },
  61. { pid: '001', num: 'SS-t-xp9BDKfzhR', date: '2022-09-03' },
  62. { pid: '001', num: 'SS-t-lc5OWhZPaC', date: '2022-09-05' },
  63. { pid: '001', num: 'SS-t-Y6gLRFwxE5', date: '2022-09-10' },
  64. ])
  65. const highlighted = computed(() => {
  66. let dates = []
  67. if (datepickName.value) {
  68. dates = scenes.map(item => item.date.toDate())
  69. }
  70. return {
  71. dates: dates,
  72. }
  73. })
  74. let getView = ()=>{
  75. let camera = sourceApp.viewer.mainViewport.camera
  76. return {
  77. position : camera.position,
  78. quaternion : camera.quaternion,
  79. fov : camera.fov
  80. }
  81. }
  82. const initConvertView = () => {
  83. if(sourceApp && targetApp/* && this.sourceSceneName != sourceApp.Potree.settings.number*/){//存在且和当前不同
  84. views.init(sourceApp, targetApp , sourceApp.viewer.inputHandler.domElement, 'laser', getView(),
  85. sourceApp.viewer.images360.panos.slice(0,2).map(e=>e.position))
  86. }
  87. }
  88. const onLoadSource = () => {
  89. sourceApp = sourceFrame.value.contentWindow
  90. sourceApp.loaded.then(sdk => {
  91. if (mode.value != 0) {
  92. sdk.scene.changeMode(mode.value)
  93. }
  94. window.viewer1 = sourceApp.viewer
  95. initConvertView()
  96. sourceSceneName = sourceApp.Potree.settings.number
  97. sourceApp.viewer.addEventListener('camera_changed', e => {
  98. targetApp && views.receive( getView() )
  99. })
  100. })
  101. }
  102. const onLoadTarget = () => {
  103. targetApp = targetFrame.value.contentWindow
  104. targetApp.loader.then(viewer=>{
  105. //console.log(viewer.getViewer().camera)
  106. window.viewer2 = targetApp.viewer
  107. initConvertView()
  108. })
  109. // targetApp.Scene.on('loaded', () => {
  110. // targetApp.Camera.setCompassDisplay(false)
  111. // targetApp.Connect.sync.start()
  112. // targetApp.VRScreenSYNC = false
  113. // console.log('targetApp.Scene loaded')
  114. // views.bind({ targetApp })
  115. // sourceApp && sourceApp.Connect.sync.sync()
  116. // })
  117. // targetApp.Connect.sync.on('data', data => {
  118. // if (sourceApp) {
  119. // views.applyDiff(sourceApp, data)
  120. // sourceApp.Connect.sync.receive(data)
  121. // }
  122. // })
  123. }
  124. const onModeChange = targetMode => {
  125. if (sourceApp) {
  126. sourceApp.loaded.then(sdk => sdk.scene.changeMode(targetMode))
  127. mode.value = targetMode
  128. }
  129. }
  130. const onPickDate = name => {
  131. if (name == 'target') {
  132. datepickValue.value = target.value.date.toDate()
  133. } else {
  134. datepickValue.value = source.value.date.toDate()
  135. }
  136. datepickName.value = name
  137. }
  138. const onPickClose = () => {
  139. datepickName.value = null
  140. datepickValue.value = null
  141. }
  142. const onSelected = payload => {
  143. if (!payload) {
  144. return
  145. }
  146. var date = payload.format('YYYY-mm-dd')
  147. var dates = highlighted.value.dates.map(item => item.format('YYYY-mm-dd'))
  148. if (dates.indexOf(date) != -1) {
  149. var find = scenes.find(c => c.date == date)
  150. if (find) {
  151. if (datepickName.value) {
  152. if (datepickName.value == 'all' || datepickName.value == 'source') {
  153. if (find.num != source.value.num) {
  154. source.value = find
  155. }
  156. } else if (datepickName.value == 'target') {
  157. if (find.num != target.value.num) {
  158. target.value = find
  159. }
  160. }
  161. } else {
  162. if (find.num != source.value.num) {
  163. source.value = find
  164. }
  165. }
  166. }
  167. }
  168. datepickName.value = null
  169. }
  170. const onCompare = () => {
  171. if (target.value) {
  172. target.value = null
  173. targetApp = null
  174. views.clear()
  175. return
  176. }
  177. let index = scenes.findIndex(item => item.num == source.value.num)
  178. if (index == -1) {
  179. return
  180. }
  181. if (++index > scenes.length - 1) {
  182. index = 0
  183. }
  184. target.value = scenes[index]
  185. }
  186. const onPrevDate = name => {
  187. let scene = null
  188. if (!name || name == 'source') {
  189. scene = source
  190. } else {
  191. scene = target
  192. }
  193. let index = scenes.findIndex(item => item.num == scene.value.num)
  194. if (index == -1) {
  195. return
  196. }
  197. if (--index == -1) {
  198. index = scenes.length - 1
  199. }
  200. // if (name) {
  201. // if (name == 'source') {
  202. // if (scenes[index].num == target.value.num) {
  203. // index--
  204. // }
  205. // } else {
  206. // if (scenes[index].num == source.value.num) {
  207. // index--
  208. // }
  209. // }
  210. // }
  211. // if (index == -1) {
  212. // index = scenes.length - 1
  213. // }
  214. scene.value = scenes[index]
  215. }
  216. const onNextDate = name => {
  217. let scene = null
  218. if (!name || name == 'source') {
  219. scene = source
  220. } else {
  221. scene = target
  222. }
  223. let index = scenes.findIndex(item => item.num == scene.value.num)
  224. if (index == -1) {
  225. return
  226. }
  227. if (++index > scenes.length - 1) {
  228. index = 0
  229. }
  230. // if (name) {
  231. // if (name == 'source') {
  232. // if (scenes[index].num == target.value.num) {
  233. // index++
  234. // }
  235. // } else {
  236. // if (scenes[index].num == source.value.num) {
  237. // index++
  238. // }
  239. // }
  240. // }
  241. // if (index > scenes.length - 1) {
  242. // index = 0
  243. // }
  244. scene.value = scenes[index]
  245. }
  246. onMounted(() => {
  247. project.value = projects[0]
  248. if (project.value) {
  249. source.value = scenes[2] //scenes.find(item => item.num == project.value.num)
  250. }
  251. })
  252. </script>
  253. <style lang="scss" scoped>
  254. header {
  255. height: 60px;
  256. background-color: rgba(0, 0, 0, 0.8);
  257. display: flex;
  258. justify-content: center;
  259. align-items: center;
  260. font-size: 18px;
  261. }
  262. article {
  263. display: flex;
  264. width: 100%;
  265. height: 100%;
  266. overflow: hidden;
  267. }
  268. aside {
  269. width: 160px;
  270. height: 100%;
  271. background-color: rgba(0, 0, 0, 0.8);
  272. h4 {
  273. font-size: 16px;
  274. text-align: center;
  275. }
  276. ul {
  277. margin-top: 20px;
  278. }
  279. li {
  280. margin: 0;
  281. padding: 0;
  282. font-size: 16px;
  283. margin-left: 20px;
  284. cursor: pointer;
  285. &:hover,
  286. &.active {
  287. color: #00c8af;
  288. }
  289. }
  290. }
  291. main {
  292. flex: 1;
  293. width: 100%;
  294. height: 100%;
  295. position: relative;
  296. display: flex;
  297. &.full {
  298. .split {
  299. width: 50%;
  300. }
  301. }
  302. iframe {
  303. position: absolute;
  304. left: 0;
  305. top: 0;
  306. z-index: 1000;
  307. width: 100%;
  308. height: 100%;
  309. }
  310. .split {
  311. width: 100%;
  312. height: 100%;
  313. overflow: hidden;
  314. position: relative;
  315. .tools {
  316. width: 100%;
  317. padding-left: 20px;
  318. padding-right: 20px;
  319. justify-content: space-between;
  320. left: 0;
  321. transform: none;
  322. .item-mode {
  323. display: flex;
  324. align-items: center;
  325. justify-content: space-around;
  326. height: 34px;
  327. border-radius: 17px;
  328. background-color: rgba(0, 0, 0, 0.3);
  329. > div {
  330. position: relative;
  331. margin-left: 20px;
  332. margin-right: 20px;
  333. cursor: pointer;
  334. &.active {
  335. color: #00c8af;
  336. }
  337. }
  338. i {
  339. font-size: 18px;
  340. }
  341. }
  342. }
  343. }
  344. .tools {
  345. position: absolute;
  346. left: 50%;
  347. transform: translateX(-50%);
  348. bottom: 10px;
  349. z-index: 1000;
  350. display: flex;
  351. justify-content: center;
  352. align-items: center;
  353. color: #fff;
  354. i {
  355. font-size: 18px;
  356. }
  357. .item-date {
  358. position: relative;
  359. height: 34px;
  360. border-radius: 17px;
  361. background-color: rgba(0, 0, 0, 0.3);
  362. padding: 0 30px;
  363. display: flex;
  364. justify-content: center;
  365. align-items: center;
  366. margin-left: 10px;
  367. margin-right: 10px;
  368. span {
  369. cursor: pointer;
  370. }
  371. .prev,
  372. .next {
  373. position: absolute;
  374. left: 5px;
  375. }
  376. .next {
  377. left: auto;
  378. right: 5px;
  379. transform: rotate(180deg);
  380. }
  381. }
  382. .item-split {
  383. display: flex;
  384. justify-content: center;
  385. align-items: center;
  386. width: 34px;
  387. height: 34px;
  388. border-radius: 50%;
  389. background-color: rgba(0, 0, 0, 0.3);
  390. cursor: pointer;
  391. }
  392. }
  393. .popup {
  394. position: absolute;
  395. left: 0;
  396. top: 0;
  397. width: 100%;
  398. height: 100%;
  399. z-index: 1000;
  400. display: flex;
  401. align-items: center;
  402. justify-content: center;
  403. > div {
  404. position: relative;
  405. color: #444;
  406. span {
  407. position: absolute;
  408. right: -20px;
  409. top: -20px;
  410. cursor: pointer;
  411. background-color: rgba(0, 0, 0, 0.3);
  412. width: 24px;
  413. height: 24px;
  414. border-radius: 50%;
  415. z-index: 1000;
  416. display: flex;
  417. justify-content: center;
  418. align-items: center;
  419. color: #fff;
  420. }
  421. i {
  422. font-size: 12px;
  423. }
  424. }
  425. }
  426. }
  427. </style>
  428. <style lang="scss">
  429. #app {
  430. background-color: rgba(0, 0, 0, 0.8);
  431. display: flex;
  432. flex-direction: column;
  433. }
  434. .vuejs3-datepicker__calendar-topbar {
  435. display: none !important;
  436. }
  437. .highlighted {
  438. background: #4ebde1 !important;
  439. }
  440. .selected {
  441. background: #00c8af !important;
  442. }
  443. </style>