index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  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. peopleData:null,
  46. petData:null,
  47. redBoxData:null,
  48. bgMusicData:null,
  49. scale:1,
  50. }
  51. },
  52. props:{
  53. videoUrl: {
  54. type: String,
  55. default: '',
  56. },
  57. bgUrl: {
  58. type: String,
  59. default: '',
  60. },
  61. muted: {
  62. type: [Boolean,String],
  63. default: true,
  64. },
  65. // scale: {
  66. // type: [Number,String],
  67. // default: 1,
  68. // },
  69. coordinate: {
  70. type: String,
  71. default: '',
  72. },
  73. },
  74. watch: {
  75. videoUrl: {
  76. handler(newVal,oldVal) {
  77. if (newVal && newVal.length>0) {
  78. console.warn("***videoUrl-webgl_rxdz_krpanoVideo***", newVal,oldVal)
  79. if(this.sceneLoaded){
  80. // this.playVideo(newVal)
  81. }
  82. }
  83. },
  84. immediate:true,
  85. },
  86. bgUrl: {
  87. handler(newVal,oldVal) {
  88. console.warn("***bgUrl-webgl_rxdz_krpanoVideo***", newVal,oldVal)
  89. if(this.panoramicKrpano){
  90. this.setSphereUrl(newVal)
  91. }
  92. },
  93. immediate: true,
  94. },
  95. muted: {
  96. handler(newVal,oldVal) {
  97. console.warn("***muted-webgl_rxdz_krpanoVideo***", newVal,oldVal)
  98. if(this.panoramicKrpano){
  99. this.panoramicKrpano.call(`toggleMute(${newVal})`);
  100. let video = this.panoramicKrpano.get("hotspot[video]");
  101. if(video && video.visible){
  102. console.warn("**peopleAtv***",video.ath,video.atv)
  103. }
  104. }
  105. },
  106. immediate: true,
  107. },
  108. // coordinate: {
  109. // handler(newVal,oldVal) {
  110. // console.warn("***coordinate-webgl_rxdz_krpanoVideo***", newVal,oldVal)
  111. // },
  112. // immediate: true,
  113. // },
  114. },
  115. methods: {
  116. redBoxChange(type){
  117. // console.warn("**redBoxChange****",type)
  118. if(type=='add'){
  119. let url = "https://dm.static.elab-plus.com/miniProgram/redbox.mp4"
  120. if(this.$parent.isIOS){
  121. wx.config({
  122. debug: false,
  123. appId: '',
  124. timestamp: '',
  125. nonceStr: '',
  126. signature: '',
  127. jsApiList: []
  128. })
  129. wx.ready(()=> {
  130. // 在这里面进行操作即可,估计应该是微信的sdk对Safari的内核做了一些对应的操作吧
  131. this.panoramicKrpano.call(`showRedBox(${url})`);
  132. })
  133. }else{
  134. this.panoramicKrpano.call(`showRedBox(${url})`);
  135. }
  136. }else if(type=='canel'){
  137. this.panoramicKrpano.call(`hideRedBox()`);
  138. }
  139. },
  140. scaleChange(scale,tabIndex){
  141. console.warn("**scaleChange****",scale,tabIndex)
  142. if(tabIndex==0){//数字人
  143. this.panoramicKrpano.call(`scalePeopleChange(${scale})`);
  144. let image_hotspot = this.panoramicKrpano.get("hotspot[image_hotspot]");
  145. if(image_hotspot){
  146. image_hotspot.scale = scale;
  147. }
  148. this.scale = scale;//缩放比例
  149. }else if(tabIndex==1){//数字宠物
  150. this.panoramicKrpano.call(`scalePetChange(${scale})`);
  151. }
  152. },
  153. initPeople(item){
  154. if(item.url){
  155. this.playVideo(item.url)
  156. }
  157. if(item.scale){
  158. this.panoramicKrpano.call(`scalePeopleChange(${item.scale})`);
  159. let image_hotspot = this.panoramicKrpano.get("hotspot[image_hotspot]");
  160. if(image_hotspot){
  161. image_hotspot.scale = item.scale;
  162. }
  163. this.scale = item.scale;
  164. }
  165. if(item.ath){
  166. let object = this.panoramicKrpano.get("hotspot[video]");
  167. object.ath = item.ath;
  168. object.atv = item.atv;
  169. let image_hotspot = this.panoramicKrpano.get("hotspot[image_hotspot]");
  170. if(image_hotspot){
  171. image_hotspot.ath = item.ath;
  172. image_hotspot.atv = item.atv;
  173. }
  174. //移动视角到AI人物上
  175. this.panoramicKrpano.set('view.hlookat', item.ath);
  176. this.panoramicKrpano.set('view.vlookat', item.atv);
  177. }
  178. if(item.deg){
  179. this.panoramicKrpano.call(`rotateVideo(${item.deg})`);
  180. }
  181. },
  182. initPet(item){
  183. if(item.url){
  184. this.playPetVideo(item.url)
  185. }
  186. if(item.scale){
  187. this.panoramicKrpano.call(`scalePetChange(${item.scale})`);
  188. }
  189. if(item.ath){
  190. let object = this.panoramicKrpano.get("hotspot[petVideo]");
  191. object.ath = item.ath;
  192. object.atv = item.atv;
  193. }
  194. },
  195. initRedBox(item){
  196. if(item.url){
  197. this.redBoxChange('add')
  198. }
  199. if(item.ath){
  200. let object = this.panoramicKrpano.get("hotspot[redBox]");
  201. object.ath = item.ath;
  202. object.atv = item.atv;
  203. }
  204. },
  205. initbgMusic(item){
  206. if(item.url){
  207. this.playBgMusic(item.url)
  208. }
  209. },
  210. rotateVideo(deg){
  211. this.panoramicKrpano.call(`rotateVideo(${deg})`);
  212. },
  213. updataVideoSize(item){
  214. //如果存在视频尺寸
  215. if(!item.width || !item.height){
  216. item.width = 180;
  217. item.height = 320;
  218. }
  219. let object = this.panoramicKrpano.get("hotspot[video]");
  220. let image_hotspot = this.panoramicKrpano.get("hotspot[image_hotspot]");
  221. if(Number(item.width)>= Number(item.height)){//横屏
  222. let realWidth = 480;
  223. let realHeight = item.height/(item.width/480);
  224. object.width = realWidth;
  225. object.height = realHeight;
  226. object.scale = this.scale;
  227. if(image_hotspot){
  228. // let _scale = realWidth/640;
  229. image_hotspot.width = realWidth;
  230. image_hotspot.height = realHeight;
  231. image_hotspot.scale = this.scale;
  232. image_hotspot.url = 'https://dm.static.elab-plus.com/miniProgram/shadow22.png';
  233. }
  234. }else{//竖直版视频
  235. let realWidth = 180;
  236. let realHeight = item.height/(item.width/180);
  237. object.width = realWidth;
  238. object.height = realHeight;
  239. object.scale = this.scale;
  240. if(image_hotspot){
  241. // let _scale = realWidth/360;
  242. image_hotspot.width = realWidth;
  243. image_hotspot.height = realHeight;
  244. image_hotspot.scale = this.scale;
  245. image_hotspot.url = 'https://dm.static.elab-plus.com/miniProgram/shadow11.png';
  246. }
  247. }
  248. console.warn("**updataVideoSize****",item.width,item.height,Number(item.width)>= Number(item.height),this.scale);
  249. },
  250. aiChange(item,type,tabIndex){
  251. console.warn("**aiChange****",item,type,tabIndex)
  252. if(tabIndex==0){
  253. if(type=='add'){
  254. this.playVideo(item.url);
  255. this.updataVideoSize(item);
  256. }else if(type=='canel'){
  257. this.stopPeopleVideo()
  258. }
  259. }else if(tabIndex==1){
  260. if(type=='add'){
  261. this.playPetVideo(item.url)
  262. }else if(type=='canel'){
  263. this.stopPetVideo()
  264. }
  265. }else if(tabIndex==3){
  266. if(type=='add'){
  267. this.playBgMusic(item.url)
  268. }else if(type=='canel'){
  269. this.stopBgMusic()
  270. }
  271. }
  272. },
  273. playVideo(url){
  274. if(this.$parent.isIOS){
  275. wx.config({
  276. debug: false,
  277. appId: '',
  278. timestamp: '',
  279. nonceStr: '',
  280. signature: '',
  281. jsApiList: []
  282. })
  283. wx.ready(()=> {
  284. // 在这里面进行操作即可,估计应该是微信的sdk对Safari的内核做了一些对应的操作吧
  285. this.panoramicKrpano.call(`playSceneName(${url})`);
  286. })
  287. }else{
  288. this.panoramicKrpano.call(`playSceneName(${url})`);
  289. }
  290. console.warn("***playSceneName-playVideo***")
  291. },
  292. stopPeopleVideo(){
  293. this.panoramicKrpano.call(`stopPeopleVideo()`);
  294. console.warn("***playSceneName-stopPeopleVideo***")
  295. },
  296. playPetVideo(url){
  297. // this.panoramicKrpano.call(`playPetVideo(${url})`);
  298. if(this.$parent.isIOS){
  299. wx.config({
  300. debug: false,
  301. appId: '',
  302. timestamp: '',
  303. nonceStr: '',
  304. signature: '',
  305. jsApiList: []
  306. })
  307. wx.ready(()=> {
  308. // 在这里面进行操作即可,估计应该是微信的sdk对Safari的内核做了一些对应的操作吧
  309. this.panoramicKrpano.call(`playPetVideo(${url})`);
  310. })
  311. }else{
  312. this.panoramicKrpano.call(`playPetVideo(${url})`);
  313. }
  314. console.warn("***playSceneName-playPetVideo***")
  315. },
  316. stopPetVideo(){
  317. this.panoramicKrpano.call(`stopPetVideo()`);
  318. console.warn("***playSceneName-stopPetVideo***")
  319. },
  320. playBgMusic(url){
  321. this.panoramicKrpano.call(`playBgMusic(${url},${this.muted})`);
  322. },
  323. stopBgMusic(url){
  324. this.panoramicKrpano.call(`closeVoice()`);
  325. },
  326. panoramic() {
  327. console.warn("***panoramicKrpano***",this.videoUrl)
  328. this.panoramicKrpano = document.getElementById('panoramic');
  329. if(this.bgUrl){
  330. // 设置全景图的路径
  331. this.setSphereUrl(this.bgUrl)
  332. }
  333. // 场景加载完毕了
  334. window.sceneload = ()=>{
  335. console.warn("***sceneLoad***")
  336. this.videoBefore = false;
  337. this.sceneLoaded = true;
  338. // this.playVideo();//播放绿幕视频
  339. setTimeout(()=>{
  340. if(this.peopleData && this.peopleData.ath){
  341. this.initPeople(this.peopleData)
  342. this.updataVideoSize(this.peopleData);
  343. }
  344. if(this.petData && this.petData.ath){
  345. this.initPet(this.petData)
  346. }
  347. if(this.redBoxData && this.redBoxData.ath){
  348. this.initRedBox(this.redBoxData)
  349. }
  350. if(this.bgMusicData && this.bgMusicData.url){
  351. this.initbgMusic(this.bgMusicData)
  352. }
  353. console.warn("***sceneLoad1***",this.peopleData,this.petData,this.redBoxData,this.bgMusicData)
  354. },200)
  355. }
  356. // 视频加载完
  357. window.videoready = () => {
  358. console.warn("***videoready***",this.$parent.isIOS,this.isTouchstart)
  359. // 兼容苹果手机, 当视频加载完也算触屏了, 显示引导用户触屏
  360. if(this.$parent.isIOS){
  361. if (!this.isShowOneGuideMask) {
  362. // 视频加载完
  363. this.isTouchstart = true;
  364. }
  365. }
  366. };
  367. // 视频暂停了,自动刷新页面, 并且保存,当前的参数
  368. window.videopausedFunc = () => {
  369. }
  370. //红包被点击中了,说明抢到了红包
  371. window.toggleRedBox = () => {
  372. console.warn("***winLottery***")
  373. this.$parent.winLottery();//中奖了
  374. }
  375. //截图成功了
  376. window.show_img = (shotImg='',shareImg='') => {
  377. console.warn("***show_img***",shotImg,shareImg)
  378. let param = {
  379. type: 'CLK', //埋点类型
  380. clkId: 'clk_2cmina_23121401', //点击ID
  381. clkName: 'webgl_cover_clk', //点击前往的页面名称
  382. clkParams: {
  383. locusName: "封面确认",
  384. locusValue: shotImg
  385. }
  386. };
  387. util.trackRequest(param);
  388. this.$parent.closeToast();
  389. if(window.__wxjs_environment === 'miniprogram'){
  390. wx.miniProgram.postMessage({data: {bgUrl:shotImg,shareImg:shareImg}})
  391. wx.miniProgram.navigateBack();
  392. }else{
  393. // window.location.href = shottingImg;
  394. window.open(shotImg)
  395. }
  396. }
  397. // 视频播放
  398. window.onvideoplay = () => {
  399. console.warn("***onvideoplay***")
  400. }
  401. //针对手机端的处理
  402. document.addEventListener("touchend", ()=> {
  403. if(this.isShowOneGuideMask==false){
  404. this.isShowOneGuideMask = true;
  405. this.isTouchstart = true;
  406. }
  407. // console.warn("***kpanoraTouch***",this.isTouchstart)
  408. })
  409. //针对PC端的处理
  410. document.addEventListener("click", ()=> {
  411. if(this.isShowOneGuideMask==false){
  412. this.isShowOneGuideMask = true;
  413. this.isTouchstart = true;
  414. }
  415. // console.warn("***kpanoraTouch***",this.isTouchstart)
  416. })
  417. window.getScaleHandle = (scale) => {
  418. console.warn("***getScaleHandle***",scale)
  419. }
  420. },
  421. makescreenshot(){
  422. // let screenshotcanvas = this.panoramicKrpano.webGL("krpano[webGL]");
  423. let pix = 1 || window.devicePixelRatio;
  424. let x = parseInt(this.$parent.bottomLeftX*pix);
  425. let y = parseInt(this.$parent.top*pix);
  426. let width = parseInt(this.$parent.width*pix);
  427. let height = parseInt(this.$parent.height*pix);
  428. let hasRedBox = this.redBoxData && this.redBoxData.ath?true:false;
  429. console.warn("***screenshotcanvas***",x,y,width,height,hasRedBox)
  430. this.panoramicKrpano.call("makescreenshot("
  431. + x+','
  432. + y+','
  433. + width+','
  434. + height+','
  435. + hasRedBox+")");
  436. },
  437. // getScale(){
  438. // let video = this.panoramicKrpano.get("hotspot[video]");
  439. // console.warn("***getPeolpeScale***",video.scale);
  440. // },
  441. // getPetScale(){
  442. // let petVideo = this.panoramicKrpano.get("hotspot[petVideo]");
  443. // console.warn("***getPetScale***",petVideo.scale);
  444. // },
  445. getPosition(){
  446. let posi = {}
  447. let video = this.panoramicKrpano.get("hotspot[video]");
  448. if(video && video.visible){
  449. posi.peopleAth = video.ath;
  450. posi.peopleAtv = video.atv;
  451. }
  452. let petVideo = this.panoramicKrpano.get("hotspot[petVideo]");
  453. if(petVideo && petVideo.visible){
  454. posi.petAth = petVideo.ath;
  455. posi.petAtv = petVideo.atv;
  456. }
  457. let redBox = this.panoramicKrpano.get("hotspot[redBox]");
  458. if(redBox && redBox.visible){
  459. posi.redBoxAth = redBox.ath;
  460. posi.redBoxAtv = redBox.atv;
  461. }
  462. // console.warn("***getPosition***",posi);
  463. return posi
  464. },
  465. setPosition(position){
  466. let video = this.panoramicKrpano.get("hotspot[video]");
  467. let image_hotspot = this.panoramicKrpano.get("hotspot[image_hotspot]");
  468. video.ath = position.ath;
  469. video.atv = position.atv;
  470. if(image_hotspot){
  471. image_hotspot.ath = position.ath;
  472. image_hotspot.atv = position.atv;
  473. }
  474. //移动视角到AI人物上
  475. this.panoramicKrpano.set('view.hlookat', position.ath);
  476. this.panoramicKrpano.set('view.vlookat', position.atv);
  477. console.warn("***setPosition***",position);
  478. },
  479. //设置全景图图片地址
  480. setSphereUrl(url){
  481. if(!url){
  482. return false
  483. }
  484. this.panoramicKrpano.set("panorama_url",url)
  485. console.warn("***setSphereUrl***",url);
  486. },
  487. //设置视频地址
  488. // setVideoUrl(url){
  489. // if(!url){
  490. // return false
  491. // }
  492. // this.panoramicKrpano.set("video_url",url)
  493. // console.warn("***setVideoUrl***",url);
  494. // },
  495. },
  496. mounted() {
  497. embedpano({
  498. swf: "https://dm.static.elab-plus.com/krpano.swf",
  499. xml: this.$parent.pvCurPageName == 'add_AI_people' ? panoramicXML : panoramicNODragXML,
  500. bgcolor: "#fff",
  501. target: "panoramic-krpano",
  502. passQueryParameters: false,
  503. consolelog: true,
  504. id: "panoramic",
  505. mobilescale: 0.5, //移动设备缩放,1表示不缩放,默认0.5
  506. onready: this.panoramic,
  507. });
  508. this.scale = this.$parent.peopleScale;
  509. // console.warn("***mounted***",this.$route.query.AIPeople,this.$route.query.bgMusic);
  510. // this.peopleData = this.$route.query.AIPeople ? JSON.parse(this.$route.query.AIPeople) : {};
  511. // this.petData = this.$route.query.AIPet ? JSON.parse(this.$route.query.AIPet) : {};
  512. // this.redBoxData = this.$route.query.bgMusic ? JSON.parse(this.$route.query.bgMusic) : {};
  513. // this.bgMusicData = this.$route.query.redBox ? JSON.parse(this.$route.query.redBox) : {};
  514. },
  515. created() {
  516. console.warn("***this.type***")
  517. let screenWidth = window.screen.width;
  518. let screenHeight = window.screen.height;
  519. if (window.innerWidth && window.screen.width) {
  520. screenWidth = Math.min(window.innerWidth, window.screen.width)
  521. }
  522. if (window.innerHeight && window.screen.height) {
  523. screenHeight = Math.min(window.innerHeight, window.screen.height)
  524. }
  525. this.canvasHeight = this.$parent.pvCurPageName == 'add_AI_people' ? screenWidth : screenHeight;
  526. this.pvCurPageName = this.$parent.pvCurPageName
  527. // // 监听屏幕大小变化
  528. // window.addEventListener('resize', ()=>{
  529. // });
  530. },
  531. beforeDestroy() {
  532. // this.panoramicKrpano.call(`closeVoice()`);
  533. }
  534. }
  535. </script>
  536. <style scoped lang="scss">
  537. @import "index.scss";
  538. </style>