OpeningMobile.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. <template>
  2. <!-- 视频 -->
  3. <div
  4. class="videocon"
  5. v-if="isVideoMode || isMixinMode"
  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"
  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. } from "vue";
  103. import { useStore } from "vuex";
  104. import { useApp } from "@/app";
  105. import { useI18n, getLocale } from "@/i18n";
  106. const { t } = useI18n({ useScope: "global" });
  107. const zIndex = ref(1);
  108. const useZIndex = () => {
  109. zIndex.value++;
  110. return unref(zIndex);
  111. };
  112. const props = defineProps({
  113. coverData: {
  114. type: [Boolean, Object],
  115. default: () => {
  116. return {};
  117. },
  118. },
  119. });
  120. const store = useStore();
  121. const openvideo$ = ref(null);
  122. const videoNeedPlay = ref(true);
  123. const isToApp = ref(false);
  124. const isMixinMode = computed(
  125. () => props.coverData.coverSelect.toLowerCase().indexOf("and") > -1
  126. );
  127. const isImageMode = computed(
  128. () => props.coverData.coverSelect.toLowerCase() === "img"
  129. );
  130. const isVideoMode = computed(
  131. () => props.coverData.coverSelect.toLowerCase() === "video"
  132. );
  133. // 字段意思有误
  134. const showImageFirst = computed(
  135. () => props.coverData.coverImageOrder === "before"
  136. );
  137. const show = ref(true);
  138. const countdownImg = ref(3);
  139. const countdownVideo = ref(3);
  140. const imgTimer = ref(null);
  141. const videotimer = ref(null);
  142. const isImageCountDone = ref(false);
  143. const isVideoCountDone = ref(false);
  144. const isImageAutoNext = computed(() => props.coverData.coverImageInWay === 1);
  145. const isVideoAutoNext = computed(() => props.coverData.coverVideoInWay === 1);
  146. const imgShow = ref(false);
  147. const videoShow = ref(false);
  148. const imgIndex = ref(1);
  149. const videoIndex = ref(1);
  150. const handleVideoPlay = () => {
  151. // window.alert("play");
  152. let video = unref(openvideo$);
  153. video && video.play();
  154. };
  155. //手动跳转
  156. /**
  157. * 跳转逻辑PM设定非奇怪,要注意
  158. * @TODO 图片模式 button 3秒倒只作装饰显示,不参与逻辑
  159. *
  160. * */
  161. const jumpImage = (from = 0) => {
  162. // 0 来自元素click, 1.来自跳转按钮
  163. if (unref(isMixinMode)) {
  164. if (unref(showImageFirst)) {
  165. imgShow.value = false;
  166. videoShow.value = true;
  167. startVideoCount();
  168. } else {
  169. // 强制跳转
  170. // 非自动模式强制跳转
  171. if (from === 0 && !unref(isImageAutoNext)) {
  172. toApp();
  173. }
  174. if (from === 1) {
  175. toApp();
  176. }
  177. if (unref(isImageAutoNext) && unref(isImageCountDone)) {
  178. toApp();
  179. }
  180. }
  181. } else {
  182. // 非自动模式强制跳转
  183. if (from === 0 && !unref(isImageAutoNext)) {
  184. toApp();
  185. }
  186. // 非自动模式强制跳转
  187. if (from === 1) {
  188. toApp();
  189. }
  190. if (unref(isImageAutoNext) && unref(isImageCountDone)) {
  191. toApp();
  192. }
  193. }
  194. };
  195. //手动跳转
  196. const jumpVideo = () => {
  197. if (unref(isMixinMode)) {
  198. if (!unref(showImageFirst)) {
  199. imgShow.value = true;
  200. videoShow.value = false;
  201. startImageCount();
  202. } else {
  203. toApp();
  204. }
  205. } else {
  206. if (unref(isVideoCountDone)) {
  207. toApp();
  208. }
  209. }
  210. };
  211. const startImageCount = () => {
  212. imgTimer.value = setInterval(() => {
  213. countdownImg.value--;
  214. if (countdownImg.value <= 0) {
  215. clearInterval(imgTimer.value);
  216. countdownImg.value = 0
  217. isImageCountDone.value = true;
  218. imgTimer.value = null;
  219. return;
  220. }
  221. }, 1000);
  222. };
  223. const startVideoCount = () => {
  224. const nextIndex = useZIndex();
  225. videoIndex.value = nextIndex;
  226. videotimer.value = setInterval(() => {
  227. countdownVideo.value--;
  228. if (countdownVideo.value <= 0) {
  229. clearInterval(videotimer.value);
  230. countdownVideo.value = 0
  231. isVideoCountDone.value = true;
  232. videotimer.value = null;
  233. return;
  234. }
  235. }, 1000);
  236. };
  237. //开始全监听
  238. watch(
  239. [isMixinMode, isImageMode, isVideoMode, showImageFirst],
  240. ([val1, val2, val3, val4]) => {
  241. //混合模式
  242. if (unref(val1)) {
  243. //图片优先
  244. if (unref(val4)) {
  245. imgShow.value = true;
  246. startImageCount();
  247. } else {
  248. videoShow.value = true;
  249. startVideoCount();
  250. }
  251. } else {
  252. //非混合模式
  253. if (unref(val2)) {
  254. imgShow.value = true;
  255. startImageCount();
  256. }
  257. if (unref(val3)) {
  258. videoShow.value = true;
  259. startVideoCount();
  260. }
  261. }
  262. },
  263. {
  264. deep: true,
  265. immediate: true,
  266. }
  267. );
  268. //倒数完全监听
  269. watch(
  270. [isMixinMode, isImageCountDone, isVideoCountDone, showImageFirst],
  271. ([val1, val2, val3, val4]) => {
  272. //混合模式
  273. if (unref(val1)) {
  274. //图片优先
  275. if (unref(val4)) {
  276. //图片倒数完
  277. if (unref(val2)) {
  278. if (unref(isImageAutoNext)) {
  279. imgShow.value = false;
  280. videoShow.value = true;
  281. startVideoCount();
  282. }
  283. }
  284. } else {
  285. //图片非优先
  286. if (unref(val2)) {
  287. if (unref(isImageAutoNext)) {
  288. toApp();
  289. }
  290. }
  291. }
  292. } else {
  293. //非混合模式
  294. if (unref(val2)) {
  295. if (unref(isImageAutoNext)) {
  296. toApp();
  297. }
  298. }
  299. }
  300. },
  301. {
  302. deep: true,
  303. }
  304. );
  305. //跳转到app
  306. const toApp = () => {
  307. if (!unref(isToApp)) {
  308. console.log("跳转到app", unref(isToApp));
  309. imgShow.value = false;
  310. videoShow.value = false;
  311. isToApp.value = true;
  312. useApp().then((app) => {
  313. setTimeout(() => {
  314. app.render();
  315. }, 1000);
  316. });
  317. }
  318. };
  319. onMounted(() => {
  320. console.log("coverData", unref(props.coverData));
  321. if (openvideo$.value) {
  322. openvideo$.value.addEventListener("ended", () => {
  323. if (isVideoAutoNext.value) {
  324. //混合模式
  325. if (unref(isMixinMode)) {
  326. //视频优先 直达图片
  327. if (!unref(showImageFirst)) {
  328. videoShow.value = false;
  329. imgShow.value = true;
  330. startImageCount();
  331. } else {
  332. toApp();
  333. }
  334. } else {
  335. toApp();
  336. }
  337. }
  338. });
  339. openvideo$.value.addEventListener("playing", () => {
  340. if (videoNeedPlay.value) {
  341. videoNeedPlay.value = false;
  342. }
  343. });
  344. openvideo$.value.addEventListener("pause", () => {
  345. if (!videoNeedPlay.value) {
  346. videoNeedPlay.value = true;
  347. }
  348. });
  349. // document.addEventListener(
  350. // "WeixinJSBridgeReady",
  351. // () => {
  352. // openvideo$.value.play();
  353. // },
  354. // false
  355. // );
  356. }
  357. }),
  358. useApp().then((app) => {
  359. app.Scene.on("ready", () => {
  360. if (show.value) {
  361. show.value = false;
  362. }
  363. });
  364. });
  365. </script>
  366. <style lang="scss" scoped>
  367. .imgcon,
  368. .videocon {
  369. position: fixed;
  370. left: 0;
  371. right: 0;
  372. top: 0;
  373. bottom: 0;
  374. width: 100%;
  375. height: 100%;
  376. z-index: 1;
  377. }
  378. .video-background {
  379. background-repeat: repeat;
  380. position: absolute;
  381. left: 0;
  382. right: 0;
  383. top: 0;
  384. bottom: 0;
  385. width: 100%;
  386. height: 100%;
  387. z-index: 1;
  388. }
  389. .imgcon {
  390. // z-index: 10;
  391. .image-front,
  392. .img-background {
  393. background-position: center;
  394. width: 100%;
  395. height: 100%;
  396. position: absolute;
  397. top: 0;
  398. z-index: 1;
  399. bottom: 0;
  400. left: 0;
  401. }
  402. .img-background {
  403. background-repeat: repeat;
  404. }
  405. .image-front {
  406. z-index: 10;
  407. }
  408. }
  409. .videocon {
  410. text-align: center;
  411. > video {
  412. max-width: inherit;
  413. height: auto;
  414. min-height: 100%;
  415. top: 50%;
  416. left: 50%;
  417. z-index: 99;
  418. display: inline-block;
  419. transform: translate(-50%, -50%);
  420. position: absolute;
  421. }
  422. .contain {
  423. height: 100%;
  424. }
  425. .cover {
  426. height: 100%;
  427. width: 100%;
  428. object-fit: cover;
  429. }
  430. .videoPlay {
  431. position: absolute;
  432. top: 50%;
  433. transform: translate(-50%, -50%);
  434. left: 50%;
  435. width: 80px;
  436. height: 80px;
  437. z-index: 99999;
  438. }
  439. }
  440. .videoPlayFirst {
  441. z-index: 99;
  442. }
  443. .jump {
  444. position: absolute;
  445. right: 15px;
  446. top: 20px;
  447. background: rgba(255, 255, 255, 0.5);
  448. text-align: center;
  449. line-height: 28px;
  450. font-size: 16px;
  451. z-index: 999;
  452. color: #333333;
  453. border-radius: 1px;
  454. padding: 4px 12px;
  455. cursor: pointer;
  456. }
  457. @keyframes loading {
  458. 100% {
  459. left: -900px;
  460. }
  461. }
  462. </style>