OpeningMobile.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  1. <template>
  2. <!-- 视频 -->
  3. <div
  4. class="videocon"
  5. v-if="(isVideoMode || isMixinMode) && !isToApp"
  6. v-show="videoShow"
  7. :style="{
  8. zIndex: videoIndex,
  9. }"
  10. >
  11. <div
  12. class="video-background"
  13. v-if="coverData.videoMoLoc !== 'full'"
  14. :style="{
  15. backgroundImage:
  16. coverData.coverVideoBac === 'imgTile'
  17. ? `url(${coverData.videoBacImg})`
  18. : 'none',
  19. backgroundColor:
  20. coverData.coverVideoBac === 'imgTile'
  21. ? `rgba(0,0,0,1)`
  22. : `${coverData.videoColorSelec}`,
  23. }"
  24. ></div>
  25. <video
  26. v-if="coverData.videoMo"
  27. x5-playsinline="true"
  28. playsinline="true"
  29. webkit-playsinline="true"
  30. x5-video-orientation="portraint"
  31. x5-video-player-fullscreen="true"
  32. class="video"
  33. ref="openvideo$"
  34. preload
  35. autoplay
  36. :poster="coverData.videoMoIcon"
  37. :class="coverData.videoMoLoc == 'center' ? 'contain' : 'cover'"
  38. :src="coverData.videoMo"
  39. :controls="Boolean(coverData.coverVideoControl)"
  40. muted
  41. ></video>
  42. <img
  43. v-show="videoNeedPlay"
  44. @click.stop="handleVideoPlay"
  45. class="videoPlay"
  46. :src="require('@/assets/images/default/bofang.png')"
  47. alt=""
  48. />
  49. <div @click.stop="jumpVideo" class="jump" v-if="countdownVideo == 0">
  50. {{ $t("common.jump") }}
  51. </div>
  52. </div>
  53. <!-- 图片 -->
  54. <div
  55. class="imgcon"
  56. v-if="(isImageMode || isMixinMode) && !isToApp"
  57. v-show="imgShow"
  58. :style="{
  59. zIndex: imgIndex,
  60. }"
  61. >
  62. <div
  63. @click="jumpImage(0)"
  64. class="image-front"
  65. :style="{
  66. backgroundImage: `url(${coverData.coverMo})`,
  67. backgroundSize: coverData.coverMoLoc == 'center' ? 'contain' : 'cover',
  68. }"
  69. ></div>
  70. <div
  71. class="img-background"
  72. v-if="coverData.coverMoLoc !== 'full'"
  73. :style="{
  74. backgroundImage:
  75. coverData.coverImgBac == 'imgTile'
  76. ? `url(${coverData.coverBac})`
  77. : `none`,
  78. backgroundColor:
  79. coverData.coverImgBac == 'imgTile'
  80. ? `none`
  81. : `${coverData.imgColorSelec}`,
  82. }"
  83. ></div>
  84. <div @click.stop="jumpImage(1)" class="jump">
  85. {{
  86. countdownImg > 0
  87. ? $t("common.jumpTips", { second: countdownImg })
  88. : $t("common.jump")
  89. }}
  90. </div>
  91. </div>
  92. </template>
  93. <script setup>
  94. import {
  95. ref,
  96. watch,
  97. computed,
  98. onMounted,
  99. defineProps,
  100. unref,
  101. watchEffect,
  102. onUnmounted,
  103. } from "vue";
  104. import { useStore } from "vuex";
  105. import { useApp } from "@/app";
  106. import { useI18n, getLocale } from "@/i18n";
  107. const { t } = useI18n({ useScope: "global" });
  108. const zIndex = ref(1000);
  109. const useZIndex = () => {
  110. zIndex.value++;
  111. return unref(zIndex);
  112. };
  113. const props = defineProps({
  114. coverData: {
  115. type: [Boolean, Object],
  116. default: () => {
  117. return {};
  118. },
  119. },
  120. });
  121. const store = useStore();
  122. const openvideo$ = ref(null);
  123. const videoNeedPlay = ref(true);
  124. const isToApp = ref(false);
  125. const isMixinMode = computed(
  126. () => props.coverData.coverSelect.toLowerCase().indexOf("and") > -1
  127. );
  128. const isImageMode = computed(
  129. () => props.coverData.coverSelect.toLowerCase() === "img"
  130. );
  131. const isVideoMode = computed(
  132. () => props.coverData.coverSelect.toLowerCase() === "video"
  133. );
  134. // 字段意思有误
  135. const showImageFirst = computed(
  136. () => props.coverData.coverImageOrder === "before"
  137. );
  138. const show = ref(true);
  139. const countdownImg = ref(3);
  140. const countdownVideo = ref(3);
  141. const imgTimer = ref(null);
  142. const videotimer = ref(null);
  143. const isImageCountDone = ref(false);
  144. const isVideoCountDone = ref(false);
  145. const isImageAutoNext = computed(() => props.coverData.coverImageInWay === 1);
  146. const isVideoAutoNext = computed(() => props.coverData.coverVideoInWay === 1);
  147. const imgShow = ref(false);
  148. const videoShow = ref(false);
  149. const imgIndex = ref(1);
  150. const videoIndex = ref(1);
  151. const handleVideoPlay = () => {
  152. // window.alert("play");
  153. let video = unref(openvideo$);
  154. video && video.play();
  155. };
  156. //手动跳转
  157. /**
  158. * 跳转逻辑PM设定非奇怪,要注意
  159. * @TODO 图片模式 button 3秒倒只作装饰显示,不参与逻辑
  160. *
  161. * */
  162. const jumpImage = (from = 0) => {
  163. // 0 来自元素click, 1.来自跳转按钮
  164. if (unref(isMixinMode)) {
  165. if (unref(showImageFirst)) {
  166. imgShow.value = false;
  167. videoShow.value = true;
  168. startVideoCount();
  169. } else {
  170. // 强制跳转
  171. // 非自动模式强制跳转
  172. if (from === 0 && !unref(isImageAutoNext)) {
  173. toApp();
  174. }
  175. if (from === 1) {
  176. toApp();
  177. }
  178. if (unref(isImageAutoNext) && unref(isImageCountDone)) {
  179. toApp();
  180. }
  181. }
  182. } else {
  183. // 非自动模式强制跳转
  184. if (from === 0 && !unref(isImageAutoNext)) {
  185. toApp();
  186. }
  187. // 非自动模式强制跳转
  188. if (from === 1) {
  189. toApp();
  190. }
  191. if (unref(isImageAutoNext) && unref(isImageCountDone)) {
  192. toApp();
  193. }
  194. }
  195. };
  196. //手动跳转
  197. const jumpVideo = () => {
  198. if (unref(isMixinMode)) {
  199. if (!unref(showImageFirst)) {
  200. imgShow.value = true;
  201. videoShow.value = false;
  202. startImageCount();
  203. } else {
  204. toApp();
  205. }
  206. } else {
  207. if (unref(isVideoCountDone)) {
  208. toApp();
  209. }
  210. }
  211. };
  212. const startImageCount = () => {
  213. imgTimer.value = setInterval(() => {
  214. countdownImg.value--;
  215. if (countdownImg.value <= 0) {
  216. clearInterval(imgTimer.value);
  217. countdownImg.value = 0;
  218. isImageCountDone.value = true;
  219. imgTimer.value = null;
  220. return;
  221. }
  222. }, 1000);
  223. };
  224. const startVideoCount = () => {
  225. const nextIndex = useZIndex();
  226. videoIndex.value = nextIndex;
  227. videotimer.value = setInterval(() => {
  228. countdownVideo.value--;
  229. if (countdownVideo.value <= 0) {
  230. clearInterval(videotimer.value);
  231. countdownVideo.value = 0;
  232. isVideoCountDone.value = true;
  233. videotimer.value = null;
  234. return;
  235. }
  236. }, 1000);
  237. };
  238. //开始全监听
  239. watch(
  240. [isMixinMode, isImageMode, isVideoMode, showImageFirst],
  241. ([val1, val2, val3, val4]) => {
  242. //混合模式
  243. if (unref(val1)) {
  244. //图片优先
  245. if (unref(val4)) {
  246. imgShow.value = true;
  247. startImageCount();
  248. } else {
  249. videoShow.value = true;
  250. startVideoCount();
  251. }
  252. } else {
  253. //非混合模式
  254. if (unref(val2)) {
  255. imgShow.value = true;
  256. startImageCount();
  257. }
  258. if (unref(val3)) {
  259. videoShow.value = true;
  260. startVideoCount();
  261. }
  262. }
  263. },
  264. {
  265. deep: true,
  266. immediate: true,
  267. }
  268. );
  269. //倒数完全监听
  270. watch(
  271. [isMixinMode, isImageCountDone, isVideoCountDone, showImageFirst],
  272. ([val1, val2, val3, val4]) => {
  273. //混合模式
  274. if (unref(val1)) {
  275. //图片优先
  276. if (unref(val4)) {
  277. //图片倒数完
  278. if (unref(val2)) {
  279. if (unref(isImageAutoNext)) {
  280. imgShow.value = false;
  281. videoShow.value = true;
  282. startVideoCount();
  283. }
  284. }
  285. } else {
  286. //图片非优先
  287. if (unref(val2)) {
  288. if (unref(isImageAutoNext)) {
  289. toApp();
  290. }
  291. }
  292. }
  293. } else {
  294. //非混合模式
  295. if (unref(val2)) {
  296. if (unref(isImageAutoNext)) {
  297. toApp();
  298. }
  299. }
  300. }
  301. },
  302. {
  303. deep: true,
  304. }
  305. );
  306. //跳转到app
  307. const toApp = () => {
  308. if (!unref(isToApp)) {
  309. console.log("跳转到app", unref(isToApp));
  310. imgShow.value = false;
  311. videoShow.value = false;
  312. isToApp.value = true;
  313. store.commit("scene/setDoneforCover", true);
  314. useApp().then((app) => {
  315. setTimeout(() => {
  316. app.render();
  317. }, 1000);
  318. });
  319. }
  320. };
  321. const handleVideoEnded = () => {
  322. if (isVideoAutoNext.value) {
  323. //混合模式
  324. if (unref(isMixinMode)) {
  325. //视频优先 直达图片
  326. if (!unref(showImageFirst)) {
  327. videoShow.value = false;
  328. imgShow.value = true;
  329. startImageCount();
  330. } else {
  331. toApp();
  332. }
  333. } else {
  334. toApp();
  335. }
  336. }
  337. };
  338. onUnmounted(() => {
  339. if (openvideo$.value) {
  340. openvideo$.value.addEventListener("ended", handleVideoEnded, false);
  341. }
  342. });
  343. onMounted(() => {
  344. console.log("coverData", unref(props.coverData));
  345. if (openvideo$.value) {
  346. openvideo$.value.addEventListener("ended", handleVideoEnded, false);
  347. openvideo$.value.addEventListener("playing", () => {
  348. if (videoNeedPlay.value) {
  349. videoNeedPlay.value = false;
  350. }
  351. });
  352. openvideo$.value.addEventListener("pause", () => {
  353. if (!videoNeedPlay.value) {
  354. videoNeedPlay.value = true;
  355. }
  356. });
  357. // document.addEventListener(
  358. // "WeixinJSBridgeReady",
  359. // () => {
  360. // openvideo$.value.play();
  361. // },
  362. // false
  363. // );
  364. }
  365. }),
  366. useApp().then((app) => {
  367. app.Scene.on("ready", () => {
  368. if (show.value) {
  369. show.value = false;
  370. }
  371. });
  372. });
  373. </script>
  374. <style lang="scss" scoped>
  375. .imgcon,
  376. .videocon {
  377. position: fixed;
  378. left: 0;
  379. right: 0;
  380. top: 0;
  381. bottom: 0;
  382. width: 100%;
  383. height: 100%;
  384. z-index: 1;
  385. }
  386. .video-background {
  387. background-repeat: repeat;
  388. position: absolute;
  389. left: 0;
  390. right: 0;
  391. top: 0;
  392. bottom: 0;
  393. width: 100%;
  394. height: 100%;
  395. z-index: 1;
  396. }
  397. .imgcon {
  398. // z-index: 10;
  399. .image-front,
  400. .img-background {
  401. background-position: center;
  402. width: 100%;
  403. height: 100%;
  404. position: absolute;
  405. top: 0;
  406. z-index: 1;
  407. bottom: 0;
  408. left: 0;
  409. }
  410. .img-background {
  411. background-repeat: repeat;
  412. }
  413. .image-front {
  414. z-index: 10;
  415. }
  416. }
  417. .videocon {
  418. text-align: center;
  419. > video {
  420. max-width: inherit;
  421. height: auto;
  422. min-height: 100%;
  423. top: 50%;
  424. left: 50%;
  425. z-index: 99;
  426. display: inline-block;
  427. transform: translate(-50%, -50%);
  428. position: absolute;
  429. }
  430. .contain {
  431. width: 100%;
  432. height: auto;
  433. object-fit: scale-down;
  434. }
  435. .cover {
  436. height: 100%;
  437. width: 100%;
  438. object-fit: cover;
  439. }
  440. .videoPlay {
  441. position: absolute;
  442. top: 50%;
  443. transform: translate(-50%, -50%);
  444. left: 50%;
  445. width: 80px;
  446. height: 80px;
  447. z-index: 99999;
  448. }
  449. }
  450. .videoPlayFirst {
  451. z-index: 99;
  452. }
  453. .jump {
  454. position: absolute;
  455. right: 15px;
  456. top: 20px;
  457. background: rgba(0, 0, 0, 0.6);
  458. border-radius: 17px;
  459. text-align: center;
  460. line-height: 28px;
  461. font-size: 16px;
  462. z-index: 999;
  463. color: #fff;
  464. padding: 4px 12px;
  465. cursor: pointer;
  466. }
  467. @keyframes loading {
  468. 100% {
  469. left: -900px;
  470. }
  471. }
  472. </style>