index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  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. // this.scale = 1;//这里要注意,当2D模式下,绿幕视频隐射到canvas的关系暂不清楚,似乎会放的很大?所以这里使用了极小的缩放值
  222. if(Number(item.width)>= Number(item.height)){//横屏
  223. let realWidth = 350;
  224. let realHeight = item.height/(item.width/realWidth);
  225. object.width = realWidth;
  226. object.height = realHeight;
  227. object.scale = this.scale;
  228. if(image_hotspot){
  229. // let _scale = realWidth/640;
  230. image_hotspot.width = realWidth;
  231. image_hotspot.height = realHeight;
  232. image_hotspot.scale = this.scale;
  233. image_hotspot.url = 'https://dm.static.elab-plus.com/miniProgram/shadow22.png';
  234. }
  235. }else{//竖直版视频
  236. let realWidth = 350;
  237. let realHeight = item.height/(item.width/realWidth);
  238. object.width = realWidth;
  239. object.height = realHeight;
  240. object.scale = this.scale;
  241. if(image_hotspot){
  242. // let _scale = realWidth/360;
  243. image_hotspot.width = realWidth;
  244. image_hotspot.height = realHeight;
  245. image_hotspot.scale = this.scale;
  246. image_hotspot.url = 'https://dm.static.elab-plus.com/miniProgram/shadow11.png';
  247. }
  248. }
  249. console.warn("**updataVideoSize****",item.width,item.height,Number(item.width)>= Number(item.height),object.width,object.height,this.scale);
  250. },
  251. aiChange(item,type,tabIndex){
  252. console.warn("**aiChange****",item,type,tabIndex)
  253. if(tabIndex==0){
  254. if(type=='add'){
  255. this.playVideo(item.url);
  256. this.updataVideoSize(item);
  257. }else if(type=='canel'){
  258. this.stopPeopleVideo()
  259. }
  260. }else if(tabIndex==1){
  261. if(type=='add'){
  262. this.playPetVideo(item.url)
  263. }else if(type=='canel'){
  264. this.stopPetVideo()
  265. }
  266. }else if(tabIndex==3){
  267. if(type=='add'){
  268. this.playBgMusic(item.url)
  269. }else if(type=='canel'){
  270. this.stopBgMusic()
  271. }
  272. }
  273. },
  274. playVideo(url){
  275. if(this.$parent.isIOS){
  276. wx.config({
  277. debug: false,
  278. appId: '',
  279. timestamp: '',
  280. nonceStr: '',
  281. signature: '',
  282. jsApiList: []
  283. })
  284. wx.ready(()=> {
  285. // 在这里面进行操作即可,估计应该是微信的sdk对Safari的内核做了一些对应的操作吧
  286. this.panoramicKrpano.call(`playSceneName(${url})`);
  287. })
  288. }else{
  289. this.panoramicKrpano.call(`playSceneName(${url})`);
  290. }
  291. console.warn("***playSceneName-playVideo***")
  292. },
  293. stopPeopleVideo(){
  294. this.panoramicKrpano.call(`stopPeopleVideo()`);
  295. console.warn("***playSceneName-stopPeopleVideo***")
  296. },
  297. playPetVideo(url){
  298. // this.panoramicKrpano.call(`playPetVideo(${url})`);
  299. if(this.$parent.isIOS){
  300. wx.config({
  301. debug: false,
  302. appId: '',
  303. timestamp: '',
  304. nonceStr: '',
  305. signature: '',
  306. jsApiList: []
  307. })
  308. wx.ready(()=> {
  309. // 在这里面进行操作即可,估计应该是微信的sdk对Safari的内核做了一些对应的操作吧
  310. this.panoramicKrpano.call(`playPetVideo(${url})`);
  311. })
  312. }else{
  313. this.panoramicKrpano.call(`playPetVideo(${url})`);
  314. }
  315. console.warn("***playSceneName-playPetVideo***")
  316. },
  317. stopPetVideo(){
  318. this.panoramicKrpano.call(`stopPetVideo()`);
  319. console.warn("***playSceneName-stopPetVideo***")
  320. },
  321. playBgMusic(url){
  322. this.panoramicKrpano.call(`playBgMusic(${url},${this.muted})`);
  323. },
  324. stopBgMusic(url){
  325. this.panoramicKrpano.call(`closeVoice()`);
  326. },
  327. panoramic() {
  328. console.warn("***panoramicKrpano***",this.videoUrl)
  329. this.panoramicKrpano = document.getElementById('panoramic');
  330. if(this.bgUrl){
  331. // 设置全景图的路径
  332. this.setSphereUrl(this.bgUrl)
  333. }
  334. // 场景加载完毕了
  335. window.sceneload = ()=>{
  336. console.warn("***sceneLoad***")
  337. this.videoBefore = false;
  338. this.sceneLoaded = true;
  339. // this.playVideo();//播放绿幕视频
  340. setTimeout(()=>{
  341. if(this.peopleData && this.peopleData.ath){
  342. this.initPeople(this.peopleData)
  343. this.updataVideoSize(this.peopleData);
  344. }
  345. if(this.petData && this.petData.ath){
  346. this.initPet(this.petData)
  347. }
  348. if(this.redBoxData && this.redBoxData.ath){
  349. this.initRedBox(this.redBoxData)
  350. }
  351. if(this.bgMusicData && this.bgMusicData.url){
  352. this.initbgMusic(this.bgMusicData)
  353. }
  354. console.warn("***sceneLoad1***",this.peopleData,this.petData,this.redBoxData,this.bgMusicData)
  355. },200)
  356. }
  357. // 视频加载完
  358. window.videoready = () => {
  359. console.warn("***videoready***",this.$parent.isIOS,this.isTouchstart)
  360. // 兼容苹果手机, 当视频加载完也算触屏了, 显示引导用户触屏
  361. if(this.$parent.isIOS){
  362. if (!this.isShowOneGuideMask) {
  363. // 视频加载完
  364. this.isTouchstart = true;
  365. }
  366. }
  367. };
  368. // 视频暂停了,自动刷新页面, 并且保存,当前的参数
  369. window.videopausedFunc = () => {
  370. }
  371. //红包被点击中了,说明抢到了红包
  372. window.toggleRedBox = () => {
  373. console.warn("***winLottery***")
  374. this.$parent.winLottery();//中奖了
  375. }
  376. //截图成功了
  377. window.show_img = (shotImg='',shareImg='') => {
  378. console.warn("***show_img***",shotImg,shareImg)
  379. let param = {
  380. type: 'CLK', //埋点类型
  381. clkId: 'clk_2cmina_23121401', //点击ID
  382. clkName: 'webgl_cover_clk', //点击前往的页面名称
  383. clkParams: {
  384. locusName: "封面确认",
  385. locusValue: shotImg
  386. }
  387. };
  388. util.trackRequest(param);
  389. this.$parent.closeToast();
  390. if(window.__wxjs_environment === 'miniprogram'){
  391. wx.miniProgram.postMessage({data: {bgUrl:shotImg,shareImg:shareImg}})
  392. wx.miniProgram.navigateBack();
  393. }else{
  394. // window.location.href = shottingImg;
  395. window.open(shotImg)
  396. }
  397. }
  398. // 视频播放
  399. window.onvideoplay = () => {
  400. console.warn("***onvideoplay***")
  401. }
  402. //针对手机端的处理
  403. document.addEventListener("touchend", ()=> {
  404. if(this.isShowOneGuideMask==false){
  405. this.isShowOneGuideMask = true;
  406. this.isTouchstart = true;
  407. }
  408. // console.warn("***kpanoraTouch***",this.isTouchstart)
  409. })
  410. //针对PC端的处理
  411. document.addEventListener("click", ()=> {
  412. if(this.isShowOneGuideMask==false){
  413. this.isShowOneGuideMask = true;
  414. this.isTouchstart = true;
  415. }
  416. // console.warn("***kpanoraTouch***",this.isTouchstart)
  417. })
  418. window.getScaleHandle = (scale) => {
  419. console.warn("***getScaleHandle***",scale)
  420. }
  421. },
  422. makescreenshot(){
  423. // let screenshotcanvas = this.panoramicKrpano.webGL("krpano[webGL]");
  424. let pix = 1 || window.devicePixelRatio;
  425. let x = parseInt(this.$parent.bottomLeftX*pix);
  426. let y = parseInt(this.$parent.top*pix);
  427. let width = parseInt(this.$parent.width*pix);
  428. let height = parseInt(this.$parent.height*pix);
  429. let hasRedBox = this.redBoxData && this.redBoxData.ath?true:false;
  430. console.warn("***screenshotcanvas***",x,y,width,height,hasRedBox)
  431. this.panoramicKrpano.call("makescreenshot("
  432. + x+','
  433. + y+','
  434. + width+','
  435. + height+','
  436. + hasRedBox+")");
  437. },
  438. // getScale(){
  439. // let video = this.panoramicKrpano.get("hotspot[video]");
  440. // console.warn("***getPeolpeScale***",video.scale);
  441. // },
  442. // getPetScale(){
  443. // let petVideo = this.panoramicKrpano.get("hotspot[petVideo]");
  444. // console.warn("***getPetScale***",petVideo.scale);
  445. // },
  446. getPosition(){
  447. let posi = {}
  448. let video = this.panoramicKrpano.get("hotspot[video]");
  449. if(video && video.visible){
  450. posi.peopleAth = video.ath;
  451. posi.peopleAtv = video.atv;
  452. }
  453. let petVideo = this.panoramicKrpano.get("hotspot[petVideo]");
  454. if(petVideo && petVideo.visible){
  455. posi.petAth = petVideo.ath;
  456. posi.petAtv = petVideo.atv;
  457. }
  458. let redBox = this.panoramicKrpano.get("hotspot[redBox]");
  459. if(redBox && redBox.visible){
  460. posi.redBoxAth = redBox.ath;
  461. posi.redBoxAtv = redBox.atv;
  462. }
  463. // console.warn("***getPosition***",posi);
  464. return posi
  465. },
  466. setPosition(position){
  467. let video = this.panoramicKrpano.get("hotspot[video]");
  468. let image_hotspot = this.panoramicKrpano.get("hotspot[image_hotspot]");
  469. video.ath = position.ath;
  470. video.atv = position.atv;
  471. if(image_hotspot){
  472. image_hotspot.ath = position.ath;
  473. image_hotspot.atv = position.atv;
  474. }
  475. //移动视角到AI人物上
  476. this.panoramicKrpano.set('view.hlookat', position.ath);
  477. this.panoramicKrpano.set('view.vlookat', position.atv);
  478. console.warn("***setPosition***",position);
  479. },
  480. //设置全景图图片地址
  481. setSphereUrl(url){
  482. if(!url){
  483. return false
  484. }
  485. this.panoramicKrpano.set("panorama_url",url)
  486. console.warn("***setSphereUrl***",url);
  487. },
  488. //设置视频地址
  489. // setVideoUrl(url){
  490. // if(!url){
  491. // return false
  492. // }
  493. // this.panoramicKrpano.set("video_url",url)
  494. // console.warn("***setVideoUrl***",url);
  495. // },
  496. },
  497. mounted() {
  498. embedpano({
  499. swf: "https://dm.static.elab-plus.com/krpano.swf",
  500. xml: this.$parent.pvCurPageName == 'add_AI_people' ? panoramicXML : panoramicNODragXML,
  501. bgcolor: "#fff",
  502. target: "panoramic-krpano",
  503. passQueryParameters: false,
  504. consolelog: true,
  505. id: "panoramic",
  506. mobilescale: 0.5, //移动设备缩放,1表示不缩放,默认0.5
  507. onready: this.panoramic,
  508. });
  509. this.scale = this.$parent.peopleScale;
  510. // console.warn("***mounted***",this.$route.query.AIPeople,this.$route.query.bgMusic);
  511. // this.peopleData = this.$route.query.AIPeople ? JSON.parse(this.$route.query.AIPeople) : {};
  512. // this.petData = this.$route.query.AIPet ? JSON.parse(this.$route.query.AIPet) : {};
  513. // this.redBoxData = this.$route.query.bgMusic ? JSON.parse(this.$route.query.bgMusic) : {};
  514. // this.bgMusicData = this.$route.query.redBox ? JSON.parse(this.$route.query.redBox) : {};
  515. },
  516. created() {
  517. console.warn("***this.type***")
  518. let screenWidth = window.screen.width;
  519. let screenHeight = window.screen.height;
  520. if (window.innerWidth && window.screen.width) {
  521. screenWidth = Math.min(window.innerWidth, window.screen.width)
  522. }
  523. if (window.innerHeight && window.screen.height) {
  524. screenHeight = Math.min(window.innerHeight, window.screen.height)
  525. }
  526. this.canvasHeight = this.$parent.pvCurPageName == 'add_AI_people' ? screenWidth : screenHeight;
  527. this.pvCurPageName = this.$parent.pvCurPageName
  528. // // 监听屏幕大小变化
  529. // window.addEventListener('resize', ()=>{
  530. // });
  531. },
  532. beforeDestroy() {
  533. // this.panoramicKrpano.call(`closeVoice()`);
  534. }
  535. }
  536. </script>
  537. <style scoped lang="scss">
  538. @import "index.scss";
  539. </style>