OpeningMobile.vue 9.8 KB

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