SViewer.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. <template>
  2. <main>
  3. <iframe ref="sourceFrame" v-if="sourceURL" :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-if="source" 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 , setPanoWithBim} from '@/utils/sync'
  31. // 点位信息
  32. let lastFakeApp = null
  33. let panoData
  34. // 是否BIM模式
  35. const showBim = ref(browser.urlHasValue('bim'))
  36. const showBimTips = ref(false)
  37. const showTips = ref(null)
  38. const bimChecked = ref(null)
  39. const sourceFrame = ref(null)
  40. const mode = ref(0)
  41. const source = ref(null)
  42. const target = ref(null)
  43. const project = ref(null)
  44. const scenes = computed(() => {
  45. if (!project.value) {
  46. return []
  47. }
  48. return project.value.sceneList.map(item => {
  49. return {
  50. num: item.num,
  51. type: item.type,
  52. createTime: item.createTime,
  53. }
  54. })
  55. })
  56. const sourceURL = computed(() => {
  57. /*if (source.value.type < 2) {
  58. let pose = ''
  59. // 获取当前点位旋转值
  60. if (sourceFrame.value && sourceFrame.value.contentWindow.app && sourceFrame.value.contentWindow.app.Camera) {
  61. let sdk = sourceFrame.value.contentWindow.app
  62. lastFakeApp = sync.views.createFakeApp(sourceFrame.value.contentWindow, true);
  63. //pose = '&'+sdk.Camera.getPoseUrlParams()
  64. }
  65. // 看看、看见场景
  66. return `smart-kankan.html?m=${source.value.num}`//`smart-kankan.html?m=${source.value.num}${pose}`
  67. } else {
  68. // 深时场景
  69. return `smart-kankan.html?m=${source.value.num}`//`smart-laser.html?m=${source.value.num}&dev`
  70. }*/
  71. if(lastFakeApp/*sourceFrame.value && (bimChecked.value || sourceFrame.value.contentWindow.app || sourceFrame.value.contentWindow.loaded)*/){
  72. sync.views.fakeAppUpdateView(sourceFrame.value.contentWindow)
  73. }
  74. if(bimChecked.value){
  75. return `smart-bim.html?m=${project.value.bimData.bimOssFilePath}`
  76. }
  77. if(!source.value){
  78. return
  79. }
  80. if(source.value.type < 2) {
  81. return `smart-kankan.html?m=${source.value.num}`
  82. } else {
  83. return `smart-laser.html?m=${source.value.num}&dev`
  84. }
  85. })
  86. const onLoadSource = () => {
  87. let win = sourceFrame.value.contentWindow
  88. window.app = win
  89. let loaded = ()=>{
  90. if (lastFakeApp) {
  91. if(bimChecked.value || lastFakeApp.sceneType == 'bim'){//->bim
  92. sync.views.bindFakeWithBim(lastFakeApp, win, panoData)
  93. }else{
  94. sync.views.bindWithSameFakeType(lastFakeApp,win)
  95. }
  96. }
  97. if(project.value.sceneList.length) {
  98. lastFakeApp = sync.views.createFakeApp(sourceFrame.value.contentWindow);
  99. }
  100. }
  101. if(bimChecked.value){//bim
  102. win.sceneType = 'bim'
  103. win.loaded.then(sdk => {
  104. loaded()
  105. })
  106. }else if (source.value.type < 2) {
  107. win.sceneType = 'kankan'
  108. let sdk = win.app
  109. sdk.Scene.on('loaded', () => {
  110. loaded()
  111. })
  112. }else{
  113. win.sceneType = 'laser'
  114. win.loaded.then(sdk => {
  115. sync.views.laserCancelFly(app)//win.viewer.images360.cancelFlyToPano()
  116. loaded();
  117. setTimeout(()=>{//laser的代码中莫名会请求showPointCloud,所以尽量晚一点覆盖它
  118. if(win.Potree){
  119. win.Potree.settings.displayMode = mode.value == 0 ? "showPanos" : "showPointCloud"
  120. }
  121. }, sync.views.settings.checkModeDelay)
  122. })
  123. }
  124. }
  125. const sourceDate = computed(() => {
  126. if (source.value) {
  127. return source.value.createTime.toDate()
  128. }
  129. })
  130. const sourceDays = computed(() => {
  131. const outDays = { year: [], month: [], day: [] }
  132. if (!scenes.value) {
  133. return outDays
  134. }
  135. const inDays = scenes.value.map(item => item.createTime.split(' ')[0].split('-'))
  136. inDays.forEach(item => {
  137. const [year, month, day] = item
  138. if (outDays.year.indexOf(year) == -1) {
  139. outDays.year.push(year)
  140. }
  141. if (outDays.month.indexOf(month) == -1) {
  142. outDays.month.push(month)
  143. }
  144. if (outDays.day.indexOf(day) == -1) {
  145. outDays.day.push(day)
  146. }
  147. })
  148. return outDays
  149. })
  150. const onModeChange = targetMode => {
  151. if (sourceFrame.value && sourceFrame.value.contentWindow.loaded) {
  152. sourceFrame.value.contentWindow.loaded.then(sdk => sdk.scene.changeMode(targetMode))
  153. mode.value = targetMode
  154. }
  155. }
  156. const onSelected = data => {
  157. if (!data.payload) {
  158. return
  159. }
  160. let { payload } = data
  161. let time = payload.format('YYYY-mm-dd')
  162. let find = scenes.value.find(c => c.createTime.indexOf(time) != -1)
  163. if (find) {
  164. if (find.num != source.value.num) {
  165. source.value = find
  166. }
  167. }
  168. }
  169. const onPrevDate = name => {
  170. let index = scenes.value.findIndex(item => item.num == source.value.num)
  171. if (index == -1) {
  172. return
  173. }
  174. if (--index == -1) {
  175. index = scenes.value.length - 1
  176. }
  177. source.value = scenes.value[index]
  178. }
  179. const onNextDate = name => {
  180. let index = scenes.value.findIndex(item => item.num == source.value.num)
  181. if (index == -1) {
  182. return
  183. }
  184. if (++index > scenes.value.length - 1) {
  185. index = 0
  186. }
  187. source.value = scenes.value[index]
  188. }
  189. // bim点击
  190. const onBimChecked = () => {
  191. showBimTips.value = true
  192. setTimeout(() => {
  193. showBimTips.value = false
  194. }, 2000)
  195. if (!project.value || !project.value.bimData) {
  196. showTips.value = '未发现BIM文件'
  197. return
  198. }
  199. if (bimChecked.value) {
  200. bimChecked.value = false
  201. showBimTips.value = false
  202. } else {
  203. bimChecked.value = true
  204. }
  205. }
  206. onMounted(() => {
  207. const projectId = browser.valueFromUrl('projectId') || 1
  208. http.get(`smart-site/project/info?projectId=${projectId}&sceneOrder=asc`)
  209. .then(response => {
  210. if (response.success) {
  211. project.value = response.data
  212. if (showBim.value) {
  213. onBimChecked()
  214. }
  215. if (project.value.sceneList.length) {
  216. source.value = project.value.sceneList[0]
  217. }
  218. if(response.data.panos){
  219. response.data.panos = JSON.parse(response.data.panos)
  220. panoData = response.data.panos //convert with bim
  221. }
  222. } else {
  223. showTips.value = response.message
  224. }
  225. })
  226. .catch(err => {
  227. showTips.value = '服务器连接失败'
  228. })
  229. })
  230. </script>
  231. <style lang="scss" scoped>
  232. main {
  233. width: 100%;
  234. height: 100%;
  235. iframe {
  236. width: 100%;
  237. height: 100%;
  238. }
  239. .tools {
  240. position: absolute;
  241. width: 100%;
  242. bottom: 40px;
  243. z-index: 2000;
  244. display: flex;
  245. justify-content: center;
  246. align-items: center;
  247. color: #fff;
  248. pointer-events: none;
  249. > div {
  250. pointer-events: all;
  251. }
  252. .item-mode {
  253. height: 50px;
  254. background: rgba(27, 27, 28, 0.8);
  255. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
  256. border-radius: 47px 47px 47px 47px;
  257. border: 1px solid #000000;
  258. display: flex;
  259. justify-content: center;
  260. align-items: center;
  261. margin-left: 10px;
  262. margin-right: 10px;
  263. font-size: 16px;
  264. padding: 0 16px;
  265. div {
  266. cursor: pointer;
  267. font-size: 18px;
  268. }
  269. div:last-child {
  270. margin-left: 20px;
  271. }
  272. div.active {
  273. color: #0076f6;
  274. }
  275. }
  276. }
  277. .model {
  278. position: absolute;
  279. left: 15px;
  280. top: 20px;
  281. z-index: 1000;
  282. display: flex;
  283. flex-direction: column;
  284. span {
  285. position: absolute;
  286. left: 130%;
  287. top: 48%;
  288. background: rgba(27, 27, 28, 0.8);
  289. padding: 4px;
  290. border-radius: 4px;
  291. color: #fff;
  292. &::before {
  293. content: '';
  294. position: absolute;
  295. right: 100%;
  296. top: 50%;
  297. margin-top: -7px;
  298. width: 0;
  299. height: 0;
  300. border-top: 7px solid transparent;
  301. border-right: 14px solid rgba(27, 27, 28, 0.8);
  302. border-bottom: 7px solid transparent;
  303. }
  304. }
  305. > div {
  306. cursor: pointer;
  307. width: 50px;
  308. height: 50px;
  309. margin-top: 16px;
  310. background: rgba(27, 27, 28, 0.8);
  311. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
  312. border-radius: 47px 47px 47px 47px;
  313. border: 1px solid #000000;
  314. display: flex;
  315. flex-direction: column;
  316. align-items: center;
  317. justify-content: center;
  318. > div {
  319. width: 100%;
  320. height: 100%;
  321. display: flex;
  322. flex-direction: column;
  323. align-items: center;
  324. justify-content: center;
  325. }
  326. &.active {
  327. color: #0076f6;
  328. }
  329. &.disable {
  330. opacity: 0.5;
  331. }
  332. i {
  333. font-size: 20px;
  334. }
  335. }
  336. }
  337. }
  338. </style>
  339. <style lang="scss">
  340. #app {
  341. background-color: rgba(0, 0, 0, 0.8);
  342. display: flex;
  343. flex-direction: column;
  344. }
  345. </style>