index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. <template>
  2. <div class="panocon">
  3. <template v-if="showInfo">
  4. <iframe allowfullscreen="true" v-if="activeItem.type=='4dkk'"
  5. :src="`/spc.html?m=${activeItem.sceneCode}`" frameborder="0"></iframe>
  6. <div v-show="activeItem.type!='4dkk'" id="pano"></div>
  7. <div class="pano-logo" v-if="showInfo.isLogo&&activeItem.type!='4dkk'">
  8. <img :src="showInfo.logo||require('@/assets/images/default/img_logoshow@2x.png')" alt="" />
  9. </div>
  10. <div
  11. class="oper-tips"
  12. :class="{ hidetips: !showTips }"
  13. v-if="localRemind"
  14. >
  15. <img
  16. :src="
  17. showInfo.pcIcon ||
  18. require('@/assets/images/default/show/img_tipspc_default.png')
  19. "
  20. alt=""
  21. />
  22. </div>
  23. <list v-if="canLoad" @select="handleSelect" :select="activeItem"></list>
  24. <password
  25. :bg="showInfo.icon"
  26. :show="showPassword"
  27. @submit="handlePassword"
  28. @close="showPassword = false"
  29. />
  30. <popup :title="'简介'" :show="showIntro" @close="showIntro = false">
  31. <div slot="content" class="introcon">
  32. {{ showInfo.description || "暂无简介" }}
  33. </div>
  34. </popup>
  35. <preview
  36. :item="currentHotspot"
  37. :show="showPreview"
  38. @close="showPreview = false"
  39. />
  40. <ul class="aside" v-if="activeItem.type!='4dkk'">
  41. <li v-for="(item, i) in aside" :key="i">
  42. <span @click="handleItem(item)">
  43. <i class="iconfont" :class="item.icon"></i>
  44. </span>
  45. </li>
  46. </ul>
  47. </template>
  48. <template v-else>
  49. <div class="hasDel" v-if="loadFinish">
  50. <div>
  51. <img :src="$noresult" alt="">
  52. <p>作品已被删除</p>
  53. </div>
  54. </div>
  55. </template>
  56. </div>
  57. </template>
  58. <script>
  59. import * as krfn from "@/core/index.js";
  60. import { getPanoInfo, checkPassword,checkWork } from "@/api";
  61. import password from "./popup/password";
  62. import preview from "./popup/preview";
  63. import { $smallWaiting } from '@/components/shared/loading'
  64. import popup from "./popup/";
  65. import { mapGetters } from "vuex";
  66. import list from "./list";
  67. let __krfn = krfn.default;
  68. export default {
  69. components: {
  70. list,
  71. password,
  72. popup,
  73. preview,
  74. },
  75. computed: {
  76. ...mapGetters({
  77. showInfo: "showInfo",
  78. }),
  79. },
  80. data() {
  81. return {
  82. showPreview: false,
  83. isFullscreen:false,
  84. showTips: false,
  85. canLoad: false,
  86. loadFinish:false,
  87. showPassword: false,
  88. showIntro: false,
  89. localRemind: false,
  90. password: "",
  91. activeItem: "",
  92. someData: "",
  93. currentHotspot: "",
  94. list: [],
  95. aside: [
  96. {
  97. id: "about",
  98. icon: "icontool_about",
  99. },
  100. {
  101. id: "vr",
  102. icon: "icontool_vr",
  103. },
  104. {
  105. id: "full",
  106. icon: "icontool_full",
  107. },
  108. ],
  109. };
  110. },
  111. methods: {
  112. onFullScreen() {
  113. let element = document.documentElement;
  114. if (this.isFullscreen) {
  115. if (document.exitFullscreen) {
  116. document.exitFullscreen();
  117. } else if (document.webkitCancelFullScreen) {
  118. document.webkitCancelFullScreen();
  119. } else if (document.mozCancelFullScreen) {
  120. document.mozCancelFullScreen();
  121. } else if (document.msExitFullscreen) {
  122. document.msExitFullscreen();
  123. }
  124. } else {
  125. if (element.requestFullscreen) {
  126. element.requestFullscreen();
  127. } else if (element.webkitRequestFullScreen) {
  128. element.webkitRequestFullScreen();
  129. } else if (element.mozRequestFullScreen) {
  130. element.mozRequestFullScreen();
  131. } else if (element.msRequestFullscreen) {
  132. element.msRequestFullscreen();
  133. }
  134. }
  135. // 改变当前全屏状态
  136. this.isFullscreen = !this.isFullscreen;
  137. },
  138. handleItem(data) {
  139. if (data.id == "about") {
  140. this.showIntro = true;
  141. }
  142. if (data.id == "full") {
  143. this.onFullScreen()
  144. }
  145. if (data.id == "vr") {
  146. var krpano = document.getElementById("krpanoSWFObject");
  147. var webvr = krpano.get("webvr");
  148. webvr.entervr();
  149. // window.webvr.enterVR()
  150. }
  151. },
  152. handlePassword(data) {
  153. checkPassword(
  154. {
  155. password: data,
  156. },
  157. (res) => {
  158. if (res.code == 0) {
  159. this.showPassword = false;
  160. this.canLoad = true;
  161. }
  162. }
  163. );
  164. },
  165. startLoad() {
  166. this.canLoad = true;
  167. },
  168. handleSelect(data) {
  169. this.activeItem = data;
  170. },
  171. fixData() {
  172. let tmp = [];
  173. this.showInfo.scenes.forEach((item) => {
  174. this.showInfo.catalogs.forEach((sub) => {
  175. if (item.category == sub.id) {
  176. tmp.push(sub);
  177. }
  178. });
  179. });
  180. tmp = this.$unique(tmp)
  181. this.showInfo.catalogs = tmp;
  182. let rootmp = [];
  183. tmp.forEach((item) => {
  184. this.showInfo.catalogRoot.forEach((sub) => {
  185. sub.children = this.$unique(sub.children)
  186. if (sub.children.indexOf(item.id) > -1) {
  187. rootmp.push(sub);
  188. }
  189. });
  190. });
  191. rootmp = this.$unique(rootmp)
  192. this.showInfo.catalogRoot = rootmp.map((item) => {
  193. let temp = [];
  194. item.children = this.$unique(item.children)
  195. item.children.forEach((sub) => {
  196. tmp.forEach((jj) => {
  197. if (jj.id == sub) {
  198. temp.push(sub);
  199. }
  200. });
  201. });
  202. return {
  203. ...item,
  204. children: temp,
  205. };
  206. });
  207. this.showInfo.catalogs = tmp
  208. let cid = 'c_'+this.$randomWord(true,8,8)
  209. if (this.showInfo.catalogRoot.length <= 0) {
  210. this.showInfo.catalogRoot.push({
  211. id: 'r_'+this.$randomWord(true,8,8),
  212. name: "全部场景",
  213. children:[cid]
  214. });
  215. }
  216. if (this.showInfo.catalogs.length <= 0) {
  217. this.showInfo.catalogs.push({
  218. id: cid,
  219. name: "默认二级分组",
  220. });
  221. }
  222. if (this.showInfo.firstScene) {
  223. this.showInfo.firstScene = this.showInfo.scenes.find(item=>item.sceneCode==this.showInfo.firstScene.sceneCode)
  224. }
  225. this.$store.commit("SetShowInfo", this.showInfo);
  226. },
  227. getSceneInfo() {
  228. checkWork("",data=>{
  229. if (data.data) {
  230. getPanoInfo(
  231. "",
  232. (res) => {
  233. this.$store.commit("SetShowInfo", res);
  234. this.fixData()
  235. this.loadFinish = true
  236. }
  237. );
  238. } else{
  239. this.loadFinish = true
  240. }
  241. })
  242. }
  243. },
  244. watch: {
  245. currentHotspot: {
  246. deep: true,
  247. handler: function (newVal) {
  248. if (newVal) {
  249. if (newVal.hotspotType == "link") {
  250. window.open(newVal.hyperlink, "_blank");
  251. return;
  252. }
  253. if (newVal.hotspotType == "scene") {
  254. this.activeItem = newVal.secne;
  255. return;
  256. }
  257. this.showPreview = true;
  258. }
  259. },
  260. },
  261. canLoad(newVal) {
  262. if (newVal) {
  263. setTimeout(() => {
  264. this.showTips = this.localRemind
  265. setTimeout(() => {
  266. this.showTips = false;
  267. }, this.showInfo.remindTime * 1000);
  268. }, 1000);
  269. }
  270. },
  271. showInfo: {
  272. deep: true,
  273. immediate: true,
  274. handler: function (newVal) {
  275. if (newVal) {
  276. document.title = newVal.name || '无标题'
  277. let locoR = "localRemind"+newVal.id
  278. if (!newVal.description) {
  279. this.aside.shift()
  280. }
  281. if (newVal.isRemind==1) {
  282. this.localRemind = localStorage.getItem(locoR) == 1 ? false : true
  283. localStorage.setItem(locoR, 1);
  284. }
  285. else{
  286. this.localRemind = true;
  287. localStorage.setItem(locoR, 0);
  288. }
  289. if (this.showInfo.firstScene) {
  290. if (this.showInfo.firstScene.type == '4dkk') {
  291. this.localRemind = false;
  292. }
  293. }
  294. newVal.password ? (this.showPassword = true) : this.startLoad();
  295. }
  296. },
  297. },
  298. activeItem: {
  299. handler(newVal) {
  300. $("#pano").empty();
  301. window.vrInitFn = () => {
  302. $smallWaiting.hide()
  303. var krpano = document.getElementById("krpanoSWFObject");
  304. __krfn.utils.initHotspot(krpano, newVal && newVal.someData, false);
  305. };
  306. window.vrViewFn = () => {
  307. try {
  308. let tmp = newVal.initVisual||{};
  309. var krpano = document.getElementById("krpanoSWFObject");
  310. krpano.set("view.vlookat", tmp.vlookat||0);
  311. krpano.set("view.hlookat", tmp.hlookat||0);
  312. krpano.set("autorotate.enabled", Boolean(this.showInfo.isAuto));
  313. } catch (error) {
  314. error;
  315. }
  316. };
  317. var settings = {
  318. "events[skin_events].onxmlcomplete": "js(window.vrViewFn());",
  319. "events[skin_events].onloadcomplete": "js(window.vrInitFn());",
  320. };
  321. if (newVal) {
  322. if (newVal.type=='4dkk') {
  323. removepano("#pano");
  324. $("#pano").empty();
  325. return
  326. }
  327. removepano("#pano");
  328. $smallWaiting.show()
  329. embedpano({
  330. // xml: "%HTMLPATH%/static/template/tour.xml",
  331. xml: `${this.$cdn}/720yun_fd_manage/${newVal.sceneCode}/vtour/tour.xml`,
  332. swf: "%HTMLPATH%/static/template/tour.swf",
  333. target: "pano",
  334. html5: "auto",
  335. mobilescale: 1,
  336. vars: settings,
  337. passQueryParameters: true,
  338. });
  339. }
  340. },
  341. },
  342. },
  343. mounted() {
  344. window.__krfn = __krfn;
  345. this.$bus.on("clickHotspot", (data) => {
  346. let someData = JSON.parse(this.activeItem.someData);
  347. let idx = someData.hotspots.findIndex((item) => item.name == data);
  348. this.currentHotspot = someData.hotspots[idx];
  349. });
  350. this.getSceneInfo();
  351. },
  352. };
  353. </script>
  354. <style lang="less" scoped>
  355. .panocon {
  356. width: 100%;
  357. height: 100%;
  358. .hasDel{
  359. background: #fff;
  360. width: 100%;
  361. height: 100%;
  362. position: relative;
  363. >div{
  364. position: absolute;
  365. top: 50%;
  366. left: 50%;
  367. transform: translate(-50%,-50%);
  368. color: #909090;
  369. text-align: center;
  370. font-size: 18px;
  371. >p{
  372. margin-top: 20px;
  373. }
  374. }
  375. }
  376. #pano {
  377. width: 100%;
  378. height: 100%;
  379. }
  380. >iframe{
  381. width: 100%;
  382. height: 100%;
  383. }
  384. .pano-logo {
  385. position: absolute;
  386. top: 20px;
  387. left: 20px;
  388. > img {
  389. max-width: 120px;
  390. max-height: 100px;
  391. pointer-events: none;
  392. }
  393. }
  394. .oper-tips {
  395. position: absolute;
  396. top: 50%;
  397. left: 50%;
  398. transform: translate(-50%, -50%);
  399. transition: display 0.3s ease;
  400. > img {
  401. max-width: 300px;
  402. }
  403. }
  404. .hidetips {
  405. display: none;
  406. }
  407. .aside {
  408. position: fixed;
  409. z-index: 999;
  410. right: 10px;
  411. top: 50%;
  412. transform: translateY(-50%);
  413. > li {
  414. margin: 5px 0;
  415. > span {
  416. width: 36px;
  417. height: 36px;
  418. display: inline-block;
  419. background: rgba(0, 0, 0, 0.3);
  420. border: 1px solid rgba(255, 255, 255, 0.2);
  421. opacity: 1;
  422. border-radius: 18px;
  423. position: relative;
  424. cursor: pointer;
  425. > i {
  426. position: absolute;
  427. top: 50%;
  428. left: 50%;
  429. transform: translate(-50%, -50%);
  430. }
  431. }
  432. }
  433. }
  434. .introcon {
  435. line-height: 20px;
  436. word-break: break-all;
  437. text-align: justify;
  438. }
  439. }
  440. </style>