Viewer.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. <template>
  2. <AppHeader v-show="!fscChecked" :project="project" :show-adjust="showAdjust" @update="onPointsUpdate" />
  3. <article>
  4. <main>
  5. <div class="split" v-if="source">
  6. <iframe ref="sourceFrame" :src="sourceURL" frameborder="0" @load="onLoadSource"></iframe>
  7. <div class="tools" v-show="!showAdjust && !fscChecked && (dbsChecked || (!target && !bimChecked))">
  8. <div class="item-date">
  9. <calendar name="source" :count="scenes.length" :value="sourceDate" :highlighted="sourceDays" @selected="onSelected" @pick="onPickDate" @prev="onPrevDate" @next="onNextDate"></calendar>
  10. </div>
  11. <div class="item-mode" v-if="source.type == 2">
  12. <div class="iconfont icon-show_roaming" :class="{ active: mode == 0 }" @click="onModeChange(0)"></div>
  13. <div class="iconfont icon-show_plane" :class="{ active: mode == 1 }" @click="onModeChange(1)"></div>
  14. </div>
  15. </div>
  16. <div class="points" v-if="showAdjust">
  17. <div :class="{ active: points.p1 }">
  18. <i class="iconfont" :class="[points.p1 ? 'icon-positioning01' : 'icon-positioning02']"></i>
  19. <span>P1</span>
  20. </div>
  21. <div :class="{ active: points.p2 }">
  22. <i class="iconfont" :class="[points.p2 ? 'icon-positioning01' : 'icon-positioning02']"></i>
  23. <span>P2</span>
  24. </div>
  25. </div>
  26. </div>
  27. <div class="split" v-if="target">
  28. <iframe ref="targetFrame" :src="targetURL" frameborder="0" @load="onLoadTarget"></iframe>
  29. <div class="tools" v-show="!fscChecked && !bimChecked">
  30. <div class="item-date target">
  31. <calendar name="target" :value="targetDate" :highlighted="targetDays" @selected="onSelected" @pick="onPickDate" @prev="onPrevDate" @next="onNextDate"></calendar>
  32. </div>
  33. </div>
  34. <div class="points" v-if="showAdjust">
  35. <div :class="{ active: points.p1 }">
  36. <i class="iconfont" :class="[points.p1 ? 'icon-positioning01' : 'icon-positioning02']"></i>
  37. <span>P1</span>
  38. </div>
  39. <div :class="{ active: points.p2 }">
  40. <i class="iconfont" :class="[points.p2 ? 'icon-positioning01' : 'icon-positioning02']"></i>
  41. <span>P2</span>
  42. </div>
  43. </div>
  44. </div>
  45. <div class="model" v-show="!showAdjust">
  46. <div class="bim" :class="{ active: bimChecked, disable: project && !project.bimData }" v-show="!fscChecked">
  47. <div @click="onBimChecked">
  48. <i class="iconfont icon-BIM"></i>
  49. <span>BIM</span>
  50. </div>
  51. </div>
  52. <div class="dbs" :class="{ active: dbsChecked, disable: scenes.length < 2 && !bimChecked }" @click="onDbsChecked" v-show="!fscChecked">
  53. <i class="iconfont icon-split_screen"></i>
  54. <span>分屏</span>
  55. </div>
  56. <div class="fsc" :class="{ active: fscChecked }" @click="onFscChecked">
  57. <i class="iconfont" :class="[fscChecked ? 'icon-full_screen_selected' : 'icon-full_screen_normal']"></i>
  58. <span>全屏</span>
  59. </div>
  60. </div>
  61. </main>
  62. <Toast v-if="showBimTips" type="warn" content="未发现BIM文件" :close="() => (showBimTips = false)" />
  63. <Toast v-if="showDbsTips" type="warn" content="未发现对比场景" :close="() => (showDbsTips = false)" />
  64. </article>
  65. </template>
  66. <script setup>
  67. import { ref, onMounted, computed, nextTick } from 'vue'
  68. import { http } from '@/utils/request'
  69. import browser from '@/utils/browser'
  70. import Toast from '@/components/dialog/Toast'
  71. import AppHeader from '@/components/header'
  72. import Calendar from '@/components/calendar'
  73. import sync, { loadSourceScene, loadTargetScene, setPanoWithBim} from '@/utils/sync'
  74. // 是否BIM模式
  75. const showBim = ref(browser.urlHasValue('bim'))
  76. // 是否校准模式
  77. const showSplit = ref(browser.urlHasValue('split'))
  78. const showAdjust = ref(browser.urlHasValue('adjust'))
  79. const bimChecked = ref()
  80. const dbsChecked = ref(null)
  81. const fscChecked = ref(null)
  82. const datepickName = ref(null)
  83. const sourceFrame = ref(null)
  84. const targetFrame = ref(null)
  85. const mode = ref(0)
  86. const source = ref(null)
  87. const target = ref(null)
  88. const project = ref(null)
  89. const points = ref({ p1: false, p2: false })
  90. const showBimTips = ref(false)
  91. const showDbsTips = ref(false)
  92. const scenes = computed(() => {
  93. if (!project.value) {
  94. return []
  95. }
  96. return project.value.sceneList.map(item => {
  97. return {
  98. num: item.num,
  99. type: item.type,
  100. createTime: item.createTime,
  101. }
  102. })
  103. })
  104. const sourceURL = computed(() => {
  105. if (bimChecked.value && !dbsChecked.value) {
  106. return `smart-bim.html?m=${project.value.bimData.bimOssFilePath}`
  107. }
  108. if (source.value.type < 2) {
  109. // 看看、看见场景
  110. return `smart-kankan.html?m=${source.value.num}&dev`
  111. } else {
  112. // 深时场景
  113. return `smart-laser.html?m=${source.value.num}&dev`
  114. }
  115. })
  116. const targetURL = computed(() => {
  117. if (bimChecked.value) {
  118. return `smart-bim.html?m=${project.value.bimData.bimOssFilePath}`
  119. }
  120. if (source.value.type < 2) {
  121. // 看看、看见场景
  122. return `smart-kankan.html?m=${target.value.num}&dev`
  123. } else {
  124. // 深时场景
  125. return `smart-laser.html?m=${target.value.num}&dev`
  126. }
  127. })
  128. const sourceDate = computed(() => {
  129. if (source.value) {
  130. console.log(source.value.createTime.toDate())
  131. return source.value.createTime.toDate()
  132. }
  133. })
  134. const targetDate = computed(() => {
  135. if (target.value) {
  136. return target.value.createTime.toDate()
  137. }
  138. })
  139. const sourceDays = computed(() => {
  140. let dates = []
  141. if (datepickName.value == 'source') {
  142. if (dbsChecked.value) {
  143. // 分屏模式
  144. if (bimChecked.value) {
  145. // BIM模式
  146. dates = scenes.value.map(item => item.createTime.toDate())
  147. } else {
  148. // 非BIM模式
  149. dates = scenes.value.filter(item => item.createTime != target.value.createTime).map(item => item.createTime.toDate())
  150. }
  151. } else {
  152. // 非分屏模式
  153. dates = scenes.value.map(item => item.createTime.toDate())
  154. }
  155. }
  156. return {
  157. dates: dates,
  158. }
  159. })
  160. const targetDays = computed(() => {
  161. let dates = []
  162. if (datepickName.value == 'target') {
  163. dates = scenes.value.filter(item => item.createTime != source.value.createTime).map(item => item.createTime.toDate())
  164. }
  165. return {
  166. dates: dates,
  167. }
  168. })
  169. const onLoadSource = () => {
  170. if (bimChecked.value && !dbsChecked.value) {
  171. // BIM单屏模式
  172. return
  173. }
  174. loadSourceScene(sourceFrame, source.value.type < 2 ? 'kankan' : 'laser')
  175. }
  176. const onLoadTarget = () => {
  177. if (bimChecked.value) {
  178. loadTargetScene(targetFrame, 'bim')
  179. } else {
  180. loadTargetScene(targetFrame, target.value.type < 2 ? 'kankan' : 'laser', mode.value)
  181. }
  182. }
  183. const onModeChange = targetMode => {
  184. window.Log('changeMode:' + targetMode, '#3cffff')
  185. if (sync.sourceInst) {
  186. sync.sourceInst.loaded.then(sdk => sdk.scene.changeMode(targetMode))
  187. mode.value = targetMode
  188. }
  189. }
  190. const onPickDate = name => {
  191. datepickName.value = name
  192. }
  193. const onSelected = data => {
  194. if (!data.payload) {
  195. return
  196. }
  197. let { name, payload } = data
  198. let date = payload.format('YYYY-mm-dd')
  199. let dates = (name == 'source' ? sourceDays : targetDays).value.dates.map(item => item.format('YYYY-mm-dd'))
  200. if (dates.indexOf(date) != -1) {
  201. let time = payload.format('YYYY-mm-dd HH:MM')
  202. let find = scenes.value.find(c => c.createTime.indexOf(time) != -1)
  203. if (find) {
  204. if (name == 'source') {
  205. if (find.num != source.value.num) {
  206. source.value = find
  207. }
  208. } else {
  209. if (find.num != target.value.num) {
  210. target.value = find
  211. }
  212. }
  213. }
  214. }
  215. datepickName.value = null
  216. }
  217. const onPrevDate = name => {
  218. let scene = null
  219. if (name == 'source') {
  220. scene = source
  221. } else {
  222. scene = target
  223. }
  224. let index = scenes.value.findIndex(item => item.num == scene.value.num)
  225. if (index == -1) {
  226. return
  227. }
  228. if (--index == -1) {
  229. index = scenes.value.length - 1
  230. }
  231. if (target.value) {
  232. // 分屏模式判断
  233. if (name == 'source') {
  234. if (scenes.value[index].createTime == target.value.createTime) {
  235. index--
  236. }
  237. } else {
  238. if (scenes.value[index].createTime == source.value.createTime) {
  239. index--
  240. }
  241. }
  242. if (index == -1) {
  243. index = scenes.value.length - 1
  244. }
  245. }
  246. scene.value = scenes.value[index]
  247. }
  248. const onNextDate = name => {
  249. let scene = null
  250. if (name == 'source') {
  251. scene = source
  252. } else {
  253. scene = target
  254. }
  255. let index = scenes.value.findIndex(item => item.num == scene.value.num)
  256. if (index == -1) {
  257. return
  258. }
  259. if (++index > scenes.value.length - 1) {
  260. index = 0
  261. }
  262. if (target.value) {
  263. // 分屏模式判断
  264. if (name == 'source') {
  265. if (scenes.value[index].createTime == target.value.createTime) {
  266. index++
  267. }
  268. } else {
  269. if (scenes.value[index].createTime == source.value.createTime) {
  270. index++
  271. }
  272. }
  273. if (index > scenes.value.length - 1) {
  274. index = 0
  275. }
  276. }
  277. scene.value = scenes.value[index]
  278. }
  279. // bim点击
  280. const onBimChecked = () => {
  281. if (!project.value || !project.value.bimData) {
  282. showBimTips.value = true
  283. return
  284. }
  285. if (bimChecked.value) {
  286. bimChecked.value = false
  287. if (dbsChecked.value) {
  288. // 如果没有多场景数据,取消分屏
  289. if (scenes.value.length < 2) {
  290. onDbsChecked()
  291. return
  292. }
  293. // 判断是否分屏状态
  294. let index = scenes.value.findIndex(item => item.num == source.value.num)
  295. if (index == -1) {
  296. return
  297. }
  298. if (++index > scenes.value.length - 1) {
  299. index = 0
  300. }
  301. target.value = scenes.value[index]
  302. }
  303. } else {
  304. bimChecked.value = true
  305. }
  306. }
  307. // 分屏点击
  308. const onDbsChecked = () => {
  309. if (!dbsChecked.value && scenes.value.length < 2 && !bimChecked.value) {
  310. showDbsTips.value = true
  311. return
  312. }
  313. dbsChecked.value = !dbsChecked.value
  314. if (dbsChecked.value) {
  315. if (bimChecked.value) {
  316. // BIM分屏
  317. source.value = scenes.value[0]
  318. target.value = project.value.bimData
  319. } else {
  320. // 四维看看、激光场景分屏
  321. let index = scenes.value.findIndex(item => item.num == source.value.num)
  322. if (index == -1) {
  323. return
  324. }
  325. if (++index > scenes.value.length - 1) {
  326. index = 0
  327. }
  328. target.value = scenes.value[index]
  329. }
  330. } else {
  331. target.value = null
  332. //targetApp = null
  333. views.clear()
  334. }
  335. }
  336. // 全屏点击
  337. const onFscChecked = () => {
  338. let element = document.documentElement
  339. fscChecked.value = !fscChecked.value
  340. if (fscChecked.value) {
  341. if (element.requestFullscreen) {
  342. element.requestFullscreen()
  343. } else if (element.webkitRequestFullScreen) {
  344. element.webkitRequestFullScreen()
  345. } else if (element.mozRequestFullScreen) {
  346. element.mozRequestFullScreen()
  347. } else if (element.msRequestFullscreen) {
  348. element.msRequestFullscreen()
  349. }
  350. } else {
  351. if (document.exitFullscreen) {
  352. document.exitFullscreen()
  353. } else if (document.webkitCancelFullScreen) {
  354. document.webkitCancelFullScreen()
  355. } else if (document.mozCancelFullScreen) {
  356. document.mozCancelFullScreen()
  357. } else if (document.msExitFullscreen) {
  358. document.msExitFullscreen()
  359. }
  360. }
  361. }
  362. const onPointsUpdate = type => {
  363. points.value[type] = true
  364. }
  365. onMounted(() => {
  366. const num = browser.valueFromUrl('m') || ''
  367. const projectId = browser.valueFromUrl('projectId') || 1
  368. http.get(`smart-site/project/info?projectId=${projectId}`)
  369. .then(response => {
  370. if (response.success) {
  371. if (response.data) {
  372. if (response.data.panos) {
  373. try {
  374. response.data.panos = JSON.parse(response.data.panos)
  375. points.value.p1 = true
  376. points.value.p2 = true
  377. setPanoWithBim(response.data.panos)
  378. } catch (error) {
  379. console.error(error)
  380. }
  381. }
  382. project.value = response.data
  383. if (project.value.sceneList.length) {
  384. if (num) {
  385. source.value = project.value.sceneList.find(c => c.num == num)
  386. }
  387. if (!source.value) {
  388. source.value = project.value.sceneList[0]
  389. }
  390. if (showAdjust.value || showSplit.value) {
  391. onBimChecked()
  392. nextTick(() => onDbsChecked())
  393. } else if (showBim.value) {
  394. onBimChecked()
  395. }
  396. }
  397. }
  398. } else {
  399. alert('获取数据失败')
  400. }
  401. })
  402. .catch(() => {
  403. alert('服务器连接失败')
  404. })
  405. })
  406. </script>
  407. <style lang="scss" scoped>
  408. article {
  409. display: flex;
  410. width: 100%;
  411. height: 100%;
  412. overflow: hidden;
  413. }
  414. aside {
  415. width: 160px;
  416. height: 100%;
  417. background-color: rgba(0, 0, 0, 0.8);
  418. h4 {
  419. font-size: 16px;
  420. text-align: center;
  421. }
  422. ul {
  423. margin-top: 20px;
  424. }
  425. li {
  426. margin: 0;
  427. padding: 0;
  428. font-size: 16px;
  429. margin-left: 20px;
  430. cursor: pointer;
  431. &:hover,
  432. &.active {
  433. color: #00c8af;
  434. }
  435. }
  436. }
  437. main {
  438. flex: 1;
  439. width: 100%;
  440. height: 100%;
  441. position: relative;
  442. display: flex;
  443. &.full {
  444. .split {
  445. width: 50%;
  446. }
  447. }
  448. iframe {
  449. position: absolute;
  450. left: 0;
  451. top: 0;
  452. z-index: 1000;
  453. width: 100%;
  454. height: 100%;
  455. }
  456. .split {
  457. margin-left: 2px;
  458. width: 100%;
  459. height: 100%;
  460. overflow: hidden;
  461. position: relative;
  462. &:first-child,
  463. &:last-child {
  464. margin-left: 0;
  465. }
  466. .points {
  467. position: absolute;
  468. left: 50%;
  469. top: 64px;
  470. z-index: 9999;
  471. display: flex;
  472. transform: translateX(-50%);
  473. div {
  474. margin-left: 20px;
  475. width: 70px;
  476. height: 88px;
  477. background: rgba(27, 27, 28, 0.8);
  478. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25), inset 0px 0px 0px 2px rgba(255, 255, 255, 0.1);
  479. border-radius: 8px 8px 8px 8px;
  480. opacity: 1;
  481. border: 1px solid #000000;
  482. display: flex;
  483. flex-direction: column;
  484. align-items: center;
  485. justify-content: center;
  486. &.active {
  487. color: #0076f6;
  488. }
  489. i {
  490. font-size: 24px;
  491. }
  492. span {
  493. font-size: 16px;
  494. margin-top: 10px;
  495. }
  496. }
  497. }
  498. }
  499. .model {
  500. position: absolute;
  501. left: 50px;
  502. bottom: 40px;
  503. z-index: 1000;
  504. display: flex;
  505. flex-direction: column;
  506. > div {
  507. cursor: pointer;
  508. width: 50px;
  509. height: 50px;
  510. margin-top: 16px;
  511. background: rgba(27, 27, 28, 0.8);
  512. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
  513. border-radius: 47px 47px 47px 47px;
  514. border: 1px solid #000000;
  515. display: flex;
  516. flex-direction: column;
  517. align-items: center;
  518. justify-content: center;
  519. > div {
  520. width: 100%;
  521. height: 100%;
  522. display: flex;
  523. flex-direction: column;
  524. align-items: center;
  525. justify-content: center;
  526. }
  527. &.active {
  528. color: #0076f6;
  529. }
  530. &.disable {
  531. opacity: 0.5;
  532. }
  533. span {
  534. font-size: 12px;
  535. padding-top: 1px;
  536. transform: scale(0.8);
  537. }
  538. }
  539. }
  540. .tools {
  541. position: absolute;
  542. width: 100%;
  543. bottom: 40px;
  544. z-index: 2000;
  545. display: flex;
  546. justify-content: center;
  547. align-items: center;
  548. color: #fff;
  549. pointer-events: none;
  550. > div {
  551. pointer-events: all;
  552. }
  553. .item-mode {
  554. height: 50px;
  555. background: rgba(27, 27, 28, 0.8);
  556. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
  557. border-radius: 47px 47px 47px 47px;
  558. border: 1px solid #000000;
  559. display: flex;
  560. justify-content: center;
  561. align-items: center;
  562. margin-left: 10px;
  563. margin-right: 10px;
  564. font-size: 16px;
  565. padding: 0 16px;
  566. div {
  567. cursor: pointer;
  568. font-size: 18px;
  569. }
  570. div:last-child {
  571. margin-left: 20px;
  572. }
  573. div.active {
  574. color: #0076f6;
  575. }
  576. }
  577. }
  578. }
  579. </style>
  580. <style lang="scss">
  581. #app {
  582. background-color: rgba(0, 0, 0, 0.8);
  583. display: flex;
  584. flex-direction: column;
  585. }
  586. .vuejs3-datepicker__calendar {
  587. background: rgba(27, 27, 28, 0.8);
  588. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
  589. border-radius: 4px 4px 4px 4px;
  590. opacity: 1;
  591. border: 1px solid #000000;
  592. filter: blur(undefinedpx);
  593. color: #fff;
  594. }
  595. .vuejs3-datepicker__calendar-topbar {
  596. display: none !important;
  597. }
  598. .vuejs3-datepicker__calendar header .up:not(.disabled):hover {
  599. background: rgba(0, 0, 0, 0.3);
  600. color: #fff;
  601. }
  602. .vuejs3-datepicker__calendar header .prev:after {
  603. border-left: 1px solid #fff;
  604. border-bottom: 1px solid #fff;
  605. }
  606. .vuejs3-datepicker__calendar header .prev:not(.disabled):hover {
  607. background: rgba(0, 0, 0, 0.3);
  608. }
  609. .vuejs3-datepicker__calendar header .next:after {
  610. border-top: 1px solid #fff;
  611. border-right: 1px solid #fff;
  612. }
  613. .vuejs3-datepicker__calendar header .next:not(.disabled):hover {
  614. background: rgba(0, 0, 0, 0.3);
  615. }
  616. .highlighted {
  617. background: #4ebde1 !important;
  618. }
  619. .selected {
  620. background: #0076f6 !important;
  621. }
  622. </style>