index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <template>
  2. <div class="pano-body">
  3. <div class="none-center" v-show="!activeItem">请先上传或添加场景素材</div>
  4. <div v-show="activeItem" id="pano"></div>
  5. <template v-if="showSnapshot&&activeItem">
  6. <snapshot :showFlash="showFlash"></snapshot>
  7. <button class="ui-button submit" @click="onClick">将当前视角设为初始画面</button>
  8. </template>
  9. </div>
  10. </template>
  11. <script>
  12. import * as krfn from "@/core/index.js";
  13. import { uploadCover } from "@/api";
  14. import { $waiting } from '@/components/shared/loading'
  15. import { mapGetters } from "vuex";
  16. import Snapshot from "@/components/Snapshot";
  17. import config from "@/config";
  18. let __krfn = krfn.default;
  19. export default {
  20. components: { Snapshot },
  21. data() {
  22. return {
  23. activeItem:'',
  24. showFlash:false,
  25. someData:''
  26. };
  27. },
  28. computed: {
  29. ...mapGetters({
  30. info: "info",
  31. backupInfo: "backupInfo"
  32. }),
  33. showSnapshot() {
  34. return this.$route.name == "screen";
  35. },
  36. krpano() {
  37. return this.$getKrpano();
  38. },
  39. },
  40. methods: {
  41. updateInfo(){
  42. let iidx = this.info.scenes.findIndex(item=>this.activeItem.sceneCode == item.sceneCode)
  43. if (iidx>-1) {
  44. this.info.scenes[iidx] = {
  45. ...this.activeItem
  46. }
  47. }
  48. this.$store.commit("SetInfo", this.info);
  49. },
  50. onClick() {
  51. this.$bus.emit('toggleFlash',true)
  52. let canvas = $("#krpanoSWFObject canvas")[0];
  53. let krpano = document.getElementById('krpanoSWFObject');
  54. let data = __krfn.utils.setInitView(krpano, canvas);
  55. console.log(data.url);
  56. uploadCover(
  57. { file: data.url, filename: "initCover.jpg" },
  58. res => {
  59. if (res.code==0) {
  60. this.activeItem.icon = res.data
  61. this.activeItem.initVisual= {
  62. hlookat: data.hlookat,
  63. vlookat: data.vlookat
  64. }
  65. this.$bus.emit('toggleFlash',false)
  66. this.$bus.emit("initView", res.data);
  67. this.updateInfo()
  68. this.$msg.success("设置成功")
  69. this.$store.commit("SetInfo", this.info);
  70. }
  71. });
  72. },
  73. addhotspot(param) {
  74. let krpano = document.getElementById('krpanoSWFObject');
  75. __krfn.utils.addhotspot(krpano, param, true);
  76. }
  77. },
  78. watch:{
  79. '$route.name':function(newVal){
  80. let krpano = document.getElementById('krpanoSWFObject');
  81. __krfn.utils.toggleHotspot(krpano,newVal!='screen');
  82. },
  83. activeItem:{
  84. handler(newVal) {
  85. if (newVal) {
  86. this.$nextTick(()=>{
  87. this.$bus.emit("initView", newVal.icon);
  88. })
  89. }
  90. $('#pano').empty();
  91. window.vrInitFn = ()=>{
  92. $waiting.hide()
  93. var krpano = document.getElementById('krpanoSWFObject');
  94. __krfn.utils.initHotspot(krpano,newVal&&newVal.someData,true);
  95. __krfn.utils.toggleHotspot(krpano,this.$route.name!='screen');
  96. }
  97. window.vrViewFn = ()=>{
  98. try {
  99. let tmp = newVal.initVisual
  100. var krpano = document.getElementById('krpanoSWFObject');
  101. krpano.set('view.vlookat',tmp.vlookat);
  102. krpano.set('view.hlookat',tmp.hlookat);
  103. } catch (error) {
  104. error
  105. }
  106. }
  107. var settings = {
  108. 'events[skin_events].onxmlcomplete':'js(window.vrViewFn());',
  109. 'events[skin_events].onloadcomplete': 'js(window.vrInitFn());'
  110. };
  111. if(newVal){
  112. removepano('#pano')
  113. $waiting.show()
  114. embedpano({
  115. // http://oss-xiaoan.oss-cn-shenzhen.aliyuncs.com/720yun_fd_manage/fd720_Va0LrkXW3/vtour/tour.xml
  116. // xml: "%HTMLPATH%/static/template/tour.xml",
  117. xml: `${this.$cdn}/720yun_fd_manage/${newVal.sceneCode}/vtour/tour.xml`,
  118. swf: "%HTMLPATH%/static/template/tour.swf",
  119. target: "pano",
  120. html5: "auto",
  121. mobilescale: 1,
  122. vars:settings,
  123. webglsettings: { preserveDrawingBuffer: true },
  124. passQueryParameters: true,
  125. });
  126. // $waiting.hide()
  127. }
  128. },
  129. immediate: true
  130. }
  131. },
  132. mounted() {
  133. window.__krfn = __krfn;
  134. this.$bus.on('currentPcode',data=>{
  135. this.activeItem = data
  136. })
  137. this.$bus.on("addhotspot", data => {
  138. this.addhotspot(data);
  139. });
  140. },
  141. };
  142. </script>
  143. <style lang="less" scoped>
  144. .pano-body {
  145. width: 100%;
  146. position: relative;
  147. height: 100%;
  148. .none-center{
  149. position: absolute;
  150. top: 50%;
  151. left: 50%;
  152. transform: translate(-50%,-50%);
  153. }
  154. #pano {
  155. width: 100%;
  156. height: 100%;
  157. }
  158. .btn {
  159. position: absolute;
  160. top: 20px;
  161. left: 20px;
  162. background: #000;
  163. cursor: pointer;
  164. }
  165. .ui-button {
  166. position: absolute;
  167. bottom: 20px;
  168. min-width: 200px;
  169. left: 50%;
  170. transform: translateX(-50%);
  171. z-index: 99;
  172. }
  173. }
  174. </style>