OpeningMobile.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  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(1);
  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. useApp().then((app) => {
  314. setTimeout(() => {
  315. app.render();
  316. }, 1000);
  317. });
  318. }
  319. };
  320. const handleVideoEnded = () => {
  321. if (isVideoAutoNext.value) {
  322. //混合模式
  323. if (unref(isMixinMode)) {
  324. //视频优先 直达图片
  325. if (!unref(showImageFirst)) {
  326. videoShow.value = false;
  327. imgShow.value = true;
  328. startImageCount();
  329. } else {
  330. toApp();
  331. }
  332. } else {
  333. toApp();
  334. }
  335. }
  336. };
  337. onUnmounted(() => {
  338. if (openvideo$.value) {
  339. openvideo$.value.addEventListener("ended", handleVideoEnded, false);
  340. }
  341. });
  342. onMounted(() => {
  343. console.log("coverData", unref(props.coverData));
  344. if (openvideo$.value) {
  345. openvideo$.value.addEventListener("ended", handleVideoEnded, false);
  346. openvideo$.value.addEventListener("playing", () => {
  347. if (videoNeedPlay.value) {
  348. videoNeedPlay.value = false;
  349. }
  350. });
  351. openvideo$.value.addEventListener("pause", () => {
  352. if (!videoNeedPlay.value) {
  353. videoNeedPlay.value = true;
  354. }
  355. });
  356. // document.addEventListener(
  357. // "WeixinJSBridgeReady",
  358. // () => {
  359. // openvideo$.value.play();
  360. // },
  361. // false
  362. // );
  363. }
  364. }),
  365. useApp().then((app) => {
  366. app.Scene.on("ready", () => {
  367. if (show.value) {
  368. show.value = false;
  369. }
  370. });
  371. });
  372. </script>
  373. <style lang="scss" scoped>
  374. .imgcon,
  375. .videocon {
  376. position: fixed;
  377. left: 0;
  378. right: 0;
  379. top: 0;
  380. bottom: 0;
  381. width: 100%;
  382. height: 100%;
  383. z-index: 1;
  384. }
  385. .video-background {
  386. background-repeat: repeat;
  387. position: absolute;
  388. left: 0;
  389. right: 0;
  390. top: 0;
  391. bottom: 0;
  392. width: 100%;
  393. height: 100%;
  394. z-index: 1;
  395. }
  396. .imgcon {
  397. // z-index: 10;
  398. .image-front,
  399. .img-background {
  400. background-position: center;
  401. width: 100%;
  402. height: 100%;
  403. position: absolute;
  404. top: 0;
  405. z-index: 1;
  406. bottom: 0;
  407. left: 0;
  408. }
  409. .img-background {
  410. background-repeat: repeat;
  411. }
  412. .image-front {
  413. z-index: 10;
  414. }
  415. }
  416. .videocon {
  417. text-align: center;
  418. > video {
  419. max-width: inherit;
  420. height: auto;
  421. min-height: 100%;
  422. top: 50%;
  423. left: 50%;
  424. z-index: 99;
  425. display: inline-block;
  426. transform: translate(-50%, -50%);
  427. position: absolute;
  428. }
  429. .contain {
  430. height: 100%;
  431. }
  432. .cover {
  433. height: 100%;
  434. width: 100%;
  435. object-fit: cover;
  436. }
  437. .videoPlay {
  438. position: absolute;
  439. top: 50%;
  440. transform: translate(-50%, -50%);
  441. left: 50%;
  442. width: 80px;
  443. height: 80px;
  444. z-index: 99999;
  445. }
  446. }
  447. .videoPlayFirst {
  448. z-index: 99;
  449. }
  450. .jump {
  451. position: absolute;
  452. right: 15px;
  453. top: 20px;
  454. background: rgba(0, 0, 0, 0.6);
  455. border-radius: 17px;
  456. text-align: center;
  457. line-height: 28px;
  458. font-size: 16px;
  459. z-index: 999;
  460. color: #fff;
  461. padding: 4px 12px;
  462. cursor: pointer;
  463. }
  464. @keyframes loading {
  465. 100% {
  466. left: -900px;
  467. }
  468. }
  469. </style>