index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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.toString().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. redBoxChange(type){
  122. // console.warn("**redBoxChange****",type)
  123. if(type=='add'){
  124. let url = "https://dm.static.elab-plus.com/miniProgram/redbox.mp4"
  125. this.panoramicKrpano.call(`showRedBox(${url})`);
  126. }else if(type=='canel'){
  127. this.panoramicKrpano.call(`hideRedBox()`);
  128. }
  129. },
  130. scaleChange(scale,tabIndex){
  131. console.warn("**scaleChange****",scale,tabIndex)
  132. if(tabIndex==0){//数字人
  133. this.panoramicKrpano.call(`scalePeopleChange(${scale})`);
  134. }else if(tabIndex==1){//数字宠物
  135. this.panoramicKrpano.call(`scalePetChange(${scale})`);
  136. }
  137. },
  138. aiChange(item,type,tabIndex){
  139. console.warn("**aiChange****",item,type,tabIndex)
  140. if(tabIndex==0){
  141. if(type=='add'){
  142. this.playVideo(item.url)
  143. }else if(type=='canel'){
  144. this.stopPeopleVideo()
  145. }
  146. }else if(tabIndex==1){
  147. if(type=='add'){
  148. this.playPetVideo(item.url)
  149. }else if(type=='canel'){
  150. this.stopPetVideo()
  151. }
  152. }else if(tabIndex==3){
  153. if(type=='add'){
  154. this.playBgMusic(item.url)
  155. }else if(type=='canel'){
  156. this.stopBgMusic()
  157. }
  158. }
  159. },
  160. playVideo(url){
  161. this.panoramicKrpano.call(`playSceneName(${url})`);
  162. // wx.config({
  163. // debug: false,
  164. // appId: '',
  165. // timestamp: '',
  166. // nonceStr: '',
  167. // signature: '',
  168. // jsApiList: []
  169. // })
  170. // wx.ready(()=> {
  171. // // 在这里面进行操作即可,估计应该是微信的sdk对Safari的内核做了一些对应的操作吧
  172. // this.panoramicKrpano.call(`playSceneName(${this.videoUrl})`);
  173. // })
  174. console.warn("***playSceneName-playVideo***")
  175. },
  176. stopPeopleVideo(){
  177. this.panoramicKrpano.call(`stopPeopleVideo()`);
  178. console.warn("***playSceneName-stopPeopleVideo***")
  179. },
  180. playPetVideo(url){
  181. this.panoramicKrpano.call(`playPetVideo(${url})`);
  182. console.warn("***playSceneName-playPetVideo***")
  183. },
  184. stopPetVideo(){
  185. this.panoramicKrpano.call(`stopPetVideo()`);
  186. console.warn("***playSceneName-stopPetVideo***")
  187. },
  188. playBgMusic(url){
  189. this.panoramicKrpano.call(`playBgMusic(${url})`);
  190. },
  191. stopBgMusic(url){
  192. this.panoramicKrpano.call(`closeVoice()`);
  193. },
  194. panoramic() {
  195. console.warn("***panoramicKrpano***",this.videoUrl)
  196. this.panoramicKrpano = document.getElementById('panoramic');
  197. if(this.bgUrl){
  198. // 设置全景图的路径
  199. this.setSphereUrl(this.bgUrl)
  200. }
  201. // 场景加载完毕了
  202. window.sceneload = ()=>{
  203. console.warn("***sceneLoad***")
  204. this.videoBefore = false;
  205. this.sceneLoaded = true;
  206. // this.playVideo();//播放绿幕视频
  207. if(this.coordinate){
  208. let position = JSON.parse(this.coordinate);
  209. if(position.ath && position.atv){
  210. this.setPosition(position);
  211. }
  212. }
  213. }
  214. // 视频加载完
  215. window.videoready = () => {
  216. console.warn("***videoready***",this.$parent.isIOS,this.isTouchstart)
  217. // 兼容苹果手机, 当视频加载完也算触屏了, 显示引导用户触屏
  218. if(this.$parent.isIOS){
  219. if (!this.isShowOneGuideMask) {
  220. // 视频加载完
  221. this.isTouchstart = true;
  222. }
  223. }
  224. };
  225. // 视频暂停了,自动刷新页面, 并且保存,当前的参数
  226. window.videopausedFunc = () => {
  227. }
  228. //截图成功了
  229. window.show_img = (shottingImg) => {
  230. console.warn("***show_img***",shottingImg)
  231. let param = {
  232. type: 'CLK', //埋点类型
  233. clkId: 'clk_2cmina_23121401', //点击ID
  234. clkName: 'webgl_cover_clk', //点击前往的页面名称
  235. clkParams: {
  236. locusName: "封面确认",
  237. locusValue: shottingImg
  238. }
  239. };
  240. util.trackRequest(param);
  241. if(window.__wxjs_environment === 'miniprogram'){
  242. wx.miniProgram.postMessage({data: {bgUrl:shottingImg}})
  243. wx.miniProgram.navigateBack();
  244. }else{
  245. window.location.href = shottingImg
  246. }
  247. }
  248. // 视频播放
  249. window.onvideoplay = () => {
  250. console.warn("***onvideoplay***")
  251. }
  252. document.addEventListener("touchend", ()=> {
  253. if(this.isShowOneGuideMask==false){
  254. this.isShowOneGuideMask = true;
  255. this.isTouchstart = true;
  256. }
  257. // console.warn("***kpanoraTouch***",this.isTouchstart)
  258. })
  259. window.getScaleHandle = (scale) => {
  260. console.warn("***getScaleHandle***",scale)
  261. }
  262. },
  263. makescreenshot(){
  264. // let screenshotcanvas = this.panoramicKrpano.webGL("krpano[webGL]");
  265. let pix = 1 || window.devicePixelRatio;
  266. let x = parseInt(this.$parent.bottomLeftX*pix);
  267. let y = parseInt(this.$parent.top*pix);
  268. let width = parseInt(this.$parent.width*pix);
  269. let height = parseInt(this.$parent.height*pix);
  270. console.warn("***screenshotcanvas***",x,y,width,height)
  271. this.panoramicKrpano.call("makescreenshot("
  272. + x+','
  273. + y+','
  274. + width+','
  275. + height+")");
  276. },
  277. // getScale(){
  278. // let video = this.panoramicKrpano.get("hotspot[video]");
  279. // console.warn("***getPeolpeScale***",video.scale);
  280. // },
  281. // getPetScale(){
  282. // let petVideo = this.panoramicKrpano.get("hotspot[petVideo]");
  283. // console.warn("***getPetScale***",petVideo.scale);
  284. // },
  285. getPosition(){
  286. let posi = {}
  287. let video = this.panoramicKrpano.get("hotspot[video]");
  288. if(video && video.visible){
  289. posi.peopleAth = video.ath;
  290. posi.peopleAtv = video.atv;
  291. }
  292. let petVideo = this.panoramicKrpano.get("hotspot[petVideo]");
  293. if(petVideo && petVideo.visible){
  294. posi.petAth = petVideo.ath;
  295. posi.petAtv = petVideo.atv;
  296. }
  297. let redBox = this.panoramicKrpano.get("hotspot[redBox]");
  298. if(redBox && redBox.visible){
  299. posi.redBoxAth = redBox.ath;
  300. posi.redBoxAtv = redBox.atv;
  301. }
  302. // console.warn("***getPosition***",posi);
  303. return posi
  304. },
  305. setPosition(position){
  306. let video = this.panoramicKrpano.get("hotspot[video]");
  307. let image_hotspot = this.panoramicKrpano.get("hotspot[image_hotspot]");
  308. video.ath = position.ath;
  309. video.atv = position.atv;
  310. if(image_hotspot){
  311. image_hotspot.ath = position.ath;
  312. image_hotspot.atv = position.atv;
  313. }
  314. //移动视角到AI人物上
  315. this.panoramicKrpano.set('view.hlookat', position.ath);
  316. this.panoramicKrpano.set('view.vlookat', position.atv);
  317. console.warn("***setPosition***",position);
  318. },
  319. //设置全景图图片地址
  320. setSphereUrl(url){
  321. if(!url){
  322. return false
  323. }
  324. this.panoramicKrpano.set("panorama_url",url)
  325. console.warn("***setSphereUrl***",url);
  326. },
  327. //设置视频地址
  328. // setVideoUrl(url){
  329. // if(!url){
  330. // return false
  331. // }
  332. // this.panoramicKrpano.set("video_url",url)
  333. // console.warn("***setVideoUrl***",url);
  334. // },
  335. },
  336. mounted() {
  337. embedpano({
  338. swf: "https://dm.static.elab-plus.com/krpano.swf",
  339. xml: this.$parent.pvCurPageName == 'add_AI_people' ? panoramicXML : panoramicNODragXML,
  340. bgcolor: "#fff",
  341. target: "panoramic-krpano",
  342. passQueryParameters: false,
  343. consolelog: true,
  344. id: "panoramic",
  345. mobilescale: 0.5, //移动设备缩放,1表示不缩放,默认0.5
  346. onready: this.panoramic,
  347. });
  348. },
  349. created() {
  350. console.warn("***this.type***")
  351. let screenWidth = window.screen.width;
  352. let screenHeight = window.screen.height;
  353. if (window.innerWidth && window.screen.width) {
  354. screenWidth = Math.min(window.innerWidth, window.screen.width)
  355. }
  356. if (window.innerHeight && window.screen.height) {
  357. screenHeight = Math.min(window.innerHeight, window.screen.height)
  358. }
  359. this.canvasHeight = this.$parent.pvCurPageName == 'add_AI_people' ? screenWidth : screenHeight;
  360. this.pvCurPageName = this.$parent.pvCurPageName
  361. // // 监听屏幕大小变化
  362. // window.addEventListener('resize', ()=>{
  363. // });
  364. },
  365. beforeDestroy() {
  366. // this.panoramicKrpano.call(`closeVoice()`);
  367. }
  368. }
  369. </script>
  370. <style scoped lang="scss">
  371. @import "index.scss";
  372. </style>