Guide.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  1. <template>
  2. <div v-show="player.showWidgets" class="root-panel">
  3. <div class="guide-panel" >
  4. <div class="g-con">
  5. <div class="swiper-container" id="sw-guide">
  6. <ul class="swiper-wrapper" v-if="tours.length > 1">
  7. <li
  8. class="swiper-slide"
  9. :style="`background-image:url(${i.frameId ? common.changeUrl(i.list[i.frameId].enter.cover) : common.changeUrl(i.list[0].enter.cover)});`"
  10. :class="{ active: isPlay && partId == index }"
  11. @click="changeFrame(1, index)"
  12. v-for="(i, index) in tours"
  13. :key="index"
  14. >
  15. <div>{{ i.name }}</div>
  16. <span v-if="partId == index && progressNum > 0" class="bar" :style="{ '--w': progressNum + '%' }"></span>
  17. </li>
  18. </ul>
  19. <ul class="swiper-wrapper" v-else>
  20. <li
  21. class="swiper-slide"
  22. :style="`background-image:url(${common.changeUrl(i.enter.cover)});`"
  23. :class="{ active: isPlay && frameId == index }"
  24. @click="changeFrame(2, index)"
  25. v-for="(i, index) in tours[0].list"
  26. :key="index"
  27. >
  28. <div>{{ i.name }}</div>
  29. <span v-if="frameId == index && progressNum > 0" class="bar" :style="{ '--w': progressNum + '%' }"></span>
  30. </li>
  31. </ul>
  32. </div>
  33. <div class="back" @click.stop="playTour">
  34. <ui-icon type="back"></ui-icon>
  35. <div>返回</div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script setup>
  42. import { useStore } from "vuex";
  43. import common from "@/utils/common";
  44. import { onMounted, watch, computed, ref, nextTick } from "vue";
  45. import { useApp, getApp } from "@/app";
  46. import { useMusicPlayer } from "@/utils/sound";
  47. let timer = null
  48. const store = useStore();
  49. const musicPlayer = useMusicPlayer();
  50. const flying = computed(() => store.getters['flying'])
  51. const isSelect = ref(false)
  52. const isPlay = computed(() => {
  53. let status = store.getters["tour/isPlay"];
  54. let map = document.querySelector(".kankan-app div[xui_min_map]");
  55. if (map) {
  56. if (status) {
  57. map.classList.add("disabled");
  58. } else {
  59. map.classList.remove("disabled");
  60. }
  61. }
  62. return status;
  63. });
  64. const partId = computed(() => store.getters["tour/partId"]);
  65. const frameId = computed(() => store.getters["tour/frameId"]);
  66. const playTour = async () => {
  67. let player = await getApp().TourManager.player;
  68. if (isPlay.value) {
  69. store.commit("tour/setData", { isPlay: true });
  70. player.pause();
  71. } else {
  72. store.commit("tour/setData", { isPlay: true });
  73. player.play(partId.value);
  74. }
  75. };
  76. const progressNum = ref(0);
  77. const metadata = computed(() => store.getters["scene/metadata"]);
  78. const controls = computed(() => metadata.value.controls);
  79. const player = computed(() => store.getters["player"]);
  80. const tours = computed(() => store.getters["tour/tours"]);
  81. const menulist = ref([
  82. {
  83. icon: "customer_service",
  84. name: "客服",
  85. },
  86. {
  87. icon: "guided_shopping",
  88. name: "導購",
  89. },
  90. {
  91. icon: "shopping",
  92. name: "購物",
  93. },
  94. ]);
  95. const categorylist = ref([
  96. {
  97. id: "all",
  98. name: "全部",
  99. },
  100. {
  101. id: "all",
  102. name: "香化",
  103. },
  104. {
  105. id: "all",
  106. name: "香化",
  107. },
  108. {
  109. id: "all",
  110. name: "香化",
  111. },
  112. {
  113. id: "all",
  114. name: "香化",
  115. },
  116. {
  117. id: "all",
  118. name: "全部",
  119. },
  120. {
  121. id: "all",
  122. name: "全部",
  123. },
  124. ]);
  125. const brandlist = ref([]);
  126. const brandScroll = () => {
  127. nextTick(() => {
  128. let t = setTimeout(() => {
  129. clearTimeout(t);
  130. new Swiper("#sw-guide", {
  131. freeMode: true,
  132. slidesPerView: "auto",
  133. spaceBetween: 6,
  134. on: {
  135. touchMove(swiper, e) {
  136. e.stopPropagation();
  137. e.preventDefault();
  138. },
  139. },
  140. });
  141. }, 100);
  142. });
  143. };
  144. const changeFrame = async (type, id) => {
  145. if (flying.value || isSelect.value) {
  146. return
  147. }
  148. progressNum.value = 0
  149. // recorder.selectFrame(id)
  150. let player = await getApp().TourManager.player
  151. // player.selectFrame(id)
  152. isSelect.value = true
  153. if (type == 1) {
  154. player.selectPart(id)
  155. let f_id = 0
  156. if (tours.value[id].frameId) {
  157. f_id = tours.value[id].frameId
  158. }
  159. player.selectFrame(f_id).then(() => {
  160. isSelect.value = false
  161. })
  162. store.commit('tour/setData', {
  163. frameId: f_id,
  164. partId: id,
  165. })
  166. } else {
  167. player.selectFrame(id).then(() => {
  168. isSelect.value = false
  169. })
  170. store.commit('tour/setData', {
  171. frameId: id,
  172. })
  173. }
  174. }
  175. const onClickHandler = async () => {
  176. if (isPlay.value) {
  177. let player = await getApp().TourManager.player
  178. player.pause()
  179. musicPlayer.resume()
  180. }
  181. }
  182. const cancelTimer = () => {
  183. if (timer) {
  184. KanKan.Animate.transitions.cancel(timer)
  185. timer = null
  186. }
  187. }
  188. const hanlderTour = async () => {
  189. let player = await getApp().TourManager.player;
  190. player.on("play", (data) => {
  191. musicPlayer.pause(true);
  192. // if (tours.value.length > 1) {
  193. // let time = getPartTime(data.partId)
  194. // hanlderTourPartPlay(time)
  195. // }
  196. });
  197. player.on("pause", (tours) => {
  198. console.log("pause", player);
  199. musicPlayer.resume();
  200. progressNum.value = 0;
  201. cancelTimer();
  202. store.commit("tour/setData", { isPlay: false });
  203. });
  204. player.on("end", (tours) => {
  205. musicPlayer.resume();
  206. progressNum.value = 100;
  207. store.commit("tour/setData", { isPlay: false });
  208. cancelTimer();
  209. });
  210. let currPartId = null;
  211. let currProgress = 0;
  212. let currFrames = 0;
  213. player.on("progress", (data) => {
  214. if (tours.value.length == 1) {
  215. progressNum.value = data.progress * 100;
  216. } else {
  217. // let time = getPartTime(data.partId)
  218. // hanlderTourPartPlay(time)
  219. if (currPartId != data.partId) {
  220. currPartId = data.partId;
  221. currFrames = Math.max(tours.value[data.partId].list.length-1,1);
  222. currProgress = 0;
  223. } else {
  224. console.log(currFrames);
  225. currProgress += data.progress / currFrames;
  226. if (currProgress >= 100) {
  227. currProgress = 100;
  228. }
  229. console.log(currProgress);
  230. progressNum.value = currProgress;
  231. }
  232. }
  233. store.commit("tour/setData", { partId: data.partId, frameId: data.frameId, isPlay: true });
  234. });
  235. // nextTick(() => {
  236. // editorMain.value = document.querySelector('.ui-editor-main')
  237. // })
  238. };
  239. onMounted(() => {
  240. useApp().then(async (sdk) => {
  241. hanlderTour();
  242. brandScroll();
  243. });
  244. nextTick(() => {
  245. let player = document.querySelector('.player[name="main"]')
  246. player.addEventListener('touchstart', onClickHandler)
  247. })
  248. });
  249. </script>
  250. <style lang="scss" scoped>
  251. .root-panel {
  252. position: absolute;
  253. bottom: 46px;
  254. left: 0;
  255. right: 0;
  256. z-index: 99;
  257. width: 100%;
  258. background: rgba(0,0,0,0.3000);
  259. border: 1px solid rgba(255,255,255,0.2000);
  260. .guide-panel {
  261. width: 100%;
  262. position: relative;
  263. .g-con {
  264. background: rgba(0, 0, 0, 0.3);
  265. border-radius: 4px;
  266. border: 1px solid rgba(255, 255, 255, 0.2);
  267. width: 100%;
  268. height: 100%;
  269. margin: 0 auto;
  270. padding: 6px 10px;
  271. box-sizing: border-box;
  272. display: flex;
  273. align-items: center;
  274. flex-direction: column;
  275. .back {
  276. text-align: center;
  277. width: 100%;
  278. font-size: 0;
  279. margin-right: 10px;
  280. display: flex;
  281. justify-content: center;
  282. align-items: center;
  283. border-top: solid 1px rgba(255,255,255,0.2000);
  284. height: 48px;
  285. > div {
  286. font-size: 14px;
  287. margin-left: 10px;
  288. }
  289. }
  290. #sw-guide {
  291. width: 100%;
  292. flex: auto;
  293. overflow: hidden;
  294. padding-right: 2px;
  295. position: relative;
  296. padding-bottom: 6px;
  297. > ul {
  298. > li {
  299. border-radius: 2px;
  300. position: relative;
  301. font-size: 0;
  302. width: 154px;
  303. height: 82px;
  304. overflow: hidden;
  305. background-size: cover;
  306. > img {
  307. width: 100%;
  308. }
  309. > div {
  310. width: 100%;
  311. position: absolute;
  312. font-size: 12px;
  313. left: 50%;
  314. top: 50%;
  315. transform: translate(-50%, -50%);
  316. text-overflow: ellipsis;
  317. white-space: nowrap;
  318. overflow: hidden;
  319. text-align: center;
  320. padding: 0 4px;
  321. box-sizing: border-box;
  322. word-break: break-all;
  323. }
  324. &.active {
  325. &::before {
  326. position: absolute;
  327. top: 0;
  328. left: 0;
  329. width: 100%;
  330. height: 100%;
  331. content: "";
  332. display: inline-block;
  333. background: rgba(24, 24, 24, 0.5);
  334. }
  335. color: var(--editor-main-color);
  336. .bar {
  337. display: inline-block;
  338. width: 70%;
  339. height: 2px;
  340. background: rgba(0, 0, 0, 0.5);
  341. border-radius: 2px;
  342. position: absolute;
  343. z-index: 9;
  344. bottom: 10%;
  345. left: 50%;
  346. transform: translateX(-50%);
  347. &::after {
  348. content: "";
  349. width: var(--w);
  350. background: var(--editor-main-color);
  351. height: 100%;
  352. position: absolute;
  353. left: 0;
  354. top: 0;
  355. }
  356. }
  357. }
  358. }
  359. }
  360. }
  361. }
  362. }
  363. }
  364. </style>