SViewer.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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, {laserChangeMode, 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.fakeAppUpdateInfo(sourceFrame.value.contentWindow) //这两个怎么都会报错? bim的得不到app.viewer
  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.laserInit(win, mode.value)
  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. sync.views.laserChangeMode(mode.value)
  155. }
  156. }
  157. const onSelected = data => {
  158. if (!data.payload) {
  159. return
  160. }
  161. let { payload } = data
  162. let time = payload.format('YYYY-mm-dd')
  163. let find = scenes.value.find(c => c.createTime.indexOf(time) != -1)
  164. if (find) {
  165. if (find.num != source.value.num) {
  166. source.value = find
  167. }
  168. }
  169. }
  170. const onPrevDate = name => {
  171. let index = scenes.value.findIndex(item => item.num == source.value.num)
  172. if (index == -1) {
  173. return
  174. }
  175. if (--index == -1) {
  176. index = scenes.value.length - 1
  177. }
  178. source.value = scenes.value[index]
  179. }
  180. const onNextDate = name => {
  181. let index = scenes.value.findIndex(item => item.num == source.value.num)
  182. if (index == -1) {
  183. return
  184. }
  185. if (++index > scenes.value.length - 1) {
  186. index = 0
  187. }
  188. source.value = scenes.value[index]
  189. }
  190. // bim点击
  191. const onBimChecked = () => {
  192. showBimTips.value = true
  193. setTimeout(() => {
  194. showBimTips.value = false
  195. }, 2000)
  196. if (!project.value || !project.value.bimData) {
  197. showTips.value = '未发现BIM文件'
  198. return
  199. }
  200. if (bimChecked.value) {
  201. bimChecked.value = false
  202. showBimTips.value = false
  203. } else {
  204. bimChecked.value = true
  205. }
  206. }
  207. onMounted(() => {
  208. const projectId = browser.valueFromUrl('projectId') || 1
  209. http.get(`smart-site/project/info?projectId=${projectId}`)
  210. .then(response => {
  211. if (response.success) {
  212. project.value = response.data
  213. if (showBim.value) {
  214. onBimChecked()
  215. }
  216. if (project.value.sceneList.length) {
  217. source.value = project.value.sceneList[0]
  218. }
  219. if(response.data.panos){
  220. response.data.panos = JSON.parse(response.data.panos)
  221. panoData = response.data.panos //convert with bim
  222. }
  223. } else {
  224. showTips.value = response.message
  225. }
  226. })
  227. .catch(err => {
  228. showTips.value = '服务器连接失败'
  229. })
  230. })
  231. </script>
  232. <style lang="scss" scoped>
  233. main {
  234. width: 100%;
  235. height: 100%;
  236. iframe {
  237. width: 100%;
  238. height: 100%;
  239. }
  240. .tools {
  241. position: absolute;
  242. width: 100%;
  243. bottom: 40px;
  244. z-index: 2000;
  245. display: flex;
  246. justify-content: center;
  247. align-items: center;
  248. color: #fff;
  249. pointer-events: none;
  250. > div {
  251. pointer-events: all;
  252. }
  253. .item-mode {
  254. height: 50px;
  255. background: rgba(27, 27, 28, 0.8);
  256. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
  257. border-radius: 47px 47px 47px 47px;
  258. border: 1px solid #000000;
  259. display: flex;
  260. justify-content: center;
  261. align-items: center;
  262. margin-left: 10px;
  263. margin-right: 10px;
  264. font-size: 16px;
  265. padding: 0 16px;
  266. div {
  267. cursor: pointer;
  268. font-size: 18px;
  269. }
  270. div:last-child {
  271. margin-left: 20px;
  272. }
  273. div.active {
  274. color: #0076f6;
  275. }
  276. }
  277. }
  278. .model {
  279. position: absolute;
  280. left: 15px;
  281. top: 20px;
  282. z-index: 1000;
  283. display: flex;
  284. flex-direction: column;
  285. span {
  286. position: absolute;
  287. left: 130%;
  288. top: 48%;
  289. background: rgba(27, 27, 28, 0.8);
  290. padding: 4px;
  291. border-radius: 4px;
  292. color: #fff;
  293. &::before {
  294. content: '';
  295. position: absolute;
  296. right: 100%;
  297. top: 50%;
  298. margin-top: -7px;
  299. width: 0;
  300. height: 0;
  301. border-top: 7px solid transparent;
  302. border-right: 14px solid rgba(27, 27, 28, 0.8);
  303. border-bottom: 7px solid transparent;
  304. }
  305. }
  306. > div {
  307. cursor: pointer;
  308. width: 50px;
  309. height: 50px;
  310. margin-top: 16px;
  311. background: rgba(27, 27, 28, 0.8);
  312. box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
  313. border-radius: 47px 47px 47px 47px;
  314. border: 1px solid #000000;
  315. display: flex;
  316. flex-direction: column;
  317. align-items: center;
  318. justify-content: center;
  319. > div {
  320. width: 100%;
  321. height: 100%;
  322. display: flex;
  323. flex-direction: column;
  324. align-items: center;
  325. justify-content: center;
  326. }
  327. &.active {
  328. color: #0076f6;
  329. }
  330. &.disable {
  331. opacity: 0.5;
  332. }
  333. i {
  334. font-size: 20px;
  335. }
  336. }
  337. }
  338. }
  339. </style>
  340. <style lang="scss">
  341. #app {
  342. background-color: rgba(0, 0, 0, 0.8);
  343. display: flex;
  344. flex-direction: column;
  345. }
  346. </style>