index.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. <template>
  2. <!-- @touchstart="touchstartFunc" -->
  3. <div class="panoramic-components">
  4. <!-- 刷新按钮 -->
  5. <!-- <div class="refresh-btn" @click="refreshPage">
  6. <img src="https://dm.static.elab-plus.com/refresh-btn.png">
  7. </div> -->
  8. <!-- 引导用户 触屏图片 -->
  9. <div v-if="pvCurPageName!='webgl_clipImg'" class="prompt-720-img" :class="isTouchstart ? 'img-hide' : ''">
  10. <img src="https://dm.static.elab-plus.com/guide-mask.png" />
  11. </div>
  12. <!-- 封面引导 蒙层图 -->
  13. <div class="krpano-img-before" :class="videoBefore ? '' : 'hide'">
  14. <img src="https://dm.static.elab-plus.com/hqc-loading.png" />
  15. </div>
  16. <!-- <div class="play-img" :class="isPlayImg ? 'play-img-show': ''">
  17. <img src="https://dm.static.elab-plus.com/hqc-img/play-img.png" />
  18. </div> -->
  19. <!-- 免责声明 -->
  20. <!-- <div class="disclaimer">
  21. <a
  22. href="https://dm-mng.elab-plus.cn/touFangBao/index.html#/pages/preview?id=3176&templateCode=0&brandId=52&foot=no">本资料仅供宣传参考示意</a>
  23. </div> -->
  24. <!-- krpano -->
  25. <div id="panoramic-krpano" :style="{'height':canvasHeight+'px'}"></div>
  26. </div>
  27. </template>
  28. <script>
  29. // import BScroll from 'better-scroll';
  30. const panoramicXML = require("./panoramic.xml");
  31. const panoramicNODragXML = require("./panoramic_no_drag.xml");
  32. const util = require('@/utils/util.js').default;
  33. export default {
  34. data() {
  35. return {
  36. tabList: [],
  37. selectTabIndex: 0,
  38. isPayVoice: false,
  39. isPromptShow: true,
  40. sceneObj: { id: '', name: '' },
  41. isTouchstart: false, // 是否触屏一次
  42. isShowOneGuideMask: false, //是否显示过一次引导用户出的操作
  43. videoBefore: true,//显示引导蒙层图
  44. sceneLoaded:false,//场景是否加载完毕了
  45. }
  46. },
  47. props:{
  48. videoUrl: {
  49. type: String,
  50. default: '',
  51. },
  52. bgUrl: {
  53. type: String,
  54. default: '',
  55. },
  56. muted: {
  57. type: [Boolean,String],
  58. default: true,
  59. },
  60. scale: {
  61. type: [Number,String],
  62. default: 1,
  63. },
  64. coordinate: {
  65. type: String,
  66. default: '',
  67. },
  68. },
  69. watch: {
  70. videoUrl: {
  71. handler(newVal,oldVal) {
  72. if (newVal && newVal.length>0) {
  73. console.warn("***videoUrl-webgl_rxdz_krpanoVideo***", newVal,oldVal)
  74. if(this.sceneLoaded){
  75. this.playVideo(newVal)
  76. }
  77. }
  78. },
  79. immediate:true,
  80. },
  81. bgUrl: {
  82. handler(newVal,oldVal) {
  83. console.warn("***bgUrl-webgl_rxdz_krpanoVideo***", newVal,oldVal)
  84. if(this.panoramicKrpano){
  85. this.setSphereUrl(newVal)
  86. }
  87. },
  88. immediate: true,
  89. },
  90. muted: {
  91. handler(newVal,oldVal) {
  92. console.warn("***muted-webgl_rxdz_krpanoVideo***", newVal,oldVal)
  93. if(this.panoramicKrpano){
  94. this.panoramicKrpano.call(`toggleMute(${newVal})`);
  95. }
  96. },
  97. immediate: true,
  98. },
  99. scale: {
  100. handler(newVal,oldVal) {
  101. console.warn("***scale-webgl_rxdz_krpanoVideo***", newVal,'---',oldVal)
  102. if(this.panoramicKrpano){
  103. let sc = newVal;
  104. if(newVal.includes('{')){
  105. let scale = JSON.parse(newVal);
  106. sc = scale.x;
  107. }
  108. this.panoramicKrpano.call(`scaleChange(${sc})`);
  109. }
  110. },
  111. immediate: true,
  112. },
  113. coordinate: {
  114. handler(newVal,oldVal) {
  115. console.warn("***coordinate-webgl_rxdz_krpanoVideo***", newVal,oldVal)
  116. },
  117. immediate: true,
  118. },
  119. },
  120. methods: {
  121. playVideo(){
  122. this.panoramicKrpano.call(`playSceneName(${this.videoUrl})`);
  123. // wx.config({
  124. // debug: false,
  125. // appId: '',
  126. // timestamp: '',
  127. // nonceStr: '',
  128. // signature: '',
  129. // jsApiList: []
  130. // })
  131. // wx.ready(()=> {
  132. // // 在这里面进行操作即可,估计应该是微信的sdk对Safari的内核做了一些对应的操作吧
  133. // this.panoramicKrpano.call(`playSceneName(${this.videoUrl})`);
  134. // })
  135. console.warn("***playSceneName-playVideo***")
  136. },
  137. panoramic() {
  138. console.warn("***panoramicKrpano***",this.videoUrl)
  139. this.panoramicKrpano = document.getElementById('panoramic');
  140. if(this.bgUrl){
  141. // 设置全景图的路径
  142. this.setSphereUrl(this.bgUrl)
  143. }
  144. // 场景加载完毕了
  145. window.sceneload = ()=>{
  146. console.warn("***sceneLoad***")
  147. this.videoBefore = false;
  148. this.sceneLoaded = true;
  149. this.playVideo();//播放绿幕视频
  150. if(this.coordinate){
  151. let position = JSON.parse(this.coordinate);
  152. if(position.ath && position.atv){
  153. this.setPosition(position);
  154. }
  155. }
  156. }
  157. // 视频加载完
  158. window.videoready = () => {
  159. console.warn("***videoready***",this.$parent.isIOS,this.isTouchstart)
  160. // 兼容苹果手机, 当视频加载完也算触屏了, 显示引导用户触屏
  161. if(this.$parent.isIOS){
  162. if (!this.isShowOneGuideMask) {
  163. // 视频加载完
  164. this.isTouchstart = true;
  165. }
  166. }
  167. };
  168. // 视频暂停了,自动刷新页面, 并且保存,当前的参数
  169. window.videopausedFunc = () => {
  170. }
  171. //截图成功了
  172. window.show_img = (shottingImg) => {
  173. console.warn("***show_img***",shottingImg)
  174. let param = {
  175. type: 'CLK', //埋点类型
  176. clkId: 'clk_2cmina_23121401', //点击ID
  177. clkName: 'webgl_cover_clk', //点击前往的页面名称
  178. clkParams: {
  179. locusName: "封面确认",
  180. locusValue: shottingImg
  181. }
  182. };
  183. util.trackRequest(param);
  184. if(window.__wxjs_environment === 'miniprogram'){
  185. wx.miniProgram.postMessage({data: {bgUrl:shottingImg}})
  186. wx.miniProgram.navigateBack();
  187. }else{
  188. window.location.href = shottingImg
  189. }
  190. }
  191. // 视频播放
  192. window.onvideoplay = () => {
  193. console.warn("***onvideoplay***")
  194. }
  195. document.addEventListener("touchend", ()=> {
  196. if(this.isShowOneGuideMask==false){
  197. this.isShowOneGuideMask = true;
  198. this.isTouchstart = true;
  199. }
  200. // console.warn("***kpanoraTouch***",this.isTouchstart)
  201. })
  202. window.getScaleHandle = (scale) => {
  203. console.warn("***getScaleHandle***",scale)
  204. }
  205. },
  206. makescreenshot(){
  207. // let screenshotcanvas = this.panoramicKrpano.webGL("krpano[webGL]");
  208. let pix = 1 || window.devicePixelRatio;
  209. let x = parseInt(this.$parent.bottomLeftX*pix);
  210. let y = parseInt(this.$parent.top*pix);
  211. let width = parseInt(this.$parent.width*pix);
  212. let height = parseInt(this.$parent.height*pix);
  213. console.warn("***screenshotcanvas***",x,y,width,height)
  214. this.panoramicKrpano.call("makescreenshot("
  215. + x+','
  216. + y+','
  217. + width+','
  218. + height+")");
  219. },
  220. getScale(){
  221. let video = this.panoramicKrpano.get("hotspot[video]");
  222. console.warn("***getScale***",video.scale);
  223. },
  224. getPosition(){
  225. let video = this.panoramicKrpano.get("hotspot[video]");
  226. let posi = {
  227. ath:video.ath,
  228. atv:video.atv,
  229. }
  230. console.warn("***getPosition***",posi);
  231. return posi
  232. },
  233. setPosition(position){
  234. let video = this.panoramicKrpano.get("hotspot[video]");
  235. video.ath = position.ath;
  236. video.atv = position.atv;
  237. console.warn("***setPosition***",position);
  238. },
  239. //设置全景图图片地址
  240. setSphereUrl(url){
  241. if(!url){
  242. return false
  243. }
  244. this.panoramicKrpano.set("panorama_url",url)
  245. console.warn("***setSphereUrl***",url);
  246. },
  247. //设置视频地址
  248. setVideoUrl(url){
  249. if(!url){
  250. return false
  251. }
  252. this.panoramicKrpano.set("video_url",url)
  253. console.warn("***setVideoUrl***",url);
  254. },
  255. },
  256. mounted() {
  257. embedpano({
  258. swf: "https://dm.static.elab-plus.com/krpano.swf",
  259. xml: this.$parent.pvCurPageName == 'add_AI_people' ? panoramicXML : panoramicNODragXML,
  260. bgcolor: "#fff",
  261. target: "panoramic-krpano",
  262. passQueryParameters: false,
  263. consolelog: true,
  264. id: "panoramic",
  265. mobilescale: 0.5, //移动设备缩放,1表示不缩放,默认0.5
  266. onready: this.panoramic,
  267. });
  268. },
  269. created() {
  270. console.warn("***this.type***")
  271. let screenWidth = window.screen.width;
  272. let screenHeight = window.screen.height;
  273. if (window.innerWidth && window.screen.width) {
  274. screenWidth = Math.min(window.innerWidth, window.screen.width)
  275. }
  276. if (window.innerHeight && window.screen.height) {
  277. screenHeight = Math.min(window.innerHeight, window.screen.height)
  278. }
  279. this.canvasHeight = this.$parent.pvCurPageName == 'add_AI_people' ? screenWidth : screenHeight;
  280. this.pvCurPageName = this.$parent.pvCurPageName
  281. // // 监听屏幕大小变化
  282. // window.addEventListener('resize', ()=>{
  283. // });
  284. },
  285. beforeDestroy() {
  286. // this.panoramicKrpano.call(`closeVoice()`);
  287. }
  288. }
  289. </script>
  290. <style scoped lang="scss">
  291. @import "index.scss";
  292. </style>